2016-04-21 00:53:21 +00:00
|
|
|
|
using System.IO;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
2016-04-21 00:53:21 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Infrastructure.Storage
|
2016-04-21 00:53:21 +00:00
|
|
|
|
{
|
2025-02-08 11:12:53 +00:00
|
|
|
|
public class PluginJsonStorage<T> : JsonStorage<T> where T : new()
|
2016-04-21 00:53:21 +00:00
|
|
|
|
{
|
2025-02-08 11:12:53 +00:00
|
|
|
|
// Use assembly name to check which plugin is using this storage
|
|
|
|
|
|
public readonly string AssemblyName;
|
|
|
|
|
|
|
2021-06-21 11:31:07 +00:00
|
|
|
|
public PluginJsonStorage()
|
2016-04-21 00:53:21 +00:00
|
|
|
|
{
|
2021-05-11 19:10:03 +00:00
|
|
|
|
// C# related, add python related below
|
2017-02-07 00:21:39 +00:00
|
|
|
|
var dataType = typeof(T);
|
2025-02-08 11:12:53 +00:00
|
|
|
|
AssemblyName = dataType.Assembly.GetName().Name;
|
|
|
|
|
|
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, AssemblyName);
|
2017-02-07 00:21:39 +00:00
|
|
|
|
Helper.ValidateDirectory(DirectoryPath);
|
2016-04-27 01:15:53 +00:00
|
|
|
|
|
2017-02-07 00:21:39 +00:00
|
|
|
|
FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}");
|
2016-04-21 00:53:21 +00:00
|
|
|
|
}
|
2021-02-14 10:08:30 +00:00
|
|
|
|
|
2021-06-21 11:31:07 +00:00
|
|
|
|
public PluginJsonStorage(T data) : this()
|
2021-02-14 10:08:30 +00:00
|
|
|
|
{
|
2023-01-07 19:11:43 +00:00
|
|
|
|
Data = data;
|
2021-02-14 10:08:30 +00:00
|
|
|
|
}
|
2025-02-08 11:12:53 +00:00
|
|
|
|
|
|
|
|
|
|
public void DeleteDirectory()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Directory.Exists(DirectoryPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(DirectoryPath, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-21 00:53:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|