diff --git a/.idea/WeChatMsg.iml b/.idea/WeChatMsg.iml
index aad402c..ec63674 100644
--- a/.idea/WeChatMsg.iml
+++ b/.idea/WeChatMsg.iml
@@ -4,7 +4,4 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c863de7..c369a83 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,18 +4,24 @@
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
@@ -27,8 +33,8 @@
-
+
@@ -170,7 +176,7 @@
-
+
@@ -182,7 +188,28 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -233,34 +260,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -276,27 +282,6 @@
1672848140146
-
- 1699797862964
-
-
-
- 1699797862964
-
-
- 1699883702805
-
-
-
- 1699883702806
-
-
- 1699884085863
-
-
-
- 1699884085863
-
1699973547832
@@ -619,7 +604,28 @@
1701272464442
-
+
+ 1701353500149
+
+
+
+ 1701353500149
+
+
+ 1701354905621
+
+
+
+ 1701354905621
+
+
+ 1701361381301
+
+
+
+ 1701361381302
+
+
@@ -655,9 +661,6 @@
-
-
-
@@ -680,7 +683,10 @@
-
+
+
+
+
@@ -702,6 +708,21 @@
103
+
+ file://$PROJECT_DIR$/app/DataBase/msg.py
+ 104
+
+
+
+ file://$PROJECT_DIR$/app/DataBase/misc.py
+ 64
+
+
+
+ file://$PROJECT_DIR$/app/ui_pc/tool/pc_decrypt/pc_decrypt.py
+ 201
+
+
diff --git a/app/DataBase/__init__.py b/app/DataBase/__init__.py
index 94ae7f2..ec2c05a 100644
--- a/app/DataBase/__init__.py
+++ b/app/DataBase/__init__.py
@@ -7,7 +7,15 @@
@Version : Python3.10
@comment : ···
"""
+from .hard_link import HardLink
+from .micro_msg import MicroMsg
# from . import data
# from . import output
+from .misc import Misc
+from .msg import Msg
-__all__ = ["data", 'output']
+misc_db = Misc()
+msg_db = Msg()
+micro_msg_db = MicroMsg()
+hard_link_db = HardLink()
+__all__ = ["data", 'output', 'misc_db', 'micro_msg_db', 'msg_db', 'hard_link_db']
diff --git a/app/DataBase/hard_link.py b/app/DataBase/hard_link.py
index 4927396..3714028 100644
--- a/app/DataBase/hard_link.py
+++ b/app/DataBase/hard_link.py
@@ -11,44 +11,9 @@ DB = None
cursor = None
db_path = "./app/Database/Msg/HardLinkImage.db"
root_path = 'FileStorage/MsgAttach/'
-if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
-
-
-def init_database():
- global DB
- global cursor
- if not DB:
- if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
-
-
-def get_image_by_md5(md5: bytes):
- sql = '''
- select Md5Hash,MD5,FileName,HardLinkImageID.Dir as DirName1,HardLinkImageID2.Dir as DirName2
- from HardLinkImageAttribute
- join HardLinkImageID on HardLinkImageAttribute.DirID1 = HardLinkImageID.DirID
- join HardLinkImageID as HardLinkImageID2 on HardLinkImageAttribute.DirID2 = HardLinkImageID2.DirID
- where MD5 = ?;
- '''
- try:
- lock.acquire(True)
- try:
- cursor.execute(sql, [md5])
- except AttributeError:
- init_database()
- finally:
- cursor.execute(sql, [md5])
- result = cursor.fetchone()
- return result
- finally:
- lock.release()
+@log
def get_md5_from_xml(content):
# 解析XML
root = ET.fromstring(content)
@@ -58,23 +23,84 @@ def get_md5_from_xml(content):
return md5_value
-@log
-def get_image(content, thumb=False):
- md5 = get_md5_from_xml(content)
- result = get_image_by_md5(binascii.unhexlify(md5))
- if result:
- # print(result)
- dir1 = result[3]
- dir2 = result[4]
- data_image = result[2]
- dir0 = 'Thumb' if thumb else 'Image'
- dat_image = os.path.join(root_path, dir1, dir0, dir2, data_image)
- return dat_image
+def singleton(cls):
+ _instance = {}
+
+ def inner():
+ if cls not in _instance:
+ _instance[cls] = cls()
+ return _instance[cls]
+
+ return inner
-def close():
- if DB:
- DB.close()
+@singleton
+class HardLink:
+ def __init__(self):
+ self.DB = None
+ self.cursor = None
+ self.open_flag = False
+ self.init_database()
+
+ def init_database(self):
+ if not self.open_flag:
+ if os.path.exists(db_path):
+ self.DB = sqlite3.connect(db_path, check_same_thread=False)
+ # '''创建游标'''
+ self.cursor = self.DB.cursor()
+ self.open_flag = True
+ if lock.locked():
+ lock.release()
+
+ def get_image_by_md5(self, md5: bytes):
+ if not md5:
+ return None
+ if not self.open_flag:
+ return None
+ sql = '''
+ select Md5Hash,MD5,FileName,HardLinkImageID.Dir as DirName1,HardLinkImageID2.Dir as DirName2
+ from HardLinkImageAttribute
+ join HardLinkImageID on HardLinkImageAttribute.DirID1 = HardLinkImageID.DirID
+ join HardLinkImageID as HardLinkImageID2 on HardLinkImageAttribute.DirID2 = HardLinkImageID2.DirID
+ where MD5 = ?;
+ '''
+ try:
+ lock.acquire(True)
+ try:
+ self.cursor.execute(sql, [md5])
+ except AttributeError:
+ self.init_database()
+ finally:
+ self.cursor.execute(sql, [md5])
+ result = self.cursor.fetchone()
+ return result
+ finally:
+ lock.release()
+
+ def get_image(self, content, thumb=False):
+ md5 = get_md5_from_xml(content)
+ if not md5:
+ return None
+ result = self.get_image_by_md5(binascii.unhexlify(md5))
+ if result:
+ dir1 = result[3]
+ dir2 = result[4]
+ data_image = result[2]
+ dir0 = 'Thumb' if thumb else 'Image'
+ dat_image = os.path.join(root_path, dir1, dir0, dir2, data_image)
+ return dat_image
+
+ def close(self):
+ if self.open_flag:
+ try:
+ lock.acquire(True)
+ self.open_flag = False
+ self.DB.close()
+ finally:
+ lock.release()
+
+ def __del__(self):
+ self.close()
# 6b02292eecea118f06be3a5b20075afc_t
@@ -82,9 +108,10 @@ def close():
if __name__ == '__main__':
msg_root_path = './Msg/'
db_path = "./Msg/HardLinkImage.db"
- init_database()
+ hard_link_db = HardLink()
+ hard_link_db.init_database()
content = '''\n\t
\n\t\n\t\n\n'''
- print(get_image(content))
- print(get_image(content, thumb=False))
+ print(hard_link_db.get_image(content))
+ print(hard_link_db.get_image(content, thumb=False))
result = get_md5_from_xml(content)
print(result)
diff --git a/app/DataBase/micro_msg.py b/app/DataBase/micro_msg.py
index 106865e..5f00bd2 100644
--- a/app/DataBase/micro_msg.py
+++ b/app/DataBase/micro_msg.py
@@ -5,48 +5,71 @@ import threading
lock = threading.Lock()
DB = None
cursor = None
-micromsg_path = "./app/Database/Msg/MicroMsg.db"
-if os.path.exists(micromsg_path):
- DB = sqlite3.connect(micromsg_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
+db_path = "./app/Database/Msg/MicroMsg.db"
-def init_database():
- global DB
- global cursor
- if not DB:
- if os.path.exists(micromsg_path):
- DB = sqlite3.connect(micromsg_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
+def singleton(cls):
+ _instance = {}
+
+ def inner():
+ if cls not in _instance:
+ _instance[cls] = cls()
+ return _instance[cls]
+
+ return inner
def is_database_exist():
- return os.path.exists(micromsg_path)
+ return os.path.exists(db_path)
-def get_contact():
- try:
- lock.acquire(True)
- sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
- from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
- where Type%2=1 and Alias is not null
- order by PYInitial
- '''
- cursor.execute(sql)
- result = cursor.fetchall()
- finally:
- lock.release()
- # DB.commit()
- return result
+@singleton
+class MicroMsg:
+ def __init__(self):
+ self.DB = None
+ self.cursor = None
+ self.open_flag = False
+ self.init_database()
+ def init_database(self):
+ if not self.open_flag:
+ if os.path.exists(db_path):
+ self.DB = sqlite3.connect(db_path, check_same_thread=False)
+ # '''创建游标'''
+ self.cursor = self.DB.cursor()
+ self.open_flag = True
+ if lock.locked():
+ lock.release()
-def close():
- global DB
- if DB:
- DB.close()
+ def get_contact(self):
+ if not self.open_flag:
+ return None
+ try:
+ lock.acquire(True)
+ sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
+ from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
+ where Type%2=1 and Alias is not null
+ order by PYInitial
+ '''
+ self.cursor.execute(sql)
+ result = self.cursor.fetchall()
+ finally:
+ lock.release()
+ return result
+
+ def close(self):
+ if self.open_flag:
+ try:
+ lock.acquire(True)
+ self.open_flag = False
+ self.DB.close()
+ finally:
+ lock.release()
+
+ def __del__(self):
+ self.close()
if __name__ == '__main__':
- get_contact()
+ pass
+ # get_contact()
diff --git a/app/DataBase/misc.py b/app/DataBase/misc.py
index 29a5221..8691bae 100644
--- a/app/DataBase/misc.py
+++ b/app/DataBase/misc.py
@@ -1,58 +1,79 @@
import os.path
import sqlite3
import threading
-import time
lock = threading.Lock()
DB = None
cursor = None
db_path = "./app/Database/Msg/Misc.db"
-# misc_path = './Msg/Misc.db'
-if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
-def init_database():
- global DB
- global cursor
- if not DB:
- if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
+# db_path = './Msg/Misc.db'
-def get_avatar_buffer(userName):
- sql = '''
- select smallHeadBuf
- from ContactHeadImg1
- where usrName=?;
- '''
- try:
- lock.acquire(True)
+def singleton(cls):
+ _instance = {}
+
+ def inner():
+ if cls not in _instance:
+ _instance[cls] = cls()
+ return _instance[cls]
+
+ return inner
+
+
+@singleton
+class Misc:
+ def __init__(self):
+ self.DB = None
+ self.cursor = None
+ self.open_flag = False
+ self.init_database()
+
+ def init_database(self):
+ if not self.open_flag:
+ if os.path.exists(db_path):
+ self.DB = sqlite3.connect(db_path, check_same_thread=False)
+ # '''创建游标'''
+ self.cursor = self.DB.cursor()
+ self.open_flag = True
+ if lock.locked():
+ lock.release()
+
+ def get_avatar_buffer(self, userName):
+ if not self.open_flag:
+ return None
+ sql = '''
+ select smallHeadBuf
+ from ContactHeadImg1
+ where usrName=?;
+ '''
+ if not self.open_flag:
+ self.init_database()
try:
- cursor.execute(sql, [userName])
- except:
- time.sleep(0.5)
- init_database()
+ lock.acquire(True)
+ self.cursor.execute(sql, [userName])
+ result = self.cursor.fetchall()
+ # print(result[0][0])
+ if result:
+ return result[0][0]
finally:
- cursor.execute(sql, [userName])
- result = cursor.fetchall()
- # print(result[0][0])
- if result:
- return result[0][0]
- finally:
- lock.release()
- return None
+ lock.release()
+ return None
+ def close(self):
+ if self.open_flag:
+ try:
+ lock.acquire(True)
+ self.open_flag = False
+ self.DB.close()
+ finally:
+ lock.release()
-def close():
- global DB
- if DB:
- DB.close()
+ def __del__(self):
+ self.close()
if __name__ == '__main__':
- get_avatar_buffer('wxid_al2oan01b6fn11')
+ Misc()
+ print(Misc().get_avatar_buffer('wxid_al2oan01b6fn11'))
diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py
index ce6ca18..dbd8fac 100644
--- a/app/DataBase/msg.py
+++ b/app/DataBase/msg.py
@@ -1,96 +1,126 @@
import os.path
import sqlite3
import threading
+import traceback
from pprint import pprint
+from app.log import logger
+
DB = None
cursor = None
db_path = "./app/Database/Msg/MSG.db"
lock = threading.Lock()
-# misc_path = './Msg/Misc.db'
-if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
-
def is_database_exist():
return os.path.exists(db_path)
-def init_database():
- global DB
- global cursor
- if not DB:
- if os.path.exists(db_path):
- DB = sqlite3.connect(db_path, check_same_thread=False)
- # '''创建游标'''
- cursor = DB.cursor()
+def singleton(cls):
+ _instance = {}
+
+ def inner():
+ if cls not in _instance:
+ _instance[cls] = cls()
+ return _instance[cls]
+
+ return inner
-def get_messages(username_):
- sql = '''
- select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
- from MSG
- where StrTalker=?
- order by CreateTime
- '''
- try:
- lock.acquire(True)
- cursor.execute(sql, [username_])
- result = cursor.fetchall()
- finally:
- lock.release()
- result.sort(key=lambda x: x[5])
- return result
+@singleton
+class Msg:
+ def __init__(self):
+ self.DB = None
+ self.cursor = None
+ self.open_flag = False
+ self.init_database()
+ def init_database(self):
+ if not self.open_flag:
+ if os.path.exists(db_path):
+ self.DB = sqlite3.connect(db_path, check_same_thread=False)
+ # '''创建游标'''
+ self.cursor = self.DB.cursor()
+ self.open_flag = True
+ if lock.locked():
+ lock.release()
-def get_messages_all():
- sql = '''
- select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
- from MSG
- order by CreateTime
- '''
- try:
- lock.acquire(True)
- cursor.execute(sql)
- result = cursor.fetchall()
- finally:
- lock.release()
- result.sort(key=lambda x: x[5])
- return result
-
-
-def get_message_by_num(username_, local_id):
- sql = '''
+ def get_messages(self, username_):
+ if not self.open_flag:
+ return None
+ sql = '''
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
from MSG
- where StrTalker = ? and localId < ?
- order by CreateTime desc
- limit 10
+ where StrTalker=?
+ order by CreateTime
'''
- try:
- lock.acquire(True)
- cursor.execute(sql, [username_, local_id])
- result = cursor.fetchall()
- finally:
- lock.release()
- # result.sort(key=lambda x: x[5])
- return result
+ try:
+ lock.acquire(True)
+ self.cursor.execute(sql, [username_])
+ result = self.cursor.fetchall()
+ finally:
+ lock.release()
+ result.sort(key=lambda x: x[5])
+ return result
+ def get_messages_all(self):
+ sql = '''
+ select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
+ from MSG
+ order by CreateTime
+ '''
+ if not self.open_flag:
+ return None
+ try:
+ lock.acquire(True)
+ self.cursor.execute(sql)
+ result = self.cursor.fetchall()
+ finally:
+ lock.release()
+ result.sort(key=lambda x: x[5])
+ return result
-def close():
- global DB
- if DB:
- DB.close()
+ def get_message_by_num(self, username_, local_id):
+ sql = '''
+ select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
+ from MSG
+ where StrTalker = ? and localId < ?
+ order by CreateTime desc
+ limit 10
+ '''
+ result = None
+ if not self.open_flag:
+ return None
+ try:
+ lock.acquire(True)
+ self.cursor.execute(sql, [username_, local_id])
+ result = self.cursor.fetchall()
+ except sqlite3.DatabaseError:
+ logger.error(f'{traceback.format_exc()}\n数据库损坏请删除msg文件夹重试')
+ finally:
+ lock.release()
+ # result.sort(key=lambda x: x[5])
+ return result
+
+ def close(self):
+ if self.open_flag:
+ try:
+ lock.acquire(True)
+ self.open_flag = False
+ self.DB.close()
+ finally:
+ lock.release()
+
+ def __del__(self):
+ self.close()
if __name__ == '__main__':
- msg_root_path = './Msg/'
- init_database()
- result = get_message_by_num('wxid_0o18ef858vnu22', 9999999)
+ db_path = "./Msg/MSG.db"
+ msg = Msg()
+ msg.init_database()
+ result = msg.get_message_by_num('wxid_0o18ef858vnu22', 9999999)
print(result)
print(result[-1][0])
local_id = result[-1][0]
- pprint(get_message_by_num('wxid_0o18ef858vnu22', local_id))
+ pprint(msg.get_message_by_num('wxid_0o18ef858vnu22', local_id))
diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py
index 8dead80..94ba7e4 100644
--- a/app/DataBase/output_pc.py
+++ b/app/DataBase/output_pc.py
@@ -4,8 +4,8 @@ import os
from PyQt5.QtCore import pyqtSignal, QThread
-from . import msg
-from ..DataBase import hard_link
+from . import msg_db
+from ..DataBase import hard_link_db
from ..person_pc import MePC
from ..util import get_abs_path
@@ -152,7 +152,7 @@ class ChildThread(QThread):
columns = ['localId', 'TalkerId', 'Type', 'SubType',
'IsSender', 'CreateTime', 'Status', 'StrContent',
'StrTime']
- messages = msg.get_messages(self.contact.wxid)
+ messages = msg_db.get_messages(self.contact.wxid)
# 写入CSV文件
with open(filename, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
@@ -170,7 +170,7 @@ class ChildThread(QThread):
columns = ['localId', 'TalkerId', 'Type', 'SubType',
'IsSender', 'CreateTime', 'Status', 'StrContent',
'StrTime']
- messages = msg.get_messages_all()
+ messages = msg_db.get_messages_all()
# 写入CSV文件
with open(filename, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
@@ -183,7 +183,7 @@ class ChildThread(QThread):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}"
if not os.path.exists(origin_docx_path):
os.mkdir(origin_docx_path)
- messages = msg.get_messages(self.contact.wxid)
+ messages = msg_db.get_messages(self.contact.wxid)
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html"
f = open(filename, 'w', encoding='utf-8')
html_head = '''
@@ -441,7 +441,7 @@ class ChildThread(QThread):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}"
if not os.path.exists(origin_docx_path):
os.mkdir(origin_docx_path)
- messages = msg.get_messages(self.contact.wxid)
+ messages = msg_db.get_messages(self.contact.wxid)
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html"
f = open(filename, 'w', encoding='utf-8')
html_head = '''
@@ -738,7 +738,7 @@ const chatMessages = [
if match:
continue
- image_path = hard_link.get_image(content=str_content, thumb=False)
+ image_path = hard_link_db.get_image(content=str_content, thumb=False)
image_path = get_abs_path(image_path)
image_path = image_path.replace('\\', '/')
# print(f"tohtml:---{image_path}")
diff --git a/app/ui_pc/chat/chat_info.py b/app/ui_pc/chat/chat_info.py
index 1129d61..d9a0378 100644
--- a/app/ui_pc/chat/chat_info.py
+++ b/app/ui_pc/chat/chat_info.py
@@ -3,7 +3,7 @@ import traceback
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
-from app.DataBase import msg, hard_link
+from app.DataBase import msg_db, hard_link_db
from app.components.bubble_message import BubbleMessage, ChatWidget, Notice
from app.person_pc import MePC
from app.util import get_abs_path
@@ -106,7 +106,7 @@ class ChatInfo(QWidget):
time_message = Notice(self.last_str_time)
self.last_str_time = str_time
self.chat_window.add_message_item(time_message, 0)
- image_path = hard_link.get_image(content=str_content, thumb=False)
+ image_path = hard_link_db.get_image(content=str_content, thumb=False)
image_path = get_abs_path(image_path)
bubble_message = BubbleMessage(
image_path,
@@ -146,7 +146,7 @@ class ShowChatThread(QThread):
self.wxid = contact.wxid
def run(self) -> None:
- messages = msg.get_message_by_num(self.wxid, self.last_message_id)
+ messages = msg_db.get_message_by_num(self.wxid, self.last_message_id)
if messages:
self.last_message_id = messages[-1][0]
for message in messages:
diff --git a/app/ui_pc/chat/chat_window.py b/app/ui_pc/chat/chat_window.py
index bd45f4a..e5a6ba1 100644
--- a/app/ui_pc/chat/chat_window.py
+++ b/app/ui_pc/chat/chat_window.py
@@ -1,7 +1,7 @@
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
-from app.DataBase import micro_msg, misc, msg
+from app.DataBase import micro_msg_db, misc_db, msg_db
from app.components import ContactQListWidgetItem
from app.person_pc import ContactPC
from app.ui_pc.Icon import Icon
@@ -72,9 +72,9 @@ class ChatWindow(QWidget, Ui_Form):
def show_chats(self):
if self.ok_flag:
return
- msg.init_database()
- micro_msg.init_database()
- if not msg.is_database_exist():
+ msg_db.init_database()
+ micro_msg_db.init_database()
+ if not msg_db.open_flag:
QMessageBox.critical(self, "错误", "数据库不存在\n请先解密数据库")
self.show_thread = ShowThread()
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
@@ -127,7 +127,7 @@ class ShowContactThread(QThread):
super().__init__()
def run(self) -> None:
- contact_info_lists = micro_msg.get_contact()
+ contact_info_lists = micro_msg_db.get_contact()
for contact_info_list in contact_info_lists:
# UserName, Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl,bigHeadImgUrl
contact_info = {
@@ -139,7 +139,7 @@ class ShowContactThread(QThread):
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
- contact.smallHeadImgBLOG = misc.get_avatar_buffer(contact.wxid)
+ contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
# pprint(contact.__dict__)
diff --git a/app/ui_pc/contact/contact_window.py b/app/ui_pc/contact/contact_window.py
index f18beab..a37177f 100644
--- a/app/ui_pc/contact/contact_window.py
+++ b/app/ui_pc/contact/contact_window.py
@@ -1,7 +1,7 @@
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
-from app.DataBase import micro_msg, misc
+from app.DataBase import micro_msg_db, misc_db
from app.components import ContactQListWidgetItem
from app.person_pc import ContactPC
from app.ui_pc.Icon import Icon
@@ -72,14 +72,15 @@ class ContactWindow(QWidget, Ui_Form):
def show_contacts(self):
if self.ok_flag:
return
- micro_msg.init_database()
- if not micro_msg.is_database_exist():
+ micro_msg_db.init_database()
+ if not micro_msg_db.open_flag:
QMessageBox.critical(self, "错误", "数据库不存在\n请先解密数据库")
self.show_thread = ShowThread()
self.show_thread.showSingal.connect(self.show_contact)
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
self.show_thread.start()
return
+
self.show_thread = ShowContactThread()
self.show_thread.showSingal.connect(self.show_contact)
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
@@ -116,7 +117,7 @@ class ShowContactThread(QThread):
super().__init__()
def run(self) -> None:
- contact_info_lists = micro_msg.get_contact()
+ contact_info_lists = micro_msg_db.get_contact()
for contact_info_list in contact_info_lists:
# UserName, Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl,bigHeadImgUrl
contact_info = {
@@ -128,7 +129,7 @@ class ShowContactThread(QThread):
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
- contact.smallHeadImgBLOG = misc.get_avatar_buffer(contact.wxid)
+ contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
# pprint(contact.__dict__)
diff --git a/app/ui_pc/mainview.py b/app/ui_pc/mainview.py
index 982c504..957eb12 100644
--- a/app/ui_pc/mainview.py
+++ b/app/ui_pc/mainview.py
@@ -15,7 +15,7 @@ from PyQt5.QtGui import QPixmap, QFont, QDesktopServices
from PyQt5.QtWidgets import *
from app import config
-from app.DataBase import msg, misc, micro_msg, hard_link
+from app.DataBase import msg_db, misc_db, micro_msg_db, hard_link_db
from app.ui_pc.Icon import Icon
from . import mainwindow
from .chat import ChatWindow
@@ -119,7 +119,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
myinfo_item = QListWidgetItem(Icon.Home_Icon, '我的', self.listWidget)
tool_window = ToolWindow()
tool_window.get_info_signal.connect(self.set_my_info)
- tool_window.decrypt_success_signal.connect(self.load_data)
+ tool_window.decrypt_success_signal.connect(self.decrypt_success)
tool_window.load_finish_signal.connect(self.loading)
self.stackedWidget.addWidget(tool_window)
self.chat_window = ChatWindow()
@@ -153,9 +153,11 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
def set_my_info(self, wxid):
self.avatar = QPixmap()
try:
- img_bytes = misc.get_avatar_buffer(wxid)
+ img_bytes = misc_db.get_avatar_buffer(wxid)
except AttributeError:
return
+ if not img_bytes:
+ return
if img_bytes[:4] == b'\x89PNG':
self.avatar.loadFromData(img_bytes, format='PNG')
else:
@@ -206,14 +208,18 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
'''
)
+ def decrypt_success(self):
+ QMessageBox.about(self, "解密成功", "请重新启动")
+ self.close()
+
def close(self) -> bool:
- del self.listWidget
- del self.stackedWidget
- misc.close()
- msg.close()
- micro_msg.close()
- hard_link.close()
+ super().close()
+ misc_db.close()
+ msg_db.close()
+ micro_msg_db.close()
+ hard_link_db.close()
self.contact_window.close()
+ self.exitSignal.emit(True)
class LoadWindowThread(QThread):
diff --git a/app/ui_pc/tool/pc_decrypt/decryptUi.py b/app/ui_pc/tool/pc_decrypt/decryptUi.py
index e240b31..889744d 100644
--- a/app/ui_pc/tool/pc_decrypt/decryptUi.py
+++ b/app/ui_pc/tool/pc_decrypt/decryptUi.py
@@ -146,6 +146,9 @@ class Ui_Dialog(object):
self.pushButton_3.setMaximumSize(QtCore.QSize(100, 16777215))
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_2.addWidget(self.pushButton_3)
+ self.label_tip = QtWidgets.QLabel(Dialog)
+ self.label_tip.setObjectName("label_tip")
+ self.horizontalLayout_2.addWidget(self.label_tip)
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem5)
self.verticalLayout.addLayout(self.horizontalLayout_2)
@@ -185,4 +188,5 @@ class Ui_Dialog(object):
self.btn_getinfo.setText(_translate("Dialog", "获取信息"))
self.btn_db_dir.setText(_translate("Dialog", "设置微信路径"))
self.pushButton_3.setText(_translate("Dialog", "开始解密"))
+ self.label_tip.setText(_translate("Dialog", "TextLabel"))
self.label_ready.setText(_translate("Dialog", "未就绪"))
diff --git a/app/ui_pc/tool/pc_decrypt/decryptUi.ui b/app/ui_pc/tool/pc_decrypt/decryptUi.ui
index 43b4513..1f01ccb 100644
--- a/app/ui_pc/tool/pc_decrypt/decryptUi.ui
+++ b/app/ui_pc/tool/pc_decrypt/decryptUi.ui
@@ -319,6 +319,13 @@
+ -
+
+
+ TextLabel
+
+
+
-
diff --git a/app/ui_pc/tool/pc_decrypt/pc_decrypt.py b/app/ui_pc/tool/pc_decrypt/pc_decrypt.py
index b7c4eb3..7958114 100644
--- a/app/ui_pc/tool/pc_decrypt/pc_decrypt.py
+++ b/app/ui_pc/tool/pc_decrypt/pc_decrypt.py
@@ -7,7 +7,7 @@ from PyQt5.QtCore import pyqtSignal, QThread, QUrl, QFile, QIODevice, QTextStrea
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QWidget, QMessageBox, QFileDialog
-from app.DataBase import msg, micro_msg, misc, hard_link
+from app.DataBase import msg_db, misc_db
from app.DataBase.merge import merge_databases
from app.decrypt import get_wx_info, decrypt
from app.log import logger
@@ -29,6 +29,7 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog):
self.lineEdit.returnPressed.connect(self.set_wxid)
self.lineEdit.textChanged.connect(self.set_wxid_)
self.btn_help.clicked.connect(self.show_help)
+ self.label_tip.setVisible(False)
self.info = {}
self.lineEdit.setFocus()
self.ready = False
@@ -125,7 +126,8 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog):
if not os.path.exists(db_dir):
QMessageBox.critical(self, "错误", "文件夹选择错误\n一般以wxid_xxx结尾")
return
-
+ self.label_tip.setVisible(True)
+ self.label_tip.setText('点我之后没有反应那就多等儿吧,不要再点了')
self.thread2 = DecryptThread(db_dir, self.info['key'])
self.thread2.maxNumSignal.connect(self.setProgressBarMaxNum)
self.thread2.signal.connect(self.progressBar_view)
@@ -196,12 +198,10 @@ class DecryptThread(QThread):
pass
def run(self):
- misc.close()
- msg.close()
- micro_msg.close()
- hard_link.close()
- QThread.sleep(1)
- # data.decrypt(self.db_path, self.key)
+ misc_db.close()
+ msg_db.close()
+ # micro_msg_db.close()
+ # hard_link_db.close()
output_dir = 'app/DataBase/Msg'
try:
if not os.path.exists(output_dir):
diff --git a/app/util/path.py b/app/util/path.py
index 13129b4..d6e2c8f 100644
--- a/app/util/path.py
+++ b/app/util/path.py
@@ -24,7 +24,7 @@ def wx_path():
## 获取当前用户名
users = os.path.expandvars('$HOMEPATH')
## 找到3ebffe94.ini配置文件
- f = open(r'C:' + users + '\\AppData\\Roaming\\Tencent\\WeChat\\All Users\\config\\3ebffe94.ini')
+ f = open(r'C:' + users + '\\AppData\\Roaming\\Tencent\\WeChat\\All Users\\config\\3ebffe94.ini', encoding='utf-8')
txt = f.read()
f.close()
# 打开Windows注册表
diff --git a/main_pc.py b/main_pc.py
index cd25342..fd44266 100644
--- a/main_pc.py
+++ b/main_pc.py
@@ -1,10 +1,12 @@
import ctypes
import sys
import time
+import traceback
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
+from app.log import logger
from app.ui_pc import mainview
from app.ui_pc.tool.pc_decrypt import pc_decrypt
@@ -37,11 +39,16 @@ class ViewController(QWidget):
username = ''
start = time.time()
self.viewMainWIndow = mainview.MainWinController(username=username)
- self.viewMainWIndow.setWindowTitle("Chat")
- self.viewMainWIndow.show()
- end = time.time()
- print('ok', end - start)
- self.viewMainWIndow.init_ui()
+ self.viewMainWIndow.exitSignal.connect(self.close)
+ try:
+ self.viewMainWIndow.setWindowTitle("Chat")
+ self.viewMainWIndow.show()
+ end = time.time()
+ print('ok', end - start)
+ self.viewMainWIndow.init_ui()
+ except Exception as e:
+ print(f"Exception: {e}")
+ logger.error(traceback.print_exc())
def show_success(self):
QMessageBox.about(self, "解密成功", "数据库文件存储在\napp/DataBase/Msg\n文件夹下")
@@ -50,8 +57,12 @@ class ViewController(QWidget):
if __name__ == '__main__':
app = QApplication(sys.argv)
view = ViewController()
- # view.loadPCDecryptView()
- view.loadMainWinView()
- # view.show()
- # view.show_success()
- sys.exit(app.exec_())
+ try:
+ # view.loadPCDecryptView()
+ view.loadMainWinView()
+ # view.show()
+ # view.show_success()
+ sys.exit(app.exec_())
+ except Exception as e:
+ print(f"Exception: {e}")
+ logger.error(traceback.print_exc())