Skip to content

Commit ab874fb

Browse files
committed
Exe now outputs to "..", shell outputs to "Output".
1 parent 7dfbdcf commit ab874fb

File tree

3 files changed

+25
-44
lines changed

3 files changed

+25
-44
lines changed

main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Run: python main.py output
2+
# Build: pyinstaller --noconsole --onefile --icon=media/cclmc-icon.ico --name="Legacy Mod Converter" main.py
3+
14
from Python import gui
25

36
gui.init_window_theme()

python/convert.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
total_progress = 0
1111
conversion_rules = {}
1212

13+
# If an exe executes this program then sys is frozen.
14+
output_folder = ".." if getattr(sys, 'frozen', False) else "Output"
15+
1316

1417
def load_conversion_rules():
1518
json_parser = JsonComment(json)
@@ -23,8 +26,8 @@ def load_conversion_rules():
2326
load_conversion_rules()
2427

2528

26-
def main():
27-
global progress, total_progress
29+
def convert():
30+
global progress, total_progress, output_folder
2831

2932
time_start = time.time()
3033

@@ -34,14 +37,14 @@ def main():
3437

3538
for input_folder_path, input_subfolders, full_filename_list in os.walk(cfg.sg.user_settings_get_entry("input_folder")):
3639
mod_subfolder = get_mod_subfolder(input_folder_path)
37-
output_folder = get_output_folder_path(mod_subfolder)
40+
output_subfolder = os.path.join(output_folder, mod_subfolder)
3841

3942
try_print_mod_name(mod_subfolder)
40-
create_folder(input_folder_path, output_folder)
41-
process_file(full_filename_list, input_folder_path, output_folder)
43+
create_folder(input_folder_path, output_subfolder)
44+
process_file(full_filename_list, input_folder_path, output_subfolder)
4245

4346
if cfg.sg.user_settings_get_entry("output_zips"):
44-
create_zips()
47+
create_zips(output_folder)
4548

4649
progress = 0
4750
total_progress = 0
@@ -72,10 +75,6 @@ def get_mod_subfolder(input_folder_path):
7275
return input_folder_path.replace(cfg.sg.user_settings_get_entry("input_folder") + "\\", "") # TODO: Find proper replacement for removing the \\ part that will also work for Unix.
7376

7477

75-
def get_output_folder_path(mod_subfolder):
76-
return os.path.join(cfg.sg.user_settings_get_entry("output_folder"), mod_subfolder)
77-
78-
7978
def try_print_mod_name(mod_subfolder):
8079
input_folder_path_tuple = pathlib.Path(mod_subfolder).parts
8180

@@ -204,9 +203,8 @@ def regex_replace_bmps_and_wavs(all_lines):
204203
return all_lines
205204

206205

207-
def create_zips():
206+
def create_zips(output_folder):
208207
# Get mod folder names from the input_folder.
209-
output_folder = cfg.sg.user_settings_get_entry("output_folder")
210208
folder_names = [f for f in os.listdir(cfg.sg.user_settings_get_entry("input_folder")) if os.path.isdir(os.path.join(output_folder, f))]
211209

212210
for f in folder_names:
@@ -218,8 +216,4 @@ def create_zips():
218216

219217

220218
def pluralize(word, count):
221-
return word + "s" if count != 1 else word
222-
223-
224-
if __name__ == "__main__":
225-
main()
219+
return word + "s" if count != 1 else word

python/gui.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Run: python gui.py
2-
# Build: pyinstaller --noconsole --onefile --icon=media/cclmc-icon.ico --name="Legacy Mod Converter" main.py
3-
41
import os.path, pathlib, webbrowser
52
import PySimpleGUI as sg
63

@@ -33,26 +30,15 @@ def init_window():
3330
paths_column = [
3431
[sg.Frame(layout=[
3532
[
36-
sg.Text("Folder with legacy mod(s)"),
33+
sg.Text("Mod to convert"),
3734
sg.In(
3835
sg.user_settings_get_entry("input_folder"),
39-
size=(25, 1),
36+
size=(34, 1),
4037
enable_events=True,
4138
key="-INPUT FOLDER-",
4239
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("input_folder") else no_path_set_color
4340
),
4441
sg.FolderBrowse()
45-
],
46-
[
47-
sg.Text("Output CCCP folder"),
48-
sg.In(
49-
sg.user_settings_get_entry("output_folder"),
50-
size=(25, 1),
51-
enable_events=True,
52-
key="-OUTPUT FOLDER-",
53-
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("output_folder") else no_path_set_color
54-
),
55-
sg.FolderBrowse()
5642
]
5743
], title="Paths", element_justification="right")]
5844
]
@@ -67,14 +53,14 @@ def init_window():
6753
run_column = [
6854
[sg.Frame(layout=[
6955
[sg.Button("Convert", key="-CONVERT-")],
70-
[sg.ProgressBar(100, size=(17.45, 20), key="-PROGRESS BAR-")]
56+
[sg.ProgressBar(100, size=(17.4, 20), key="-PROGRESS BAR-")]
7157
], title="Run", element_justification="center")]
7258
]
7359

7460
info_column = [
7561
[sg.Frame(layout=[
76-
[sg.Image("media/github-icon.png", enable_events=True, key="-GITHUB-")],
77-
[sg.Image("media/discord-icon.png", enable_events=True, key="-DISCORD-")]
62+
[sg.Image("media/github-icon.png", enable_events=True, key="-GITHUB-", tooltip=" Visit this program's GitHub page ")],
63+
[sg.Image("media/discord-icon.png", enable_events=True, key="-DISCORD-", tooltip=" Visit the CCCP Discord server ")]
7864
], title="", pad=(0, (8, 0)))]
7965
]
8066

@@ -110,19 +96,17 @@ def run_window(window):
11096
input_folder_or_file = values[event]
11197
if input_folder_or_file != "":
11298
sg.user_settings_set_entry("input_folder", get_input_folder(input_folder_or_file))
113-
window[event](background_color=sg.theme_input_background_color())
114-
elif event == "-OUTPUT FOLDER-":
115-
output_folder = values[event]
116-
if output_folder != "":
117-
sg.user_settings_set_entry("output_folder", output_folder)
118-
window[event](background_color=sg.theme_input_background_color())
99+
window[event](background_color = sg.theme_input_background_color())
100+
119101
elif event == "-OUTPUT ZIPS-":
120102
sg.user_settings_set_entry("output_zips", values["-OUTPUT ZIPS-"])
121103
elif event == "-PLAY FINISH SOUND-":
122104
sg.user_settings_set_entry("play_finish_sound", values["-PLAY FINISH SOUND-"])
105+
123106
elif event == "-CONVERT-":
124-
if sg.user_settings_get_entry("input_folder") not in (None, "") and sg.user_settings_get_entry("output_folder") not in (None, ""):
125-
convert.main()
107+
if sg.user_settings_get_entry("input_folder") not in (None, ""):
108+
convert.convert()
109+
126110
elif event == "-GITHUB-":
127111
webbrowser.open("https://github.com/cortex-command-community/Cortex-Command-Legacy-Mod-Converter")
128112
elif event == "-DISCORD-":

0 commit comments

Comments
 (0)