Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 017a331

Browse files
authored
Update and rename file_copier.py to ModTool.py
Overhaul
1 parent 11c2443 commit 017a331

2 files changed

Lines changed: 162 additions & 119 deletions

File tree

ModTool.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import os
2+
import shutil
3+
import json
4+
from datetime import datetime
5+
from PyQt5 import QtWidgets, QtGui, QtCore
6+
7+
CONFIG_FILE = "config.json"
8+
MODIFIED_FILES_JSON = "modified_files.json"
9+
10+
class ModManager(QtWidgets.QWidget):
11+
def __init__(self):
12+
super().__init__()
13+
self.file_paths = []
14+
self.backup_location = ""
15+
self.destination_dir = ""
16+
self.load_configuration()
17+
self.init_ui()
18+
19+
def init_ui(self):
20+
self.setWindowTitle("Combat Master Mod Manager")
21+
self.setGeometry(300, 300, 800, 400)
22+
main_layout = QtWidgets.QVBoxLayout()
23+
button_layout = QtWidgets.QHBoxLayout()
24+
self.files_list_widget = QtWidgets.QListWidget()
25+
main_layout.addWidget(self.files_list_widget)
26+
select_files_button = QtWidgets.QPushButton("Select Files")
27+
select_files_button.clicked.connect(self.select_files)
28+
button_layout.addWidget(select_files_button)
29+
remove_files_button = QtWidgets.QPushButton("Remove Selected File")
30+
remove_files_button.clicked.connect(self.remove_selected_file)
31+
button_layout.addWidget(remove_files_button)
32+
self.backup_checkbox = QtWidgets.QCheckBox("Backup destination folder before copying")
33+
button_layout.addWidget(self.backup_checkbox)
34+
select_backup_location_button = QtWidgets.QPushButton("Select Backup Location")
35+
select_backup_location_button.clicked.connect(self.select_backup_location)
36+
button_layout.addWidget(select_backup_location_button)
37+
main_layout.addLayout(button_layout)
38+
copy_files_button = QtWidgets.QPushButton("Start Copying")
39+
copy_files_button.clicked.connect(self.copy_files)
40+
main_layout.addWidget(copy_files_button)
41+
self.setLayout(main_layout)
42+
self.load_modified_files()
43+
44+
def select_files(self):
45+
files, _ = QtWidgets.QFileDialog.getOpenFileNames(self, "Select Files")
46+
if files:
47+
self.file_paths.extend(files)
48+
for file in files:
49+
file_name = os.path.basename(file)
50+
self.files_list_widget.addItem(file_name)
51+
self.update_modified_files()
52+
53+
def remove_selected_file(self):
54+
selected_items = self.files_list_widget.selectedItems()
55+
for item in selected_items:
56+
index = self.files_list_widget.row(item)
57+
self.files_list_widget.takeItem(index)
58+
del self.file_paths[index]
59+
self.update_modified_files()
60+
61+
def select_backup_location(self):
62+
backup_location = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Backup Location")
63+
if backup_location:
64+
self.backup_location = backup_location
65+
66+
def backup_destination(self, destination_dir):
67+
if not self.backup_location:
68+
QtWidgets.QMessageBox.critical(self, "Error", "No backup location selected.")
69+
return False
70+
71+
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
72+
backup_dir = os.path.join(self.backup_location, f"backup_{timestamp}")
73+
try:
74+
shutil.copytree(destination_dir, backup_dir)
75+
QtWidgets.QMessageBox.information(self, "Backup", f"Backup created at: {backup_dir}")
76+
except Exception as e:
77+
QtWidgets.QMessageBox.critical(self, "Error", f"Failed to create backup: {str(e)}")
78+
return False
79+
80+
return True
81+
82+
def copy_files(self):
83+
if not os.path.exists(self.destination_dir):
84+
QtWidgets.QMessageBox.critical(self, "Error", "Destination folder not found. Please ensure Combat Master is installed.")
85+
self.prompt_user_for_path()
86+
return
87+
88+
if self.backup_checkbox.isChecked():
89+
if not self.backup_destination(self.destination_dir):
90+
return
91+
92+
if not self.file_paths:
93+
QtWidgets.QMessageBox.warning(self, "Warning", "No files selected.")
94+
return
95+
96+
for i, file_path in enumerate(self.file_paths):
97+
try:
98+
shutil.copy(file_path, self.destination_dir)
99+
except Exception as e:
100+
QtWidgets.QMessageBox.critical(self, "Error", f"Failed to copy {os.path.basename(file_path)}: {str(e)}")
101+
return
102+
103+
QtWidgets.QMessageBox.information(self, "Success", "All files successfully copied to your game files.")
104+
105+
def update_modified_files(self):
106+
with open(MODIFIED_FILES_JSON, "w") as file:
107+
json.dump(self.file_paths, file, indent=4)
108+
109+
def load_modified_files(self):
110+
if os.path.exists(MODIFIED_FILES_JSON):
111+
with open(MODIFIED_FILES_JSON, "r") as file:
112+
self.file_paths = json.load(file)
113+
for file_path in self.file_paths:
114+
file_name = os.path.basename(file_path)
115+
self.files_list_widget.addItem(file_name)
116+
117+
def load_configuration(self):
118+
if os.path.exists(CONFIG_FILE):
119+
with open(CONFIG_FILE, "r") as file:
120+
config = json.load(file)
121+
self.destination_dir = config.get("destination_dir", "")
122+
if self.destination_dir and os.path.exists(self.destination_dir):
123+
return # Config is valid
124+
125+
self.destination_dir = self.find_game_folder()
126+
if not self.destination_dir:
127+
self.prompt_user_for_path()
128+
else:
129+
self.save_configuration()
130+
131+
def save_configuration(self):
132+
config = {"destination_dir": self.destination_dir}
133+
with open(CONFIG_FILE, "w") as file:
134+
json.dump(config, file, indent=4)
135+
136+
def find_game_folder(self):
137+
possible_drives = [f"{chr(drive)}:\\" for drive in range(65, 91) if os.path.exists(f"{chr(drive)}:\\")]
138+
possible_paths = [
139+
"Steam\\steamapps\\common\\Combat Master\\Data\\StreamingAssets\\Bundles",
140+
"SteamLibrary\\steamapps\\common\\Combat Master\\Data\\StreamingAssets\\Bundles"
141+
]
142+
143+
for drive in possible_drives:
144+
for path in possible_paths:
145+
potential_path = os.path.join(drive, path)
146+
if os.path.exists(potential_path):
147+
return potential_path
148+
149+
return ""
150+
151+
def prompt_user_for_path(self):
152+
path = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Combat Master Bundles Folder")
153+
if path:
154+
self.destination_dir = path
155+
self.save_configuration()
156+
157+
if __name__ == "__main__":
158+
import sys
159+
app = QtWidgets.QApplication(sys.argv)
160+
mod_manager = ModManager()
161+
mod_manager.show()
162+
sys.exit(app.exec_())

file_copier.py

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)