Full correctness check against the docs: safer writes, reverts and texts
Safety - Writes are serialized (Workspace.lock): two background jobs rebuilding one package (a sound and its subtitle applied side by side) lost an edit. - A store copies a bank file or package as "original" only if it matches the shipped catalog (Workspace.unoriginal_files: in-memory sounds, bank copies of voice lines, subtitles); the editor refuses to switch stores while changes are applied. A second store could otherwise resurrect a reverted sound. - Mod import in the editor asks before overwriting files changed outside the tool (it forced silently). - Revert all in the editor reverts texts too; the uninstaller counts text edits before offering to delete the store. - ackit restore-backup: the full-backup restore decisions.md described; it keeps the sounds of WADs without a full copy recorded. - build_catalog also stops when a subtitle differs from the catalog. Languages and texts - Game.language() returns languages without voices (JPN, RUS, ...) and Game.voice_archive() their INT voices; ackit text --lang JPN works. - Menu lookups parse one cached file (find & replace: minutes -> ms). - Subtitles decode cp1252 as Windows does: the UTF-8-in-cp1252 line Speech_TAPE_J_Answer_1_00 (KOR/POL/POR/RUS) is written back byte-for-byte; SUB_KOR/SUB_RUS rebuilt from the original game (only those rows changed). - Mods exported while another language is loaded keep name and line. Other fixes - Down-mix folds extra channels in at -3 dB (a 5.1 centre voice was dropped). - e2e_editor no longer overwrites the user's settings.json; kill_game waits for the game to exit before reverts. - Recorder handles Int32/UInt8 input and split frames; package block cache locked; conflict messages, CLI help examples, stale docstrings and doc references fixed; tests no longer read this PC's game language. Docs (decisions, user guide, README, subtitles.md, banks.md, catalog README, REPORT, NOTES, CLAUDE.md) updated; check_docs: 102 claims match. 148 tests; e2e_features 9/9, e2e_editor and verify PASS; game original afterwards.
This commit is contained in:
@@ -163,7 +163,8 @@ class Recorder(QObject):
|
||||
self.chunks = []
|
||||
self.rate = 48000
|
||||
self.channels = 1
|
||||
self.fmt_float = False
|
||||
self.sample = "<i2" # numpy type of the device's samples
|
||||
self._rest = b"" # bytes of an incomplete frame, completed by the next read
|
||||
self._sim = None
|
||||
|
||||
def set_device(self, device):
|
||||
@@ -173,7 +174,7 @@ class Recorder(QObject):
|
||||
return self.source is not None or self._sim is not None
|
||||
|
||||
def start(self):
|
||||
self.chunks = []
|
||||
self.chunks, self._rest = [], b""
|
||||
dev = self.device if (self.device is not None and not self.device.isNull()) else (
|
||||
QMediaDevices.defaultAudioInput() if audio_enabled() else None)
|
||||
if dev is None or dev.isNull():
|
||||
@@ -186,7 +187,8 @@ class Recorder(QObject):
|
||||
if not dev.isFormatSupported(fmt):
|
||||
fmt = dev.preferredFormat()
|
||||
self.rate, self.channels = fmt.sampleRate(), fmt.channelCount()
|
||||
self.fmt_float = fmt.sampleFormat() == QAudioFormat.SampleFormat.Float
|
||||
F = QAudioFormat.SampleFormat
|
||||
self.sample = {F.Float: "<f4", F.Int32: "<i4", F.UInt8: "u1"}.get(fmt.sampleFormat(), "<i2")
|
||||
self.source = QAudioSource(dev, fmt, self)
|
||||
self.io = self.source.start()
|
||||
if self.io is None:
|
||||
@@ -202,13 +204,20 @@ class Recorder(QObject):
|
||||
self._ingest(bytes(self.io.readAll()))
|
||||
|
||||
def _ingest(self, raw):
|
||||
raw = self._rest + raw
|
||||
frame = np.dtype(self.sample).itemsize * self.channels
|
||||
n = len(raw) // frame * frame
|
||||
raw, self._rest = raw[:n], raw[n:]
|
||||
if not raw:
|
||||
return
|
||||
if self.fmt_float:
|
||||
x = np.frombuffer(raw, dtype="<f4")
|
||||
else:
|
||||
x = np.frombuffer(raw[: len(raw) // 2 * 2], dtype="<i2").astype(np.float32) / 32768.0
|
||||
x = x[: len(x) // self.channels * self.channels].reshape(-1, self.channels)
|
||||
x = np.frombuffer(raw, dtype=self.sample)
|
||||
if self.sample == "<i2":
|
||||
x = x.astype(np.float32) / 32768.0
|
||||
elif self.sample == "<i4":
|
||||
x = (x / 2147483648.0).astype(np.float32)
|
||||
elif self.sample == "u1":
|
||||
x = (x.astype(np.float32) - 128.0) / 128.0
|
||||
x = x.reshape(-1, self.channels)
|
||||
self.chunks.append(x)
|
||||
self.level.emit(float(np.max(np.abs(x))) if len(x) else 0.0)
|
||||
self.elapsed.emit(sum(len(c) for c in self.chunks) / float(self.rate))
|
||||
@@ -216,8 +225,8 @@ class Recorder(QObject):
|
||||
# simulated input (tests / no microphone) ----------------------------------------------------
|
||||
def start_simulated(self, x, rate, realtime=True):
|
||||
"""Feed `x` as if it came from a microphone (20 ms blocks)."""
|
||||
self.chunks = []
|
||||
self.rate, self.channels, self.fmt_float = rate, x.shape[1], True
|
||||
self.chunks, self._rest = [], b""
|
||||
self.rate, self.channels, self.sample = rate, x.shape[1], "<f4"
|
||||
blocks = [x[i:i + rate // 50] for i in range(0, len(x), rate // 50)]
|
||||
if not realtime:
|
||||
for b in blocks:
|
||||
|
||||
@@ -100,7 +100,9 @@ class EditorPanel(QWidget):
|
||||
gl.setVerticalSpacing(4)
|
||||
self.wf_orig = self._wave("orig")
|
||||
self.wf_inst = self._wave("inst")
|
||||
self.b_play_orig = self._btn("Original", "play", lambda: self.play("orig"), "Play the original (Space)", icons.STEEL)
|
||||
self.b_play_orig = self._btn("Original", "play", lambda: self.play("orig"),
|
||||
"Play the original (double-click the row; Space until a replacement is loaded)",
|
||||
icons.STEEL)
|
||||
self.b_play_inst = self._btn("Installed", "play", lambda: self.play("inst"), "Play what the game has now", "#8f4a4e")
|
||||
self.b_stop = self._btn("Stop", "stop", self.stop, "Stop (Esc)")
|
||||
# playback options next to the volume: icons with tooltips
|
||||
|
||||
@@ -39,8 +39,7 @@ def editor_languages(game, language=None):
|
||||
"""(language, voices): the selected language (default: the game's) and the speech archive used for it
|
||||
(the language itself, or INT for languages the game has no voices for)."""
|
||||
lang = (language or game.language() or "INT").upper()
|
||||
voices = lang if lang in game.languages else ("INT" if "INT" in game.languages else game.languages[0])
|
||||
return lang, voices
|
||||
return lang, game.voice_archive(lang)
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
@@ -100,7 +99,7 @@ class MainWindow(QMainWindow):
|
||||
tb.addWidget(self.lbl_voices)
|
||||
tb.addSeparator()
|
||||
self.act_revert_all = tb.addAction(icons.icon("revert"), "Revert all", self.revert_all)
|
||||
self.act_revert_all.setToolTip("Put every original sound back")
|
||||
self.act_revert_all.setToolTip("Put every original sound and text back (all languages)")
|
||||
tb.addAction(icons.icon("export"), "Export mod…", self.export_mod_dialog)
|
||||
tb.addAction(icons.icon("import"), "Import mod…", self.import_mod_dialog)
|
||||
tb.addSeparator()
|
||||
@@ -528,35 +527,52 @@ class MainWindow(QMainWindow):
|
||||
"Reverted %d sound(s)." % len(sounds))
|
||||
|
||||
def revert_all(self):
|
||||
"""Every change of this store: sounds, subtitles and menu texts (every language)."""
|
||||
if not self.ws:
|
||||
return
|
||||
n = len(self.ws.store.entries)
|
||||
if not n:
|
||||
self.inform("Revert all", "All sounds are already original.")
|
||||
n, t = len(self.ws.store.entries), len(self.ws.texts.records())
|
||||
if not n and not t:
|
||||
self.inform("Revert all", "All sounds and texts are already original.")
|
||||
return
|
||||
if not self.confirm("Revert all", "Put the original back for all %d changed sound(s)?" % n):
|
||||
if not self.confirm("Revert all", "Put the original back for all %d changed sound(s) and %d changed "
|
||||
"text(s)?" % (n, t)):
|
||||
return
|
||||
self._run_change("Reverting everything…", lambda job: self.ws.revert_all(job.report),
|
||||
"All sounds are original again.")
|
||||
|
||||
def _run_change(self, busy, fn, ok_msg):
|
||||
def work(job):
|
||||
self.ws.revert_all(job.report)
|
||||
self.ws.texts.revert_all(job.report)
|
||||
self._run_change("Reverting everything…", work, "All sounds and texts are original again.")
|
||||
|
||||
def _run_change(self, busy, fn, ok_msg, ask_force=False):
|
||||
"""Run a change as a background job. ask_force: fn(job, force); when files were changed outside this
|
||||
tool, ask the user and run it again with force=True."""
|
||||
self.statusBar().showMessage(busy)
|
||||
self.spinner.show()
|
||||
|
||||
def done(_):
|
||||
self.spinner.hide()
|
||||
self.statusBar().showMessage(ok_msg, 8000)
|
||||
self._after_change()
|
||||
self._texts_changed()
|
||||
if self.editor.sound:
|
||||
self.editor.set_sound(self.editor.sound)
|
||||
self._refresh_after_change()
|
||||
self.check_problems()
|
||||
|
||||
def failed(e, tb):
|
||||
self.spinner.hide()
|
||||
if self.ws:
|
||||
self._refresh_after_change() # part of the change may have been written
|
||||
if ask_force and isinstance(e, (W.ConflictError, TextConflictError)):
|
||||
if self.confirm("Changed outside this tool", "%s\n\nOverwrite them?" % e):
|
||||
self._run_change(busy, lambda job: fn(job, True), ok_msg)
|
||||
return
|
||||
self.inform("Error", str(e))
|
||||
|
||||
self.runner.start(fn, done, failed, lambda m: self.statusBar().showMessage(m))
|
||||
self.runner.start((lambda job: fn(job, False)) if ask_force else fn, done, failed,
|
||||
lambda m: self.statusBar().showMessage(m))
|
||||
|
||||
def _refresh_after_change(self):
|
||||
self._after_change()
|
||||
self._texts_changed()
|
||||
if self.editor.sound:
|
||||
self.editor.set_sound(self.editor.sound)
|
||||
|
||||
# --- changed underneath -----------------------------------------------------------------------
|
||||
def check_problems(self):
|
||||
@@ -628,12 +644,8 @@ class MainWindow(QMainWindow):
|
||||
def forget_problems(self):
|
||||
if not self.confirm("Forget", "Stop tracking these changes? The current game files are kept as they are."):
|
||||
return
|
||||
for s, _ in getattr(self, "problems", []):
|
||||
self.ws.store.forget(s.key)
|
||||
for k, _ in getattr(self, "text_problems", []):
|
||||
self.ws.texts.records().pop(k, None)
|
||||
self.ws.store.save()
|
||||
self.ws.store.gc()
|
||||
self.ws.forget([s.key for s, _ in getattr(self, "problems", [])],
|
||||
[k for k, _ in getattr(self, "text_problems", [])])
|
||||
self.banner.hide()
|
||||
self._after_change()
|
||||
|
||||
@@ -680,25 +692,22 @@ class MainWindow(QMainWindow):
|
||||
if dlg and dlg.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
ws = self.ws
|
||||
prepared = []
|
||||
|
||||
def work(job):
|
||||
prepare_import(ws, path, items, progress=job.report)
|
||||
def work(job, force):
|
||||
if not prepared: # encode once (a confirmed overwrite runs this again)
|
||||
prepare_import(ws, path, items, progress=job.report)
|
||||
prepared.append(True)
|
||||
source = {"source": "mod:" + os.path.basename(path)}
|
||||
changes = [(im.sound, im.wem, source) for im in items if im.wem]
|
||||
if changes:
|
||||
try:
|
||||
ws.apply(changes, progress=job.report)
|
||||
except W.ConflictError:
|
||||
ws.apply(changes, force=True, progress=job.report)
|
||||
ws.apply(changes, force=force, progress=job.report)
|
||||
texts = {k: v for k, v, problem in match_texts(ws, man) if not problem}
|
||||
if texts:
|
||||
try:
|
||||
ws.texts.apply(texts, progress=job.report, meta=source)
|
||||
except TextConflictError:
|
||||
ws.texts.apply(texts, force=True, progress=job.report, meta=source)
|
||||
ws.texts.apply(texts, force=force, progress=job.report, meta=source)
|
||||
return len(changes) + len(texts)
|
||||
|
||||
self._run_change("Installing mod…", work, "Installed %s" % os.path.basename(path))
|
||||
self._run_change("Installing mod…", work, "Installed %s" % os.path.basename(path), ask_force=True)
|
||||
|
||||
# --- settings ---------------------------------------------------------------------------------
|
||||
def settings_dialog(self):
|
||||
@@ -706,7 +715,16 @@ class MainWindow(QMainWindow):
|
||||
if dlg.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
old = dict(self.settings)
|
||||
self.settings.update(dlg.values())
|
||||
new = dlg.values()
|
||||
if self.ws and (new.get("store_root") or None) != (old.get("store_root") or None) and (
|
||||
self.ws.store.entries or self.ws.texts.records()):
|
||||
# the changes are recorded in the current store only; another store would take the modified files
|
||||
# as originals (and could not revert these changes)
|
||||
self.inform("Settings", "The originals store keeps the originals of the changes you have applied. "
|
||||
"Use Revert all before choosing another store folder; the store was not "
|
||||
"changed.")
|
||||
new["store_root"] = old.get("store_root")
|
||||
self.settings.update(new)
|
||||
self.save_settings()
|
||||
self._apply_output_device()
|
||||
self.sidebar.configure(self.settings)
|
||||
|
||||
Reference in New Issue
Block a user