@@ -7,7 +7,7 @@ const { promisify, format } = require('util')
7
7
const _ = require ( 'lodash' )
8
8
const { nanoid } = require ( 'nanoid' )
9
9
const sharp = require ( 'sharp' )
10
- const { spawn } = require ( 'child_process' )
10
+ const { exec } = require ( 'child_process' )
11
11
const { createHash } = require ( 'crypto' )
12
12
const sqlite3 = require ( 'sqlite3' )
13
13
const { open } = require ( 'sqlite' )
@@ -52,15 +52,16 @@ try {
52
52
setting = {
53
53
proxy : undefined ,
54
54
library : app . getPath ( 'downloads' ) ,
55
- imageExplorer : 'C:\\Windows\\explorer.exe' ,
55
+ imageExplorer : '\" C:\\Windows\\explorer.exe\" ' ,
56
56
pageSize : 10 ,
57
57
loadOnStart : false ,
58
58
requireGap : 10000 ,
59
59
thumbnailColumn : 10 ,
60
60
showTranslation : false ,
61
61
widthLimit : undefined ,
62
62
directEnter : 'detail' ,
63
- language : 'default'
63
+ language : 'default' ,
64
+ advancedSearch : true
64
65
}
65
66
fs . writeFileSync ( path . join ( STORE_PATH , 'setting.json' ) , JSON . stringify ( setting , null , ' ' ) , { encoding : 'utf-8' } )
66
67
}
@@ -184,19 +185,19 @@ let geneCover = async (filepath, type)=>{
184
185
//fileLoader: get targetFile for hash, get tempCover for cover
185
186
switch ( type ) {
186
187
case 'folder' :
187
- ; ( { targetFilePath, coverPath, tempCoverPath, pageCount} = await solveBookTypeFolder ( filepath , TEMP_PATH , COVER_PATH ) )
188
+ ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize , mtime } = await solveBookTypeFolder ( filepath , TEMP_PATH , COVER_PATH ) )
188
189
break
189
190
case 'zip' :
190
191
try {
191
- ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize} = await solveBookTypeArchive ( filepath , TEMP_PATH , COVER_PATH ) )
192
+ ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize, mtime } = await solveBookTypeArchive ( filepath , TEMP_PATH , COVER_PATH ) )
192
193
} catch ( e ) {
193
194
console . log ( e )
194
195
console . log ( `reload ${ filepath } use adm-zip` )
195
- ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize} = await solveBookTypeZip ( filepath , TEMP_PATH , COVER_PATH ) )
196
+ ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize, mtime } = await solveBookTypeZip ( filepath , TEMP_PATH , COVER_PATH ) )
196
197
}
197
198
break
198
199
case 'archive' :
199
- ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize} = await solveBookTypeArchive ( filepath , TEMP_PATH , COVER_PATH ) )
200
+ ; ( { targetFilePath, coverPath, tempCoverPath, pageCount, bundleSize, mtime } = await solveBookTypeArchive ( filepath , TEMP_PATH , COVER_PATH ) )
200
201
break
201
202
}
202
203
@@ -212,7 +213,7 @@ let geneCover = async (filepath, type)=>{
212
213
return false
213
214
} )
214
215
if ( imageResizeResult ) {
215
- return { targetFilePath, coverPath, pageCount, bundleSize, coverHash}
216
+ return { targetFilePath, coverPath, pageCount, bundleSize, mtime , coverHash}
216
217
} else {
217
218
return { targetFilePath :undefined , coverPath :undefined }
218
219
}
@@ -263,7 +264,7 @@ ipcMain.handle('load-book-list', async (event, scan)=>{
263
264
sendMessageToWebContents ( `load ${ filepath } , ${ i + 1 } of ${ listLength } ` )
264
265
foundNewBook = true
265
266
let id = nanoid ( )
266
- let { targetFilePath, coverPath, pageCount, bundleSize, coverHash} = await geneCover ( filepath , type )
267
+ let { targetFilePath, coverPath, pageCount, bundleSize, mtime , coverHash} = await geneCover ( filepath , type )
267
268
if ( targetFilePath && coverPath ) {
268
269
let hash = createHash ( 'sha1' ) . update ( fs . readFileSync ( targetFilePath ) ) . digest ( 'hex' )
269
270
existData . push ( {
@@ -275,6 +276,7 @@ ipcMain.handle('load-book-list', async (event, scan)=>{
275
276
id,
276
277
pageCount,
277
278
bundleSize,
279
+ mtime : mtime . toJSON ( ) ,
278
280
coverHash,
279
281
status : 'non-tag' ,
280
282
exist : true ,
@@ -286,7 +288,7 @@ ipcMain.handle('load-book-list', async (event, scan)=>{
286
288
foundData . exist = true
287
289
foundData . coverPath = path . join ( COVER_PATH , path . basename ( foundData . coverPath ) )
288
290
}
289
- if ( ( i + 1 ) % 100 == 0 ) {
291
+ if ( ( i + 1 ) % 100 === 0 ) {
290
292
sendMessageToWebContents ( `load ${ i + 1 } of ${ listLength } ` )
291
293
if ( foundNewBook ) {
292
294
let tempExistData = _ . cloneDeep ( existData )
@@ -360,7 +362,7 @@ ipcMain.handle('force-gene-book-list', async (event, arg)=>{
360
362
let { filepath, type} = list [ i ]
361
363
sendMessageToWebContents ( `load ${ filepath } , ${ i + 1 } of ${ listLength } ` )
362
364
let id = nanoid ( )
363
- let { targetFilePath, coverPath, pageCount, bundleSize, coverHash} = await geneCover ( filepath , type )
365
+ let { targetFilePath, coverPath, pageCount, bundleSize, mtime , coverHash} = await geneCover ( filepath , type )
364
366
if ( targetFilePath && coverPath ) {
365
367
let hash = createHash ( 'sha1' ) . update ( fs . readFileSync ( targetFilePath ) ) . digest ( 'hex' )
366
368
data . push ( {
@@ -372,13 +374,14 @@ ipcMain.handle('force-gene-book-list', async (event, arg)=>{
372
374
id,
373
375
pageCount,
374
376
bundleSize,
377
+ mtime : mtime . toJSON ( ) ,
375
378
coverHash,
376
379
status : 'non-tag' ,
377
380
date : Date . now ( )
378
381
} )
379
382
}
380
383
mainWindow . setProgressBar ( i / listLength )
381
- if ( ( i + 1 ) % 100 == 0 ) {
384
+ if ( ( i + 1 ) % 100 === 0 ) {
382
385
await saveBookListToBrFile ( data )
383
386
}
384
387
} catch ( e ) {
@@ -414,17 +417,17 @@ ipcMain.handle('patch-local-metadata', async(event, arg)=>{
414
417
let book = bookList [ i ]
415
418
let { filepath, type} = book
416
419
if ( ! type ) type = 'archive'
417
- let { targetFilePath, coverPath, pageCount, bundleSize, coverHash} = await geneCover ( filepath , type )
420
+ let { targetFilePath, coverPath, pageCount, bundleSize, mtime , coverHash} = await geneCover ( filepath , type )
418
421
if ( targetFilePath && coverPath ) {
419
422
let hash = createHash ( 'sha1' ) . update ( fs . readFileSync ( targetFilePath ) ) . digest ( 'hex' )
420
- _ . assign ( book , { type, coverPath, hash, pageCount, bundleSize, coverHash} )
423
+ _ . assign ( book , { type, coverPath, hash, pageCount, bundleSize, mtime : mtime . toJSON ( ) , coverHash} )
421
424
sendMessageToWebContents ( `patch ${ filepath } , ${ i + 1 } of ${ bookListLength } ` )
422
425
mainWindow . setProgressBar ( i / bookListLength )
423
426
}
424
427
} catch ( e ) {
425
- sendMessageToWebContents ( `patch ${ book . filepath } failed because ${ e } ` )
428
+ sendMessageToWebContents ( `patch ${ bookList [ i ] . filepath } failed because ${ e } ` )
426
429
}
427
- if ( ( i + 1 ) % 100 == 0 ) {
430
+ if ( ( i + 1 ) % 100 === 0 ) {
428
431
await saveBookListToBrFile ( bookList )
429
432
}
430
433
}
@@ -499,7 +502,7 @@ ipcMain.handle('save-book-list', async (event, list)=>{
499
502
ipcMain . handle ( 'get-folder-tree' , async ( event , bookList ) => {
500
503
let folderList = _ . uniq ( bookList . map ( b => path . dirname ( b . filepath ) ) )
501
504
let librarySplitPathsLength = setting . library . split ( path . sep ) . length - 1
502
- let bookPathSplitList = folderList . map ( fp => fp . split ( path . sep ) . slice ( librarySplitPathsLength ) )
505
+ let bookPathSplitList = folderList . sort ( ) . map ( fp => fp . split ( path . sep ) . slice ( librarySplitPathsLength ) )
503
506
let folderTreeObject = { }
504
507
for ( let folders of bookPathSplitList ) {
505
508
_ . set ( folderTreeObject , folders . map ( f => '_' + f ) , { } )
@@ -566,7 +569,7 @@ ipcMain.handle('use-new-cover', async(event, filepath)=>{
566
569
} )
567
570
568
571
ipcMain . handle ( 'open-local-book' , async ( event , filepath ) => {
569
- spawn ( setting . imageExplorer , [ filepath ] )
572
+ exec ( ` ${ setting . imageExplorer } " ${ filepath } "` )
570
573
} )
571
574
572
575
ipcMain . handle ( 'delete-local-book' , async ( event , filepath ) => {
@@ -575,8 +578,12 @@ ipcMain.handle('delete-local-book', async (event, filepath)=>{
575
578
576
579
// viewer
577
580
ipcMain . handle ( 'load-manga-image-list' , async ( event , book ) => {
578
- await fs . promises . rm ( VIEWER_PATH , { recursive : true , force : true } )
579
- await fs . promises . mkdir ( VIEWER_PATH , { recursive : true } )
581
+ try {
582
+ await fs . promises . rm ( VIEWER_PATH , { recursive : true , force : true } )
583
+ await fs . promises . mkdir ( VIEWER_PATH , { recursive : true } )
584
+ } catch ( err ) {
585
+ console . log ( err )
586
+ }
580
587
let { filepath, type} = book
581
588
582
589
let list
@@ -761,7 +768,7 @@ ipcMain.handle('import-sqlite', async(event, bookList)=>{
761
768
sendMessageToWebContents ( `${ i + 1 } of ${ bookListLength } , metadata not found for ${ book . filepath } ` )
762
769
}
763
770
}
764
- if ( ( i + 1 ) % 100 == 0 ) {
771
+ if ( ( i + 1 ) % 100 === 0 ) {
765
772
await saveBookListToBrFile ( bookList )
766
773
}
767
774
}
0 commit comments