Flow.Launcher/Flow.Launcher.Infrastructure/Storage/PluginBinaryStorage.cs

50 lines
1.5 KiB
C#
Raw Normal View History

2025-04-01 06:16:32 +00:00
using System.IO;
2025-04-04 08:45:58 +00:00
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
2025-04-01 06:16:32 +00:00
namespace Flow.Launcher.Infrastructure.Storage
{
public class PluginBinaryStorage<T> : BinaryStorage<T> where T : new()
{
2025-04-04 08:45:58 +00:00
private static readonly string ClassName = "PluginBinaryStorage";
// We should not initialize API in static constructor because it will create another API instance
private static IPublicAPI api = null;
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
2025-04-01 06:16:32 +00:00
public PluginBinaryStorage(string cacheName, string cacheDirectory)
{
DirectoryPath = cacheDirectory;
2025-04-04 08:45:58 +00:00
FilesFolders.ValidateDirectory(DirectoryPath);
2025-04-01 06:16:32 +00:00
FilePath = Path.Combine(DirectoryPath, $"{cacheName}{FileSuffix}");
}
2025-04-04 08:45:58 +00:00
public new void Save()
{
try
{
base.Save();
}
catch (System.Exception e)
{
API.LogException(ClassName, $"Failed to save plugin caches to path: {FilePath}", e);
}
}
public new async Task SaveAsync()
{
try
{
await base.SaveAsync();
}
catch (System.Exception e)
{
API.LogException(ClassName, $"Failed to save plugin caches to path: {FilePath}", e);
}
}
2025-04-01 06:16:32 +00:00
}
}