Flow.Launcher/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

59 lines
1.8 KiB
C#
Raw Permalink Normal View History

using System.IO;
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;
using Flow.Launcher.Plugin;
2025-04-04 03:46:07 +00:00
using Flow.Launcher.Plugin.SharedCommands;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Infrastructure.Storage
{
// Expose ISaveable interface in derived class to make sure we are calling the new version of Save method
public class PluginJsonStorage<T> : JsonStorage<T>, ISavable where T : new()
{
// Use assembly name to check which plugin is using this storage
public readonly string AssemblyName;
private static readonly string ClassName = "PluginJsonStorage";
2021-06-21 11:31:07 +00:00
public PluginJsonStorage()
{
2021-05-11 19:10:03 +00:00
// C# related, add python related below
var dataType = typeof(T);
AssemblyName = dataType.Assembly.GetName().Name;
DirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, AssemblyName);
FilesFolders.ValidateDirectory(DirectoryPath);
FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}");
}
2021-06-21 11:31:07 +00:00
public PluginJsonStorage(T data) : this()
{
2023-01-07 19:11:43 +00:00
Data = data;
}
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 plugin settings to path: {FilePath}", e);
}
}
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 plugin settings to path: {FilePath}", e);
}
}
}
}