Skip to content

Commit dbe2c64

Browse files
committed
Non-Python file resources now also included in the exe which were missing so far.
1 parent 8d54ab1 commit dbe2c64

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This project automates ***most*** of the conversion work required to convert the legacy (old) `Cortex Command` mods into `Cortex Command Community Project` compatible mods.
66

77
## Getting started
8-
Download the [***Legacy Mod Converter***](http://www.mediafire.com/file/ckln61cmqbv2geq/Legacy_Mod_Converter.exe/file) program. Create a new folder and put your legacy mods that you want to convert in it. Run the Legacy Mod Converter program.
8+
Download the [***Legacy Mod Converter***](http://www.mediafire.com/file/1ncoydmaehf4nyn/Legacy_Mod_Converter.exe/file) program. Create a new folder and put your legacy mods that you want to convert in it. Run the Legacy Mod Converter program.
99

1010
If you get a "`Microsoft Defender SmartScreen prevented an unrecognized app from starting. Running this app might put your PC at risk.`" popup message when trying to run the program you should press `More info` and then `Run anyway`.
1111

main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Run: python main.py output
2-
# Build: pyinstaller --noconsole --onefile --icon=media/cclmc-icon.ico --name="Legacy Mod Converter" main.py
1+
# Run manually: python main.py
2+
3+
# Build exe not from spec: pyinstaller --noconsole --onefile --icon=Media/cclmc-icon.ico --add-data "Media/github-icon.png;Media" --add-data "Media/discord-icon.png;Media" --add-data "Media/finish.wav;Media" --add-data "ConversionRules;ConversionRules" --name="Legacy Mod Converter" main.py
4+
# Build exe from spec (can be outdated): pyinstaller "Legacy Mod Converter.spec"
35

46
from Python import gui
57

python/convert.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@
22
from pathlib import Path
33
from jsoncomment import JsonComment
44
from playsound import playsound
5-
from Python import shared_globals as cfg
65

6+
from Python import shared_globals as cfg
77

8-
finishSoundPath = "media/finish.wav"
98

109
progress = 0
1110
total_progress = 0
1211
conversion_rules = {}
1312

13+
14+
# TODO: Move to shared_globals.py
15+
def resource_path(relative_path):
16+
if hasattr(sys, '_MEIPASS'):
17+
return os.path.join(sys._MEIPASS, relative_path)
18+
return os.path.join(os.path.abspath("."), relative_path)
19+
20+
21+
finishSoundPath = resource_path("Media/finish.wav")
22+
23+
1424
# If an exe executes this program then sys is frozen.
1525
output_folder = ".." if getattr(sys, 'frozen', False) else "Output"
1626

1727

1828
def load_conversion_rules():
1929
json_parser = JsonComment(json)
2030

21-
for name in os.listdir("ConversionRules"):
31+
for name in os.listdir(resource_path("ConversionRules")):
2232
if name.endswith(".json"):
23-
path = os.path.join("ConversionRules", name)
33+
path = os.path.join(resource_path("ConversionRules"), name)
2434
with open(path) as f:
2535
conversion_rules.update(json_parser.load(f))
2636

@@ -213,7 +223,6 @@ def regex_replace_bmps_and_wavs(all_lines):
213223

214224

215225
def create_zips(input_folder, output_folder):
216-
print(input_folder)
217226
if input_folder.endswith(".rte"):
218227
create_single_zip(Path(input_folder).name, output_folder)
219228
else:

python/gui.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os, sys
12
import os.path, pathlib, webbrowser
23
import PySimpleGUI as sg
34

@@ -8,6 +9,13 @@
89
sg.user_settings_filename(filename="settings.json", path=".")
910

1011

12+
# TODO: Move to shared_globals.py
13+
def resource_path(relative_path):
14+
if hasattr(sys, '_MEIPASS'):
15+
return os.path.join(sys._MEIPASS, relative_path)
16+
return os.path.join(os.path.abspath("."), relative_path)
17+
18+
1119
def init_window_theme():
1220
path_set_color = "#528b30"
1321
progress_bar_color = "#17569c"
@@ -51,8 +59,8 @@ def init_window():
5159
info_column = [
5260
[sg.Frame(layout=[
5361
[
54-
sg.Image("media/github-icon.png", enable_events=True, key="-GITHUB-", tooltip=" Visit this program's GitHub page ", size=(0, 30)),
55-
sg.Image("media/discord-icon.png", enable_events=True, key="-DISCORD-", tooltip=" Visit the CCCP Discord server for help ", size=(0, 30))
62+
sg.Image(resource_path("media/github-icon.png"), enable_events=True, key="-GITHUB-", tooltip=" Visit this program's GitHub page ", size=(0, 30)),
63+
sg.Image(resource_path("media/discord-icon.png"), enable_events=True, key="-DISCORD-", tooltip=" Visit the CCCP Discord server for help ", size=(0, 30))
5664
]
5765
], title="", pad=((9, 0), (8, 0)))]
5866
]
@@ -68,7 +76,7 @@ def init_window():
6876
]
6977

7078
cfg.sg = sg
71-
window = sg.Window("Legacy Mod Converter - v1.0", layout, icon="media/cclmc-icon.ico", button_color=(sg.theme_text_color(), "#2a3948"))
79+
window = sg.Window("Legacy Mod Converter - v1.0", layout, icon=resource_path("media/cclmc-icon.ico"), button_color=(sg.theme_text_color(), "#2a3948"))
7280
cfg.progress_bar = window["-PROGRESS BAR-"]
7381

7482
return window

0 commit comments

Comments
 (0)