From d37199a31fdd96259a7770dfc6d4d85d60fef956 Mon Sep 17 00:00:00 2001 From: ZYFDroid Date: Sat, 6 Aug 2022 17:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E5=A4=9A=E4=B8=AA=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=92=8C=E6=89=93=E5=BC=80=E5=A4=96=E9=83=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EPUBium Desktop/EPUBium Desktop.csproj | 15 +++-- EPUBium Desktop/Form1.cs | 32 ++++++++- EPUBium Desktop/Program.cs | 74 +++++++++++++++++++-- EPUBium Desktop/Properties/AssemblyInfo.cs | 4 +- EPUBium Desktop/htdocs.pak | Bin 1389002 -> 1389002 bytes EPUBium Desktop/packages.config | 2 +- 6 files changed, 112 insertions(+), 15 deletions(-) diff --git a/EPUBium Desktop/EPUBium Desktop.csproj b/EPUBium Desktop/EPUBium Desktop.csproj index d5d049b..795af38 100644 --- a/EPUBium Desktop/EPUBium Desktop.csproj +++ b/EPUBium Desktop/EPUBium Desktop.csproj @@ -87,11 +87,14 @@ ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll - - ..\packages\Microsoft.Web.WebView2.1.0.1108.44\lib\net45\Microsoft.Web.WebView2.Core.dll + + ..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.Core.dll - - ..\packages\Microsoft.Web.WebView2.1.0.1108.44\lib\net45\Microsoft.Web.WebView2.WinForms.dll + + ..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.WinForms.dll + + + ..\packages\Microsoft.Web.WebView2.1.0.1264.42\lib\net45\Microsoft.Web.WebView2.Wpf.dll C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.dll @@ -188,12 +191,12 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - + cd "$(ProjectDir)htdocs" "$(ProjectDir)zip.exe" -r -0 ..\htdocs.pak . - + \ No newline at end of file diff --git a/EPUBium Desktop/Form1.cs b/EPUBium Desktop/Form1.cs index b8ad3e0..3084e71 100644 --- a/EPUBium Desktop/Form1.cs +++ b/EPUBium Desktop/Form1.cs @@ -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 @@ -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) diff --git a/EPUBium Desktop/Program.cs b/EPUBium Desktop/Program.cs index 837cd9f..f389f62 100644 --- a/EPUBium Desktop/Program.cs +++ b/EPUBium Desktop/Program.cs @@ -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", @@ -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) @@ -206,6 +238,9 @@ public class ApiModel { private MyPakFile openingBook = null; + public string OpenFromFilePath = null; + + public ApiResponse callApi(string pathWithUrl) { int ptr = pathWithUrl.IndexOf("?"); @@ -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 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"]; @@ -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")) @@ -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); diff --git a/EPUBium Desktop/Properties/AssemblyInfo.cs b/EPUBium Desktop/Properties/AssemblyInfo.cs index 5dfb860..78bd0d7 100644 --- a/EPUBium Desktop/Properties/AssemblyInfo.cs +++ b/EPUBium Desktop/Properties/AssemblyInfo.cs @@ -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")] diff --git a/EPUBium Desktop/htdocs.pak b/EPUBium Desktop/htdocs.pak index 8ecc619ea14d41575c28fe064efade474f6d4446..8caf912bc6ac65019e9eae461b63bc9ed4af1c85 100644 GIT binary patch delta 591 zcmX^0IONphkO{k)<;>qr+;;>-O>Sk}!~D#fQfi=Ri zf|C!dVVRseVJTSDalPhdyNN7JFeRH~Cx2ssax^#B&!}evaW*r~@`Ndg-n?Rt1&pJ) znP{jV^!t=Np4?yjP*<)h}B*q!3MWgs`7HptlNyK1=C zgN1TxxgWZNg#wOpZvmUZevG@F{TL4r^8zs+5c31E01yjqXFn!%paHD$l$&s?Dwq|N zBb+V>X6>mJeyPX~bVriKwttfY=Y(%(ULdT*1Qyx86(pjvJz$Y=GB`-KZ(9PC;{d7d z78OsLY`9cqveqn~?E=e%W55BiJ%5#O8zWf3CvmU>VNeR#0k*6C^j_iZr}v8dF9rbf CFMB!a0wt{g|N~iR}Vwgk=RM zA6UaOId{TRu&CpD&CPZbS(so-Hpfo>#scMNZmyqE&j{jdW}M{-Qxd&-#T*M5M{_gJ zd}pwd$sm)e7u3UKBqqmB7TB!17;d!Y=Fp`R5lV%Y$D%5owelj&p_-eguU!tY*m1od zs1ScwTNvVAK^L}h!xBH?6kkZj+!1SrP=Qr#^o zo;2BTsmf%nSv=bXmJ7##17dsrD&aOpu!2wGUp75QHb0QHc@ An*aa+ diff --git a/EPUBium Desktop/packages.config b/EPUBium Desktop/packages.config index 834862f..7287a3c 100644 --- a/EPUBium Desktop/packages.config +++ b/EPUBium Desktop/packages.config @@ -1,6 +1,6 @@  - +