Add option for .local/share/HackerSM64/UNFLoader-dir.txt

This allows referencing a custom UNFLoader path to be used, ideally for placing on the C drive for WSL instances. UNFLoader tends to hang for an unbearably long time when saved somewhere within the WSL directory structure, and simply using the Linux build isn't an option because it can't access Windows USB devices trivially.
This commit is contained in:
Gregory Heskett
2024-08-03 19:09:22 -04:00
parent 74cb8ce062
commit e3472e05cf
2 changed files with 28 additions and 17 deletions

View File

@@ -562,10 +562,19 @@ endif
EMU_FLAGS =
# Adding a txt file to this location will then reference a UNFLoader path specified in the file, instead of locally.
# This is expecially important for WSL users because UNFLoader.exe is incredibly slow when run within WSL's filesystem, so this can be used to point to the C drive.
# The file should only contain the directory path that contains UNFLoader[.exe] (do not specify the filename).
LOADER_DIR_FILE_SPECIFICATION_PATH = ~/.local/share/HackerSM64/UNFLoader-dir.txt
LOADER_DIR = ./$(TOOLS_DIR)
ifneq (,$(wildcard $(LOADER_DIR_FILE_SPECIFICATION_PATH)))
LOADER_DIR = $(shell cat $(LOADER_DIR_FILE_SPECIFICATION_PATH))
endif
ifneq (,$(call find-command,wslview))
LOADER = ./$(TOOLS_DIR)/UNFLoader.exe
LOADER_EXEC = $(LOADER_DIR)/UNFLoader.exe
else
LOADER = ./$(TOOLS_DIR)/UNFLoader
LOADER_EXEC = $(LOADER_DIR)/UNFLoader
endif
SHA1SUM = sha1sum
@@ -621,17 +630,17 @@ test-pj64: $(ROM)
# someone2639
# download and extract most recent unfloader build if needed
$(LOADER):
ifeq (,$(wildcard $(LOADER)))
$(LOADER_EXEC):
ifeq (,$(wildcard $(LOADER_EXEC)))
@$(PRINT) "Downloading latest UNFLoader...$(NO_COL)\n"
$(PYTHON) $(TOOLS_DIR)/get_latest_unfloader.py $(TOOLS_DIR)
$(PYTHON) $(TOOLS_DIR)/get_latest_unfloader.py $(LOADER_DIR)
endif
load: $(ROM) $(LOADER)
$(LOADER) -r $<
load: $(ROM) $(LOADER_EXEC)
$(LOADER_EXEC) -r $<
unf: $(ROM) $(LOADER)
$(LOADER) -d -r $<
unf: $(ROM) $(LOADER_EXEC)
$(LOADER_EXEC) -d -r $<
libultra: $(BUILD_DIR)/libultra.a

View File

@@ -13,7 +13,9 @@ def get_latest_build_artifacts_url():
return os.path.join(body['value'][0]['url'], 'artifacts')
def main():
destpath = sys.argv[1] if len(sys.argv) > 1 else './'
destpath = sys.argv[1] if len(sys.argv) > 1 else '.'
unfloader_zip_path = os.path.join(destpath, "UNFLoader.zip")
os.makedirs(destpath, exist_ok=True)
is_wsl = 'microsoft-standard' in str(platform.uname()).lower()
unf_fn = 'UNFLoader.exe' if is_wsl else 'UNFLoader'
artifact_url = get_latest_build_artifacts_url()
@@ -32,24 +34,24 @@ def main():
# download unf zipfile
artifact_res = request('GET', platform_artifact_url)
with open('UNFLoader.zip', 'wb') as unf_fp:
with open(unfloader_zip_path, 'wb') as unf_fp:
unf_fp.write(artifact_res.content)
# only extract the specific file that we need
unfpath = None
with zipfile.ZipFile('UNFLoader.zip', 'r') as zip_ref:
with zipfile.ZipFile(unfloader_zip_path, 'r') as zip_ref:
for zipinfo in zip_ref.infolist():
if not zipinfo.is_dir():
unfpath = zip_ref.extract(zipinfo)
unfpath = zip_ref.extract(zipinfo, destpath)
unf_bin_path = os.path.join(destpath, unf_fn)
# file gets extracted to ./unfloader-{platform}/UNFLoader[.exe],
# so move binary to ./UNFLoader[.exe]
# file gets extracted to [destpath]/unfloader-{platform}/UNFLoader[.exe],
# so move binary to [destpath]/UNFLoader[.exe]
os.rename(unfpath, unf_bin_path)
# remove ./unfloader-{platform}/ directory
# remove [destpath]/unfloader-{platform}/ directory
os.rmdir(unfpath.rstrip(unf_fn))
# remove UNFLoader.zip
os.remove('UNFLoader.zip')
os.remove(unfloader_zip_path)
# now need to add executable file permissions to unfloader
st = os.stat(unf_bin_path)