Skip to content

Commit

Permalink
添加主题包本地url开发模式
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYFDroid committed Feb 25, 2022
1 parent 0a240aa commit b1ece1c
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 40 deletions.
3 changes: 3 additions & 0 deletions EPUBium Desktop/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<setting name="respack" serializeAs="String">
<value />
</setting>
<setting name="devLastUrl" serializeAs="String">
<value>http://localhost:8080</value>
</setting>
</EPUBium_Desktop.Properties.Settings>
</userSettings>
<entityFramework>
Expand Down
10 changes: 10 additions & 0 deletions EPUBium Desktop/EPUBium Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,25 @@
<Compile Include="FrmChangeResource.Designer.cs">
<DependentUpon>FrmChangeResource.cs</DependentUpon>
</Compile>
<Compile Include="InputDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="InputDialog.designer.cs">
<DependentUpon>InputDialog.cs</DependentUpon>
</Compile>
<Compile Include="FromJava.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmChangeResource.resx">
<DependentUpon>FrmChangeResource.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="InputDialog.resx">
<DependentUpon>InputDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
108 changes: 70 additions & 38 deletions EPUBium Desktop/FrmChangeResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 70 additions & 1 deletion EPUBium Desktop/FrmChangeResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;

namespace EPUBium_Desktop
{
Expand Down Expand Up @@ -227,14 +228,82 @@ private void btnUse_Click(object sender, EventArgs e)
}
}

private void btnRestart_Click(object sender, EventArgs e)
private void btnThemeDev_Click(object sender, EventArgs e)
{
mnuDevMode.Show(btnThemeDev, 0, btnThemeDev.Height);
}

private void mnuThemeDevUseDir_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "开发模式可以指定本地的一个目录作为资源包的根目录,应用后刷新生效,重启或点击恢复默认按钮可还原。");
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
Program.HtDocs.Overrides?.Dispose();
Program.HtDocs.Overrides = new LocalDirRoot(Path.GetDirectoryName(openFileDialog1.FileName));
MessageBox.Show(this, "主题包已应用。在界面上右键刷新生效");
}
}

private void mnuThemeDevUseUrl_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "开发模式可以指定一个URL作为资源包的根目录,应用后刷新生效,重启或点击恢复默认按钮可还原。");
string url = InputDialog.Input(this, "请输入url根目录",Properties.Settings.Default.devLastUrl ?? "");
if (url != null)
{
if (url.StartsWith("http") && url.Contains("://"))
{
Program.HtDocs.Overrides?.Dispose();
Program.HtDocs.Overrides = new UrlPackFile(url);
Properties.Settings.Default.devLastUrl = url;
Properties.Settings.Default.Save();
MessageBox.Show(this, "主题包已应用。在界面上右键刷新生效");
}
else
{
MessageBox.Show("无效的URL路径");
}
}
}
}

class UrlPackFile : IPakFile
{

private string urlRoot;

public UrlPackFile(string urlRoot)
{
if (urlRoot.EndsWith("/"))
{
urlRoot = urlRoot.Substring(0, urlRoot.Length - 1);
}
this.urlRoot = urlRoot;
}

public IPakFile Overrides { get; set; }

public void Dispose()
{
try
{
webClient.Dispose();
}catch { }
}
private WebClient webClient = new WebClient();
public Stream OpenRead(string path)
{
if (path.StartsWith("/"))
{
path = path.Substring(1);
}
string url = urlRoot + "/" + path;
try
{
return webClient.OpenRead(url);
}catch
{
return null;
}
}
}
}
5 changes: 4 additions & 1 deletion EPUBium Desktop/FrmChangeResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="dataGridViewCellStyle16.NullValue" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<data name="dataGridViewCellStyle4.NullValue" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Qk32AgAAAAAAADYAAAAoAAAADgAAABAAAAABABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEgoTGw8bGw8bGw8bGw8bGw8bGw8bG
Expand All @@ -162,4 +162,7 @@
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="mnuDevMode.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>281, 17</value>
</metadata>
</root>
Loading

0 comments on commit b1ece1c

Please sign in to comment.