Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __pycache__/

# C extensions
*.so

*.exe
# Distribution / packaging
.Python
build/
Expand Down Expand Up @@ -165,4 +165,5 @@ toollib/frame.csv
*.evf
*.mvf
old/
发布流程.txt
发布流程.txt
src/plugins/*/*.json
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pyQt5==5.15.11
ms-toollib==1.5.1
setuptools==78.1.1
setuptools==80.9.0
pyinstaller==6.16.0

msgspec>=0.20.0
zmq>=0.0.0


110 changes: 83 additions & 27 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,50 @@
import ms_toollib as ms
import ctypes
from ctypes import wintypes
from mp_plugins.context import AppContext
from mp_plugins.events import *
from mp_plugins import PluginManager
from pathlib import Path
import os

os.environ["QT_FONT_DPI"] = "96"


# def patch_env():
# import os


# env = os.environ.copy()
# root = os.path.dirname(os.path.abspath(__file__)) # 你的项目根目录
# env["PYTHONPATH"] = root
# return env
def get_paths():
if getattr(sys, "frozen", False):
# 打包成 exe
dir = os.path.dirname(sys.executable) # exe 所在目录
else:
dir = os.path.dirname(os.path.abspath(__file__))

return dir


def patch_env():
import os
import sys

env = os.environ.copy()

if getattr(sys, "frozen", False):
# 打包成 exe,库解压到 _MEIPASS
root = getattr(sys, "_MEIPASS", None)
else:
# 调试模式,库在项目目录
root = os.path.dirname(os.path.abspath(__file__))

env["PYTHONPATH"] = root
return env


def on_new_connection(localServer: QLocalServer):
"""当新连接进来时,接受连接并将文件路径传递给主窗口"""
socket = localServer.nextPendingConnection()
Expand Down Expand Up @@ -53,7 +94,7 @@ def find_window(class_name, window_name):


"""
user32 = ctypes.WinDLL('user32', use_last_error=True)
user32 = ctypes.WinDLL("user32", use_last_error=True)
user32.FindWindowW.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR]
user32.FindWindowW.restype = wintypes.HWND

Expand All @@ -63,36 +104,39 @@ def find_window(class_name, window_name):
return hwnd



def cli_check_file(file_path: str) -> int:
if not os.path.exists(file_path):
print("ERROR: file not found")
return 2

# 搜集目录或文件下的所有evf和evfs文件
evf_evfs_files = []
if os.path.isfile(file_path) and (file_path.endswith('.evf') or file_path.endswith('.evfs')):
if os.path.isfile(file_path) and (
file_path.endswith(".evf") or file_path.endswith(".evfs")
):
evf_evfs_files = [os.path.abspath(file_path)]
elif os.path.isdir(file_path):
evf_evfs_files = [os.path.abspath(os.path.join(root, file))
for root, dirs, files in os.walk(file_path)
for file in files if file.endswith('.evf') or file.endswith('.evfs')]
evf_evfs_files = [
os.path.abspath(os.path.join(root, file))
for root, dirs, files in os.walk(file_path)
for file in files
if file.endswith(".evf") or file.endswith(".evfs")
]

if not evf_evfs_files:
print("ERROR: must be evf or evfs files or directory")
return 2



# 实例化一个MineSweeperGUI出来
app = QtWidgets.QApplication(sys.argv)
mainWindow = mainWindowGUI.MainWindow()
ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv)

for ide, e in enumerate(evf_evfs_files):
if not ui.checksum_module_ok():
print("ERROR: ???")
return 2
if e.endswith('.evf'):
if e.endswith(".evf"):
# 检验evf文件是否合法
video = ms.EvfVideo(e)
try:
Expand All @@ -101,12 +145,13 @@ def cli_check_file(file_path: str) -> int:
evf_evfs_files[ide] = (e, 2)
else:
checksum = ui.checksum_guard.get_checksum(
video.raw_data[:-(len(video.checksum) + 2)])
video.raw_data[: -(len(video.checksum) + 2)]
)
if video.checksum == checksum:
evf_evfs_files[ide] = (e, 0)
else:
evf_evfs_files[ide] = (e, 1)
elif e.endswith('.evfs'):
elif e.endswith(".evfs"):
# 检验evfs文件是否合法
videos = ms.Evfs(e)
try:
Expand All @@ -116,21 +161,22 @@ def cli_check_file(file_path: str) -> int:
else:
if videos.len() <= 0:
evf_evfs_files[ide] = (e, 2)
checksum = ui.checksum_guard.get_checksum(
videos[0].evf_video.raw_data)
checksum = ui.checksum_guard.get_checksum(videos[0].evf_video.raw_data)
if video.checksum != checksum:
evf_evfs_files[ide] = (e, 1)
continue
for idcell, cell in enumerate(videos[1:]):
checksum = ui.checksum_guard.get_checksum(
cell.evf_video.raw_data + videos[idcell - 1].checksum)
cell.evf_video.raw_data + videos[idcell - 1].checksum
)
if cell.evf_file.checksum != checksum:
evf_evfs_files[ide] = (e, 1)
continue
evf_evfs_files[ide] = (e, 0)
print(evf_evfs_files)
return 0



if __name__ == "__main__":
# metaminesweeper.exe -c filename.evf用法,检查文件的合法性
# metaminesweeper.exe -c filename.evfs
Expand All @@ -142,7 +188,11 @@ def cli_check_file(file_path: str) -> int:
if args.check:
exit_code = cli_check_file(args.check)
sys.exit(exit_code)

env = patch_env()
context = AppContext("Metasweeper", "1.0.0", "元扫雷")
PluginManager.instance().context = context

PluginManager.instance().start(Path(get_paths()) / "plugins", env)

app = QtWidgets.QApplication(sys.argv)
serverName = "MineSweeperServer"
Expand All @@ -159,7 +209,8 @@ def cli_check_file(file_path: str) -> int:
localServer = QLocalServer()
localServer.listen(serverName)
localServer.newConnection.connect(
lambda: on_new_connection(localServer=localServer))
lambda: on_new_connection(localServer=localServer)
)
mainWindow = mainWindowGUI.MainWindow()
ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv)
ui.mainWindow.show()
Expand All @@ -169,16 +220,21 @@ def cli_check_file(file_path: str) -> int:
hwnd = find_window(None, _translate("MainWindow", "元扫雷"))

SetWindowDisplayAffinity = ctypes.windll.user32.SetWindowDisplayAffinity
ui.disable_screenshot = lambda: ... if SetWindowDisplayAffinity(
hwnd, 0x00000011) else 1/0
ui.enable_screenshot = lambda: ... if SetWindowDisplayAffinity(
hwnd, 0x00000000) else 1/0
ui.disable_screenshot = lambda: ... if SetWindowDisplayAffinity(
hwnd, 0x00000011) else 1/0
ui.enable_screenshot = lambda: ... if SetWindowDisplayAffinity(
hwnd, 0x00000000) else 1/0
ui.disable_screenshot = lambda: (
... if SetWindowDisplayAffinity(hwnd, 0x00000011) else 1 / 0
)
ui.enable_screenshot = lambda: (
... if SetWindowDisplayAffinity(hwnd, 0x00000000) else 1 / 0
)
ui.disable_screenshot = lambda: (
... if SetWindowDisplayAffinity(hwnd, 0x00000011) else 1 / 0
)
ui.enable_screenshot = lambda: (
... if SetWindowDisplayAffinity(hwnd, 0x00000000) else 1 / 0
)

sys.exit(app.exec_())
PluginManager.instance().stop()
...
# except:
# pass
Expand Down
Loading