Skip to content

Commit

Permalink
Fix crash when load resource pack without meta.json
Browse files Browse the repository at this point in the history
Limit resource pack network access
  • Loading branch information
ZYFDroid committed Feb 24, 2022
1 parent fc29b98 commit a7301d1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
4 changes: 2 additions & 2 deletions EPUBium Desktop/EPUBium Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>embedded</DebugType>
<DebugType>none</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DebugSymbols>true</DebugSymbols>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
Expand Down
14 changes: 12 additions & 2 deletions EPUBium Desktop/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,27 @@ void initWebView2()
webView.DocumentTitleChanged += WebView_DocumentTitleChanged;
webView.Settings.IsPinchZoomEnabled = false;
webView.Settings.IsSwipeNavigationEnabled = false;
webView.AddWebResourceRequestedFilter("http://epub.zyf-internal.com/*", CoreWebView2WebResourceContext.All);
webView.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
resourceHandler = new ResourceHandler(webView.Environment);
webView.WebResourceRequested += WebView_WebResourceRequested;
webView.FrameNavigationStarting += WebView_FrameNavigationStarting;
}

private void WebView_FrameNavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
{
if (!e.Uri.StartsWith(urlbase))
{
e.Cancel = true;
}
}

const string urlbase = "http://epub.zyf-internal.com";
private void WebView_WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
e.Response = handleRequest(e.Request);
e.GetDeferral().Complete();
}

public CoreWebView2WebResourceResponse handleRequest(CoreWebView2WebResourceRequest request)
{
if (request.Uri.StartsWith(urlbase))
Expand Down
22 changes: 15 additions & 7 deletions EPUBium Desktop/FrmChangeResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ void loadData()
resPackInfo.metadata = new ResPackMeta();
}
}
resPackInfo.metadata.safeValue(file);
}
else
{
resPackInfo.metadata = new ResPackMeta();

}

resPackInfo.metadata.safeValue(file);
}
catch { }
}
Expand Down Expand Up @@ -122,21 +128,23 @@ class ResPackMeta

public void safeValue(string filename)
{
name = name.Trim() == "" ? null : name;
description = description.Trim() == "" ? null : description;
author = author.Trim() == "" ? null : author;
version = name.Trim() == "" ? null : version;
link = name.Trim() == "" ? null : link;

name = name ?? Path.GetFileName(filename);
description = description ?? "";
author = author ?? "";
version = version ?? "";
link = link ?? "";

name = name.Trim() == "" ? Path.GetFileName(filename) : name;


}

public override string ToString()
{
if(version == "" || author == "")
{
return $"{name}\r\n \r\n ";
}
return $"{name} v{version}\r\n{description}\r\n作者:{author}";
}
}
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.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: AssemblyVersion("3.0.0.1")]
[assembly: AssemblyFileVersion("3.0.0.1")]
Binary file modified EPUBium Desktop/htdocs.pak
Binary file not shown.
12 changes: 8 additions & 4 deletions EPUBium Desktop/htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@
});

$(function (){
loadFolderList();
loadAll();
})

function loadFolderList(){
$.ajax({url:"/api/folders",success:function (result) {
menuController.folders = JSON.parse(result);
}});
loadAll();
})
}

function loadFolder(folder){
$.ajax({url:"/api/folder/"+folder.UUID,success:function (result) {
Expand Down Expand Up @@ -180,12 +184,12 @@
unblockloading();
toast(result);
loadAll();
loadFolder();
loadFolderList();
},
err:function(a,b,c){
toast("扫描出错");
loadAll();
loadFolder();
loadFolderList();
}
});
}
Expand Down

0 comments on commit a7301d1

Please sign in to comment.