@@ -25,6 +25,11 @@ public static class SettingsManager
2525 /// </summary>
2626 private static string SettingsFolderName => "Settings" ;
2727
28+ /// <summary>
29+ /// Settings backups directory name.
30+ /// </summary>
31+ private static string BackupFolderName => "Backups" ;
32+
2833 /// <summary>
2934 /// Settings file name.
3035 /// </summary>
@@ -38,6 +43,7 @@ public static class SettingsManager
3843 /// <summary>
3944 /// Legacy XML settings file extension.
4045 /// </summary>
46+ [ Obsolete ( "Legacy XML settings are no longer used, but the extension is kept for migration purposes." ) ]
4147 private static string LegacySettingsFileExtension => ".xml" ;
4248
4349 /// <summary>
@@ -77,6 +83,15 @@ public static string GetSettingsFolderLocation()
7783 AssemblyManager . Current . Name , SettingsFolderName ) ;
7884 }
7985
86+ /// <summary>
87+ /// Method to get the path of the settings backup folder.
88+ /// </summary>
89+ /// <returns>Path to the settings backup folder.</returns>
90+ public static string GetSettingsBackupFolderLocation ( )
91+ {
92+ return Path . Combine ( GetSettingsFolderLocation ( ) , BackupFolderName ) ;
93+ }
94+
8095 /// <summary>
8196 /// Method to get the settings file name.
8297 /// </summary>
@@ -86,6 +101,16 @@ public static string GetSettingsFileName()
86101 return $ "{ SettingsFileName } { SettingsFileExtension } ";
87102 }
88103
104+ /// <summary>
105+ /// Method to get the legacy settings file name.
106+ /// </summary>
107+ /// <returns>Legacy settings file name.</returns>
108+ [ Obsolete ( "Legacy XML settings are no longer used, but the method is kept for migration purposes." ) ]
109+ public static string GetLegacySettingsFileName ( )
110+ {
111+ return $ "{ SettingsFileName } { LegacySettingsFileExtension } ";
112+ }
113+
89114 /// <summary>
90115 /// Method to get the settings file path.
91116 /// </summary>
@@ -99,9 +124,10 @@ public static string GetSettingsFilePath()
99124 /// Method to get the legacy XML settings file path.
100125 /// </summary>
101126 /// <returns>Legacy XML settings file path.</returns>
127+ [ Obsolete ( "Legacy XML settings are no longer used, but the method is kept for migration purposes." ) ]
102128 private static string GetLegacySettingsFilePath ( )
103129 {
104- return Path . Combine ( GetSettingsFolderLocation ( ) , $ " { SettingsFileName } { LegacySettingsFileExtension } " ) ;
130+ return Path . Combine ( GetSettingsFolderLocation ( ) , GetLegacySettingsFileName ( ) ) ;
105131 }
106132
107133 #endregion
@@ -151,16 +177,17 @@ public static void Load()
151177 // Save in new JSON format
152178 Save ( ) ;
153179
154- // Backup the old XML file with timestamp to avoid overwriting existing backups
155- // If a backup with the same timestamp exists (unlikely), it will be overwritten
156- // since it represents the same migration attempt
157- var backupFilePath = Path . Combine ( GetSettingsFolderLocation ( ) ,
158- $ "{ SettingsFileName } _{ TimestampHelper . GetTimestamp ( ) } { LegacySettingsFileExtension } .backup") ;
180+ // Create a backup of the legacy XML file and delete the original
181+ Directory . CreateDirectory ( GetSettingsBackupFolderLocation ( ) ) ;
182+
183+ var backupFilePath = Path . Combine ( GetSettingsBackupFolderLocation ( ) ,
184+ $ "{ TimestampHelper . GetTimestamp ( ) } _{ GetLegacySettingsFileName ( ) } ") ;
185+
159186 File . Copy ( legacyFilePath , backupFilePath , true ) ;
160- Log . Info ( $ "Legacy XML settings file backed up to: { backupFilePath } ") ;
161187
162- // Note: The original XML file is intentionally not deleted to allow users to revert if needed.
163- // Users can manually delete Settings.xml after verifying the migration was successful.
188+ File . Delete ( legacyFilePath ) ;
189+
190+ Log . Info ( $ "Legacy XML settings file backed up to: { backupFilePath } ") ;
164191
165192 Log . Info ( "Settings migration from XML to JSON completed successfully." ) ;
166193
@@ -182,11 +209,6 @@ private static SettingsInfo DeserializeFromFile(string filePath)
182209
183210 var settingsInfo = JsonSerializer . Deserialize < SettingsInfo > ( jsonString , JsonOptions ) ;
184211
185- if ( settingsInfo == null )
186- {
187- throw new InvalidOperationException ( "Failed to deserialize settings from JSON file. The result was null." ) ;
188- }
189-
190212 return settingsInfo ;
191213 }
192214
@@ -195,6 +217,7 @@ private static SettingsInfo DeserializeFromFile(string filePath)
195217 /// </summary>
196218 /// <param name="filePath">Path to the XML settings file.</param>
197219 /// <returns>Settings as <see cref="SettingsInfo" />.</returns>
220+ [ Obsolete ( "Legacy XML settings are no longer used, but the method is kept for migration purposes." ) ]
198221 private static SettingsInfo DeserializeFromXmlFile ( string filePath )
199222 {
200223 var xmlSerializer = new XmlSerializer ( typeof ( SettingsInfo ) ) ;
@@ -203,11 +226,6 @@ private static SettingsInfo DeserializeFromXmlFile(string filePath)
203226
204227 var settingsInfo = xmlSerializer . Deserialize ( fileStream ) as SettingsInfo ;
205228
206- if ( settingsInfo == null )
207- {
208- throw new InvalidOperationException ( "Failed to deserialize settings from XML file. The result was null." ) ;
209- }
210-
211229 return settingsInfo ;
212230 }
213231
@@ -239,6 +257,19 @@ private static void SerializeToFile(string filePath)
239257
240258 #endregion
241259
260+ #region Backup
261+ /*
262+ private static void Backup()
263+ {
264+ Log.Info("Creating settings backup...");
265+
266+ // Create the backup directory if it does not exist
267+ Directory.CreateDirectory(GetSettingsBackupFolderLocation());
268+ }
269+ */
270+
271+ #endregion
272+
242273 #region Upgrade
243274
244275 /// <summary>
0 commit comments