2023-04-25 12:04:08 +00:00
|
|
|
|
using System.IO;
|
2025-04-04 02:34:59 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure.Logger;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
2025-06-06 10:37:17 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2025-04-04 03:46:07 +00:00
|
|
|
|
using Flow.Launcher.Plugin.SharedCommands;
|
2017-02-07 00:21:39 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Infrastructure.Storage
|
2017-02-07 00:21:39 +00:00
|
|
|
|
{
|
2025-06-06 10:37:17 +00:00
|
|
|
|
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
|
|
|
|
|
|
public class FlowLauncherJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
|
2017-02-07 00:21:39 +00:00
|
|
|
|
{
|
2025-04-04 02:34:59 +00:00
|
|
|
|
private static readonly string ClassName = "FlowLauncherJsonStorage";
|
|
|
|
|
|
|
2020-04-21 12:16:10 +00:00
|
|
|
|
public FlowLauncherJsonStorage()
|
2017-02-07 00:21:39 +00:00
|
|
|
|
{
|
2025-04-11 14:13:58 +00:00
|
|
|
|
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName);
|
|
|
|
|
|
FilesFolders.ValidateDirectory(DirectoryPath);
|
2017-02-07 00:21:39 +00:00
|
|
|
|
|
|
|
|
|
|
var filename = typeof(T).Name;
|
2025-04-11 14:13:58 +00:00
|
|
|
|
FilePath = Path.Combine(DirectoryPath, $"{filename}{FileSuffix}");
|
2017-02-07 00:21:39 +00:00
|
|
|
|
}
|
2025-04-04 02:34:59 +00:00
|
|
|
|
|
|
|
|
|
|
public new void Save()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
|
{
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Exception(ClassName, $"Failed to save FL settings to path: {FilePath}", e);
|
2025-04-04 02:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public new async Task SaveAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
await base.SaveAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
|
{
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Exception(ClassName, $"Failed to save FL settings to path: {FilePath}", e);
|
2025-04-04 02:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-02-07 00:21:39 +00:00
|
|
|
|
}
|
2025-04-04 02:34:59 +00:00
|
|
|
|
}
|