mirror of
https://github.com/LC044/WeChatMsg
synced 2024-11-14 22:01:54 +08:00
增加合并音频数据的代码
This commit is contained in:
parent
abab101821
commit
193ed08e03
@ -1,6 +1,42 @@
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
def merge_MediaMSG_databases(source_paths, target_path):
|
||||
# 创建目标数据库连接
|
||||
target_conn = sqlite3.connect(target_path)
|
||||
target_cursor = target_conn.cursor()
|
||||
try:
|
||||
# 开始事务
|
||||
target_conn.execute("BEGIN;")
|
||||
for i, source_path in enumerate(source_paths):
|
||||
if not os.path.exists(source_path):
|
||||
break
|
||||
db = sqlite3.connect(source_path)
|
||||
db.text_factory = str
|
||||
cursor = db.cursor()
|
||||
sql = '''
|
||||
SELECT Key,Reserved0,Buf,Reserved1,Reserved2 FROM Media;
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
# 附加源数据库
|
||||
target_cursor.executemany(
|
||||
"INSERT INTO Media (Key,Reserved0,Buf,Reserved1,Reserved2)"
|
||||
"VALUES(?,?,?,?,?)",
|
||||
result)
|
||||
cursor.close()
|
||||
db.close()
|
||||
# 提交事务
|
||||
target_conn.execute("COMMIT;")
|
||||
|
||||
except Exception as e:
|
||||
# 发生异常时回滚事务
|
||||
target_conn.execute("ROLLBACK;")
|
||||
raise e
|
||||
|
||||
finally:
|
||||
# 关闭目标数据库连接
|
||||
target_conn.close()
|
||||
|
||||
def merge_databases(source_paths, target_path):
|
||||
# 创建目标数据库连接
|
||||
|
@ -8,7 +8,7 @@ from PyQt5.QtGui import QDesktopServices
|
||||
from PyQt5.QtWidgets import QWidget, QMessageBox, QFileDialog
|
||||
|
||||
from app.DataBase import msg_db, misc_db
|
||||
from app.DataBase.merge import merge_databases
|
||||
from app.DataBase.merge import merge_databases, merge_MediaMSG_databases
|
||||
from app.decrypt import get_wx_info, decrypt
|
||||
from app.log import logger
|
||||
from app.util import path
|
||||
@ -173,7 +173,7 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog):
|
||||
except:
|
||||
with open('./info.json', 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(dic))
|
||||
# 目标数据库文件
|
||||
# 目标数据库文件
|
||||
target_database = "app/DataBase/Msg/MSG.db"
|
||||
# 源数据库文件列表
|
||||
source_databases = [f"app/DataBase/Msg/MSG{i}.db" for i in range(1, 20)]
|
||||
@ -184,6 +184,19 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog):
|
||||
merge_databases(source_databases, target_database)
|
||||
except FileNotFoundError:
|
||||
QMessageBox.critical(self, "错误", "数据库不存在\n请检查微信版本是否为最新")
|
||||
|
||||
# 音频数据库文件
|
||||
target_database = "app/DataBase/Msg/MediaMSG.db"
|
||||
# 源数据库文件列表
|
||||
source_databases = [f"app/DataBase/Msg/MediaMSG{i}.db" for i in range(1, 20)]
|
||||
import shutil
|
||||
shutil.copy("app/DataBase/Msg/MediaMSG0.db", target_database) # 使用一个数据库文件作为模板
|
||||
# 合并数据库
|
||||
try:
|
||||
merge_MediaMSG_databases(source_databases, target_database)
|
||||
except FileNotFoundError:
|
||||
QMessageBox.critical(self, "错误", "数据库不存在\n请检查微信版本是否为最新")
|
||||
|
||||
self.DecryptSignal.emit(True)
|
||||
self.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user