Skip to content

Commit 6388a9e

Browse files
committed
Fix: Stuck in a loop trying to read an epub file when the epub or zip is corrupt
1 parent a4887c3 commit 6388a9e

File tree

7 files changed

+119
-20
lines changed

7 files changed

+119
-20
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919
- eBook not working with decimal device pixel ratio (1.5, 2.5, etc) [`4962724`](https://github.com/ollm/OpenComic/commit/496272442747e466638e890a187f84b100deda14)
2020
- Blurry cover/poster images [`23ae46d`](https://github.com/ollm/OpenComic/commit/23ae46d3d77847f5262f10799a21d7ee0141b226)
2121
- Using the first image as a poster does not work [`fd6c748`](https://github.com/ollm/OpenComic/commit/dfd6c748090088109416b847a5e7581d80e36ea7)
22-
- Some errors in scroll reading
22+
- Some errors in scroll reading [`a4887c3`](https://github.com/ollm/OpenComic/commit/a4887c3bfe3f0ec8b75d3cdceedfaae8684fe6df)
23+
- Stuck in a loop trying to read an epub file when the epub or zip is corrupt
2324

2425
## [v1.1.0](https://github.com/ollm/OpenComic/releases/tag/v1.1.0) (13-01-2024)
2526

scripts/dom.js

+58-15
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,19 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
738738
}
739739
else if(openFirstImage && !fromGoBack && !notAutomaticBrowsing)
740740
{
741-
let first = await file.images(1);
741+
let first;
742+
743+
try
744+
{
745+
first = await file.images(1);
746+
}
747+
catch(error)
748+
{
749+
console.error(error);
750+
dom.compressedError(error);
751+
752+
return;
753+
}
742754

743755
if(first)
744756
{
@@ -909,16 +921,30 @@ function continueReadingError()
909921
});
910922
}
911923

912-
function compressedError(error)
924+
function compressedError(error, showInPage = true)
913925
{
914-
//console.log(error);
926+
// console.error(error);
915927

916-
electronRemote.dialog.showMessageBox({
917-
type: 'error',
918-
title: language.error.uncompress.title,
919-
message: language.error.uncompress.message,
920-
detail: error.detail || error.message,
921-
});
928+
if(showInPage)
929+
{
930+
handlebarsContext.compressedError = (error.detail || error.message);
931+
handlebarsContext.contentRightMessage = template.load('content.right.message.compressed.error.html');
932+
template._contentRight().firstElementChild.innerHTML = template.load('content.right.message.html');
933+
}
934+
else
935+
{
936+
events.snackbar({
937+
key: 'compressedError',
938+
text: language.error.uncompress.title+': '+(error.detail || error.message),
939+
duration: 6,
940+
buttons: [
941+
{
942+
text: language.buttons.dismiss,
943+
function: 'events.closeSnackbar();',
944+
},
945+
],
946+
});
947+
}
922948
}
923949

924950
function addSepToEnd(path)
@@ -1151,7 +1177,7 @@ async function getFolderThumbnails(path)
11511177
else
11521178
{
11531179
console.error(error);
1154-
dom.compressedError(error);
1180+
dom.compressedError(error, false);
11551181
}
11561182
}
11571183

@@ -1810,14 +1836,19 @@ async function comicContextMenu(path, fromIndex = true, fromIndexNotMasterFolder
18101836
addPoster.style.display = 'block';
18111837
deletePoster.style.display = 'block';
18121838

1813-
18141839
if(folder)
18151840
{
18161841
addPoster.style.display = 'block';
18171842

1818-
let file = fileManager.file(path);
1819-
let images = await file.images(2, false, true);
1820-
file.destroy();
1843+
let images = [];
1844+
1845+
try
1846+
{
1847+
let file = fileManager.file(path);
1848+
images = await file.images(2, false, true);
1849+
file.destroy();
1850+
}
1851+
catch{}
18211852

18221853
let poster = !Array.isArray(images) ? images : false;
18231854

@@ -1907,7 +1938,19 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
19071938

19081939
// Load files
19091940
let file = fileManager.file(path);
1910-
let files = await file.read({filtered: false});
1941+
let files = [];
1942+
1943+
try
1944+
{
1945+
files = await file.read({filtered: false});
1946+
}
1947+
catch(error)
1948+
{
1949+
console.error(error);
1950+
dom.compressedError(error);
1951+
1952+
return;
1953+
}
19111954

19121955
let hasMusic = await reading.music.has(files);
19131956
handlebarsContext.hasMusic = hasMusic;

scripts/file-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
10231023

10241024
let type = await fileType(this.realPath);
10251025

1026-
if(inArray(type.ext, compressedExtensions.all))
1026+
if(inArray(type.ext, compressedExtensions.all) && type.ext != 'epub')
10271027
return type.ext;
10281028

10291029
return this.features.ext;

scripts/queue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function processTheQueue(key)
1717
catch(error)
1818
{
1919
if(key == 'folderThumbnails')
20-
dom.compressedError(error);
20+
dom.compressedError(error, false);
2121
else
2222
_error = error;
2323

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<i class="icon-96 material-icon">problem{{!-- web_asset_off --}}</i>
2+
<br>
3+
<span class="title-large">{{language.error.uncompress.title}}</span>
4+
<br>
5+
<span class="body-medium">
6+
{{language.error.uncompress.message}}
7+
<br>
8+
{{compressedError}}
9+
</span>
10+
<br>
11+
<div class="content-message-buttons">
12+
<div class="simple-button filled-tonal gamepad-item" onclick="openComicDialog();">
13+
<div class="touch-effect"><i class="icon-24 material-icon">file_open</i>{{language.menu.file.openFile}}</div>
14+
</div>
15+
<div class="simple-button filled-tonal gamepad-item" onclick="openComicDialog(true);">
16+
<div class="touch-effect"><i class="icon-24 material-icon">folder_open</i>{{language.menu.file.openFolder}}</div>
17+
</div>
18+
</div>

templates/content.right.message.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="content-message">
2+
{{{contentRightMessage}}}
3+
</div>

themes/material-design/theme.css

+36-2
Original file line numberDiff line numberDiff line change
@@ -1040,18 +1040,43 @@ cb
10401040
margin-top: -40px !important;
10411041
}
10421042

1043-
.server-connection-error
1043+
.server-connection-error,
1044+
.content-message-buttons
10441045
{
10451046
display: flex;
10461047
justify-content: center;
10471048
margin: 16px;
10481049
}
10491050

1050-
.server-connection-error > div
1051+
.server-connection-error > div,
1052+
.content-message-buttons > div
10511053
{
10521054
margin: 0px 4px;
10531055
}
10541056

1057+
.content-message
1058+
{
1059+
text-align: center;
1060+
position: absolute;
1061+
left: 0px;
1062+
width: 100%;
1063+
top: 50%;
1064+
transform: translate(0px, -50%);
1065+
font-size: 15px;
1066+
}
1067+
1068+
.content-message .title-large
1069+
{
1070+
line-height: 30px;
1071+
margin-bottom: 12px;
1072+
display: inline-block;
1073+
}
1074+
1075+
.content-message .body-medium
1076+
{
1077+
line-height: 22px;
1078+
}
1079+
10551080
/* separators */
10561081

10571082
.separator-1
@@ -1110,6 +1135,15 @@ cb
11101135
background-repeat: no-repeat;
11111136
}
11121137

1138+
.icon-96
1139+
{
1140+
height: 96px;
1141+
width: 96px;
1142+
background-size: 96px;
1143+
font-size: 96px;
1144+
background-repeat: no-repeat;
1145+
}
1146+
11131147
.icon-18
11141148
{
11151149
height: 18px;

0 commit comments

Comments
 (0)