whenexits

This commit is contained in:
恍兮惚兮 2024-08-08 14:12:04 +08:00
parent 54df5ba959
commit 2615f5ff2c
22 changed files with 73 additions and 31 deletions

View File

@ -28,6 +28,7 @@ from myutils.wrapper import (
from myutils.utils import ( from myutils.utils import (
find_or_create_uid, find_or_create_uid,
str2rgba, str2rgba,
duplicateconfig,
get_time_stamp, get_time_stamp,
gamdidchangedtask, gamdidchangedtask,
checkpostlangmatch, checkpostlangmatch,
@ -1729,7 +1730,7 @@ def startgamecheck(self, gameuid):
startgame(gameuid) startgame(gameuid)
def addgamesingle(callback, targetlist): def addgamesingle(parent, callback, targetlist):
f = QFileDialog.getOpenFileName(options=QFileDialog.Option.DontResolveSymlinks) f = QFileDialog.getOpenFileName(options=QFileDialog.Option.DontResolveSymlinks)
res = f[0] res = f[0]
@ -1739,9 +1740,19 @@ def addgamesingle(callback, targetlist):
uid = find_or_create_uid(targetlist, res) uid = find_or_create_uid(targetlist, res)
if uid in targetlist: if uid in targetlist:
idx = targetlist.index(uid) idx = targetlist.index(uid)
if idx == 0: response = QMessageBox.question(
return parent,
targetlist.pop(idx) "",
_TR("游戏已存在,是否重复添加?"),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
if response == QMessageBox.StandardButton.No:
if idx == 0:
return
targetlist.pop(idx)
else:
uid = duplicateconfig(uid)
targetlist.insert(0, uid) targetlist.insert(0, uid)
callback(uid) callback(uid)
@ -1904,7 +1915,7 @@ class dialog_savedgame_new(QWidget):
addgamebatch(self.addgame, self.reflist) addgamebatch(self.addgame, self.reflist)
def clicked3(self): def clicked3(self):
addgamesingle(self.addgame, self.reflist) addgamesingle(self, self.addgame, self.reflist)
def tagschanged(self, tags): def tagschanged(self, tags):
self.currtags = tags self.currtags = tags
@ -2365,7 +2376,7 @@ class dialog_savedgame_lagacy(QWidget):
self.newline(0, uid) self.newline(0, uid)
self.table.setCurrentIndex(self.model.index(0, 0)) self.table.setCurrentIndex(self.model.index(0, 0))
addgamesingle(call, savehook_new_list) addgamesingle(self, call, savehook_new_list)
def clicked(self): def clicked(self):
startgamecheck( startgamecheck(
@ -3462,7 +3473,7 @@ class dialog_savedgame_v3(QWidget):
addgamebatch(self.addgame, getreflist(self.reftagid)) addgamebatch(self.addgame, getreflist(self.reftagid))
def clicked3(self): def clicked3(self):
addgamesingle(self.addgame, getreflist(self.reftagid)) addgamesingle(self, self.addgame, getreflist(self.reftagid))
def clicked(self): def clicked(self):
startgamecheck(self, self.currentfocusuid) startgamecheck(self, self.currentfocusuid)

View File

@ -2,7 +2,7 @@ import windows
import os, time import os, time
import codecs, hashlib, shutil import codecs, hashlib, shutil
import socket, gobject, uuid, subprocess, functools import socket, gobject, uuid, subprocess, functools
import ctypes, importlib import ctypes, importlib, json
import ctypes.wintypes import ctypes.wintypes
from qtsymbols import * from qtsymbols import *
from traceback import print_exc from traceback import print_exc
@ -249,6 +249,12 @@ def initanewitem(title):
return uid return uid
def duplicateconfig(uidold):
uid = f"{time.time()}_{uuid.uuid4()}"
savehook_new_data[uid] = json.loads(json.dumps(savehook_new_data[uidold]))
return uid
def find_or_create_uid(targetlist, gamepath, title=None): def find_or_create_uid(targetlist, gamepath, title=None):
uids = findgameuidofpath(gamepath, findall=True) uids = findgameuidofpath(gamepath, findall=True)
if len(uids) == 0: if len(uids) == 0:
@ -263,10 +269,15 @@ def find_or_create_uid(targetlist, gamepath, title=None):
trysearchforid(uid, [title] + guessmaybetitle(gamepath, title)) trysearchforid(uid, [title] + guessmaybetitle(gamepath, title))
return uid return uid
else: else:
intarget = uids[0]
index = len(targetlist)
for uid in uids: for uid in uids:
if uid in targetlist: if uid in targetlist:
return uid thisindex = targetlist.index(uid)
return uids[0] if thisindex < index:
index = thisindex
intarget = uid
return intarget
kanjichs2ja = str.maketrans(static_data["kanjichs2ja"]) kanjichs2ja = str.maketrans(static_data["kanjichs2ja"])
@ -517,7 +528,7 @@ def parsemayberegexreplace(lst: list, line: str):
if escape: if escape:
line = line.replace( line = line.replace(
codecs.escape_decode(bytes(key, "utf-8"))[0].decode("utf-8"), codecs.escape_decode(bytes(key, "utf-8"))[0].decode("utf-8"),
codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8") codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8"),
) )
else: else:
line = line.replace(key, value) line = line.replace(key, value)

View File

@ -852,5 +852,6 @@
"作用于翻译": "العمل على الترجمة", "作用于翻译": "العمل على الترجمة",
"字符串替换": "سلسلة استبدال", "字符串替换": "سلسلة استبدال",
"转义": "هروب", "转义": "هروب",
"不推荐使用": "لا ينصح باستخدام" "不推荐使用": "لا ينصح باستخدام",
"游戏已存在,是否重复添加?": "اللعبة موجودة بالفعل ، هل تريد تكرار ذلك ؟"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "作用於翻譯", "作用于翻译": "作用於翻譯",
"字符串替换": "字串替換", "字符串替换": "字串替換",
"转义": "轉義", "转义": "轉義",
"不推荐使用": "不推薦使用" "不推荐使用": "不推薦使用",
"游戏已存在,是否重复添加?": "遊戲已存在,是否重複添加?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Použití na překlad", "作用于翻译": "Použití na překlad",
"字符串替换": "Náhrada řetězce", "字符串替换": "Náhrada řetězce",
"转义": "Útěk", "转义": "Útěk",
"不推荐使用": "Nedoporučuje se k použití" "不推荐使用": "Nedoporučuje se k použití",
"游戏已存在,是否重复添加?": "Hra již existuje, chtěli byste ji znovu přidat?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Auf Übersetzungen angewendet", "作用于翻译": "Auf Übersetzungen angewendet",
"字符串替换": "Zeichenfolgenersatz", "字符串替换": "Zeichenfolgenersatz",
"转义": "Flucht", "转义": "Flucht",
"不推荐使用": "Nicht empfohlen für die Anwendung" "不推荐使用": "Nicht empfohlen für die Anwendung",
"游戏已存在,是否重复添加?": "Das Spiel existiert bereits, möchtest du es noch einmal hinzufügen?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Applied to translation", "作用于翻译": "Applied to translation",
"字符串替换": "String replacement", "字符串替换": "String replacement",
"转义": "Escaping", "转义": "Escaping",
"不推荐使用": "Not recommended for use" "不推荐使用": "Not recommended for use",
"游戏已存在,是否重复添加?": "The game already exists, would you like to add it again?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Actuar sobre la traducción", "作用于翻译": "Actuar sobre la traducción",
"字符串替换": "Reemplazo de cadenas", "字符串替换": "Reemplazo de cadenas",
"转义": "Transliteración", "转义": "Transliteración",
"不推荐使用": "No se recomienda usar" "不推荐使用": "No se recomienda usar",
"游戏已存在,是否重复添加?": "¿El juego ya existe, ¿ se repite la adición?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Agir sur la traduction", "作用于翻译": "Agir sur la traduction",
"字符串替换": "Remplacement de chaîne", "字符串替换": "Remplacement de chaîne",
"转义": "échappement", "转义": "échappement",
"不推荐使用": "Utilisation non recommandée" "不推荐使用": "Utilisation non recommandée",
"游戏已存在,是否重复添加?": "Le jeu existe déjà, y a - t - il des ajouts répétés?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Applicato alla traduzione", "作用于翻译": "Applicato alla traduzione",
"字符串替换": "Sostituzione stringa", "字符串替换": "Sostituzione stringa",
"转义": "Scappare", "转义": "Scappare",
"不推荐使用": "Non raccomandato per l'uso" "不推荐使用": "Non raccomandato per l'uso",
"游戏已存在,是否重复添加?": "Il gioco esiste già, vuoi aggiungerlo di nuovo?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "翻訳に役立つ", "作用于翻译": "翻訳に役立つ",
"字符串替换": "文字列置換", "字符串替换": "文字列置換",
"转义": "エスケープ", "转义": "エスケープ",
"不推荐使用": "使用を推奨しない" "不推荐使用": "使用を推奨しない",
"游戏已存在,是否重复添加?": "ゲームは既に存在します。追加を繰り返しますか?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "번역에 적용", "作用于翻译": "번역에 적용",
"字符串替换": "문자열 대체", "字符串替换": "문자열 대체",
"转义": "전의", "转义": "전의",
"不推荐使用": "권장하지 않음" "不推荐使用": "권장하지 않음",
"游戏已存在,是否重复添加?": "게임이 이미 존재합니다. 다시 추가하시겠습니까?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Toegepast op vertaling", "作用于翻译": "Toegepast op vertaling",
"字符串替换": "Vervanging van tekenreeks", "字符串替换": "Vervanging van tekenreeks",
"转义": "Ontsnappen", "转义": "Ontsnappen",
"不推荐使用": "Niet aanbevolen voor gebruik" "不推荐使用": "Niet aanbevolen voor gebruik",
"游戏已存在,是否重复添加?": "Het spel bestaat al, wil je het opnieuw toevoegen?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Zastosowanie do tłumaczenia", "作用于翻译": "Zastosowanie do tłumaczenia",
"字符串替换": "Zastąpienie ciągu", "字符串替换": "Zastąpienie ciągu",
"转义": "Ucieczka", "转义": "Ucieczka",
"不推荐使用": "Nie zaleca się stosowania" "不推荐使用": "Nie zaleca się stosowania",
"游戏已存在,是否重复添加?": "Gra już istnieje, chcesz dodać ją ponownie?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Aplicado à tradução", "作用于翻译": "Aplicado à tradução",
"字符串替换": "Substituição de strings", "字符串替换": "Substituição de strings",
"转义": "Escapar", "转义": "Escapar",
"不推荐使用": "Não recomendado para utilização" "不推荐使用": "Não recomendado para utilização",
"游戏已存在,是否重复添加?": "O jogo já existe, você gostaria de adicioná-lo novamente?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Роль перевода", "作用于翻译": "Роль перевода",
"字符串替换": "Замена строки", "字符串替换": "Замена строки",
"转义": "Транслитерация", "转义": "Транслитерация",
"不推荐使用": "Не рекомендуется использовать" "不推荐使用": "Не рекомендуется использовать",
"游戏已存在,是否重复添加?": "Игра уже существует, добавляется ли повторно?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Tillämpad på översättning", "作用于翻译": "Tillämpad på översättning",
"字符串替换": "Strängersättning", "字符串替换": "Strängersättning",
"转义": "Flykt", "转义": "Flykt",
"不推荐使用": "Rekommenderas inte för användning" "不推荐使用": "Rekommenderas inte för användning",
"游戏已存在,是否重复添加?": "Spelet finns redan, vill du lägga till det igen?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "บทบาทในการแปล", "作用于翻译": "บทบาทในการแปล",
"字符串替换": "การแทนที่สตริง", "字符串替换": "การแทนที่สตริง",
"转义": "แปลความหมาย", "转义": "แปลความหมาย",
"不推荐使用": "ไม่แนะนำให้ใช้" "不推荐使用": "ไม่แนะนำให้ใช้",
"游戏已存在,是否重复添加?": "มีเกมอยู่แล้วคุณต้องการเพิ่มซ้ำหรือไม่?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Çevirmeye uygulandı", "作用于翻译": "Çevirmeye uygulandı",
"字符串替换": "String Replacement", "字符串替换": "String Replacement",
"转义": "Kaçmak", "转义": "Kaçmak",
"不推荐使用": "Kullanmak için önerilmez" "不推荐使用": "Kullanmak için önerilmez",
"游戏已存在,是否重复添加?": "Oyun zaten var, tekrar eklemek ister misiniz?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Застосовано до перекладу", "作用于翻译": "Застосовано до перекладу",
"字符串替换": "Заміна рядків", "字符串替换": "Заміна рядків",
"转义": "Бег", "转义": "Бег",
"不推荐使用": "Не рекомендується використовувати" "不推荐使用": "Не рекомендується використовувати",
"游戏已存在,是否重复添加?": "Гра вже існує, бажаєте додати її знову?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "Hành động để dịch", "作用于翻译": "Hành động để dịch",
"字符串替换": "Thay thế chuỗi", "字符串替换": "Thay thế chuỗi",
"转义": "Thoát", "转义": "Thoát",
"不推荐使用": "Không khuyến khích sử dụng" "不推荐使用": "Không khuyến khích sử dụng",
"游戏已存在,是否重复添加?": "Trò chơi đã tồn tại, có được thêm nhiều lần không?"
} }

View File

@ -852,5 +852,6 @@
"作用于翻译": "", "作用于翻译": "",
"字符串替换": "", "字符串替换": "",
"转义": "", "转义": "",
"不推荐使用": "" "不推荐使用": "",
"游戏已存在,是否重复添加?": ""
} }