-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Main.cs
259 lines (245 loc) · 11.3 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Controls;
using Community.PowerToys.Run.Plugin.Everything.Properties;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Plugin;
using Wox.Plugin.Logger;
using static Community.PowerToys.Run.Plugin.Everything.Interop.NativeMethods;
namespace Community.PowerToys.Run.Plugin.Everything
{
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IPluginI18n
{
public static string PluginID => "A86867E2D932459CBD77D176373DD657";
public string Name => Resources.plugin_name;
public string Description => Resources.plugin_description;
private readonly Settings _setting = new();
private Everything _everything;
private ContextMenuLoader _contextMenuLoader;
private bool _disposed;
public IEnumerable<PluginAdditionalOption> AdditionalOptions =>
[
new()
{
Key = nameof(Settings.Context),
DisplayLabel = Resources.Context,
DisplayDescription = Resources.Context_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.Context,
},
new()
{
Key = nameof(Settings.Sort),
DisplayLabel = Resources.Sort,
DisplayDescription = Resources.Sort_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
ComboBoxItems = Enum.GetValues(typeof(Sort)).Cast<int>().Select(v => new KeyValuePair<string, string>(((Sort)v).ToString(), v + string.Empty)).ToList(),
ComboBoxValue = (int)_setting.Sort,
},
new()
{
Key = nameof(Settings.Max),
DisplayLabel = Resources.Max,
DisplayDescription = Resources.Max_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Numberbox,
NumberValue = _setting.Max,
},
new()
{
Key = nameof(Settings.Prefix),
DisplayLabel = Resources.Prefix,
DisplayDescription = Resources.Prefix_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.Prefix,
},
new()
{
Key = nameof(Settings.EverythingPath),
DisplayLabel = Resources.EverythingPath,
DisplayDescription = Resources.EverythingPath_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.EverythingPath,
},
new()
{
Key = nameof(Settings.CustomProgram),
DisplayLabel = Resources.CustomProgram,
DisplayDescription = Resources.CustomProgram_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.CustomProgram,
},
new()
{
Key = nameof(Settings.CustomArg),
DisplayLabel = Resources.CustomArg,
DisplayDescription = Resources.CustomArg_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.CustomArg,
},
new()
{
Key = nameof(Settings.Copy),
DisplayLabel = Resources.SwapCopy,
DisplayDescription = Resources.SwapCopy_Description,
Value = _setting.Copy,
},
new()
{
Key = nameof(Settings.EnvVar),
DisplayLabel = Resources.EnvVar,
DisplayDescription = Resources.EnvVar_Description,
Value = _setting.EnvVar,
},
new()
{
Key = nameof(Settings.MatchPath),
DisplayLabel = Resources.Match_path,
DisplayDescription = Resources.Match_path_Description,
Value = _setting.MatchPath,
},
new()
{
Key = nameof(Settings.Preview),
DisplayLabel = Resources.Preview,
DisplayDescription = Resources.Preview_Description,
Value = _setting.Preview,
},
new()
{
Key = nameof(Settings.QueryText),
DisplayLabel = Resources.QueryText,
DisplayDescription = Resources.QueryText_Description,
Value = _setting.QueryText,
},
new()
{
Key = nameof(Settings.RegEx),
DisplayLabel = Resources.RegEx,
DisplayDescription = Resources.RegEx_Description,
Value = _setting.RegEx,
},
new()
{
Key = nameof(Settings.ShowMore),
DisplayLabel = Resources.ShowMore,
DisplayDescription = Resources.ShowMore_Description,
Value = _setting.ShowMore,
},
new()
{
Key = nameof(Settings.Updates),
DisplayLabel = Resources.Updates,
DisplayDescription = $"v{Assembly.GetExecutingAssembly().GetName().Version}",
Value = _setting.Updates,
},
#if DEBUG
new()
{
Key = nameof(Settings.Log),
DisplayLabel = "Debug Mode",
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
ComboBoxItems = Enum.GetValues(typeof(LogLevel)).Cast<int>().Select(d => new KeyValuePair<string, string>(((LogLevel)d).ToString(), d + string.Empty)).ToList(),
ComboBoxValue = (int)_setting.Log,
},
#endif
];
public void Init(PluginInitContext context)
{
if (_setting.Updates)
Task.Run(() => new Update().UpdateAsync(Assembly.GetExecutingAssembly().GetName().Version, _setting));
if (Everything_GetMinorVersion() < 5) _setting.Getfilters();
_everything = new Everything(_setting);
_contextMenuLoader = new ContextMenuLoader(context, _setting.Context);
_contextMenuLoader.Update(_setting);
#if DEBUG
if (_setting.Log > LogLevel.None)
Debugger.Write("Init Complete\r\n");
#endif
}
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
if (settings.AdditionalOptions != null)
{
_setting.Sort = (Sort)settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Sort)).ComboBoxValue;
_setting.Max = (uint)settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Max)).NumberValue;
_setting.Context = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Context)).TextValue;
_setting.RegEx = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.RegEx)).Value;
_setting.Preview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Preview)).Value;
_setting.MatchPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.MatchPath)).Value;
_setting.Copy = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Copy)).Value;
_setting.QueryText = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.QueryText)).Value;
_setting.EnvVar = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.EnvVar)).Value;
_setting.Updates = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Updates)).Value;
_setting.Prefix = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Prefix)).TextValue;
_setting.EverythingPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.EverythingPath)).TextValue;
_setting.CustomProgram = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.CustomProgram)).TextValue;
_setting.CustomArg = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.CustomArg)).TextValue;
_setting.ShowMore = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.ShowMore)).Value;
#if DEBUG
_setting.Log = (LogLevel)settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Log)).ComboBoxValue;
#endif
_everything?.UpdateSettings(_setting);
_contextMenuLoader?.Update(_setting);
}
}
public List<Result> Query(Query query)
{
List<Result> results = [];
return results;
}
public List<Result> Query(Query query, bool delayedExecution)
{
List<Result> results = [];
if (!string.IsNullOrEmpty(query.Search))
{
string searchQuery = query.Search;
try
{
results.AddRange(_everything.Query(searchQuery, _setting));
}
catch (System.ComponentModel.Win32Exception)
{
results.Add(new Result()
{
Title = Resources.Everything_not_running,
SubTitle = Resources.Everything_ini,
IcoPath = "Images/warning.png",
Score = int.MaxValue,
});
}
catch (Exception e)
{
#if DEBUG
if (_setting.Log > LogLevel.None)
Debugger.Write($"Everything Exception: {e.Message}\r\n{e.StackTrace}\r\n");
#endif
Log.Exception($"Everything Exception: {e.Message}\r\n{e.StackTrace}\r\n", e, GetType());
}
}
return results;
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
}
_disposed = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult) => _contextMenuLoader.LoadContextMenus(selectedResult);
public Control CreateSettingPanel() => throw new NotImplementedException();
public string GetTranslatedPluginTitle() => Resources.plugin_name;
public string GetTranslatedPluginDescription() => Resources.plugin_description;
}
}