diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 637d5bd1..a898ebf7 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -12,7 +12,7 @@ from myutils.config import ( _TR, static_data, ) -import threading +import zipfile from myutils.utils import ( minmaxmoveobservefunc, kanjitrans, @@ -694,11 +694,38 @@ class MAINUI: else: pids = self.textsource.pids if sum([int(pid_running(pid)) for pid in pids]) == 0: + self.safebackupsavedata( + self.textsource.pname, + self.textsource.basename + "_" + self.textsource.md5, + ) self.textsource = None + except: print_exc() + @threader + def safebackupsavedata(self, exe, signame): + path = savehook_new_data[exe]["autosavesavedata"] + if not os.path.exists(path): + return + data_head = time.strftime("%Y-%m-%d-%H-%M-%S.zip", time.localtime()) + savedirbase = globalconfig["backupsavedatato"] + if os.path.exists(savedirbase) == False: + savedirbase = "./cache/backup" + savedir = os.path.join(savedirbase, signame) + os.makedirs(savedir, exist_ok=True) + + def zip_directory(directory_path, output_path): + with zipfile.ZipFile(output_path, "w", zipfile.ZIP_DEFLATED) as zipf: + for root, _, files in os.walk(directory_path): + for file in files: + file_path = os.path.join(root, file) + relative_path = os.path.relpath(file_path, directory_path) + zipf.write(file_path, relative_path) + + zip_directory(path, savedir + "/" + data_head) + def autohookmonitorthread(self): for game in savehook_new_data: checkifnewgame(game) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index 58f05494..6dd407ab 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -7,29 +7,21 @@ import platform, os if __name__ == "__main__": dirname = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(dirname) + for p in ( + "./userconfig/memory", + "./userconfig/memory", + "./userconfig/posts", + "./translation_record", + "./translation_record/cache", + "./cache", + "./cache/ocr", + "./cache/update", + "./cache/screenshot", + "./cache/tts", + "./cache/icon", + ): - if os.path.exists("./userconfig") == False: - os.mkdir("./userconfig") - if os.path.exists("./userconfig/memory") == False: - os.mkdir("./userconfig/memory") - if os.path.exists("./userconfig/posts") == False: - os.mkdir("./userconfig/posts") - if os.path.exists("./translation_record") == False: - os.mkdir("./translation_record") - if os.path.exists("./translation_record/cache") == False: - os.mkdir("./translation_record/cache") - if os.path.exists("./cache") == False: - os.mkdir("./cache") - if os.path.exists("./cache/ocr") == False: - os.mkdir("./cache/ocr") - if os.path.exists("./cache/update") == False: - os.mkdir("./cache/update") - if os.path.exists("./cache/screenshot") == False: - os.mkdir("./cache/screenshot") - if os.path.exists("./cache/tts") == False: - os.mkdir("./cache/tts") - if os.path.exists("./cache/icon") == False: - os.mkdir("./cache/icon") + os.makedirs(p, exist_ok=True) from myutils.config import _TR, static_data, testpriv, globalconfig diff --git a/LunaTranslator/LunaTranslator/gobject.py b/LunaTranslator/LunaTranslator/gobject.py index 7e659049..67bf0e03 100644 --- a/LunaTranslator/LunaTranslator/gobject.py +++ b/LunaTranslator/LunaTranslator/gobject.py @@ -32,12 +32,20 @@ class debugoutput(io.IOBase): self.originfile.flush() -def overridepathexists(): +def dopathexists(file): + if not file: + return False + if not file.strip(): + return False PathFileExists = windll.Shlwapi.PathFileExistsW PathFileExists.argtypes = (wintypes.LPCWSTR,) PathFileExists.restype = wintypes.BOOL + return bool(PathFileExists(os.path.abspath(file))) + + +def overridepathexists(): # win7上,如果假如没有D盘,然后os.path.exists("D:/..."),就会弹窗说不存在D盘 - os.path.exists = lambda file: bool(PathFileExists(os.path.abspath(file))) + os.path.exists = dopathexists def overridestdio(): diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 9ffb1306..4e33da1b 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -580,12 +580,75 @@ class dialog_setting_game(QDialog): methodtab.addTab(self.getttssetting(exepath), _TR("语音")) methodtab.addTab(self.getlabelsetting(exepath), _TR("标签")) methodtab.addTab(self.getstatistic(exepath), _TR("统计信息")) + methodtab.addTab(self.getbackup(exepath), _TR("存档备份")) vbox.addWidget(formwidget) vbox.addWidget(methodtab) self.show() + def selectbackupdir(self, edit): + res = QFileDialog.getExistingDirectory( + directory=edit.text(), + options=QFileDialog.DontResolveSymlinks, + ) + if not res: + return + res = os.path.abspath(res) + edit.setText(res) + + def getbackup(self, exepath): + _w = QWidget() + formLayout = QFormLayout() + _w.setLayout(formLayout) + + editpath = QLineEdit(savehook_new_data[exepath]["autosavesavedata"]) + editpath.textChanged.connect( + lambda _: savehook_new_data[exepath].__setitem__("autosavesavedata", _) + ) + editpath.setReadOnly(True) + formLayout.addRow( + _TR("路径"), + getboxlayout( + [ + editpath, + getcolorbutton( + "", + "", + functools.partial(self.selectbackupdir, editpath), + icon="fa.gear", + constcolor="#FF69B4", + ), + ] + ), + ) + + if os.path.exists(globalconfig["backupsavedatato"]) == False: + globalconfig["backupsavedatato"] = os.path.abspath("./cache/backup") + editpath = QLineEdit(globalconfig["backupsavedatato"]) + editpath.textChanged.connect( + lambda _: globalconfig.__setitem__("backupsavedatato", _) + ) + + editpath.setReadOnly(True) + formLayout.addRow( + _TR("备份到"), + getboxlayout( + [ + editpath, + getcolorbutton( + "", + "", + functools.partial(self.selectbackupdir, editpath), + icon="fa.gear", + constcolor="#FF69B4", + ), + ] + ), + ) + + return _w + def starttab(self, exepath): _w = QWidget() formLayout = QFormLayout() @@ -1260,28 +1323,8 @@ class TagWidget(QWidget): layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) - layout.addWidget(QLabel(_TR("标签"))) - self.setLayout(layout) - - self.lineEdit = QComboBox() - self.lineEdit.setLineEdit(QLineEdit()) - self.lineEdit.lineEdit().returnPressed.connect( - lambda: self.addTag(self.lineEdit.currentText()) - ) - - self.lineEdit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) - - layout.addWidget(self.lineEdit) - self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) - - self.tag2widget = {} - - def refreshcombo(): - self.lineEdit.clear() - self.lineEdit.addItems(globalconfig["labelset"]) - - refreshcombo() + layout.addWidget(QLabel(_TR("过滤"))) layout.addWidget( getcolorbutton( "", @@ -1302,6 +1345,28 @@ class TagWidget(QWidget): constcolor="#FF69B4", ), ) + self.setLayout(layout) + + self.lineEdit = QComboBox() + self.lineEdit.setLineEdit(QLineEdit()) + self.lineEdit.lineEdit().returnPressed.connect( + lambda: self.addTag(self.lineEdit.currentText()) + ) + + self.lineEdit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) + + layout.addWidget(self.lineEdit) + self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) + + self.tag2widget = {} + + def refreshcombo(): + _ = self.lineEdit.currentText() + self.lineEdit.clear() + self.lineEdit.addItems(globalconfig["labelset"]) + self.lineEdit.setCurrentText(_) + + refreshcombo() def addTag(self, tag): try: @@ -1316,7 +1381,7 @@ class TagWidget(QWidget): layout = self.layout() # layout.insertLayout(layout.count() - 1, tagLayout) - layout.insertWidget(layout.count() - 2, qw) + layout.insertWidget(layout.count() - 1, qw) self.tag2widget[tag] = qw self.lineEdit.clearEditText() self.lineEdit.setFocus() diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 008e8563..525bc1dd 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -89,6 +89,7 @@ def getdefaultsavehook(gamepath, title=None): "vndbtags": [], "usertags": [], "traceplaytime_v2": [], # [[start,end]] + "autosavesavedata": "", } if gamepath == "0": default["title"] = "No Game" diff --git a/LunaTranslator/LunaTranslator/myutils/hwnd.py b/LunaTranslator/LunaTranslator/myutils/hwnd.py index 9ccd89cd..07bcd52a 100644 --- a/LunaTranslator/LunaTranslator/myutils/hwnd.py +++ b/LunaTranslator/LunaTranslator/myutils/hwnd.py @@ -25,8 +25,6 @@ def pid_running(pid): @threader def grabwindow(): - tm = time.localtime() - fnamebase = "./cache/screenshot/{}".format(0) try: if gobject.baseobject.textsource.md5 != "0": @@ -37,8 +35,8 @@ def grabwindow(): pass if os.path.exists(fnamebase) == False: os.mkdir(fnamebase) - fname = "{}/{}-{}-{}-{}-{}-{}".format( - fnamebase, tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec + fname = "{}/{}".format( + fnamebase, time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) ) hwnd = windows.FindWindow( diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 4cd3e483..bfb1fa0c 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1245,5 +1245,6 @@ "vndbcache":{ "tagid2name":{} }, - "labelset":[] + "labelset":[], + "backupsavedatato":"" } diff --git a/LunaTranslator/files/defaultconfig/static_data.json b/LunaTranslator/files/defaultconfig/static_data.json index af2a25eb..313cd106 100644 --- a/LunaTranslator/files/defaultconfig/static_data.json +++ b/LunaTranslator/files/defaultconfig/static_data.json @@ -1,5 +1,5 @@ { - "version":"v2.45.1", + "version":"v2.45.2", "themes":{ "dark":[ {"file":"dark1.qss","name":"PyQtDarkTheme"}, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index bd8bc56b..c64957aa 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -756,5 +756,9 @@ "时": "وقت", "禁止自动朗读的人名": "أسماء الأشخاص المحظورين من القراءة التلقائية", "启动": "بدء", - "批量添加": "إضافة دفعة" + "批量添加": "إضافة دفعة", + "过滤": "تصفية", + "备份路径": "مسار النسخ الاحتياطي", + "存档备份": "أرشيف النسخ الاحتياطي", + "备份到": "النسخ الاحتياطي" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 152fccec..a040e75a 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -756,5 +756,9 @@ "时": "時", "禁止自动朗读的人名": "禁止自動朗讀的人名", "启动": "啟動", - "批量添加": "批量添加" + "批量添加": "批量添加", + "过滤": "過濾", + "备份路径": "備份路徑", + "存档备份": "存檔備份", + "备份到": "備份到" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 2cb00b10..833929a2 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -756,5 +756,9 @@ "时": "Time", "禁止自动朗读的人名": "Names that are prohibited from automatic reading", "启动": "start-up", - "批量添加": "Batch Add" + "批量添加": "Batch Add", + "过滤": "filter", + "备份路径": "Backup path", + "存档备份": "Archive backup", + "备份到": "Back up to" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 2acea8fd..88eb71c2 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -756,5 +756,9 @@ "时": "Hora", "禁止自动朗读的人名": "Nombres de personas cuya lectura automática está prohibida", "启动": "Inicio", - "批量添加": "Añadir por lotes" + "批量添加": "Añadir por lotes", + "过滤": "Filtrar", + "备份路径": "Ruta de respaldo", + "存档备份": "Archivo de copias de Seguridad", + "备份到": "Copia de Seguridad a" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index a8e1b86c..bfc9588d 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -756,5 +756,9 @@ "时": "Lorsque", "禁止自动朗读的人名": "Noms de personnes interdits de Lecture automatique", "启动": "Démarrage", - "批量添加": "Ajouter par lot" + "批量添加": "Ajouter par lot", + "过滤": "Filtration", + "备份路径": "Chemin de sauvegarde", + "存档备份": "Sauvegarde archivée", + "备份到": "Sauvegarder à" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 6961e381..3317a5f5 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -756,5 +756,9 @@ "时": "Tempo", "禁止自动朗读的人名": "Nomi vietati dalla lettura automatica", "启动": "avviamento", - "批量添加": "Aggiungi batch" + "批量添加": "Aggiungi batch", + "过滤": "filtro", + "备份路径": "Percorso di backup", + "存档备份": "Archivia backup", + "备份到": "Torna a" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index fc19ee21..acd9164a 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -756,5 +756,9 @@ "时": "時", "禁止自动朗读的人名": "自動朗読禁止の人名", "启动": "スタートアップ", - "批量添加": "一括追加" + "批量添加": "一括追加", + "过滤": "フィルタリング", + "备份路径": "バックアップパス", + "存档备份": "アーカイブバックアップ", + "备份到": "バックアップ先" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index a0be16da..529b9b36 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -756,5 +756,9 @@ "时": "시", "禁止自动朗读的人名": "자동 발음이 금지된 사람 이름", "启动": "시작", - "批量添加": "대량 추가" + "批量添加": "대량 추가", + "过滤": "필터링", + "备份路径": "백업 경로", + "存档备份": "아카이브 백업", + "备份到": "백업 대상" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index c14a7b23..eef6c931 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -756,5 +756,9 @@ "时": "Czas", "禁止自动朗读的人名": "Nazwy, które są zabronione automatycznego odczytu", "启动": "uruchomienie", - "批量添加": "Dodaj partię" + "批量添加": "Dodaj partię", + "过滤": "filtr", + "备份路径": "Ścieżka kopii zapasowej", + "存档备份": "Kopia zapasowa archiwum", + "备份到": "Powrót do" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index 487bc804..29eee08e 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -756,5 +756,9 @@ "时": "Время", "禁止自动朗读的人名": "Имя человека, которое запрещено читать автоматически", "启动": "Запуск", - "批量添加": "Добавление пакетов" + "批量添加": "Добавление пакетов", + "过滤": "Фильтр", + "备份路径": "Путь к резервному копированию", + "存档备份": "Архивное резервное копирование", + "备份到": "Резервное копирование" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index f81dd0bd..671276e5 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -756,5 +756,9 @@ "时": "เวลา", "禁止自动朗读的人名": "ชื่อของบุคคลที่ห้ามอ่านออกเสียงโดยอัตโนมัติ", "启动": "เริ่ม", - "批量添加": "เพิ่มจำนวนมาก" + "批量添加": "เพิ่มจำนวนมาก", + "过滤": "การกรอง", + "备份路径": "เส้นทางการสำรองข้อมูล", + "存档备份": "การสำรองข้อมูลที่เก็บถาวร", + "备份到": "สำรองข้อมูลไปยัง" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index ce9d01da..c23c9929 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -756,5 +756,9 @@ "时": "Zaman", "禁止自动朗读的人名": "Otomatik okuma yasaklanmış isimler", "启动": "start-up", - "批量添加": "Toplu Ekle" + "批量添加": "Toplu Ekle", + "过滤": "filter", + "备份路径": "Yedekleme yolu", + "存档备份": "Arşiv yedekleme", + "备份到": "Geri dön." } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 5d1b122e..13f52653 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -756,5 +756,9 @@ "时": "Час", "禁止自动朗读的人名": "Назви, які заборонені автоматичне читання", "启动": "запуск", - "批量添加": "Додати партію" + "批量添加": "Додати партію", + "过滤": "фільтр", + "备份路径": "Шлях до резервної копії", + "存档备份": "Резервна копія архіву", + "备份到": "Назад до" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 68304efb..35c37bd9 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -756,5 +756,9 @@ "时": "Khi", "禁止自动朗读的人名": "Tên người bị cấm đọc tự động", "启动": "Bắt đầu", - "批量添加": "Thêm hàng loạt" + "批量添加": "Thêm hàng loạt", + "过滤": "Bộ lọc", + "备份路径": "Đường dẫn sao lưu", + "存档备份": "Lưu trữ sao lưu", + "备份到": "Sao lưu vào" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 26f9425f..43a06eea 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -756,5 +756,9 @@ "时": "", "禁止自动朗读的人名": "", "启动": "", - "批量添加": "" + "批量添加": "", + "过滤": "", + "备份路径": "", + "存档备份": "", + "备份到": "" } \ No newline at end of file