From 29e5899647a32411e097bef4635ffa9c93b801f4 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Wed, 18 Mar 2026 01:39:05 -0500 Subject: [PATCH] Clear folders when selecting new projects --- gui/workflow_tab.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gui/workflow_tab.py b/gui/workflow_tab.py index 92713ec..4525f23 100644 --- a/gui/workflow_tab.py +++ b/gui/workflow_tab.py @@ -2123,8 +2123,53 @@ class WorkflowTab(QWidget): if folder: self.folder_edit.setText(folder) self._save_setting("last_game_folder", folder) + self._ask_clear_old_files() self._detect_folder() + def _ask_clear_old_files(self): + """Prompt the user to clear /files and /translated to avoid stale data conflicts.""" + import shutil + + msg = QMessageBox(self) + msg.setWindowTitle("Clear Previous Translation Data?") + msg.setText( + "Do you want to clear the files/ and translated/ folders?\n\n" + "This is recommended when switching to a new game project to avoid " + "old translations conflicting with the new one." + ) + msg.setIcon(QMessageBox.Question) + msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) + msg.setDefaultButton(QMessageBox.Yes) + result = msg.exec_() + + if result != QMessageBox.Yes: + return + + base = Path(__file__).resolve().parent.parent + cleared = [] + errors = [] + for folder_name in ("files", "translated"): + target = base / folder_name + if target.is_dir(): + for child in target.iterdir(): + if child.name == ".gitkeep": + continue + try: + if child.is_dir(): + shutil.rmtree(child) + else: + child.unlink() + cleared.append(child.name) + except Exception as exc: # noqa: BLE001 + errors.append(f"{child.name}: {exc}") + + if cleared: + self._log(f"🗑 Cleared {len(cleared)} item(s) from files/ and translated/.") + else: + self._log("ℹ files/ and translated/ were already empty.") + for err in errors: + self._log(f"⚠ Could not remove {err}") + def _detect_folder(self): folder = self.folder_edit.text().strip() if not folder: