Skip to content

Commit

Permalink
bugfix and improvement
Browse files Browse the repository at this point in the history
- Fixed a bug that would render a .epub unreadable if it had a depth of 1 in the toc.ncx and was updated
- Added a couple try - catches to cover possible edge cases
  • Loading branch information
ErisLoona committed Jun 17, 2024
1 parent 1d95cd7 commit 3ca1b62
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Manga Library Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>ytpfp.ico</ApplicationIcon>
<NeutralLanguage>en</NeutralLanguage>
<FileVersion>2.0.3</FileVersion>
<FileVersion>2.1.0</FileVersion>
<PackageProjectUrl>https://github.com/ErisLoona/Manga-Library-Manager</PackageProjectUrl>
<Copyright>Eris Loona, pseudonym</Copyright>
<Description>A manga downloader and offline library manager.</Description>
Expand Down
2 changes: 1 addition & 1 deletion Properties/PublishProfiles/FolderProfile.pubxml.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-06-14T09:31:32.6934516Z||;True|2024-06-14T11:31:23.3706499+02:00||;True|2024-06-14T11:31:18.7205494+02:00||;True|2024-06-13T09:43:43.5390795+02:00||;True|2024-06-13T08:57:35.0322797+02:00||;True|2024-06-06T15:42:28.6568298+02:00||;True|2024-06-06T15:40:12.6240419+02:00||;True|2024-06-06T13:48:19.4662781+02:00||;True|2024-06-06T12:38:52.6425012+02:00||;True|2024-06-06T12:31:36.7948282+02:00||;True|2024-06-06T10:35:12.1369025+02:00||;True|2024-06-06T10:34:54.5189019+02:00||;True|2024-06-05T23:32:06.1114024+02:00||;True|2024-05-27T18:47:08.3065316+02:00||;True|2024-05-27T18:43:26.7575713+02:00||;True|2024-05-27T16:16:44.1211325+02:00||;True|2024-05-27T16:16:29.4947310+02:00||;True|2024-05-27T11:07:49.8981157+02:00||;True|2024-05-27T11:07:01.1240671+02:00||;True|2024-05-27T11:06:53.1694382+02:00||;True|2024-05-27T09:10:47.9526993+02:00||;True|2024-05-27T09:10:02.8503554+02:00||;True|2024-05-27T09:09:35.2317189+02:00||;True|2024-05-27T08:58:09.8645241+02:00||;True|2024-05-27T08:52:52.8051920+02:00||;True|2024-05-27T08:45:19.6197985+02:00||;True|2024-05-24T11:02:27.2916636+02:00||;True|2024-05-24T08:59:01.6326756+02:00||;True|2024-05-23T09:17:13.9644300+02:00||;True|2024-05-23T09:05:46.2467509+02:00||;True|2024-05-22T22:13:45.9526537+02:00||;True|2024-05-22T22:09:03.4000755+02:00||;True|2024-05-22T22:08:00.0350517+02:00||;True|2024-05-22T21:44:48.4725626+02:00||;True|2024-05-22T21:32:35.3627900+02:00||;True|2024-05-22T19:33:34.6467061+02:00||;True|2024-05-19T19:19:28.1467287+02:00||;True|2024-05-19T19:17:09.7006733+02:00||;True|2024-05-19T19:14:06.6668981+02:00||;True|2024-05-19T14:42:07.1301968+02:00||;True|2024-05-19T14:38:02.4943907+02:00||;True|2024-05-19T09:20:51.2871097+02:00||;True|2024-05-19T09:18:16.6124371+02:00||;True|2024-05-19T09:15:08.6048404+02:00||;True|2024-05-18T22:34:28.8521894+02:00||;True|2024-05-18T22:22:14.4673452+02:00||;True|2024-05-18T21:56:58.6143811+02:00||;True|2024-05-18T07:41:43.4161277+02:00||;True|2024-05-17T11:48:43.3293227+02:00||;True|2024-05-17T09:31:58.9329403+02:00||;True|2024-05-17T09:25:57.4957904+02:00||;True|2024-05-16T19:52:10.0997229+02:00||;True|2024-05-16T18:17:01.7850021+02:00||;True|2024-05-15T09:33:00.6957135+02:00||;True|2024-05-15T08:32:31.7735956+02:00||;True|2024-05-13T17:25:21.1454345+02:00||;True|2024-05-13T17:15:09.7285346+02:00||;True|2024-05-13T16:52:20.9054581+02:00||;True|2024-05-13T16:51:27.0891569+02:00||;True|2024-05-13T16:50:34.5522468+02:00||;True|2024-05-13T16:49:22.6946988+02:00||;</History>
<History>True|2024-06-17T08:36:25.6841440Z||;True|2024-06-14T11:31:32.6934516+02:00||;True|2024-06-14T11:31:23.3706499+02:00||;True|2024-06-14T11:31:18.7205494+02:00||;True|2024-06-13T09:43:43.5390795+02:00||;True|2024-06-13T08:57:35.0322797+02:00||;True|2024-06-06T15:42:28.6568298+02:00||;True|2024-06-06T15:40:12.6240419+02:00||;True|2024-06-06T13:48:19.4662781+02:00||;True|2024-06-06T12:38:52.6425012+02:00||;True|2024-06-06T12:31:36.7948282+02:00||;True|2024-06-06T10:35:12.1369025+02:00||;True|2024-06-06T10:34:54.5189019+02:00||;True|2024-06-05T23:32:06.1114024+02:00||;True|2024-05-27T18:47:08.3065316+02:00||;True|2024-05-27T18:43:26.7575713+02:00||;True|2024-05-27T16:16:44.1211325+02:00||;True|2024-05-27T16:16:29.4947310+02:00||;True|2024-05-27T11:07:49.8981157+02:00||;True|2024-05-27T11:07:01.1240671+02:00||;True|2024-05-27T11:06:53.1694382+02:00||;True|2024-05-27T09:10:47.9526993+02:00||;True|2024-05-27T09:10:02.8503554+02:00||;True|2024-05-27T09:09:35.2317189+02:00||;True|2024-05-27T08:58:09.8645241+02:00||;True|2024-05-27T08:52:52.8051920+02:00||;True|2024-05-27T08:45:19.6197985+02:00||;True|2024-05-24T11:02:27.2916636+02:00||;True|2024-05-24T08:59:01.6326756+02:00||;True|2024-05-23T09:17:13.9644300+02:00||;True|2024-05-23T09:05:46.2467509+02:00||;True|2024-05-22T22:13:45.9526537+02:00||;True|2024-05-22T22:09:03.4000755+02:00||;True|2024-05-22T22:08:00.0350517+02:00||;True|2024-05-22T21:44:48.4725626+02:00||;True|2024-05-22T21:32:35.3627900+02:00||;True|2024-05-22T19:33:34.6467061+02:00||;True|2024-05-19T19:19:28.1467287+02:00||;True|2024-05-19T19:17:09.7006733+02:00||;True|2024-05-19T19:14:06.6668981+02:00||;True|2024-05-19T14:42:07.1301968+02:00||;True|2024-05-19T14:38:02.4943907+02:00||;True|2024-05-19T09:20:51.2871097+02:00||;True|2024-05-19T09:18:16.6124371+02:00||;True|2024-05-19T09:15:08.6048404+02:00||;True|2024-05-18T22:34:28.8521894+02:00||;True|2024-05-18T22:22:14.4673452+02:00||;True|2024-05-18T21:56:58.6143811+02:00||;True|2024-05-18T07:41:43.4161277+02:00||;True|2024-05-17T11:48:43.3293227+02:00||;True|2024-05-17T09:31:58.9329403+02:00||;True|2024-05-17T09:25:57.4957904+02:00||;True|2024-05-16T19:52:10.0997229+02:00||;True|2024-05-16T18:17:01.7850021+02:00||;True|2024-05-15T09:33:00.6957135+02:00||;True|2024-05-15T08:32:31.7735956+02:00||;True|2024-05-13T17:25:21.1454345+02:00||;True|2024-05-13T17:15:09.7285346+02:00||;True|2024-05-13T16:52:20.9054581+02:00||;True|2024-05-13T16:51:27.0891569+02:00||;True|2024-05-13T16:50:34.5522468+02:00||;True|2024-05-13T16:49:22.6946988+02:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
52 changes: 42 additions & 10 deletions mangaDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,21 @@ private void epubMakerThread_DoWork(object sender, DoWorkEventArgs e)
XmlDocument doc = new XmlDocument();
try
{
doc.Load(Path.Join(savingPath, "content.opf"));
root = true;
try
{
doc.Load(Path.Join(savingPath, "content.opf"));
root = true;
}
catch
{
doc.Load(Path.Join(savingPath, "OEBPS", "content.opf"));
}
}
catch
{
doc.Load(Path.Join(savingPath, "OEBPS", "content.opf"));
MessageBox.Show("Could not find the content.opf!\nThe download has completed but the EPUB assembly has failed.", "Missing toc.ncx", MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = true;
return;
}
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
Expand Down Expand Up @@ -993,22 +1002,45 @@ private void epubMakerThread_DoWork(object sender, DoWorkEventArgs e)
root = false;
try
{
toc.Load(Path.Join(savingPath, "toc.ncx"));
root = true;
try
{
toc.Load(Path.Join(savingPath, "toc.ncx"));
root = true;
}
catch
{
toc.Load(Path.Join(savingPath, "OEBPS", "toc.ncx"));
}
}
catch
{
toc.Load(Path.Join(savingPath, "OEBPS", "toc.ncx"));
MessageBox.Show("Could not find the toc.ncx!\nThe download has completed but the EPUB assembly has failed.", "Missing toc.ncx", MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = true;
return;
}
bool foundUID = false, foundDepth = false;
foreach (XmlNode node in toc.DocumentElement.ChildNodes)
{
if (node.Name == "head")
foreach (XmlNode child in node.ChildNodes)
if (child.Attributes[0].Value == "dtb:uid")
{
if (child.Attributes["name"].Value == "dtb:uid")
{
child.Attributes[1].Value = doc.DocumentElement.SelectSingleNode("//dc:identifier", nsmgr).InnerText;
goto Found;
child.Attributes["content"].Value = doc.DocumentElement.SelectSingleNode("//dc:identifier", nsmgr).InnerText;
foundUID = true;
}
Found:
if (child.Attributes["name"].Value == "dtb:depth" && Convert.ToInt32(child.Attributes["content"].Value) < 2)
{
child.Attributes["content"].Value = "2";
foundDepth = true;
}
if (foundUID == true && foundDepth == true)
break;
}
if (foundUID == true && foundDepth == true)
break;

}
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("toc", toc.DocumentElement.GetAttribute("xmlns"));
toc.DocumentElement.SelectSingleNode("toc:docTitle/toc:text", ns).InnerText = becomingBook.Title;
Expand Down

0 comments on commit 3ca1b62

Please sign in to comment.