-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiimm.py
72 lines (62 loc) · 3.24 KB
/
wiimm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright (C) 2022 luckytyphlosion
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import platform
import subprocess
import dir_config
import pathlib
wit_filename = None
wszst_filename = None
wkmpt_filename = None
def get_wit_wszst_filename():
global wit_filename
global wszst_filename
if wit_filename is None and wszst_filename is None:
platform_system_lower = platform.system().lower()
if platform_system_lower == "linux":
wit_filename = f"{dir_config.wiimm_dirname}/linux/wit"
wszst_filename = f"{dir_config.wiimm_dirname}/linux/wszst"
elif platform_system_lower == "windows":
wit_filename = f"{dir_config.wiimm_dirname}/cygwin64/wit.exe"
wszst_filename = f"{dir_config.wiimm_dirname}/cygwin64/wszst.exe"
else:
raise RuntimeError(f"Unsupported operating system {platform.system()}!")
return wit_filename, wszst_filename
def get_wkmpt_filename():
global wkmpt_filename
if wkmpt_filename is None:
platform_system_lower = platform.system().lower()
if platform_system_lower == "linux":
wkmpt_filename = f"{dir_config.wiimm_dirname}/linux/wkmpt"
elif platform_system_lower == "windows":
wkmpt_filename = f"{dir_config.wiimm_dirname}/cygwin64/wkmpt.exe"
else:
raise RuntimeError(f"Unsupported operating system {platform.system()}!")
return wkmpt_filename
def check_track_has_speedmod(track_filename, wbz_converter):
wkmpt_filename = get_wkmpt_filename()
completed_process = subprocess.run((wkmpt_filename, "STGI", "-H", track_filename), capture_output=True, encoding="utf-8")
if completed_process.returncode != 0:
if wbz_converter is not None:
wbz_converter.purge_auto_add_if_onerror()
pathlib.Path(track_filename).unlink()
raise RuntimeError(f"Autogenerated SZS file from auto-downloaded WBZ is corrupted. Your ISO may be damaged. You will have to specify szs-filename manually.\n\n(Technical info: wkmpt error occurred while checking if track has speedmod! error:\n\n{completed_process.stderr})")
else:
raise RuntimeError(f"Provided SZS file \"{track_filename}\" is corrupted!\n\n(Technical info: wkmpt error occurred while checking if track has speedmod! error:\n\n{completed_process.stderr})")
wkmpt_output = completed_process.stdout
#print(f"wkmpt_output: {wkmpt_output}")
stgi_info, track_filename_from_wkmpt = wkmpt_output.strip().split(" : ", maxsplit=1)
split_stgi_info = stgi_info.split()
return split_stgi_info[2] != "--" and split_stgi_info[2] != "1.00"