Repository navigation
Expand file tree
/
Copy pathgui.py
More file actions
1352 lines (1209 loc) · 67.4 KB
/
Copy pathgui.py
File metadata and controls
1352 lines (1209 loc) · 67.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""gui.py — local web GUI for the Yakuza (PS2) Python Extractor.
Run me directly:
python3 gui.py (or double-click launch.command / launch.bat / launch.sh)
Stdlib only. Starts an HTTP server on a free localhost port, opens your
browser, and shells out to the kit's command-line scripts for the real
work; their output streams back live via Server-Sent Events. Same shape as
the Xenosaga I/III extractors' GUI: one collapsible card per command, file
pickers, a "show command" dry run, an environment panel, a job list with a
stop button, and a live log.
Everything the GUI does is a command line you could type yourself, so the
two can never disagree; press "Show command" on any card to see it.
"""
from __future__ import annotations
import http.server
import json
import os
import queue
import shlex
import signal
import socket
import socketserver
import string
import subprocess
import sys
import threading
import time
import uuid
import webbrowser
from pathlib import Path
from urllib.parse import parse_qs, unquote, urlparse
ROOT = Path(__file__).resolve().parent
PY = sys.executable or "python3"
KIT_SCRIPTS = ("cli.py", "browse.py", "render.py", "media.py", "repack.py", "blender_open.py")
BROWSE_KINDS = ("textures", "models", "previews", "audio", "sfx", "movies")
# Frozen bundle (build.py / PyInstaller): the GUI exe sits next to yakuza-cli,
# the console dispatcher (tool.py) that runs every script by name.
FROZEN = bool(getattr(sys, "frozen", False))
APP_DIR = Path(sys.executable).resolve().parent if FROZEN else ROOT
CLI_EXE = APP_DIR / ("yakuza-cli.exe" if os.name == "nt" else "yakuza-cli")
sys.path.insert(0, str(ROOT))
try:
from cli import __version__ as VERSION
except Exception: # pragma: no cover - the kit is incomplete; main() reports it
VERSION = "?"
def _fatal(title: str, body: str) -> None:
msg = f"{title}\n\n{body}"
print(f"[gui] FATAL: {msg}", file=sys.stderr)
if os.name == "nt":
try:
import ctypes
ctypes.windll.user32.MessageBoxW(0, body, f"Yakuza Extractor — {title}", 0x10)
except Exception:
pass
elif sys.platform == "darwin":
# A double-clicked .command has no console worth reading — show a dialog too.
try:
esc = body.replace("\\", "\\\\").replace('"', '\\"')
subprocess.run(["osascript", "-e",
f'display dialog "{esc}" with title "Yakuza Extractor — {title}" '
'buttons {"OK"} default button 1 with icon stop'],
timeout=120, check=False)
except Exception:
pass
sys.exit(2)
# ---------------------------------------------------------------------------
# Jobs: one subprocess each, output fanned out to SSE subscribers
# ---------------------------------------------------------------------------
class Job:
def __init__(self, name: str, cmd: list[str], reveal: str | None = None):
self.id = uuid.uuid4().hex[:12]
self.name = name
self.cmd = cmd
self.reveal = reveal
self.started_at = time.time()
self.ended_at: float | None = None
self.exit_code: int | None = None
self.stopped = False
self.lines: list[str] = []
self.subscribers: list[queue.Queue] = []
self._lock = threading.Lock()
popen_kw = {}
if os.name == "nt":
# new group so Stop can taskkill the tree; no console window flashing
# up for every job when the GUI itself is a windowed exe
popen_kw["creationflags"] = (getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
| getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000))
else:
popen_kw["start_new_session"] = True # so Stop can take the worker pool down too
self._proc = subprocess.Popen(cmd, cwd=str(ROOT), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
text=True, bufsize=1, errors="replace",
env={**os.environ, "PYTHONUNBUFFERED": "1"}, **popen_kw)
self.lines.append("$ " + " ".join(shlex.quote(c) for c in cmd))
threading.Thread(target=self._pump, daemon=True).start()
# -- streaming -------------------------------------------------------
def _broadcast(self, line):
with self._lock:
subs = list(self.subscribers)
for q in subs:
try:
q.put_nowait(line)
except queue.Full:
pass
def _pump(self):
for line in self._proc.stdout:
line = line.rstrip("\r\n")
self.lines.append(line)
self._broadcast(line)
rc = self._proc.wait()
self.exit_code = rc
self.ended_at = time.time()
tail = "[stopped]" if self.stopped else f"[exit {rc}] ({self.elapsed():.0f} s)"
self.lines.append(tail)
self._broadcast(tail)
self._broadcast(None)
def subscribe(self):
q = queue.Queue(maxsize=200000)
with self._lock:
self.subscribers.append(q)
for line in self.lines:
try:
q.put_nowait(line)
except queue.Full:
break
if self.ended_at is not None:
q.put_nowait(None)
return q
def unsubscribe(self, q):
with self._lock:
if q in self.subscribers:
self.subscribers.remove(q)
# -- control ---------------------------------------------------------
def stop(self):
if self.exit_code is not None:
return False
self.stopped = True
try:
if os.name == "nt":
subprocess.run(["taskkill", "/T", "/F", "/PID", str(self._proc.pid)], capture_output=True)
else:
os.killpg(os.getpgid(self._proc.pid), signal.SIGTERM)
except (OSError, ProcessLookupError):
try:
self._proc.terminate()
except OSError:
pass
return True
def elapsed(self):
return (self.ended_at or time.time()) - self.started_at
def status(self):
if self.exit_code is None:
return "running"
if self.stopped:
return "stopped"
return "ok" if self.exit_code == 0 else "err"
def to_summary(self):
return {"id": self.id, "name": self.name, "status": self.status(), "exit_code": self.exit_code,
"started": self.started_at, "elapsed": round(self.elapsed(), 1), "reveal": self.reveal,
"cmd": " ".join(shlex.quote(c) for c in self.cmd[1:]), "lines": len(self.lines)}
JOBS: dict[str, Job] = {}
JOBS_LOCK = threading.Lock()
# ---------------------------------------------------------------------------
# Command builders — form fields → argv (+ the folder to reveal afterwards)
# ---------------------------------------------------------------------------
def _s(form, key, default=""):
v = form.get(key, [default])
v = v[0] if isinstance(v, list) else v
return (v or default).strip()
def _bool(form, key):
return _s(form, key).lower() in ("1", "true", "yes", "on")
def _need(form, key, label):
v = _s(form, key)
if not v:
raise ValueError(f"{label} is required")
return v
def _file(form, key, label):
v = Path(_need(form, key, label)).expanduser()
if not v.is_file():
raise ValueError(f"{label}: {v} is not a file")
return str(v)
def _dir(form, key, label, must_exist=True):
v = Path(_need(form, key, label)).expanduser()
if must_exist and not v.is_dir():
raise ValueError(f"{label}: {v} is not a folder")
return str(v)
def _int(form, key, label, default=None):
v = _s(form, key)
if not v:
return default
try:
return int(v)
except ValueError:
raise ValueError(f"{label} must be a whole number, not {v!r}")
def _script(name, *args):
if FROZEN:
return [str(CLI_EXE), name[:-3] if name.endswith(".py") else name, *args]
return [PY, str(ROOT / name), *args]
def layout(work: str) -> dict[str, str]:
"""The fixed folder layout under one work folder (what the README documents)."""
w = Path(work)
d = {"work": str(w), "dump": str(w / "dump"), "browse": str(w / "browse")}
for k in BROWSE_KINDS:
d[k] = str(w / "browse" / k)
return d
def _work(form, need_dump=True):
work = _dir(form, "work", "work folder", must_exist=False)
lay = layout(work)
if need_dump and not Path(lay["dump"]).is_dir():
raise ValueError(f"no dump folder at {lay['dump']} — run Extract first")
return lay
def _common(form):
args = []
f = _s(form, "filter")
if f:
args += ["--filter", f]
j = _int(form, "jobs", "parallel jobs")
if j:
args += ["--jobs", str(j)]
return args
def b_probe(f):
return _script("cli.py", "probe", _file(f, "iso", "ISO")), None
def b_list(f):
cmd = _script("cli.py", "list", _file(f, "iso", "ISO"))
vol = _s(f, "volume")
if vol:
cmd += ["--volume", vol]
flt = _s(f, "filter")
if flt:
cmd += ["--filter", flt]
return cmd, None
def b_census(f):
return _script("cli.py", "census", _file(f, "iso", "ISO")), None
def b_extract(f):
lay = _work(f, need_dump=False)
cmd = _script("cli.py", "extract", _file(f, "iso", "ISO"), "--out", lay["dump"])
flt = _s(f, "filter")
if flt:
cmd += ["--filter", flt]
if _bool(f, "skip_existing"):
cmd.append("--skip-existing")
return cmd, lay["dump"]
def b_verify_dump(f):
lay = _work(f)
cmd = _script("cli.py", "verify-dump", lay["dump"])
iso = _s(f, "iso")
if iso:
cmd += ["--iso", _file(f, "iso", "ISO")]
return cmd, None
def b_convert(f):
lay = _work(f)
kinds = [k for k in BROWSE_KINDS if _bool(f, k)]
if not kinds:
raise ValueError("tick at least one kind to convert")
cmd = _script("cli.py", "convert", "--dump", lay["dump"], "--out", lay["browse"], "--kinds", ",".join(kinds),
*_common(f))
size = _int(f, "size", "preview size")
if size:
cmd += ["--size", str(size)]
return cmd, lay["browse"]
def b_textures(f):
lay = _work(f)
return _script("browse.py", "textures", lay["dump"], lay["textures"], *_common(f)), lay["textures"]
def b_models(f):
lay = _work(f)
return _script("browse.py", "models", lay["dump"], lay["models"], *_common(f)), lay["models"]
def b_previews(f):
lay = _work(f)
if not Path(lay["textures"]).is_dir():
raise ValueError(f"no textures at {lay['textures']} — convert textures first")
cmd = _script("render.py", lay["dump"], lay["textures"], lay["previews"], *_common(f))
size = _int(f, "size", "preview size")
if size:
cmd += ["--size", str(size)]
return cmd, lay["previews"]
def b_blender(f):
lay = _work(f, need_dump=False)
if not Path(lay["models"]).is_dir():
raise ValueError(f"no models at {lay['models']} — convert models first")
target = _s(f, "target") or _s(f, "preset")
if not target:
raise ValueError("pick a preset or type a character set / path")
return _script("blender_open.py", lay["models"], target), None
def _media(kind):
def build(f):
lay = _work(f)
return _script("media.py", kind, lay["dump"], lay[kind], *_common(f)), lay[kind]
return build
def _out_iso(f, src):
out = _s(f, "out")
if not out:
return []
if os.path.abspath(out) == os.path.abspath(src):
raise ValueError("output ISO is the same file as the source — leave it blank to patch in place")
return ["--out", out]
def b_texture(f):
iso = _file(f, "iso", "ISO")
cmd = _script("repack.py", "texture", iso, "--file", _need(f, "file", "in-game path"),
"--leaf", _need(f, "leaf", "leaf path"), "--index", str(_int(f, "index", "texture index", 0)),
"--png", _file(f, "png", "PNG"))
if _bool(f, "fit"):
cmd.append("--fit")
if _bool(f, "allow_grow"):
cmd.append("--allow-grow")
cmd += _out_iso(f, iso)
return cmd, None
def b_patch(f):
iso = _file(f, "iso", "ISO")
cmd = _script("repack.py", "patch", iso, "--file", _need(f, "file", "in-game path"),
"--with", _file(f, "with", "replacement file"))
cmd += _out_iso(f, iso)
return cmd, None
def b_verify_iso(f):
return _script("repack.py", "verify", _file(f, "iso", "ISO")), None
BUILDERS = {
"probe": b_probe, "list": b_list, "census": b_census, "extract": b_extract, "verify-dump": b_verify_dump,
"convert": b_convert, "textures": b_textures, "models": b_models, "previews": b_previews,
"audio": _media("audio"), "sfx": _media("sfx"), "movies": _media("movies"), "blender": b_blender,
"texture": b_texture, "patch": b_patch, "verify-iso": b_verify_iso,
}
# ---------------------------------------------------------------------------
# Detection helpers
# ---------------------------------------------------------------------------
def _walk_for_isos(root: Path, max_depth: int, want: int, out: list[Path]) -> None:
if len(out) >= want or max_depth < 0:
return
try:
entries = sorted(root.iterdir(), key=lambda p: (not p.is_file(), p.name.lower()))
except (OSError, PermissionError):
return
for child in entries:
if len(out) >= want:
return
try:
if child.is_file():
if child.suffix.lower() == ".iso" and child.stat().st_size > 100 * 1024 * 1024:
out.append(child)
elif child.is_dir() and not child.name.startswith("."):
_walk_for_isos(child, max_depth - 1, want, out)
except (OSError, PermissionError):
continue
def detect_isos() -> list[str]:
found: list[Path] = []
for root, depth in ((APP_DIR.parent, 2), (APP_DIR, 1), (Path.home() / "Downloads", 2),
(Path.home() / "Desktop", 3), (Path.home() / "Documents", 3)):
if root.is_dir():
_walk_for_isos(root, depth, want=12, out=found)
seen, out = set(), []
for p in found:
if str(p) not in seen:
seen.add(str(p))
out.append(str(p))
pref = [p for p in out if "yakuza" in Path(p).name.lower() or "slus-21348" in p.lower()]
return pref + [p for p in out if p not in pref]
def default_out_dir(iso: str) -> str:
sibling = APP_DIR.parent / "Yakuza (USA)"
if sibling.is_dir():
return str(sibling)
if iso:
p = Path(iso)
return str(p.parent / (p.stem if "yakuza" in p.stem.lower() else "yakuza-out"))
# no ISO found: never default into the bundle itself
return str((Path.home() if FROZEN else ROOT) / ("Yakuza (USA)" if FROZEN else "out"))
def _blender_path():
try:
import blender_open
return blender_open.blender_exe() or ""
except Exception:
return ""
def _ffmpeg_path():
try:
import media
return media.find_ffmpeg() or ""
except Exception:
import shutil
return shutil.which("ffmpeg") or ""
def _dap_path():
try:
import dap_decode
return getattr(dap_decode, "__file__", "") or "bundled"
except ImportError:
cand = ROOT.parent / "Xenosaga3PythonExtractor" / "dap_decode.py"
return str(cand) if cand.exists() else ""
def kit_present() -> bool:
return CLI_EXE.exists() if FROZEN else all((ROOT / s).exists() for s in KIT_SCRIPTS)
def detect_deps() -> dict:
deps = {"python": sys.version.split()[0], "version": VERSION, "frozen": FROZEN,
"cli": str(CLI_EXE if FROZEN else ROOT / "cli.py"),
"ffmpeg": _ffmpeg_path(), "blender": _blender_path(), "dap_decode": _dap_path(),
"scripts": kit_present()}
for mod, key in (("numpy", "numpy"), ("PIL", "pillow")):
try:
m = __import__(mod)
deps[key] = getattr(m, "__version__", "yes")
except ImportError:
deps[key] = ""
return deps
_PROBE_CACHE: dict[tuple, dict] = {}
def probe_iso(path: str) -> dict:
p = Path(path).expanduser()
if not p.is_file():
return {"error": f"{p} is not a file"}
st = p.stat()
key = (str(p), st.st_size, st.st_mtime)
if key in _PROBE_CACHE:
return _PROBE_CACHE[key]
try:
sys.path.insert(0, str(ROOT))
import cli
res = cli.probe(str(p))
except Exception as exc:
res = {"error": f"{type(exc).__name__}: {exc}", "path": str(p)}
_PROBE_CACHE[key] = res
return res
def reveal(path: str) -> str | None:
p = Path(path).expanduser()
if not p.exists():
return f"{p} does not exist (yet)"
try:
if sys.platform == "darwin":
subprocess.Popen(["open", str(p)])
elif os.name == "nt":
os.startfile(str(p)) # type: ignore[attr-defined]
else:
subprocess.Popen(["xdg-open", str(p)])
except OSError as exc:
return str(exc)
return None
# ---------------------------------------------------------------------------
# Filesystem browser
# ---------------------------------------------------------------------------
def list_roots() -> list[str]:
roots: list[str] = []
if os.name == "nt":
for d in string.ascii_uppercase:
if Path(f"{d}:\\").exists():
roots.append(f"{d}:\\")
else:
roots += ["/", str(Path.home())]
for parent in ("/Volumes", "/mnt", "/media"):
try:
pp = Path(parent)
if pp.is_dir():
roots += [str(c) for c in sorted(pp.iterdir()) if c.is_dir()]
except (OSError, PermissionError):
continue
return list(dict.fromkeys(roots))
def list_dir(path_str: str, ext_filter: str | None = None) -> dict:
p = Path(path_str).expanduser() if path_str else Path.home()
if not p.exists():
p = Path.home()
if not p.is_dir():
p = p.parent
p = p.resolve()
exts = {e.strip().lower().lstrip(".") for e in (ext_filter or "").split(",") if e.strip()}
entries, err = [], None
try:
children = sorted(p.iterdir(), key=lambda x: (not x.is_dir(), x.name.lower()))
except (OSError, PermissionError) as exc:
children, err = [], str(exc)
for c in children:
try:
if c.name.startswith(".") or (c.is_symlink() and not c.exists()):
continue
if c.is_dir():
entries.append({"name": c.name, "type": "dir", "path": str(c)})
else:
if exts and c.suffix.lower().lstrip(".") not in exts:
continue
entries.append({"name": c.name, "type": "file", "path": str(c), "size": c.stat().st_size})
except (OSError, PermissionError):
continue
return {"path": str(p), "parent": str(p.parent) if p.parent != p else None,
"entries": entries[:2000], "roots": list_roots(), "error": err}
# ---------------------------------------------------------------------------
# Page
# ---------------------------------------------------------------------------
INDEX_HTML = r"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>YAKUZA · Extractor</title>
<style>
:root {
--bg-deep: #070608;
--bg-mid: #110c0f;
--bg-card: #19121a;
--bg-input: #0b080a;
--border: rgba(232, 52, 58, 0.18);
--border-strong: rgba(232, 52, 58, 0.45);
--fg: #efe6e3;
--muted: #9a8a8c;
--accent: #e8343a;
--accent-warm: #e9c46a;
--accent-glow: rgba(232, 52, 58, 0.35);
--ok: #62e39a;
--warn: #ffc15d;
--err: #ff6e7f;
--serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Cormorant Garamond", Georgia, serif;
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0; color: var(--fg);
background:
radial-gradient(ellipse 60% 45% at 85% 0%, rgba(232, 52, 58, 0.10) 0%, transparent 70%),
radial-gradient(ellipse 40% 30% at 10% 100%, rgba(233, 196, 106, 0.05) 0%, transparent 70%),
linear-gradient(180deg, var(--bg-deep) 0%, #030204 100%);
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
font-size: 14px; line-height: 1.5; overflow: hidden;
}
body::before {
content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 1000;
background: repeating-linear-gradient(180deg, transparent 0, transparent 2px,
rgba(255, 255, 255, 0.012) 2px, rgba(255, 255, 255, 0.012) 3px);
mix-blend-mode: lighten;
}
header {
padding: 16px 28px; border-bottom: 1px solid var(--border);
display: flex; align-items: center; gap: 22px; position: relative;
background: linear-gradient(180deg, rgba(17, 12, 15, 0.95) 0%, rgba(17, 12, 15, 0.6) 100%);
}
header::after {
content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
background: linear-gradient(90deg, var(--accent) 0%, transparent 60%); opacity: 0.7;
}
header .kanji {
font-family: var(--serif); font-size: 44px; line-height: 1; color: var(--accent);
text-shadow: 0 0 18px var(--accent-glow), 0 0 2px var(--accent); font-weight: 600;
}
header .title { display: flex; flex-direction: column; gap: 3px; line-height: 1; }
header h1 {
margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 500;
letter-spacing: 0.16em; text-transform: uppercase;
}
header h1 .sep { color: var(--accent); margin: 0 0.45em; font-weight: 300; }
header h1 .extractor { font-family: inherit; font-size: 12px; letter-spacing: 0.4em; color: var(--muted); }
header .tagline { color: var(--muted); font-family: var(--serif); font-size: 13.5px; letter-spacing: 0.06em; }
header .tagline b { color: var(--accent-warm); font-weight: 500; }
header .actions { margin-left: auto; display: flex; gap: 8px; }
main { display: grid; grid-template-columns: 1fr 500px; height: calc(100vh - 78px); }
#cards { padding: 18px 28px 80px; overflow-y: auto; }
#cards::-webkit-scrollbar { width: 10px; }
#cards::-webkit-scrollbar-thumb { background: rgba(232, 52, 58, 0.22); border-radius: 5px; }
.group {
font-family: var(--serif); color: var(--accent-warm); font-size: 12px; letter-spacing: 0.3em;
text-transform: uppercase; margin: 22px 0 10px; display: flex; align-items: center; gap: 12px;
}
.group:first-child { margin-top: 4px; }
.group::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--border-strong), transparent); }
#right {
border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
background: linear-gradient(180deg, rgba(25, 18, 26, 0.85) 0%, rgba(11, 8, 10, 0.95) 100%);
}
#right h2 {
font-family: var(--serif); font-size: 13px; font-weight: 500; margin: 12px 16px 6px;
color: var(--accent); text-transform: uppercase; letter-spacing: 0.24em; position: relative; padding-left: 14px;
}
#right h2::before {
content: ''; position: absolute; left: 0; top: 50%; width: 7px; height: 1px;
background: var(--accent); transform: translateY(-50%); box-shadow: 0 0 6px var(--accent-glow);
}
#status-box { padding: 0 16px 10px; }
#status-box .row {
display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 13px;
border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
#status-box .row:last-child { border-bottom: 0; }
#status-box .row span:first-child { color: var(--muted); font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
#status-box .row .v {
font-family: var(--mono); font-size: 12px; color: var(--muted); max-width: 66%;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#status-box .row .v.ok { color: var(--ok); }
#status-box .row .v.bad { color: var(--err); }
#status-box .row .v.warn { color: var(--warn); }
#jobs { padding: 0 10px 8px; max-height: 190px; overflow-y: auto; }
#jobs .empty { color: var(--muted); font-size: 12px; padding: 2px 6px 6px; font-style: italic; }
.job {
display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center;
padding: 5px 6px; border-radius: 3px; cursor: pointer; font-size: 12.5px;
}
.job:hover { background: rgba(232, 52, 58, 0.07); }
.job.current { background: rgba(232, 52, 58, 0.12); outline: 1px solid var(--border-strong); }
.job .name { font-family: var(--serif); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .t { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.job button { padding: 3px 8px; font-size: 10px; }
#log {
flex: 1; margin: 0; padding: 12px 16px; background: #050305; color: #d9c9c6;
font-family: var(--mono); font-size: 12px; line-height: 1.5; overflow-y: auto; white-space: pre-wrap;
border-top: 1px solid var(--border); min-height: 0;
}
#log::-webkit-scrollbar { width: 8px; }
#log::-webkit-scrollbar-thumb { background: rgba(232, 52, 58, 0.25); border-radius: 4px; }
#log .err { color: var(--err); }
.card {
background: linear-gradient(180deg, rgba(25, 18, 26, 0.75) 0%, rgba(17, 12, 15, 0.75) 100%);
border: 1px solid var(--border); border-radius: 5px; padding: 14px 18px; margin-bottom: 10px;
transition: border-color 0.18s, box-shadow 0.18s; position: relative;
}
.card::before {
content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; border-radius: 5px 0 0 5px;
background: transparent; transition: background 0.18s, box-shadow 0.18s;
}
.card.run { border-color: var(--accent); box-shadow: 0 0 22px rgba(232, 52, 58, 0.14); }
.card.run::before { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.card.ok { border-color: rgba(98, 227, 154, 0.4); }
.card.ok::before { background: var(--ok); }
.card.err, .card.stopped { border-color: rgba(255, 110, 127, 0.5); }
.card.err::before { background: var(--err); }
.card.stopped::before { background: var(--warn); }
.card-head { display: flex; align-items: baseline; gap: 12px; cursor: pointer; user-select: none; }
.card-head h3 { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 500; letter-spacing: 0.03em; }
.card-head .step { font-family: var(--serif); color: var(--accent-warm); font-size: 15px; min-width: 28px; }
.card-head .badge {
font-size: 10px; padding: 3px 9px; border-radius: 2px; margin-left: auto;
background: rgba(154, 138, 140, 0.12); color: var(--muted);
text-transform: uppercase; letter-spacing: 0.14em; font-weight: 600;
}
.badge.run { background: rgba(232, 52, 58, 0.2); color: var(--accent); }
.badge.ok { background: rgba(98, 227, 154, 0.18); color: var(--ok); }
.badge.err { background: rgba(255, 110, 127, 0.18); color: var(--err); }
.badge.stopped { background: rgba(255, 193, 93, 0.18); color: var(--warn); }
.card-head .chev { color: var(--muted); transition: transform 0.2s; margin-left: 8px; font-size: 12px; }
.card.open .chev { transform: rotate(180deg); }
.card-body { display: none; margin-top: 12px; }
.card.open .card-body { display: block; }
.card-body p.help { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.card-body p.help code { color: var(--accent-warm); font-size: 12px; }
.card-body p.help em { color: var(--fg); font-style: normal; }
.card .row { display: grid; grid-template-columns: 140px 1fr; gap: 12px; margin-bottom: 8px; align-items: center; }
.card .row label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; }
.card .row .with-pick { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.card .row .check-wrap { display: flex; align-items: center; gap: 10px; }
.card .row .check-wrap span { color: var(--muted); font-size: 12px; }
.card .checks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 14px; margin-bottom: 8px; }
.card .checks label { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--fg); cursor: pointer; }
.card .checks label small { color: var(--muted); }
.card input[type=text], .card select {
width: 100%; background: var(--bg-input); color: var(--fg); border: 1px solid var(--border);
border-radius: 3px; padding: 7px 10px; font: inherit; font-family: var(--mono); font-size: 12.5px;
transition: border-color 0.15s, box-shadow 0.15s;
}
.card input[type=text]:focus, .card select:focus {
outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-glow);
}
.card select option { background: var(--bg-mid); }
.card input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.card .actions { margin-top: 12px; display: flex; gap: 8px; align-items: center; }
.card .actions .note { color: var(--muted); font-size: 12px; margin-left: 6px; }
button {
background: linear-gradient(180deg, #ef4a4f 0%, #b8232a 100%); color: #fff; border: 0;
padding: 8px 16px; border-radius: 3px; font: inherit; font-weight: 600; font-size: 12px;
letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
transition: filter 0.15s, transform 0.05s; box-shadow: 0 0 12px rgba(232, 52, 58, 0.25);
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); font-weight: 500; box-shadow: none; }
button.ghost:hover { background: rgba(232, 52, 58, 0.08); border-color: var(--accent); }
button.gold { background: linear-gradient(180deg, #f1d58a 0%, #c9a24a 100%); color: #2b1d05; box-shadow: 0 0 12px rgba(233, 196, 106, 0.25); }
button.pick {
padding: 6px 12px; font-size: 11px; background: rgba(232, 52, 58, 0.12); color: #f3a0a3;
border: 1px solid var(--border); box-shadow: none; font-weight: 500;
}
button.pick:hover { background: rgba(232, 52, 58, 0.22); border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
code, kbd { background: rgba(233, 196, 106, 0.08); color: var(--accent-warm); border-radius: 2px; padding: 1px 5px; font-family: var(--mono); font-size: 12px; }
/* ---------- file picker modal ---------- */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 2, 4, 0.82); backdrop-filter: blur(4px); animation: fadeIn 0.15s ease-out; }
.modal-window {
position: relative; z-index: 1; background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-mid) 100%);
border: 1px solid var(--border-strong);
box-shadow: 0 0 0 1px var(--border), 0 0 80px rgba(232, 52, 58, 0.18), 0 20px 60px rgba(0,0,0,0.5);
border-radius: 8px; width: 760px; max-width: 92vw; height: 580px; max-height: 88vh;
display: flex; flex-direction: column; animation: slideIn 0.18s ease-out; overflow: hidden;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal-header { padding: 14px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.modal-header h2 { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 500; letter-spacing: 0.05em; }
.modal-header .x { margin-left: auto; background: transparent; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; padding: 0 6px; box-shadow: none; text-transform: none; }
.modal-header .x:hover { color: var(--err); background: transparent; }
.fs-toolbar { padding: 10px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; background: rgba(3, 2, 4, 0.3); }
.fs-crumb { flex: 1; overflow-x: auto; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.fs-crumb a { color: var(--accent-warm); cursor: pointer; padding: 2px 4px; border-radius: 2px; }
.fs-crumb a:hover { background: rgba(232, 52, 58, 0.12); }
.fs-crumb .sep { color: var(--muted); margin: 0 2px; opacity: 0.6; }
.fs-list { flex: 1; overflow-y: auto; padding: 4px 6px; }
.fs-entry { display: flex; align-items: center; gap: 12px; padding: 7px 12px; cursor: pointer; border-radius: 3px; font-size: 13px; }
.fs-entry:hover { background: rgba(232, 52, 58, 0.08); }
.fs-entry.selected { background: rgba(232, 52, 58, 0.18); outline: 1px solid var(--accent); }
.fs-entry .icon { width: 18px; text-align: center; opacity: 0.85; }
.fs-entry .name { flex: 1; }
.fs-entry .size { margin-left: auto; color: var(--muted); font-size: 11px; font-family: var(--mono); }
.fs-empty { padding: 30px; text-align: center; color: var(--muted); font-size: 13px; }
.fs-roots, .fs-quick { padding: 8px 18px; display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; align-items: center; }
.fs-roots { border-top: 1px solid var(--border); }
.fs-quick { border-bottom: 1px solid var(--border); background: rgba(233, 196, 106, 0.03); }
.fs-roots span, .fs-quick span { color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-right: 4px; }
.fs-roots a, .fs-quick a {
color: var(--fg); padding: 3px 9px; border-radius: 2px; border: 1px solid var(--border); cursor: pointer;
font-family: var(--mono); font-size: 11px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
}
.fs-roots a:hover, .fs-quick a:hover, .fs-quick a.selected { background: rgba(232, 52, 58, 0.14); border-color: var(--accent); color: var(--accent-warm); }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; background: rgba(3, 2, 4, 0.3); }
.modal-footer .sel-path { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-footer .sel-path.has { color: var(--fg); }
.modal-error { padding: 8px 18px; color: var(--err); font-size: 12px; background: rgba(255, 110, 127, 0.06); border-bottom: 1px solid rgba(255, 110, 127, 0.2); }
@media (max-width: 1100px) {
main { grid-template-columns: 1fr; grid-template-rows: 1fr 40vh; }
#right { border-left: 0; border-top: 1px solid var(--border); }
}
</style>
</head>
<body>
<header>
<div class="kanji">龍</div>
<div class="title">
<h1><span>Yakuza</span><span class="sep">·</span><span class="extractor">EXTRACTOR</span></h1>
<div class="tagline">龍が如く · Kamurocho disc unpacker · <b>SLUS-21348</b> · <span id="ver"></span></div>
</div>
<div class="actions">
<button class="ghost" id="btn-open-all">Expand all</button>
<button class="ghost" id="btn-refresh">Refresh status</button>
</div>
</header>
<main>
<section id="cards"></section>
<aside id="right">
<h2>Environment</h2>
<div id="status-box"></div>
<h2>Jobs</h2>
<div id="jobs"><div class="empty">nothing run yet</div></div>
<h2>Output</h2>
<pre id="log">Ready. Pick a card on the left; every card shows the exact command it runs.</pre>
</aside>
</main>
<div class="modal" id="fs-modal" hidden>
<div class="modal-backdrop" data-close></div>
<div class="modal-window">
<div class="modal-header"><h2 id="fs-title">Select…</h2><button type="button" class="x" data-close>×</button></div>
<div class="fs-toolbar"><button type="button" class="ghost" id="fs-up">↑ Up</button><div class="fs-crumb" id="fs-crumb"></div></div>
<div class="modal-error" id="fs-error" hidden></div>
<div class="fs-quick" id="fs-quick" hidden></div>
<div class="fs-list" id="fs-list"></div>
<div class="fs-roots" id="fs-roots"></div>
<div class="modal-footer">
<div class="sel-path" id="fs-sel">No selection</div>
<button type="button" class="ghost" data-close>Cancel</button>
<button type="button" id="fs-select" disabled>Select</button>
</div>
</div>
</div>
<script>
const log = document.getElementById('log');
const cardEls = {};
let currentES = null, currentJob = null, detected = {}, jobsTimer = null;
function esc(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[c]); }
function fmtSize(b) { if (b < 1024) return b + ' B'; const u = ['KB','MB','GB','TB']; let v = b / 1024, i = 0; while (v >= 1024 && i < u.length - 1) { v /= 1024; i++; } return v.toFixed(v >= 10 ? 0 : 1) + ' ' + u[i]; }
function fmtDur(s) { s = Math.round(s); return s < 60 ? s + 's' : s < 3600 ? Math.floor(s / 60) + 'm' + String(s % 60).padStart(2, '0') : Math.floor(s / 3600) + 'h' + String(Math.floor(s % 3600 / 60)).padStart(2, '0'); }
function appendLog(line, cls) {
if (cls) { const sp = document.createElement('span'); sp.className = cls; sp.textContent = line + '\n'; log.appendChild(sp); }
else log.appendChild(document.createTextNode(line + '\n'));
log.scrollTop = log.scrollHeight;
}
function setStatus(name, status) {
const el = cardEls[name]; if (!el) return;
el.classList.remove('run', 'ok', 'err', 'stopped'); if (status) el.classList.add(status);
const b = el.querySelector('.badge'); b.classList.remove('run', 'ok', 'err', 'stopped');
b.textContent = status || 'idle'; if (status) b.classList.add(status);
}
// ------------------------------------------------------------------ jobs
function viewJob(id) {
if (currentES) currentES.close();
currentJob = id; log.textContent = '';
const es = new EventSource('/stream/' + id); currentES = es;
es.onmessage = e => {
if (e.data === '__eof__') { es.close(); refreshJobs(); return; }
appendLog(e.data, /^(!|\[error\]|Traceback|\w*Error:)/.test(e.data) ? 'err' : '');
};
es.onerror = () => es.close();
refreshJobs();
}
async function stopJob(id) { await fetch('/stop/' + id, {method: 'POST'}); refreshJobs(); }
async function refreshJobs() {
const jobs = await (await fetch('/jobs')).json();
const box = document.getElementById('jobs');
if (!jobs.length) { box.innerHTML = '<div class="empty">nothing run yet</div>'; return; }
box.innerHTML = jobs.map(j => `<div class="job${j.id === currentJob ? ' current' : ''}" data-id="${j.id}" title="${esc(j.cmd)}">
<span class="name">${esc(j.title || j.name)}</span>
<span class="badge ${j.status}">${j.status}</span>
<span class="t">${fmtDur(j.elapsed)}</span>
${j.status === 'running' ? `<button class="ghost stop" data-id="${j.id}">Stop</button>` :
(j.reveal ? `<button class="ghost reveal" data-path="${esc(j.reveal)}">Open</button>` : '<span></span>')}
</div>`).join('');
box.querySelectorAll('.job').forEach(el => el.addEventListener('click', () => viewJob(el.dataset.id)));
box.querySelectorAll('.stop').forEach(b => b.addEventListener('click', e => { e.stopPropagation(); stopJob(b.dataset.id); }));
box.querySelectorAll('.reveal').forEach(b => b.addEventListener('click', e => { e.stopPropagation(); openFolder(b.dataset.path); }));
jobs.forEach(j => setStatus(j.name, j.status === 'running' ? 'run' : j.status));
const anyRunning = jobs.some(j => j.status === 'running');
clearTimeout(jobsTimer); if (anyRunning) jobsTimer = setTimeout(refreshJobs, 2000);
}
async function openFolder(path) {
const r = await (await fetch('/open', {method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: new URLSearchParams({path})})).json();
if (r.error) appendLog('[open] ' + r.error, 'err');
}
// ------------------------------------------------------------------ runner
async function runCommand(name, body) {
setStatus(name, 'run');
const res = await fetch('/run/' + name, {method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body});
const j = await res.json();
if (!res.ok || j.error) { setStatus(name, 'err'); log.textContent = ''; appendLog('[error] ' + (j.error || res.statusText), 'err'); return; }
viewJob(j.job_id);
}
async function previewCommand(name, body) {
const res = await fetch('/preview/' + name, {method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body});
const j = await res.json();
if (currentES) currentES.close(); currentJob = null; log.textContent = '';
if (j.error) { appendLog('[error] ' + j.error, 'err'); return; }
appendLog('# Would run (from ' + detected.root + '):');
appendLog(j.cmd.map(c => /\s/.test(c) ? '"' + c + '"' : c).join(' '));
if (j.reveal) appendLog('# Output folder: ' + j.reveal);
refreshJobs();
}
// ------------------------------------------------------------------ picker
const fsModal = document.getElementById('fs-modal'), fsTitle = document.getElementById('fs-title'),
fsCrumb = document.getElementById('fs-crumb'), fsList = document.getElementById('fs-list'),
fsRoots = document.getElementById('fs-roots'), fsError = document.getElementById('fs-error'),
fsQuick = document.getElementById('fs-quick'), fsSel = document.getElementById('fs-sel'),
fsSelectBtn = document.getElementById('fs-select'), fsUp = document.getElementById('fs-up');
const fsState = {mode: 'file', filter: null, current: null, parent: null, selected: null, onChoose: null};
function renderQuick() {
const isos = fsState.filter === 'iso' ? (detected.isos || []) : [];
if (!isos.length) { fsQuick.hidden = true; return; }
fsQuick.hidden = false;
fsQuick.innerHTML = '<span>Detected:</span>' + isos.map(p => `<a class="qp" data-path="${esc(p)}" title="${esc(p)}">${esc(p.split(/[\\/]/).pop())}</a>`).join('');
fsQuick.querySelectorAll('.qp').forEach(a => {
a.addEventListener('click', () => { fsQuick.querySelectorAll('.qp').forEach(x => x.classList.remove('selected')); a.classList.add('selected');
fsState.selected = a.dataset.path; fsSel.classList.add('has'); fsSel.textContent = a.dataset.path; fsSelectBtn.disabled = false; });
a.addEventListener('dblclick', () => { fsState.selected = a.dataset.path; chooseAndClose(); });
});
}
function openPicker({mode, filter, startPath, title, onChoose}) {
Object.assign(fsState, {mode, filter: filter || null, current: null, parent: null, selected: null, onChoose});
fsTitle.textContent = title || (mode === 'dir' ? 'Select a folder' : 'Select a file');
fsSel.classList.remove('has'); fsSel.textContent = 'No selection'; fsSelectBtn.disabled = mode === 'file';
fsError.hidden = true; renderQuick(); fsModal.hidden = false; loadDir(startPath || '');
}
function closePicker() { fsModal.hidden = true; fsState.onChoose = null; }
async function loadDir(path) {
fsError.hidden = true;
try {
const qs = new URLSearchParams(); if (path) qs.set('path', path); if (fsState.filter) qs.set('filter', fsState.filter);
const data = await (await fetch('/browse-fs?' + qs)).json();
if (data.error) { fsError.hidden = false; fsError.textContent = data.error; }
fsState.current = data.path; fsState.parent = data.parent; fsState.selected = null;
if (fsState.mode === 'dir') { fsState.selected = data.path; fsSel.classList.add('has'); fsSel.textContent = data.path; fsSelectBtn.disabled = false; }
else { fsSel.classList.remove('has'); fsSel.textContent = 'No selection'; fsSelectBtn.disabled = true; }
fsUp.disabled = !data.parent; renderCrumb(data.path); renderList(data.entries); renderRoots(data.roots);
} catch (err) { fsError.hidden = false; fsError.textContent = 'Error loading directory: ' + err.message; }
}
function renderCrumb(full) {
const win = full.indexOf('\\') >= 0 && full.indexOf('/') < 0;
let parts = win ? full.split('\\').filter(Boolean) : ['/'].concat(full.split('/').filter(Boolean));
if (win && parts.length && /^[A-Z]:$/i.test(parts[0])) parts[0] += '\\';
let acc = '';
fsCrumb.innerHTML = parts.map((p, i) => {
if (!win) acc = i === 0 ? '/' : (acc.endsWith('/') ? acc : acc + '/') + p; else acc = i === 0 ? p : acc + (acc.endsWith('\\') ? '' : '\\') + p;
const a = `<a data-path="${esc(acc)}">${esc(p)}</a>`; return i === parts.length - 1 ? a : a + '<span class="sep">/</span>';
}).join('');
fsCrumb.querySelectorAll('a').forEach(a => a.addEventListener('click', () => loadDir(a.dataset.path)));
}
function renderList(entries) {
if (!entries.length) { fsList.innerHTML = `<div class="fs-empty">(empty${fsState.filter ? ' — no .' + fsState.filter + ' files here' : ''})</div>`; return; }
fsList.innerHTML = entries.map(e => `<div class="fs-entry" data-type="${e.type}" data-path="${esc(e.path)}">
<span class="icon">${e.type === 'dir' ? '📁' : '📄'}</span><span class="name">${esc(e.name)}</span>${e.type === 'file' ? `<span class="size">${fmtSize(e.size)}</span>` : ''}</div>`).join('');
fsList.querySelectorAll('.fs-entry').forEach(el => {
el.addEventListener('click', () => {
if (el.dataset.type === 'dir') loadDir(el.dataset.path);
else if (fsState.mode === 'file') { fsList.querySelectorAll('.selected').forEach(x => x.classList.remove('selected')); el.classList.add('selected');
fsState.selected = el.dataset.path; fsSel.classList.add('has'); fsSel.textContent = el.dataset.path; fsSelectBtn.disabled = false; }
});