1
0
mirror of https://github.com/ciromattia/kcc synced 2026-02-19 02:29:04 +00:00

Preserve file fusion input order with prefix (#1242)

* Preserve file fusion input order with prefix

Prepend a sequence index to temporary directory names to ensure user-specified order is preserved.

* don't sort items in GUI

* Add prefix only if sorted order is different

* Simplified sort prefix that will be removed from chapter name

* Restore adding prefix only when sorted order differs

* simplify prefix code

---------

Co-authored-by: Alex Xu <alexkurosakimh3@gmail.com>
This commit is contained in:
フィルターペーパー
2026-02-10 13:34:11 +08:00
committed by GitHub
parent 541b1d876b
commit ab93c03838
2 changed files with 17 additions and 4 deletions

View File

@@ -1091,7 +1091,8 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
if message[-1] == '/':
message = message[:-1]
self.handleMessage(message)
GUI.jobList.sortItems()
# sorting may conflict with manual file fusion order
# GUI.jobList.sortItems()
def forceShutdown(self):
self.saveSettings(None)

View File

@@ -1556,15 +1556,24 @@ def makeFusion(sources: List[str]):
fusion_path = first_path.parent.joinpath(first_path.name + ' [fused]')
print("Running Fusion")
for source in sources:
# Check if prefix is needed when user-specified ordering differs from OS natural sorting
path_names = [Path(s).stem if Path(s).is_file() else Path(s).name for s in sources]
needs_prefix = os_sorted(path_names) != path_names
for index, source in enumerate(sources, start=1):
print(f"Processing {source}...")
checkPre(source)
print("Checking images...")
source_path = Path(source)
# Add the fusion_0001_ prefix to maintain user-specified order if needed
prefix = ''
if needs_prefix:
prefix = f'fusion_{index:04d}_'
if source_path.is_file():
targetpath = fusion_path.joinpath(source_path.stem)
targetpath = fusion_path.joinpath(f'{prefix}{source_path.stem}')
else:
targetpath = fusion_path.joinpath(source_path.name)
targetpath = fusion_path.joinpath(f'{prefix}{source_path.name}')
getWorkFolder(source, str(targetpath))
sanitizeTree(targetpath, prefix='fusion')
# TODO: remove flattenTree when subchapters are supported
@@ -1593,6 +1602,9 @@ def makeBook(source, qtgui=None, job_progress=''):
removeNonImages(os.path.join(path, "OEBPS", "Images"))
detectSuboptimalProcessing(os.path.join(path, "OEBPS", "Images"), source)
chapterNames, cover_path = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
if options.filefusion:
# Strip the fusion_0001_ sort prefix from makeFusion if present
chapterNames = {k: sub(r'^fusion_\d{4}_', '', v) for k, v in chapterNames.items()}
cover = None
if not options.webtoon:
cover = image.Cover(cover_path, options)