@@ -31,11 +31,12 @@ namespace Flow.Launcher.Infrastructure.Storage
31
31
protected JsonStorage ( )
32
32
{
33
33
}
34
+
34
35
public JsonStorage ( string filePath )
35
36
{
36
37
FilePath = filePath ;
37
38
DirectoryPath = Path . GetDirectoryName ( filePath ) ?? throw new ArgumentException ( "Invalid file path" ) ;
38
-
39
+
39
40
Helper . ValidateDirectory ( DirectoryPath ) ;
40
41
}
41
42
@@ -97,6 +98,7 @@ private async ValueTask<T> LoadBackupOrDefaultAsync()
97
98
return default ;
98
99
}
99
100
}
101
+
100
102
private void RestoreBackup ( )
101
103
{
102
104
Log . Info ( $ "|JsonStorage.Load|Failed to load settings.json, { BackupFilePath } restored successfully") ;
@@ -179,25 +181,21 @@ private void BackupOriginFile()
179
181
public void Save ( )
180
182
{
181
183
string serialized = JsonSerializer . Serialize ( Data ,
182
- new JsonSerializerOptions
183
- {
184
- WriteIndented = true
185
- } ) ;
184
+ new JsonSerializerOptions { WriteIndented = true } ) ;
186
185
187
186
File . WriteAllText ( TempFilePath , serialized ) ;
188
187
189
188
AtomicWriteSetting ( ) ;
190
189
}
190
+
191
191
public async Task SaveAsync ( )
192
192
{
193
- var tempOutput = File . OpenWrite ( TempFilePath ) ;
193
+ await using var tempOutput = File . OpenWrite ( TempFilePath ) ;
194
194
await JsonSerializer . SerializeAsync ( tempOutput , Data ,
195
- new JsonSerializerOptions
196
- {
197
- WriteIndented = true
198
- } ) ;
195
+ new JsonSerializerOptions { WriteIndented = true } ) ;
199
196
AtomicWriteSetting ( ) ;
200
197
}
198
+
201
199
private void AtomicWriteSetting ( )
202
200
{
203
201
if ( ! File . Exists ( FilePath ) )
@@ -206,9 +204,9 @@ private void AtomicWriteSetting()
206
204
}
207
205
else
208
206
{
209
- File . Replace ( TempFilePath , FilePath , BackupFilePath ) ;
207
+ var finalFilePath = new FileInfo ( FilePath ) . LinkTarget ?? FilePath ;
208
+ File . Replace ( TempFilePath , finalFilePath , BackupFilePath ) ;
210
209
}
211
210
}
212
-
213
211
}
214
212
}
0 commit comments