forked from lin-ycv/EverythingPowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
200 lines (177 loc) · 6.75 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
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Controls;
using Community.PowerToys.Run.Plugin.Everything.Properties;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Wox.Plugin.Logger;
using static Community.PowerToys.Run.Plugin.Everything.NativeMethods;
namespace Community.PowerToys.Run.Plugin.Everything
{
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IPluginI18n
{
private const string AltIcon = nameof(AltIcon);
private const string RegEx = nameof(RegEx);
private const string NoPreview = nameof(NoPreview);
private const string MatchPath = nameof(MatchPath);
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
private bool regEx;
private bool preview;
private bool altIcon;
private bool matchPath;
#pragma warning disable SA1401
#pragma warning disable SA1307
private const string Debug = nameof(Debug);
internal bool debug;
#pragma warning restore SA1307
#pragma warning restore SA1401
public string Name => Resources.plugin_name;
public string Description => Resources.plugin_description;
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
new PluginAdditionalOption()
{
Key = AltIcon,
DisplayLabel = Resources.AltIcon,
Value = false,
},
new PluginAdditionalOption()
{
Key = MatchPath,
DisplayLabel = Resources.Match_path,
Value = false,
},
new PluginAdditionalOption()
{
Key = NoPreview,
DisplayLabel = Resources.Preview,
Value = false,
},
new PluginAdditionalOption()
{
Key = RegEx,
DisplayLabel = Resources.RegEx,
Value = false,
},
new PluginAdditionalOption()
{
Key = Debug,
DisplayLabel = "Log debug data",
Value = true,
},
};
private IContextMenu contextMenuLoader;
private PluginInitContext context;
private bool disposed;
public void Init(PluginInitContext context)
{
this.context = context;
this.contextMenuLoader = new ContextMenuLoader(context);
EverythingSetup(debug);
}
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
return results;
}
public List<Result> Query(Query query, bool delayedExecution)
{
List<Result> results = new List<Result>();
if (!string.IsNullOrEmpty(query.Search))
{
var searchQuery = query.Search;
var regexMatch = Regex.Match(searchQuery, this.reservedStringPattern);
if (!regexMatch.Success)
{
try
{
results.AddRange(EverythingSearch(searchQuery, this.preview, this.altIcon, debug));
}
catch (System.ComponentModel.Win32Exception)
{
results.Add(new Result()
{
Title = Resources.Everything_not_running,
SubTitle = Resources.Everything_ini,
IcoPath = "Images/warning.png",
QueryTextDisplay = '.' + Resources.plugin_name,
Score = int.MaxValue,
});
}
catch (Exception e)
{
Log.Exception("Everything Exception", e, this.GetType());
}
}
}
return results;
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return this.contextMenuLoader.LoadContextMenus(selectedResult);
}
public Control CreateSettingPanel()
{
throw new NotImplementedException();
}
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
var regX = false;
var nopreview = false;
var alt = false;
var debuging = false;
var searchpath = false;
if (settings != null && settings.AdditionalOptions != null)
{
regX = settings.AdditionalOptions.FirstOrDefault(x => x.Key == RegEx)?.Value ?? false;
nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false;
alt = settings.AdditionalOptions.FirstOrDefault(x => x.Key == AltIcon)?.Value ?? false;
debuging = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Debug)?.Value ?? true;
searchpath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == MatchPath)?.Value ?? false;
}
this.regEx = regX;
Everything_SetRegex(this.regEx);
this.preview = nopreview;
this.altIcon = alt;
this.debug = debuging;
this.matchPath = searchpath;
Everything_SetMatchPath(this.matchPath);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
this.disposed = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public string GetTranslatedPluginTitle()
{
return Resources.plugin_name;
}
public string GetTranslatedPluginDescription()
{
return Resources.plugin_description;
}
}
}