Skip to content

Commit f77352c

Browse files
committed
There will no longer be misleading PlaySound warnings that the user supposedly would have to manually fix.
1 parent 41bd3bd commit f77352c

File tree

7 files changed

+41
-34
lines changed

7 files changed

+41
-34
lines changed

ConversionRules/Warnings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"PlaySound": "No longer supported. Create a SoundContainer with CreateSoundContainer in the appropriate Create function.",
2+
"thisisplaceholdertext": "peepeepoopoo",
33
}
File renamed without changes.

Python/convert.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, time, shutil, math, sys, zipfile, json, pathlib, webbrowser
1+
import os, sys, time, shutil, math, zipfile, json, pathlib, webbrowser
22
from pathlib import Path
33
from jsoncomment import JsonComment
44
from playsound import playsound
@@ -25,14 +25,11 @@ def resource_path(relative_path):
2525
return os.path.join(os.path.abspath("."), relative_path)
2626

2727

28-
finishSoundPath = resource_path("Media/finish.wav")
29-
30-
3128
# If an exe executes this program then sys is frozen.
3229
output_folder = ".." if getattr(sys, 'frozen', False) else "Output"
3330

3431

35-
def load_conversion_and_warning_rules():
32+
def load_conversion_and_warning_rules():
3633
json_parser = JsonComment(json)
3734

3835
json_files_found = 0
@@ -93,7 +90,7 @@ def convert():
9390

9491
elapsed = math.floor(time.time() - time_start)
9592
if cfg.sg.user_settings_get_entry("play_finish_sound"):
96-
playsound(finishSoundPath)
93+
playsound(resource_path("Media/finish.wav"))
9794
print("Finished in {} {}".format(elapsed, pluralize("second", elapsed)))
9895

9996

@@ -143,32 +140,35 @@ def process_files(input_subfiles, input_subfolder_path, output_subfolder, input_
143140

144141

145142
def create_converted_file(input_file_path, output_file_path, input_folder_path):
146-
try: # TODO: Figure out why this try/except is necessary and why it doesn't check for an error type.
147-
with open(input_file_path, "r") as file_in:
148-
with open(output_file_path, "w") as file_out:
149-
all_lines_list = []
150-
file_path = os.path.relpath(input_file_path, input_folder_path)
143+
# try: # TODO: Figure out why this try/except is necessary and why it doesn't check for an error type.
144+
with open(input_file_path, "r") as file_in:
145+
with open(output_file_path, "w") as file_out:
146+
all_lines_list = []
147+
file_path = os.path.relpath(input_file_path, input_folder_path)
151148

152-
line_number = 0
153-
for line in file_in:
154-
line_number += 1
149+
line_number = 0
150+
for line in file_in:
151+
line_number += 1
155152

156-
if warnings_available:
157-
for old_str, new_str in warning_rules.items():
158-
if old_str in line:
159-
warnings.append("'{}' line {}: {} -> {}".format(file_path, line_number, old_str, new_str))
153+
if warnings_available:
154+
regex_rules.playsound_warning(line, file_path, line_number, warnings)
160155

161-
all_lines_list.append(line)
156+
for old_str, new_str in warning_rules.items():
157+
if old_str in line:
158+
print(old_str, new_str)
159+
warnings.append("'{}' line {}: {} -> {}".format(file_path, line_number, old_str, new_str))
162160

163-
all_lines = "".join(all_lines_list)
161+
all_lines_list.append(line)
164162

165-
for old_str, new_str in conversion_rules.items():
166-
all_lines = all_lines.replace(old_str, new_str)
163+
all_lines = "".join(all_lines_list)
167164

168-
all_lines = regex_rules.regex_replace(all_lines)
169-
file_out.write(regex_rules.regex_replace_bmps_and_wavs(all_lines))
170-
except:
171-
shutil.copyfile(input_file_path, output_file_path)
165+
for old_str, new_str in conversion_rules.items():
166+
all_lines = all_lines.replace(old_str, new_str)
167+
168+
all_lines = regex_rules.regex_replace(all_lines)
169+
file_out.write(regex_rules.regex_replace_bmps_and_wavs(all_lines))
170+
# except:
171+
# shutil.copyfile(input_file_path, output_file_path)
172172

173173

174174
def warnings_popup():

Python/gui.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ def init_window():
4545
sg.FolderBrowse()
4646
],
4747
[
48-
sg.ProgressBar(100, size=(23.9, 20), key="-PROGRESS BAR-"),
48+
sg.ProgressBar(999, size=(23.9, 20), key="-PROGRESS BAR-"),
4949
sg.Button("Convert", key="-CONVERT-")
5050
]
5151
], title="Convert Mods")]
5252
]
5353

5454
play_finish_sound_setting = sg.user_settings_get_entry("play_finish_sound")
5555
sg.user_settings_set_entry("play_finish_sound", True if play_finish_sound_setting == None else play_finish_sound_setting)
56-
# print(sg.DEFAULT_FONT)
5756

5857
options_column = [
5958
[sg.Frame(layout=[
@@ -86,7 +85,7 @@ def init_window():
8685
cfg.sg = sg
8786
convert.load_conversion_and_warning_rules()
8887

89-
window = sg.Window("Legacy Mod Converter", layout, icon=resource_path("Media/cclmc-icon.ico"))
88+
window = sg.Window("Legacy Mod Converter", layout, icon=resource_path("Media/cclmc.ico"))
9089
cfg.progress_bar = window["-PROGRESS BAR-"]
9190

9291
return window

Python/regex_rules.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,12 @@ def regex_replace_bmps_and_wavs(all_lines):
7878
all_lines = specific_replace(all_lines, regex_use_capture, False, "base\.rte(.*?)\.bmp", "Base.rte{}.png")
7979
all_lines = specific_replace(all_lines, regex_use_capture, False, "Base\.rte(.*?)\.wav", "Base.rte{}.flac")
8080
all_lines = specific_replace(all_lines, regex_use_capture, False, "base\.rte(.*?)\.wav", "Base.rte{}.flac")
81-
return all_lines
81+
return all_lines
82+
83+
84+
def playsound_warning(line, file_path, line_number, warnings):
85+
pattern = "PlaySound(.*)"
86+
message = "No longer supported. Create a SoundContainer with CreateSoundContainer in the appropriate Create function."
87+
matches = re.findall(pattern, line)
88+
if len(matches) > 0 and matches[0].count(",") > 2:
89+
warnings.append("'{}' line {}: {} -> {}".format(file_path, line_number, pattern, message))

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ This project automates ***most*** of the conversion work required to convert the
77
## Getting started
88
Download the [***Legacy Mod Converter***](https://www.mediafire.com/file/cl3vfatqkoqmop1/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

10-
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`.
11-
1210
<p align="center"><img src="Media/cclmc-screenshot.png" alt="Legacy Mod Converter screenshot"></p>
1311

12+
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`.
13+
1414
## Disclaimer
1515
This program will do most of the conversion work for you, but some conversion steps are too hard to automate, so it's likely that `CCCP` will still crash or print errors in the console. If this happens you'll have to manually fix these issues in the legacy mod folder. If you want to properly fix these errors then you should download this repository and follow the instructions below so you can add your own conversion cases to `conversion_rules.py`.
1616

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Run manually: python main.py
2-
# Build EXE for CCCP: 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
2+
# Build EXE: pyinstaller --noconsole --onefile --icon="Media/cclmc.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
33

44
from Python import gui
55

0 commit comments

Comments
 (0)