Skip to content

Commit 4cefa11

Browse files
committed
Now showing an error when the ConversionRules folder wasn't found and when the ConversionRules folder didn't contain any JSON files.
1 parent dbe2c64 commit 4cefa11

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Run manually: python main.py
22

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
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" --name="Legacy Mod Converter" main.py
44
# Build exe from spec (can be outdated): pyinstaller "Legacy Mod Converter.spec"
55

66
from Python import gui

python/convert.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from jsoncomment import JsonComment
44
from playsound import playsound
5+
import PySimpleGUI as sg
56

67
from Python import shared_globals as cfg
78

@@ -28,11 +29,23 @@ def resource_path(relative_path):
2829
def load_conversion_rules():
2930
json_parser = JsonComment(json)
3031

31-
for name in os.listdir(resource_path("ConversionRules")):
32-
if name.endswith(".json"):
33-
path = os.path.join(resource_path("ConversionRules"), name)
34-
with open(path) as f:
35-
conversion_rules.update(json_parser.load(f))
32+
github_url = "https://github.com/cortex-command-community/Cortex-Command-Legacy-Mod-Converter"
33+
34+
json_files_found = 0
35+
try:
36+
for name in os.listdir("ConversionRules"):
37+
if name.endswith(".json"):
38+
path = os.path.join("ConversionRules", name)
39+
with open(path) as f:
40+
json_files_found += 1
41+
conversion_rules.update(json_parser.load(f))
42+
except:
43+
sg.Popup("The folder 'ConversionRules' wasn't found next to this executable. You can get the missing folder from the Legacy Mod Converter GitHub repo:", github_url)
44+
sys.exit()
45+
46+
if json_files_found == 0:
47+
sg.Popup("The folder 'ConversionRules' didn't contain any JSON files. You can get the JSON files from the Legacy Mod Converter GitHub repo:", github_url)
48+
sys.exit()
3649

3750
load_conversion_rules()
3851

0 commit comments

Comments
 (0)