11using System ;
22using System . IO ;
33using System . Runtime . InteropServices ;
4- using System . Text . Json ;
4+ using GaldrJson ;
55using Microsoft . Win32 ;
66using Scum_Bag . DataAccess . Data ;
77
@@ -11,6 +11,7 @@ internal sealed class Config
1111{
1212 #region Fields
1313
14+ private readonly IGaldrJsonSerializer _jsonSerializer ;
1415 private readonly string _dataDir ;
1516 private readonly string _savesPath ;
1617 private readonly string _latestScreenshotName ;
@@ -23,8 +24,10 @@ internal sealed class Config
2324
2425 #region Constructor
2526
26- public Config ( )
27+ public Config ( IGaldrJsonSerializer jsonSerializer )
2728 {
29+ _jsonSerializer = jsonSerializer ;
30+
2831 _dataDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "Scum Bag" ) ;
2932 _backupsDirectory = _dataDir ;
3033 _savesPath = Path . Combine ( _dataDir , "saves.json" ) ;
@@ -95,7 +98,7 @@ public Settings GetSettings()
9598
9699 if ( File . Exists ( _settingsPath ) )
97100 {
98- settings = JsonSerializer . Deserialize ( File . ReadAllText ( _settingsPath ) , SaveDataJsonSerializerContext . Default . Settings ) ;
101+ settings = _jsonSerializer . Deserialize < Settings > ( File . ReadAllText ( _settingsPath ) ) ;
99102 }
100103
101104 return settings ;
@@ -105,7 +108,7 @@ public void SaveSettings(Settings settings)
105108 {
106109 _backupsDirectory = settings . BackupsDirectory ;
107110 _steamExePath = settings . SteamExePath ;
108- string settingsFileContent = JsonSerializer . Serialize ( settings , SaveDataJsonSerializerContext . Default . Settings ) ;
111+ string settingsFileContent = _jsonSerializer . Serialize ( settings ) ;
109112 File . WriteAllText ( _settingsPath , settingsFileContent ) ;
110113 }
111114
@@ -117,7 +120,7 @@ private void Initialize()
117120 {
118121 if ( File . Exists ( _settingsPath ) )
119122 {
120- Settings settings = JsonSerializer . Deserialize ( File . ReadAllText ( _settingsPath ) , SaveDataJsonSerializerContext . Default . Settings ) ;
123+ Settings settings = _jsonSerializer . Deserialize < Settings > ( File . ReadAllText ( _settingsPath ) ) ;
121124 _backupsDirectory = settings . BackupsDirectory ;
122125 _steamExePath = settings . SteamExePath ;
123126 }
@@ -126,7 +129,7 @@ private void Initialize()
126129 {
127130 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
128131 {
129- _steamExePath = Registry . CurrentUser . OpenSubKey ( "Software\\ Valve\\ Steam" ) . GetValue ( "SteamExe" ) . ToString ( ) ;
132+ _steamExePath = Registry . CurrentUser . OpenSubKey ( "Software\\ Valve\\ Steam" ) ? . GetValue ( "SteamExe" ) ? . ToString ( ) ;
130133 }
131134 else
132135 {
0 commit comments