Skip to content

Commit

Permalink
打开多个窗口和打开外部文件
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYFDroid committed Aug 6, 2022
1 parent 9b583cb commit d37199a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 15 deletions.
15 changes: 9 additions & 6 deletions EPUBium Desktop/EPUBium Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.1108.44, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1108.44\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.1264.42, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.1108.44, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1108.44\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.1264.42, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.1264.42, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="System">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.dll</HintPath>
Expand Down Expand Up @@ -188,12 +191,12 @@
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.114.0\build\net451\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.114.0\build\net451\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1108.44\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1108.44\build\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1264.42\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1264.42\build\Microsoft.Web.WebView2.targets'))" />
</Target>
<Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.114.0\build\net451\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.114.0\build\net451\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
<PropertyGroup>
<PreBuildEvent>cd "$(ProjectDir)htdocs"
"$(ProjectDir)zip.exe" -r -0 ..\htdocs.pak .</PreBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1108.44\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1108.44\build\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1264.42\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1264.42\build\Microsoft.Web.WebView2.targets')" />
</Project>
32 changes: 31 additions & 1 deletion EPUBium Desktop/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ public Form1()

}

private string startUrl = null;

public Form1(string startUrl) : this()
{
this.startUrl = startUrl;
}

private void WebView2_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
if (e.IsSuccess)
{
webView = webViewControl.CoreWebView2;
initWebView2();
webViewControl.Source = new Uri("http://epub.zyf-internal.com");
webViewControl.Source = new Uri(startUrl ?? "http://epub.zyf-internal.com");
webViewControl.NavigationCompleted += WebViewControl_NavigationCompleted;
}
else
Expand Down Expand Up @@ -137,6 +144,29 @@ void initWebView2()
resourceHandler = new ResourceHandler(webView.Environment);
webView.WebResourceRequested += WebView_WebResourceRequested;
webView.FrameNavigationStarting += WebView_FrameNavigationStarting;
webView.ContextMenuRequested += WebView_ContextMenuRequested;
webView.NewWindowRequested += WebView_NewWindowRequested;
}

private void WebView_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{
if (e.Uri.StartsWith(urlbase))
{
e.Handled = true;
new Form1(e.Uri).Show();
}
}

private void WebView_ContextMenuRequested(object sender, CoreWebView2ContextMenuRequestedEventArgs e)
{
CoreWebView2ContextMenuItem changeSkin = webView.Environment.CreateContextMenuItem("更换主题包", null, CoreWebView2ContextMenuItemKind.Command);
changeSkin.CustomItemSelected += onChangeSkinClicked;
e.MenuItems.Add(changeSkin);
}

private void onChangeSkinClicked(object sender, object e)
{
new FrmChangeResource().ShowDialog(this);
}

private void WebView_FrameNavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
Expand Down
74 changes: 69 additions & 5 deletions EPUBium Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ static int Main(string[] args)

try
{
string bookToOpen = null;
if(args.Length != 0)
{
try
{
bookToOpen = Path.GetFullPath(args[0]);
}catch(Exception ex) { }
}
Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);
if(bookToOpen != null)
{
if (File.Exists(bookToOpen))
{

}
else
{
MessageBox.Show("系统找不到指定的文件:"+bookToOpen,Application.ProductName);
return 114;
}
}

ensureDirectoryExists(
"app",
"app\\data",
Expand All @@ -44,9 +66,19 @@ static int Main(string[] args)
loadResPack();
DBUtils = new DBUtils();
ApiModel = new ApiModel();
ApiModel.OpenFromFilePath = bookToOpen;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
if(bookToOpen != null)
{

Application.Run(new Form1("http://epub.zyf-internal.com/read/SHELL/read.html"));
}
else
{

Application.Run(new Form1());
}

}
catch (Exception ex)
Expand Down Expand Up @@ -206,6 +238,9 @@ public class ApiModel
{
private MyPakFile openingBook = null;

public string OpenFromFilePath = null;


public ApiResponse callApi(string pathWithUrl)
{
int ptr = pathWithUrl.IndexOf("?");
Expand Down Expand Up @@ -418,19 +453,34 @@ public ApiResponse handlePathReadRequest(string bookuuid,string apipath, Diction
return new ApiResponse(ApiResponseType.ErrorNotFound, "404 Not Found");
}
Context appContext = null;

const string OpenFromFileUUID = "shell";

private ApiResponse handlePathReadApiRequest(string bookuuid, string api, Dictionary<string, string> param)
{
if (api.StartsWith("bmload/"))
{
if(bookuuid.ToLower() == OpenFromFileUUID)
{
return newFixedLengthResponse(JsonConvert.SerializeObject(new BookMark(-1, bookuuid, 0, "", "无存档", -1)));
}
int requestId = int.Parse(api.Replace("bmload/",""));
return newFixedLengthResponse(JsonConvert.SerializeObject(Program.DBUtils.queryBookmarks(appContext, bookuuid)[requestId]));
}
if (api==("bmloadall"))
{
if (bookuuid.ToLower() == OpenFromFileUUID)
{
return newFixedLengthResponse("[]");
}
return newFixedLengthResponse(JsonConvert.SerializeObject(Program.DBUtils.queryBookmarks(appContext, bookuuid)));
}
if (api.StartsWith("bmsave/"))
{
if (bookuuid.ToLower() == OpenFromFileUUID)
{
return newFixedLengthResponse("OK");
}
int requestId = int.Parse(api.Replace("bmsave/", ""));

String name = param["name"];
Expand All @@ -440,6 +490,10 @@ private ApiResponse handlePathReadApiRequest(string bookuuid, string api, Dictio
}
if (api==("bookname"))
{
if (bookuuid.ToLower() == OpenFromFileUUID)
{
return newFixedLengthResponse((OpenFromFilePath)) ;
}
return newFixedLengthResponse(Program.DBUtils.queryBooks("uuid = ?", bookuuid).First().getDisplayName());
}
if (api == ("close"))
Expand All @@ -463,11 +517,21 @@ private ApiResponse handlePathReadBookRequest(string bookuuid, string api, Dicti
}
if (openingBook == null)
{
string path = Program.DBUtils.queryBooks("uuid = ?", bookuuid).First().getPath();
openingBook = new MyPakFile(path)
if (bookuuid.ToLower() == OpenFromFileUUID)
{
Tag = bookuuid
};
openingBook = new MyPakFile(OpenFromFilePath)
{
Tag = bookuuid
};
}
else
{
string path = Program.DBUtils.queryBooks("uuid = ?", bookuuid).First().getPath();
openingBook = new MyPakFile(path)
{
Tag = bookuuid
};
}
}
api = HttpUtility.UrlDecode(api);
Stream stream = openingBook.OpenRead(api);
Expand Down
4 changes: 2 additions & 2 deletions EPUBium Desktop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.1.1")]
[assembly: AssemblyFileVersion("3.0.1.1")]
[assembly: AssemblyVersion("3.0.2.0")]
[assembly: AssemblyFileVersion("3.0.2.0")]
Binary file modified EPUBium Desktop/htdocs.pak
Binary file not shown.
2 changes: 1 addition & 1 deletion EPUBium Desktop/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.WebView2" version="1.0.1108.44" targetFramework="net472" />
<package id="Microsoft.Web.WebView2" version="1.0.1264.42" targetFramework="net472" />
<package id="SharpZipLib" version="1.3.3" targetFramework="net472" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.114.0" targetFramework="net452" />
<package id="System.Data.SQLite.Core" version="1.0.114.3" targetFramework="net452" />
Expand Down

0 comments on commit d37199a

Please sign in to comment.