mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
Remove instance logic for BinaryStorage and JsonStorage, part 1
1. part of #389 2. huge refactoring
This commit is contained in:
@@ -1,44 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using JsonProperty = Newtonsoft.Json.JsonPropertyAttribute;
|
||||
|
||||
namespace Wox.Plugin.Everything
|
||||
{
|
||||
public class ContextMenuStorage : JsonStrorage<ContextMenuStorage>
|
||||
public class Settings
|
||||
{
|
||||
[JsonProperty] public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
||||
public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
||||
|
||||
[JsonProperty]
|
||||
public int MaxSearchCount { get; set; }
|
||||
|
||||
public IPublicAPI API { get; set; }
|
||||
|
||||
protected override string FileName { get; } = "EverythingContextMenu";
|
||||
|
||||
protected override void OnAfterLoad(ContextMenuStorage obj)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override ContextMenuStorage LoadDefault()
|
||||
{
|
||||
MaxSearchCount = 100;
|
||||
return this;
|
||||
}
|
||||
public int MaxSearchCount { get; set; } = 100;
|
||||
}
|
||||
|
||||
public class ContextMenu
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string Command { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string Argument { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string ImagePath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ServiceProcess;
|
||||
using System.Windows;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin.Everything.Everything;
|
||||
|
||||
namespace Wox.Plugin.Everything
|
||||
@@ -16,11 +18,26 @@ namespace Wox.Plugin.Everything
|
||||
private readonly EverythingAPI _api = new EverythingAPI();
|
||||
private static readonly List<string> ImageExts = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
|
||||
private static readonly List<string> ExecutableExts = new List<string> { ".exe" };
|
||||
private const string PortableEverything = "PortableEverything";
|
||||
|
||||
private const string EverythingProcessName = "Everything";
|
||||
private const string PortableEverything = "PortableEverything";
|
||||
internal static string LibraryPath;
|
||||
|
||||
private PluginInitContext _context;
|
||||
private ContextMenuStorage _settings = ContextMenuStorage.Instance;
|
||||
|
||||
private readonly Settings _settings;
|
||||
private readonly PluginSettingsStorage<Settings> _storage;
|
||||
|
||||
public Main()
|
||||
{
|
||||
_storage = new PluginSettingsStorage<Settings>();
|
||||
_settings = _storage.Load();
|
||||
}
|
||||
|
||||
~Main()
|
||||
{
|
||||
_storage.Save();
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -31,7 +48,6 @@ namespace Wox.Plugin.Everything
|
||||
if (_settings.MaxSearchCount <= 0)
|
||||
{
|
||||
_settings.MaxSearchCount = 50;
|
||||
_settings.Save();
|
||||
}
|
||||
|
||||
if (keyword == "uninstalleverything")
|
||||
@@ -158,19 +174,22 @@ namespace Wox.Plugin.Everything
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_context = context;
|
||||
_settings.API = context.API;
|
||||
|
||||
LoadLibrary(Path.Combine(context.CurrentPluginMetadata.PluginDirectory,
|
||||
PortableEverything, GetCpuType(), "Everything.dll"));
|
||||
var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||
var libraryDirectory = Path.Combine(pluginDirectory, PortableEverything, CpuType());
|
||||
LibraryPath = Path.Combine(libraryDirectory, "Everything.dll");
|
||||
LoadLibrary(LibraryPath);
|
||||
//Helper.AddDLLDirectory(libraryDirectory);
|
||||
|
||||
StartEverything();
|
||||
}
|
||||
|
||||
private string GetCpuType()
|
||||
private string CpuType()
|
||||
{
|
||||
return (IntPtr.Size == 4) ? "x86" : "x64";
|
||||
return Environment.Is64BitOperatingSystem ? "x64" : "x86";
|
||||
}
|
||||
|
||||
|
||||
private void StartEverything()
|
||||
{
|
||||
if (!CheckEverythingServiceRunning())
|
||||
@@ -268,9 +287,11 @@ namespace Wox.Plugin.Everything
|
||||
|
||||
private string GetEverythingPath()
|
||||
{
|
||||
string directory = Path.Combine(_context.CurrentPluginMetadata.PluginDirectory,
|
||||
PortableEverything, GetCpuType(),
|
||||
"Everything.exe");
|
||||
string directory = Path.Combine(
|
||||
_context.CurrentPluginMetadata.PluginDirectory,
|
||||
PortableEverything, CpuType(),
|
||||
"Everything.exe"
|
||||
);
|
||||
return directory;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user