| 99 | self.server_path = server_path |
| 100 | |
| 101 | def run(self): |
| 102 | try: |
| 103 | # 解压整合包 |
| 104 | with ZipFile(self.zip_file, "r") as zip_ref: |
| 105 | zip_ref.extractall(self.server_path) |
| 106 | |
| 107 | # 检查是否只有一个子目录(常见的整合包结构) |
| 108 | dirs = [ |
| 109 | d |
| 110 | for d in os.listdir(self.server_path) |
| 111 | if os.path.isdir(os.path.join(self.server_path, d)) |
| 112 | ] |
| 113 | if ( |
| 114 | len(dirs) == 1 |
| 115 | and len([ |
| 116 | f |
| 117 | for f in os.listdir(self.server_path) |
| 118 | if os.path.isfile(os.path.join(self.server_path, f)) |
| 119 | ]) |
| 120 | == 0 |
| 121 | ): |
| 122 | # 如果只有一个子目录且没有其他文件,将其内容移到上层 |
| 123 | sub_dir = os.path.join(self.server_path, dirs[0]) |
| 124 | for item in os.listdir(sub_dir): |
| 125 | shutil.move(os.path.join(sub_dir, item), os.path.join(self.server_path, item)) |
| 126 | os.rmdir(sub_dir) |
| 127 | |
| 128 | # 检测jar文件 |
| 129 | jar_files = [ |
| 130 | f |
| 131 | for f in os.listdir(self.server_path) |
| 132 | if f.endswith(".jar") and os.path.isfile(os.path.join(self.server_path, f)) |
| 133 | ] |
| 134 | |
| 135 | self.success.emit(self.server_path, jar_files) |
| 136 | except Exception as e: |
| 137 | self.failed.emit(str(e)) |
| 138 | |
| 139 | |
| 140 | class JavaServerSaveThread(QThread): |