Skip to content

Commit 470b47f

Browse files
committed
Fix issues with frontend importers
1 parent 76f2420 commit 470b47f

File tree

5 files changed

+204
-283
lines changed

5 files changed

+204
-283
lines changed

scenes/popups/first_time/GamesSection.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ signal advance_section
1414
@onready var n_next_button := %NextButton
1515

1616
func _ready():
17-
set_path(RetroHubConfig.config.games_dir)
1817
set_media_path(RetroHubConfig.config.custom_gamemedia_dir)
1918
n_use_custom_media.set_pressed_no_signal(RetroHubConfig.config.custom_gamemedia_dir.is_empty())
2019
_on_use_custom_media_toggled(n_use_custom_media.button_pressed)
2120

2221
func grab_focus():
22+
set_path(RetroHubConfig.config.games_dir)
2323
if RetroHubConfig.config.accessibility_screen_reader_enabled:
2424
n_intro_lbl.grab_focus()
2525
else:

source/Config.gd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,12 @@ func _fetch_game_data(path: String, game: RetroHubGameData) -> bool:
417417
func _get_game_data_path_from_file(system_name: String, file_name: String) -> String:
418418
return _get_gamelists_dir().path_join(system_name).path_join(file_name.get_file().trim_suffix(file_name.get_extension()) + "json")
419419

420-
func _save_game_data(game_data: RetroHubGameData) -> bool:
421-
var metadata_path := _get_game_data_path_from_file(game_data.system.name, game_data.path)
420+
func _save_game_data(game_data: RetroHubGameData, system_folder_name : String = "", signal_changes : bool = true) -> bool:
421+
var metadata_path : String
422+
if system_folder_name.is_empty():
423+
metadata_path = _get_game_data_path_from_file(game_data.system.name, game_data.path)
424+
else:
425+
metadata_path = _get_game_data_path_from_file(system_folder_name, game_data.path)
422426
FileUtils.ensure_path(metadata_path)
423427
var game_data_raw := {
424428
"name": game_data.name,
@@ -457,7 +461,8 @@ func _save_game_data(game_data: RetroHubGameData) -> bool:
457461
file.store_string(JSON.stringify(game_data_raw, "\t", false))
458462
file.close()
459463

460-
emit_signal("game_data_updated", game_data)
464+
if signal_changes:
465+
emit_signal("game_data_updated", game_data)
461466
return true
462467

463468

source/data/SystemList.gd

Lines changed: 0 additions & 257 deletions
This file was deleted.

source/importers/EmulationStationImporter.gd

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var folder_size : int = -1
1414

1515
var game_datas := {}
1616

17+
var known_systems : Array[String] = []
18+
1719
const ES_MEDIA_NAMES := [
1820
"3dboxes", "marquees", "screenshots",
1921
"titlescreens", "videos"
@@ -164,6 +166,19 @@ func inspect_theme_xml(path: String) -> int:
164166
# to copy previous data and, therefore, not affect the other game library
165167
# platform. This will be run in a thread, so avoid any unsafe-thread API
166168
func begin_import(copy: bool):
169+
# We don't have information on systems yet, so workaround and load system.json to get it
170+
# Our systems names come from ES, so we can use them directly
171+
var _raw_systems = JSONUtils.load_json_file(RetroHubConfig._get_systems_file())
172+
if not _raw_systems is Array:
173+
push_error("Failed loading system.json")
174+
return
175+
for system in _raw_systems:
176+
if system.has("name"):
177+
known_systems.append(system["name"])
178+
else:
179+
push_error("Failed loading system.json")
180+
return
181+
167182
reset_major(4)
168183
progress_major("Importing configuration")
169184
import_config()
@@ -210,6 +225,7 @@ func import_metadata():
210225
next_folder = dir.get_next()
211226
reset_minor(total_games)
212227
for system in gamelists.keys():
228+
if not system in known_systems: continue
213229
var base_path := RetroHubConfig._get_gamelists_dir().path_join(system as String)
214230
FileUtils.ensure_path(base_path)
215231
var data = gamelists[system]
@@ -253,8 +269,6 @@ func process_metadata(system: String, dict: Dictionary):
253269
if dict.has("favorite"):
254270
game_data.favorite = bool(dict["favorite"])
255271
var short_path := system.path_join(game_data.path.get_file().get_basename())
256-
if(RetroHubConfig.systems.has(system)):
257-
game_data.system = RetroHubConfig.systems[system]
258272
game_data.system_path = system
259273
game_datas[short_path] = game_data
260274

@@ -313,9 +327,10 @@ func save_game_data():
313327
reset_minor(game_datas.size())
314328
for game_data in game_datas.values():
315329
progress_minor("Saving \"%s\" metadata" % game_data.name)
316-
if not RetroHubConfig._save_game_data(game_data):
330+
if not RetroHubConfig._save_game_data(game_data, game_data.system_path, false):
317331
push_error("Failed to save game data for \"%s\"" % game_data.name)
318332

319333

320334
func cleanup():
321335
game_datas.clear()
336+
known_systems.clear()

0 commit comments

Comments
 (0)