Skip to content

Commit 8729333

Browse files
committed
Introduce config versioning
1 parent 05f9b2d commit 8729333

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

source/Config.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func save_game_data(game_data: RetroHubGameData) -> bool:
404404
push_error("Error when opening file %s!" % metadata_path)
405405
return false
406406

407-
file.store_string(JSON.stringify(game_data_raw, "\t"))
407+
file.store_string(JSON.stringify(game_data_raw, "\t", false))
408408
file.close()
409409

410410
emit_signal("game_data_updated", game_data)
@@ -506,7 +506,7 @@ func save_theme_config():
506506
if not file:
507507
push_error("Error when saving theme config at %s" % theme_config_path)
508508
return
509-
file.store_string(JSON.stringify(_theme_config, "\t"))
509+
file.store_string(JSON.stringify(_theme_config, "\t", false))
510510
file.close()
511511

512512
for key in _theme_config:

source/data/ConfigData.gd

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _config_changed := false
77
var _old_config : Dictionary
88

99
# Games directory
10+
var config_version : int = 1
1011
var is_first_time : bool = true: set = _set_is_first_time
1112
var games_dir : String = FileUtils.get_home_dir() + "/ROMS": set = _set_games_dir
1213
var current_theme : String = "default": set = _set_current_theme
@@ -35,6 +36,7 @@ var virtual_keyboard_show_on_controller : bool = true: set = _set_virtual_keyboa
3536
var virtual_keyboard_show_on_mouse : bool = false: set = _set_virtual_keyboard_show_on_mouse
3637
var accessibility_screen_reader_enabled : bool = true: set = _set_accessibility_screen_reader_enabled
3738

39+
const KEY_CONFIG_VERSION = "config_version"
3840
const KEY_IS_FIRST_TIME = "is_first_time"
3941
const KEY_GAMES_DIR = "games_dir"
4042
const KEY_CURRENT_THEME = "current_theme"
@@ -65,6 +67,7 @@ const KEY_ACCESSIBILITY_SCREEN_READER_ENABLED = "accessibility_screen_reader_ena
6567

6668

6769
const _keys = [
70+
KEY_CONFIG_VERSION,
6871
KEY_IS_FIRST_TIME,
6972
KEY_GAMES_DIR,
7073
KEY_CURRENT_THEME,
@@ -162,6 +165,12 @@ static func default_virtual_keyboard_type() -> String:
162165
else:
163166
return "builtin"
164167

168+
func _get_stored_version(config: Dictionary) -> int:
169+
if config.has(KEY_CONFIG_VERSION):
170+
return int(config[KEY_CONFIG_VERSION])
171+
else:
172+
return 0
173+
165174
func _set_is_first_time(_is_first_time):
166175
mark_for_saving()
167176
is_first_time = _is_first_time
@@ -338,7 +347,7 @@ func save_config_to_path(path: String, force_save: bool = false) -> int:
338347
dict[key] = get(key)
339348

340349
# Save JSON to file
341-
var json_output := JSON.stringify(dict, "\t")
350+
var json_output := JSON.stringify(dict, "\t", false)
342351
file.store_string(json_output)
343352
file.close()
344353
_config_changed = false
@@ -363,6 +372,7 @@ func process_new_change(key: String):
363372
accessibility_screen_reader_enabled = is_first_time
364373

365374
func process_raw_config_changes(config: Dictionary):
375+
## Before config version was introduced
366376
# Scraper credentials were moved to a dedicated file
367377
var creds := [
368378
"scraper_ss_username",
@@ -424,3 +434,18 @@ func process_raw_config_changes(config: Dictionary):
424434
config[KEY_INPUT_CONTROLLER_ICON_TYPE] = "ouya"
425435
0, _:
426436
config[KEY_INPUT_CONTROLLER_ICON_TYPE] = "auto"
437+
438+
var version := _get_stored_version(config)
439+
while version < config_version:
440+
_should_save = true
441+
_handle_config_update(config, version)
442+
version += 1
443+
444+
func _handle_config_update(config: Dictionary, version: int):
445+
match version:
446+
0:
447+
# First config version; RetroHub port from Godot 3 to Godot 4
448+
# Input remaps have to be reset
449+
config[KEY_INPUT_KEY_MAP] = input_key_map
450+
config[KEY_CUSTOM_INPUT_REMAP] = custom_input_remap
451+
RetroHubUI.call_deferred("show_warning", "The following settings had to be reset due to incompatible changes in RetroHub:\n \n - Keyboard remaps\n-Controller custom layout\n \nPlease reconfigure these in the Settings menu if desired.")

source/utils/JSONUtils.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func save_json_file(json, file_path: String):
2121
var file := FileAccess.open(file_path, FileAccess.WRITE)
2222
if not file:
2323
return FileAccess.get_open_error()
24-
file.store_string(JSON.stringify(json, "\t"))
24+
file.store_string(JSON.stringify(json, "\t", false))
2525
file.close()
2626

2727
func make_system_specific(json: Dictionary, curr_system: String):

0 commit comments

Comments
 (0)