Merge pull request #1845 from Flow-Launcher/dev

Release 1.12.1
This commit is contained in:
Jeremy Wu 2023-01-25 21:30:17 +11:00 committed by GitHub
commit b1de8ae40a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View file

@ -13,12 +13,17 @@ namespace Flow.Launcher.Infrastructure.Storage
public class JsonStorage<T> where T : new()
{
protected T? Data;
// need a new directory name
public const string DirectoryName = "Settings";
public const string FileSuffix = ".json";
protected string FilePath { get; init; } = null!;
private string TempFilePath => $"{FilePath}.tmp";
private string BackupFilePath => $"{FilePath}.bak";
protected string DirectoryPath { get; init; } = null!;
@ -35,7 +40,7 @@ namespace Flow.Launcher.Infrastructure.Storage
{
try
{
Data = JsonSerializer.Deserialize<T>(serialized)?? TryLoadBackup() ?? LoadDefault();
Data = JsonSerializer.Deserialize<T>(serialized) ?? TryLoadBackup() ?? LoadDefault();
}
catch (JsonException)
{
@ -46,6 +51,7 @@ namespace Flow.Launcher.Infrastructure.Storage
{
Data = TryLoadBackup() ?? LoadDefault();
}
return Data.NonNull();
}
@ -67,12 +73,15 @@ namespace Flow.Launcher.Infrastructure.Storage
try
{
var data = JsonSerializer.Deserialize<T>(File.ReadAllText(BackupFilePath));
if (data != null)
{
Log.Info($"|JsonStorage.Load|Failed to load settings.json, {BackupFilePath} restored successfully");
File.Replace(BackupFilePath, FilePath, null);
return data;
}
return default;
}
catch (JsonException)
@ -94,14 +103,22 @@ namespace Flow.Launcher.Infrastructure.Storage
public void Save()
{
string serialized = JsonSerializer.Serialize(Data, new JsonSerializerOptions
{
WriteIndented = true
});
string serialized = JsonSerializer.Serialize(Data,
new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(TempFilePath, serialized);
File.Replace(TempFilePath, FilePath, BackupFilePath);
File.Delete(TempFilePath);
if (!File.Exists(FilePath))
{
File.Move(TempFilePath, FilePath);
}
else
{
File.Replace(TempFilePath, FilePath, BackupFilePath);
}
}
}
}

View file

@ -1,4 +1,4 @@
version: '1.12.0.{build}'
version: '1.12.1.{build}'
init:
- ps: |