修复自定义词文件写入问题

This commit is contained in:
zhoushuaikang 2024-02-29 16:36:32 +08:00
parent a04a8e68e6
commit 1b901535ab
3 changed files with 12 additions and 38 deletions

View File

@ -350,18 +350,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow, QCursorGif):
def set_my_info(self, wxid):
self.avatar = QPixmap()
try:
img_bytes = misc_db.get_avatar_buffer(wxid)
except:
logger.error(f'数据库错误:\n{traceback.format_exc()}')
QMessageBox.critical(self, "数据库错误", "请重启电脑后重试")
close_db()
import shutil
try:
shutil.rmtree(DB_DIR)
except:
pass
return
if not img_bytes:
return
if img_bytes[:4] == b'\x89PNG':
@ -377,7 +366,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow, QCursorGif):
shutil.rmtree(DB_DIR)
except:
pass
QMessageBox.critical(self, "数据库错误", "请重启电脑后重试")
QMessageBox.critical(self, "数据库错误", "数据库错误请删除app文件夹后重启电脑再运行软件")
return
me = Me()
me.set_avatar(img_bytes)

View File

@ -250,17 +250,9 @@ class DecryptThread(QThread):
import shutil
if os.path.exists(target_database):
os.remove(target_database)
try:
shutil.copy2(os.path.join(DB_DIR, 'MSG0.db'), target_database) # 使用一个数据库文件作为模板
except FileNotFoundError:
logger.error(traceback.format_exc())
self.errorSignal.emit(True)
# 合并数据库
try:
merge_databases(source_databases, target_database)
except FileNotFoundError:
logger.error(traceback.format_exc())
QMessageBox.critical("错误", "数据库不存在\n请检查微信版本是否为最新")
# 音频数据库文件
target_database = os.path.join(DB_DIR, 'MediaMSG.db')
@ -268,17 +260,10 @@ class DecryptThread(QThread):
if os.path.exists(target_database):
os.remove(target_database)
source_databases = [os.path.join(DB_DIR, f"MediaMSG{i}.db") for i in range(1, 50)]
try:
shutil.copy2(os.path.join(DB_DIR, 'MediaMSG0.db'), target_database) # 使用一个数据库文件作为模板
except FileNotFoundError:
logger.error(traceback.format_exc())
self.errorSignal.emit(True)
# 合并数据库
try:
merge_MediaMSG_databases(source_databases, target_database)
except FileNotFoundError:
logger.error(traceback.format_exc())
QMessageBox.critical("错误", "数据库不存在\n请检查微信版本是否为最新")
self.okSignal.emit('ok')
# self.signal.emit('100')

View File

@ -122,11 +122,11 @@ class SettingControl(QWidget, Ui_Form):
f.write(stopwords)
if os.path.exists('./app/data/new_words.txt'):
with open('./app/data/new_words.txt', 'r', encoding='utf-8') as f:
stopwords = set(f.read().splitlines())
new_words = set(f.read().splitlines())
self.plainTextEdit_newword.setPlainText(' '.join(new_words))
else:
self.plainTextEdit_newword.setPlainText(' '.join(new_words))
stopwords = '\n'.join(stopwords)
stopwords = '\n'.join(new_words)
with open('./app/data/new_words.txt', 'w', encoding='utf-8') as f:
f.write(stopwords)