This commit is contained in:
恍兮惚兮 2024-04-12 01:25:13 +08:00
parent 52b4c4fd21
commit a2c88a3ec9
23 changed files with 220 additions and 68 deletions

View File

@ -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)

View File

@ -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

View File

@ -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():

View File

@ -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()

View File

@ -89,6 +89,7 @@ def getdefaultsavehook(gamepath, title=None):
"vndbtags": [],
"usertags": [],
"traceplaytime_v2": [], # [[start,end]]
"autosavesavedata": "",
}
if gamepath == "0":
default["title"] = "No Game"

View File

@ -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(

View File

@ -1245,5 +1245,6 @@
"vndbcache":{
"tagid2name":{}
},
"labelset":[]
"labelset":[],
"backupsavedatato":""
}

View File

@ -1,5 +1,5 @@
{
"version":"v2.45.1",
"version":"v2.45.2",
"themes":{
"dark":[
{"file":"dark1.qss","name":"PyQtDarkTheme"},

View File

@ -756,5 +756,9 @@
"时": "وقت",
"禁止自动朗读的人名": "أسماء الأشخاص المحظورين من القراءة التلقائية",
"启动": "بدء",
"批量添加": "إضافة دفعة"
"批量添加": "إضافة دفعة",
"过滤": "تصفية",
"备份路径": "مسار النسخ الاحتياطي",
"存档备份": "أرشيف النسخ الاحتياطي",
"备份到": "النسخ الاحتياطي"
}

View File

@ -756,5 +756,9 @@
"时": "時",
"禁止自动朗读的人名": "禁止自動朗讀的人名",
"启动": "啟動",
"批量添加": "批量添加"
"批量添加": "批量添加",
"过滤": "過濾",
"备份路径": "備份路徑",
"存档备份": "存檔備份",
"备份到": "備份到"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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 à"
}

View File

@ -756,5 +756,9 @@
"时": "Tempo",
"禁止自动朗读的人名": "Nomi vietati dalla lettura automatica",
"启动": "avviamento",
"批量添加": "Aggiungi batch"
"批量添加": "Aggiungi batch",
"过滤": "filtro",
"备份路径": "Percorso di backup",
"存档备份": "Archivia backup",
"备份到": "Torna a"
}

View File

@ -756,5 +756,9 @@
"时": "時",
"禁止自动朗读的人名": "自動朗読禁止の人名",
"启动": "スタートアップ",
"批量添加": "一括追加"
"批量添加": "一括追加",
"过滤": "フィルタリング",
"备份路径": "バックアップパス",
"存档备份": "アーカイブバックアップ",
"备份到": "バックアップ先"
}

View File

@ -756,5 +756,9 @@
"时": "시",
"禁止自动朗读的人名": "자동 발음이 금지된 사람 이름",
"启动": "시작",
"批量添加": "대량 추가"
"批量添加": "대량 추가",
"过滤": "필터링",
"备份路径": "백업 경로",
"存档备份": "아카이브 백업",
"备份到": "백업 대상"
}

View File

@ -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"
}

View File

@ -756,5 +756,9 @@
"时": "Время",
"禁止自动朗读的人名": "Имя человека, которое запрещено читать автоматически",
"启动": "Запуск",
"批量添加": "Добавление пакетов"
"批量添加": "Добавление пакетов",
"过滤": "Фильтр",
"备份路径": "Путь к резервному копированию",
"存档备份": "Архивное резервное копирование",
"备份到": "Резервное копирование"
}

View File

@ -756,5 +756,9 @@
"时": "เวลา",
"禁止自动朗读的人名": "ชื่อของบุคคลที่ห้ามอ่านออกเสียงโดยอัตโนมัติ",
"启动": "เริ่ม",
"批量添加": "เพิ่มจำนวนมาก"
"批量添加": "เพิ่มจำนวนมาก",
"过滤": "การกรอง",
"备份路径": "เส้นทางการสำรองข้อมูล",
"存档备份": "การสำรองข้อมูลที่เก็บถาวร",
"备份到": "สำรองข้อมูลไปยัง"
}

View File

@ -756,5 +756,9 @@
"时": "Zaman",
"禁止自动朗读的人名": "Otomatik okuma yasaklanmış isimler",
"启动": "start-up",
"批量添加": "Toplu Ekle"
"批量添加": "Toplu Ekle",
"过滤": "filter",
"备份路径": "Yedekleme yolu",
"存档备份": "Arşiv yedekleme",
"备份到": "Geri dön."
}

View File

@ -756,5 +756,9 @@
"时": "Час",
"禁止自动朗读的人名": "Назви, які заборонені автоматичне читання",
"启动": "запуск",
"批量添加": "Додати партію"
"批量添加": "Додати партію",
"过滤": "фільтр",
"备份路径": "Шлях до резервної копії",
"存档备份": "Резервна копія архіву",
"备份到": "Назад до"
}

View File

@ -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"
}

View File

@ -756,5 +756,9 @@
"时": "",
"禁止自动朗读的人名": "",
"启动": "",
"批量添加": ""
"批量添加": "",
"过滤": "",
"备份路径": "",
"存档备份": "",
"备份到": ""
}