Skip to content

Commit 6177c27

Browse files
committed
Uniformize path concatenation
1 parent 667ad7f commit 6177c27

File tree

9 files changed

+43
-40
lines changed

9 files changed

+43
-40
lines changed

scenes/config/settings/GeneralSettings.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func set_themes():
4747
if RetroHubConfig._get_default_themes_dir() in RetroHubConfig.theme_path and \
4848
theme_pck in RetroHubConfig.theme_path:
4949
n_themes.selected = id
50-
theme_id_map[id] = "res://default_themes/" + theme_pck
50+
theme_id_map[id] = "res://default_themes".path_join(theme_pck)
5151
id += 1
5252
n_themes.add_separator()
5353
id += 1

source/Config.gd

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ func _load_config_file():
267267
# TODO: behavior for when file is corrupt
268268

269269
func _get_credential(key: String) -> String:
270-
var json : Dictionary = JSONUtils.load_json_file(_get_config_dir() + "/rh_credentials.json")
270+
var json : Dictionary = JSONUtils.load_json_file(_get_config_dir().path_join("rh_credentials.json"))
271271
if not json.is_empty() and json.has(key):
272272
return json[key]
273273
return ""
274274

275275
func _set_credential(key: String, value: String):
276-
var json : Dictionary = JSONUtils.load_json_file(_get_config_dir() + "/rh_credentials.json")
276+
var json : Dictionary = JSONUtils.load_json_file(_get_config_dir().path_join("rh_credentials.json"))
277277
json[key] = value
278-
JSONUtils.save_json_file(json, _get_config_dir() + "/rh_credentials.json")
278+
JSONUtils.save_json_file(json, _get_config_dir().path_join("rh_credentials.json"))
279279

280280
func _on_config_updated(key, old_value, new_value):
281281
match key:
@@ -552,7 +552,7 @@ func set_theme_config(key, value):
552552
func _load_theme_config():
553553
_theme_config = {}
554554
_theme_config_changed = false
555-
var theme_config_path := _get_theme_config_dir() + "/config.json"
555+
var theme_config_path := _get_theme_config_dir().path_join("config.json")
556556
# If the config file doesn't exist, don't try reading it
557557
if not FileAccess.file_exists(theme_config_path):
558558
return
@@ -566,7 +566,7 @@ func _load_theme_config():
566566

567567
func save_theme_config():
568568
if _theme_config_changed:
569-
var theme_config_path := _get_theme_config_dir() + "/config.json"
569+
var theme_config_path := _get_theme_config_dir().path_join("config.json")
570570
FileUtils.ensure_path(theme_config_path)
571571
var file := FileAccess.open(theme_config_path, FileAccess.WRITE)
572572
if not file:
@@ -597,12 +597,12 @@ func _bootstrap_config_dir():
597597
push_error("Error when creating directory " + path)
598598

