Skip to content

Commit

Permalink
Fix: Stuck in a loop trying to read an epub file when the epub or zip…
Browse files Browse the repository at this point in the history
… is corrupt
  • Loading branch information
ollm committed Jan 23, 2024
1 parent a4887c3 commit 6388a9e
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- eBook not working with decimal device pixel ratio (1.5, 2.5, etc) [`4962724`](https://github.com/ollm/OpenComic/commit/496272442747e466638e890a187f84b100deda14)
- Blurry cover/poster images [`23ae46d`](https://github.com/ollm/OpenComic/commit/23ae46d3d77847f5262f10799a21d7ee0141b226)
- Using the first image as a poster does not work [`fd6c748`](https://github.com/ollm/OpenComic/commit/dfd6c748090088109416b847a5e7581d80e36ea7)
- Some errors in scroll reading
- Some errors in scroll reading [`a4887c3`](https://github.com/ollm/OpenComic/commit/a4887c3bfe3f0ec8b75d3cdceedfaae8684fe6df)
- Stuck in a loop trying to read an epub file when the epub or zip is corrupt

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

Expand Down
73 changes: 58 additions & 15 deletions scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,19 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
}
else if(openFirstImage && !fromGoBack && !notAutomaticBrowsing)
{
let first = await file.images(1);
let first;

try
{
first = await file.images(1);
}
catch(error)
{
console.error(error);
dom.compressedError(error);

return;
}

if(first)
{
Expand Down Expand Up @@ -909,16 +921,30 @@ function continueReadingError()
});
}

function compressedError(error)
function compressedError(error, showInPage = true)
{
//console.log(error);
// console.error(error);

electronRemote.dialog.showMessageBox({
type: 'error',
title: language.error.uncompress.title,
message: language.error.uncompress.message,
detail: error.detail || error.message,
});
if(showInPage)
{
handlebarsContext.compressedError = (error.detail || error.message);
handlebarsContext.contentRightMessage = template.load('content.right.message.compressed.error.html');
template._contentRight().firstElementChild.innerHTML = template.load('content.right.message.html');
}
else
{
events.snackbar({
key: 'compressedError',
text: language.error.uncompress.title+': '+(error.detail || error.message),
duration: 6,
buttons: [
{
text: language.buttons.dismiss,
function: 'events.closeSnackbar();',
},
],
});
}
}

function addSepToEnd(path)
Expand Down Expand Up @@ -1151,7 +1177,7 @@ async function getFolderThumbnails(path)
else
{
console.error(error);
dom.compressedError(error);
dom.compressedError(error, false);
}
}

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


if(folder)
{
addPoster.style.display = 'block';

let file = fileManager.file(path);
let images = await file.images(2, false, true);
file.destroy();
let images = [];

try
{
let file = fileManager.file(path);
images = await file.images(2, false, true);
file.destroy();
}
catch{}

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

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

// Load files
let file = fileManager.file(path);
let files = await file.read({filtered: false});
let files = [];

try
{
files = await file.read({filtered: false});
}
catch(error)
{
console.error(error);
dom.compressedError(error);

return;
}

let hasMusic = await reading.music.has(files);
handlebarsContext.hasMusic = hasMusic;
Expand Down
2 changes: 1 addition & 1 deletion scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix

let type = await fileType(this.realPath);

if(inArray(type.ext, compressedExtensions.all))
if(inArray(type.ext, compressedExtensions.all) && type.ext != 'epub')
return type.ext;

return this.features.ext;
Expand Down
2 changes: 1 addition & 1 deletion scripts/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function processTheQueue(key)
catch(error)
{
if(key == 'folderThumbnails')
dom.compressedError(error);
dom.compressedError(error, false);
else
_error = error;

Expand Down
18 changes: 18 additions & 0 deletions templates/content.right.message.compressed.error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<i class="icon-96 material-icon">problem{{!-- web_asset_off --}}</i>
<br>
<span class="title-large">{{language.error.uncompress.title}}</span>
<br>
<span class="body-medium">
{{language.error.uncompress.message}}
<br>
{{compressedError}}
</span>
<br>
<div class="content-message-buttons">
<div class="simple-button filled-tonal gamepad-item" onclick="openComicDialog();">
<div class="touch-effect"><i class="icon-24 material-icon">file_open</i>{{language.menu.file.openFile}}</div>
</div>
<div class="simple-button filled-tonal gamepad-item" onclick="openComicDialog(true);">
<div class="touch-effect"><i class="icon-24 material-icon">folder_open</i>{{language.menu.file.openFolder}}</div>
</div>
</div>
3 changes: 3 additions & 0 deletions templates/content.right.message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="content-message">
{{{contentRightMessage}}}
</div>
38 changes: 36 additions & 2 deletions themes/material-design/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1040,18 +1040,43 @@ cb
margin-top: -40px !important;
}

.server-connection-error
.server-connection-error,
.content-message-buttons
{
display: flex;
justify-content: center;
margin: 16px;
}

.server-connection-error > div
.server-connection-error > div,
.content-message-buttons > div
{
margin: 0px 4px;
}

.content-message
{
text-align: center;
position: absolute;
left: 0px;
width: 100%;
top: 50%;
transform: translate(0px, -50%);
font-size: 15px;
}

.content-message .title-large
{
line-height: 30px;
margin-bottom: 12px;
display: inline-block;
}

.content-message .body-medium
{
line-height: 22px;
}

/* separators */

.separator-1
Expand Down Expand Up @@ -1110,6 +1135,15 @@ cb
background-repeat: no-repeat;
}

.icon-96
{
height: 96px;
width: 96px;
background-size: 96px;
font-size: 96px;
background-repeat: no-repeat;
}

.icon-18
{
height: 18px;
Expand Down

0 comments on commit 6388a9e

Please sign in to comment.