Add true portable mode (#259)

This commit is contained in:
Jeod
2025-09-26 15:32:42 -04:00
committed by GitHub
parent 7b0a62c765
commit 659e9f3ce8
28 changed files with 176 additions and 96 deletions

View File

@@ -26,11 +26,13 @@ var second_quest := false
var extra_worlds_win := false
const lang_codes := ["en", "fr", "es", "de", "it", "pt", "pl", "tr", "ru", "jp", "fil", "id", "ga"]
var config_path : String = get_config_path()
var rom_path := ""
var rom_assets_exist := false
const ROM_POINTER_PATH := "user://rom_pointer.smb"
const ROM_PATH := "user://baserom.nes"
const ROM_ASSETS_PATH := "user://resource_packs/BaseAssets"
var ROM_POINTER_PATH = config_path.path_join("rom_pointer.smb")
var ROM_PATH = config_path.path_join("baserom.nes")
var ROM_ASSETS_PATH = config_path.path_join("resource_packs/BaseAssets")
const ROM_PACK_NAME := "BaseAssets"
const ROM_ASSETS_VERSION := 0
@@ -169,8 +171,46 @@ func _ready() -> void:
get_server_version()
if OS.is_debug_build():
debug_mode = false
setup_config_dirs()
check_for_rom()
func setup_config_dirs() -> void:
var dirs = [
"custom_characters",
"custom_levels",
"logs",
"marathon_recordings",
"resource_packs",
"saves"
]
for d in dirs:
var full_path = Global.config_path.path_join(d)
if not DirAccess.dir_exists_absolute(full_path):
DirAccess.make_dir_recursive_absolute(full_path)
func get_config_path() -> String:
var exe_path := OS.get_executable_path()
var exe_dir := exe_path.get_base_dir()
var portable_flag := exe_dir.path_join("portable.txt")
# Test that exe dir is writeable, if not fallback to user://
if FileAccess.file_exists(portable_flag):
var test_file = exe_dir.path_join("test.txt")
var f = FileAccess.open(test_file, FileAccess.WRITE)
if f:
f.close()
var dir = DirAccess.open(exe_dir)
if dir:
dir.remove(test_file.get_file())
var local_dir = exe_dir.path_join("config")
if not DirAccess.dir_exists_absolute(local_dir):
DirAccess.make_dir_recursive_absolute(local_dir)
return local_dir
else:
push_warning("Portable flag found but exe directory is not writeable. Falling back to user://")
return "user://"
func check_for_rom() -> void:
rom_path = ""
rom_assets_exist = false
@@ -330,7 +370,7 @@ func close_freeze() -> void:
$Transition/Freeze.hide()
$Transition.hide()
var recording_dir = "user://marathon_recordings/"
var recording_dir = config_path.path_join("marathon_recordings")
func update_game_status() -> void:
var lives_str := str(Global.lives)