599599
# Bootstrap system specific configs
600-
for filename in [
600+
for filename: String in [
601601
"rh_emulators.json",
602602
"rh_systems.json",
603603
"_emulator_paths.json"
604604
]:
605-
var filepath_out := _get_config_dir() + "/" + (filename as String)
605+
var filepath_out := _get_config_dir().path_join(filename)
606606
var file := FileAccess.open(filepath_out, FileAccess.WRITE)
607607
if not file:
608608
push_error("Error when opening file " + filepath_out + " for saving")
@@ -611,7 +611,7 @@ func _bootstrap_config_dir():
611611
file.close()
612612

613613
# Bootstrap credentials file
614-
JSONUtils.save_json_file({}, _get_config_dir() + "/rh_credentials.json")
614+
JSONUtils.save_json_file({}, _get_config_dir().path_join("rh_credentials.json"))
615615

616616
func _save_config():
617617
if config.save_config_to_path(_get_config_file()):
@@ -734,7 +734,7 @@ func _determine_sc_mode():
734734
if exe_path.ends_with("MacOS") and exe_path.path_join("..").simplify_path().ends_with("Contents"):
735735
exe_path = exe_path.path_join("../../..").simplify_path()
736736

737-
if FileAccess.file_exists(exe_path + "/._sc_") or FileAccess.file_exists(exe_path + "/_sc_"):
737+
if FileAccess.file_exists(exe_path.path_join("._sc_")) or FileAccess.file_exists(exe_path.path_join("_sc_")):
738738
_is_sc = true
739739

740740
func _get_emulator_path(emulator_name: String, key: String) -> String:
@@ -759,22 +759,22 @@ func _set_emulator_path(emulator_name: String, key: String, value: String) -> vo
759759
func _get_config_dir() -> String:
760760
var path : String
761761
if _is_sc:
762-
return OS.get_executable_path().get_base_dir() + "/config"
762+
return OS.get_executable_path().get_base_dir().path_join("config")
763763

764764
match FileUtils.get_os_id():
765765
FileUtils.OS_ID.WINDOWS:
766-
path = FileUtils.get_home_dir() + "/RetroHub"
766+
path = FileUtils.get_home_dir().path_join("RetroHub")
767767
if RetroHub._is_dev_env():
768768
path += "-Dev"
769769
return path
770770
_:
771-
path = FileUtils.get_home_dir() + "/.retrohub"
771+
path = FileUtils.get_home_dir().path_join(".retrohub")
772772
if RetroHub._is_dev_env():
773773
path += "-dev"
774774
return path
775775

776776
func _get_config_file() -> String:
777-
return _get_config_dir() + "/rh_config.json"
777+
return _get_config_dir().path_join("rh_config.json")
778778

779779
func _get_systems_file() -> String:
780780
return "res://base_config/systems.json"
@@ -783,27 +783,27 @@ func _get_emulators_file() -> String:
783783
return "res://base_config/emulators.json"
784784

785785
func _get_emulator_paths_file() -> String:
786-
return _get_config_dir() + "/_emulator_paths.json"
786+
return _get_config_dir().path_join("_emulator_paths.json")
787787

788788
func _get_custom_systems_file() -> String:
789-
return _get_config_dir() + "/rh_systems.json"
789+
return _get_config_dir().path_join("rh_systems.json")
790790

791791
func _get_custom_emulators_file() -> String:
792-
return _get_config_dir() + "/rh_emulators.json"
792+
return _get_config_dir().path_join("rh_emulators.json")
793793

794794
func _get_default_themes_dir() -> String:
795795
return "res://default_themes"
796796

797797
func _get_themes_dir() -> String:
798-
return _get_config_dir() + "/themes"
798+
return _get_config_dir().path_join("themes")
799799

800800
func _get_theme_config_dir() -> String:
801-
return _get_themes_dir() + "/config/" + theme_data.id if theme_data else ""
801+
return _get_themes_dir().path_join("config").path_join(theme_data.id if theme_data else "")
802802

803803
func _get_gamelists_dir() -> String:
804-
return _get_config_dir() + "/gamelists"
804+
return _get_config_dir().path_join("gamelists")
805805

806806
func _get_gamemedia_dir() -> String:
807807
if not config.custom_gamemedia_dir.is_empty():
808808
return config.custom_gamemedia_dir
809-
return _get_config_dir() + "/gamemedia"
809+
return _get_config_dir().path_join("gamemedia")

source/data/ConfigData.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var _old_config : Dictionary
99
# Games directory
1010
var config_version : int = 2
1111
var is_first_time : bool = true: set = _set_is_first_time
12-
var games_dir : String = FileUtils.get_home_dir() + "/ROMS": set = _set_games_dir
12+
var games_dir : String = FileUtils.get_home_dir().path_join("ROMS"): set = _set_games_dir
1313
var current_theme : String = "default": set = _set_current_theme
1414
var lang : String = "en": set = _set_lang
1515
var fullscreen : bool = true: set = _set_fullscreen

source/emulators/RetroarchEmulator.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static func get_custom_core_path() -> String:
88

99
var config_file := get_config_path()
1010
if config_file:
11-
var file := FileAccess.open(config_file + "/retroarch.cfg", FileAccess.READ)
11+
var file := FileAccess.open(config_file.path_join("retroarch.cfg"), FileAccess.READ)
1212
if file:
1313
while file.get_position() < file.get_length():
1414
var line := file.get_line()
@@ -32,12 +32,12 @@ static func get_config_path() -> String:
3232
# RetroArch uses either XDG_CONFIG_HOME or HOME.
3333
var xdg := OS.get_environment("XDG_CONFIG_HOME")
3434
if not xdg.is_empty():
35-
var path := xdg + "/retroarch"
35+
var path := xdg.path_join("retroarch")
3636
if DirAccess.dir_exists_absolute(path):
3737
return path
3838
else:
3939
# Default to HOME
40-
var path := FileUtils.get_home_dir() + "/.config/retroarch"
40+
var path := FileUtils.get_home_dir().path_join(".config/retroarch")
4141
if DirAccess.dir_exists_absolute(path):
4242
return path
4343
return ""

source/importers/ESDEImporter.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ extends EmulationStationImporter
33
class_name ESDEImporter
44

55
func _init():
6-
config_path = FileUtils.get_home_dir() + "/ES-DE"
7-
media_path = config_path + "/downloaded_media"
8-
gamelists_path = config_path + "/gamelists"
9-
config_file_path = config_path + "/settings/es_settings.xml"
6+
config_path = FileUtils.get_home_dir().path_join("ES-DE")
7+
media_path = config_path.path_join("downloaded_media")
8+
gamelists_path = config_path.path_join("gamelists")
9+
config_file_path = config_path.path_join("settings/es_settings.xml")
1010

1111
# Returns this importer name
1212
func get_importer_name() -> String:

source/importers/EmulationStationImporter.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ var theme_support : int
77
# Config level 7 is already ES-DE.
88
const MAXIMUM_SUPPORTED_CONFIG_LEVEL = 7
99

10-
var config_path := FileUtils.get_home_dir() + "/.emulationstation"
11-
var media_path := config_path + "/downloaded_media"
12-
var gamelists_path := config_path + "/gamelists"
13-
var config_file_path := config_path + "/es_settings.xml"
10+
var config_path := FileUtils.get_home_dir().path_join(".emulationstation")
11+
var media_path := config_path.path_join("downloaded_media")
12+
var gamelists_path := config_path.path_join("gamelists")
13+
var config_file_path := config_path.path_join("es_settings.xml")
1414
var folder_size : int = -1
1515

1616
var game_datas := {}
@@ -95,7 +95,7 @@ func is_available() -> bool:
9595
return false
9696

9797
# Are the theme's config version too recent?
98-
var theme_path := config_path + "/themes"
98+
var theme_path := config_path.path_join("themes")
9999
var config_level : int = -1
100100
var dir := DirAccess.open(theme_path)
101101
if dir and not dir.list_dir_begin() :# TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
@@ -114,7 +114,7 @@ func is_available() -> bool:
114114
func check_theme_config_level(base_path: String) -> int:
115115

116116
# Query first at root, and only move to folders if it doesn't exist
117-
var root_file := base_path + "/theme.xml"
117+
var root_file := base_path.path_join("theme.xml")
118118
if FileAccess.file_exists(root_file):
119119
var config_level := inspect_theme_xml(root_file)
120120
if config_level != -1:

source/importers/RetroArchImporter.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func is_available() -> bool:
8282

8383
func set_paths(root: String):
8484
config_path = root
85-
thumbnails_path = config_path + "/thumbnails"
86-
playlists_path = config_path + "/playlists"
85+
thumbnails_path = config_path.path_join("thumbnails")
86+
playlists_path = config_path.path_join("playlists")
8787

8888
# Begins the import process. `copy` determines if the user wants
8989
# to copy previous data and, therefore, not affect the other game library

source/integrations/RetroAchievementsIntegration.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func _ready() -> void:
475475
Raw.http.timeout = 10
476476
add_child(Raw.http)
477477

478-
FileUtils.ensure_path(get_cheevos_dir() + "/")
478+
FileUtils.ensure_dir(get_cheevos_dir())
479479

480480
func _download_hash_cache() -> int:
481481
var path := get_cheevos_hash_cache_path()

source/utils/FileUtils.gd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ func test_for_valid_path(paths) -> String:
2020
return expanded_path
2121
return ""
2222

23+
func ensure_dir(dir: String):
24+
if DirAccess.make_dir_recursive_absolute(dir):
25+
push_error("Failed to create directory %s" % dir)
26+
2327
func ensure_path(path: String):
24-
if DirAccess.make_dir_recursive_absolute(path.get_base_dir()):
25-
push_error("Failed to create directory %s" % path.get_base_dir())
28+
ensure_dir(path.get_base_dir())
2629

2730
func expand_path(path: String) -> String:
2831
# Replace ~ by home

0 commit comments

Comments
 (0)