|
6 | 6 | from PyQt5.QtNetwork import QLocalSocket, QLocalServer |
7 | 7 | import sys |
8 | 8 | import os |
| 9 | +import argparse |
9 | 10 | import mainWindowGUI as mainWindowGUI |
10 | 11 | import mineSweeperGUI as mineSweeperGUI |
| 12 | +import ms_toollib as ms |
11 | 13 | import ctypes |
12 | 14 | from ctypes import wintypes |
13 | 15 | os.environ["QT_FONT_DPI"] = "96" |
@@ -61,9 +63,87 @@ def find_window(class_name, window_name): |
61 | 63 | return hwnd |
62 | 64 |
|
63 | 65 |
|
| 66 | + |
| 67 | +def cli_check_file(file_path: str) -> int: |
| 68 | + if not os.path.exists(file_path): |
| 69 | + print("ERROR: file not found") |
| 70 | + return 2 |
| 71 | + |
| 72 | + # 搜集目录或文件下的所有evf和evfs文件 |
| 73 | + evf_evfs_files = [] |
| 74 | + if os.path.isfile(file_path) and (file_path.endswith('.evf') or file_path.endswith('.evfs')): |
| 75 | + evf_evfs_files = [os.path.abspath(file_path)] |
| 76 | + elif os.path.isdir(file_path): |
| 77 | + evf_evfs_files = [os.path.abspath(os.path.join(root, file)) |
| 78 | + for root, dirs, files in os.walk(file_path) |
| 79 | + for file in files if file.endswith('.evf') or file.endswith('.evfs')] |
| 80 | + |
| 81 | + if not evf_evfs_files: |
| 82 | + print("ERROR: must be evf or evfs files or directory") |
| 83 | + return 2 |
| 84 | + |
| 85 | + |
| 86 | + # 实例化一个MineSweeperGUI出来 |
| 87 | + app = QtWidgets.QApplication(sys.argv) |
| 88 | + mainWindow = mainWindowGUI.MainWindow() |
| 89 | + ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv) |
| 90 | + |
| 91 | + for ide, e in enumerate(evf_evfs_files): |
| 92 | + if not ui.checksum_module_ok(): |
| 93 | + print("ERROR: ???") |
| 94 | + return 2 |
| 95 | + if e.endswith('.evf'): |
| 96 | + # 检验evf文件是否合法 |
| 97 | + video = ms.EvfVideo(e) |
| 98 | + try: |
| 99 | + video.parse() |
| 100 | + except: |
| 101 | + evf_evfs_files[ide] = (e, 2) |
| 102 | + else: |
| 103 | + checksum = ui.checksum_guard.get_checksum( |
| 104 | + video.raw_data[:-(len(video.checksum) + 2)]) |
| 105 | + if video.checksum == checksum: |
| 106 | + evf_evfs_files[ide] = (e, 0) |
| 107 | + else: |
| 108 | + evf_evfs_files[ide] = (e, 1) |
| 109 | + elif e.endswith('.evfs'): |
| 110 | + # 检验evfs文件是否合法 |
| 111 | + videos = ms.Evfs(e) |
| 112 | + try: |
| 113 | + videos.parse() |
| 114 | + except: |
| 115 | + evf_evfs_files[ide] = (e, 2) |
| 116 | + else: |
| 117 | + if videos.len() <= 0: |
| 118 | + evf_evfs_files[ide] = (e, 2) |
| 119 | + checksum = ui.checksum_guard.get_checksum( |
| 120 | + videos[0].evf_video.raw_data) |
| 121 | + if video.checksum != checksum: |
| 122 | + evf_evfs_files[ide] = (e, 1) |
| 123 | + continue |
| 124 | + for idcell, cell in enumerate(videos[1:]): |
| 125 | + checksum = ui.checksum_guard.get_checksum( |
| 126 | + cell.evf_video.raw_data + videos[idcell - 1].checksum) |
| 127 | + if cell.evf_file.checksum != checksum: |
| 128 | + evf_evfs_files[ide] = (e, 1) |
| 129 | + continue |
| 130 | + evf_evfs_files[ide] = (e, 0) |
| 131 | + print(evf_evfs_files) |
| 132 | + return 0 |
| 133 | + |
64 | 134 | if __name__ == "__main__": |
65 | | - # QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) |
66 | | - # try: |
| 135 | + # metaminesweeper.exe -c filename.evf用法,检查文件的合法性 |
| 136 | + # metaminesweeper.exe -c filename.evfs |
| 137 | + # metaminesweeper.exe -c ./somepath/replay |
| 138 | + parser = argparse.ArgumentParser() |
| 139 | + parser.add_argument("-c", "--check", help="检查文件合法性") |
| 140 | + args, _ = parser.parse_known_args() |
| 141 | + |
| 142 | + if args.check: |
| 143 | + exit_code = cli_check_file(args.check) |
| 144 | + sys.exit(exit_code) |
| 145 | + |
| 146 | + |
67 | 147 | app = QtWidgets.QApplication(sys.argv) |
68 | 148 | serverName = "MineSweeperServer" |
69 | 149 | socket = QLocalSocket() |
|
0 commit comments