Skip to content

Commit ae62ade

Browse files
committed
*优化代码结构,消除冗余变量和类型转换,提升可读性和一致性
1 parent 6f37ec7 commit ae62ade

15 files changed

Lines changed: 83 additions & 101 deletions

Core.Window/AppTools/AppTools.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ internal static void AutoStartEverything(ConcurrentDictionary<string, SearchView
5050
if (!File.Exists(
5151
$"{AppDomain.CurrentDomain.BaseDirectory}noUAC{Path.DirectorySeparatorChar}{程序名称}.lnk"))
5252
{
53-
var dialog = new DialogContent()
53+
var dialog = new DialogContent
5454
{
55-
Title = $"Kitopia提示",
55+
Title = "Kitopia提示",
5656
Content =
5757
$"Kitopia即将使用任务计划来创建绕过UAC启动Everything的快捷方式\n需要确认UAC权限\n按下取消则关闭自动启动功能\n路径:{AppDomain.CurrentDomain.BaseDirectory}noUAC{Path.DirectorySeparatorChar}{程序名称}.lnk",
5858
PrimaryButtonText = "确定",
@@ -204,9 +204,9 @@ internal static void IndexAllApps(ConcurrentDictionary<string, SearchViewItem> c
204204
foreach (var s in ErrorLnkList) c.AppendLine(s);
205205

206206
Logger.Debug(c.ToString());
207-
var dialog = new DialogContent()
207+
var dialog = new DialogContent
208208
{
209-
Title = $"Kitopia建议",
209+
Title = "Kitopia建议",
210210
Content = c.ToString(),
211211
PrimaryButtonText = "确定",
212212
SecondaryButtonText = "取消",
@@ -317,11 +317,8 @@ internal static void IndexItem(ConcurrentDictionary<string, SearchViewItem> coll
317317

318318
//Log.Debug($"完成索引:{file}");
319319
}
320-
else
321-
{
322-
// Log.Debug($"不符合要求跳过索引:{file}");
323-
}
324320

321+
// Log.Debug($"不符合要求跳过索引:{file}");
325322
break;
326323
}
327324
case ".url":
@@ -395,7 +392,7 @@ internal static void IndexItem(ConcurrentDictionary<string, SearchViewItem> coll
395392
break;
396393
}
397394

398-
collection.TryAdd(file, new SearchViewItem()
395+
collection.TryAdd(file, new SearchViewItem
399396
{
400397
ItemDisplayName = localizedName,
401398
FileType = fileType,
@@ -414,7 +411,7 @@ internal static void IndexItem(ConcurrentDictionary<string, SearchViewItem> coll
414411
if (!Directory.Exists(file)) return;
415412
if (ConfigManger.Config.ignoreItems.Contains(file)) return;
416413

417-
collection.TryAdd(file, new SearchViewItem()
414+
collection.TryAdd(file, new SearchViewItem
418415
{
419416
ItemDisplayName = file.Split(Path.DirectorySeparatorChar)
420417
.Last(),

Core.Window/AppTools/UWPTools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static void AppContainerAnalyse(FirewallApi.INET_FIREWALL_APP_CONTAINER
128128
var pa = $"{path}{Path.DirectorySeparatorChar}{logoName}.scale-200.png";
129129
if (File.Exists(pa))
130130
{
131-
var searchViewItem = new SearchViewItem()
131+
var searchViewItem = new SearchViewItem
132132
{
133133
ItemDisplayName = fileName,
134134
OnlyKey = $"{appContainer.appContainerName}!{id}",
@@ -147,7 +147,7 @@ private static void AppContainerAnalyse(FirewallApi.INET_FIREWALL_APP_CONTAINER
147147
foreach (var enumerateFile in logos.EnumerateFiles())
148148
if (enumerateFile.Name.StartsWith(logoName))
149149
{
150-
var searchViewItem = new SearchViewItem()
150+
var searchViewItem = new SearchViewItem
151151
{
152152
ItemDisplayName = fileName,
153153
OnlyKey = $"{appContainer.appContainerName}!{id}",

Core.Window/ApplicationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public async Task<bool> CheckUpdate(bool toastIfNoUpdate) {
137137
var (hasUpdate, latestVersion, downloadUrl, releaseNotes) = await gitHubUpdateService!.CheckForUpdatesAsync();
138138
if (hasUpdate && !string.IsNullOrEmpty(downloadUrl)) {
139139
Logger.Information($"发现新版本:{latestVersion}");
140-
var dialog = new DialogContent() {
140+
var dialog = new DialogContent {
141141
Title = $"Kitopia更新 - 发现新版本 {latestVersion}",
142142
Content = $"发现新版本 {latestVersion},是否前往下载?\n\n更新内容:\n{releaseNotes ?? "无更新说明"}",
143143
PrimaryButtonText = "下载并更新",

Core.Window/ClipboardWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public class ClipboardWindow : IClipboardService
2323

2424

2525
private static readonly ResiliencePipeline ResiliencePipeline = new ResiliencePipelineBuilder()
26-
.AddConcurrencyLimiter(new ConcurrencyLimiterOptions()
26+
.AddConcurrencyLimiter(new ConcurrencyLimiterOptions
2727
{
2828
PermitLimit = 1,
2929
QueueLimit = Int32.MaxValue
3030
})
3131
.AddRetry(
32-
new RetryStrategyOptions()
32+
new RetryStrategyOptions
3333
{
3434
ShouldHandle = new PredicateBuilder().Handle<Exception>(exception =>
3535
{
@@ -256,7 +256,7 @@ public bool HasImage()
256256
[STAThread]
257257
public async Task<bool> SetImageAsync(ScreenCaptureResult screenCaptureResult)
258258
{
259-
var executeAsync = await ResiliencePipeline.ExecuteAsync(async (_) =>
259+
var executeAsync = await ResiliencePipeline.ExecuteAsync(async _ =>
260260
{
261261
var tcs = new TaskCompletionSource<bool>();
262262
var thread = new Thread(() =>

Core.Window/Everything/Tools.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ public static void Index(List<string> items)
7575

7676
public static IEnumerable<SearchViewItem> Search(string s,int limit=50)
7777
{
78-
var task = Task.Run(() =>
79-
{
78+
var task = Task.Run(() => {
8079
if (IntPtr.Size == 8)
8180
// 64-bit
8281
return SearchAmd64(s,limit);
83-
else
84-
// 32-bit
85-
return SearchAmd32(s,limit);
82+
// 32-bit
83+
return SearchAmd32(s,limit);
8684
});
8785
if (!task.Wait(TimeSpan.FromSeconds(1)))
8886
{

Core.Window/ExplorerContextMenuService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using Windows.Management.Deployment;
23
using Core.Services;
34
using Core.Utils;
@@ -29,7 +30,7 @@ public Task<bool> RegisterAsync()
2930
PrimaryButtonText = "前往安装",
3031
PrimaryAction = () =>
3132
{
32-
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("ms-windows-store://pdp/?productid=9MV77XCQ37FP") { UseShellExecute = true });
33+
Process.Start(new ProcessStartInfo("ms-windows-store://pdp/?productid=9MV77XCQ37FP") { UseShellExecute = true });
3334
}
3435
};
3536
_toastService.Show(dialog.ToToastRequest());

Core.Window/HotKeyImpl.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Init()
3333
{
3434
Dispatcher.UIThread.Invoke(() =>
3535
{
36-
_globalHotKeyWindow = new Avalonia.Controls.Window()
36+
_globalHotKeyWindow = new Avalonia.Controls.Window
3737
{
3838
Height = 1,
3939
Width = 1,
@@ -71,7 +71,7 @@ private static void OnMousePressed(MouseHookEventArgs e)
7171
};
7272
value.Timer.Elapsed += (_, _) =>
7373
{
74-
ThreadPool.QueueUserWorkItem((_) => { value.CallBack.Invoke(value.HotKeyModel); });
74+
ThreadPool.QueueUserWorkItem(_ => { value.CallBack.Invoke(value.HotKeyModel); });
7575
};
7676
}
7777

@@ -110,7 +110,7 @@ public bool Add(HotKeyModel hotKeyModel, Action<HotKeyModel> rallBack,bool initH
110110
{
111111
if (!hotKeyModel.IsEnabled)
112112
{
113-
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo()
113+
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo
114114
{
115115
HotKeyModel = hotKeyModel,
116116
Id = -1,
@@ -153,7 +153,7 @@ public bool Add(HotKeyModel hotKeyModel, Action<HotKeyModel> rallBack,bool initH
153153
}
154154
else
155155
{
156-
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo()
156+
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo
157157
{
158158
HotKeyModel = hotKeyModel,
159159
Id = _id,
@@ -163,7 +163,7 @@ public bool Add(HotKeyModel hotKeyModel, Action<HotKeyModel> rallBack,bool initH
163163
}
164164
else
165165
{
166-
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo()
166+
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo
167167
{
168168
HotKeyModel = hotKeyModel,
169169
Id = -1,
@@ -183,7 +183,7 @@ public bool Add(HotKeyModel hotKeyModel, Action<HotKeyModel> rallBack,bool initH
183183
}
184184
else
185185
{
186-
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo()
186+
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo
187187
{
188188
HotKeyModel = hotKeyModel,
189189
Id = 1,
@@ -232,15 +232,15 @@ public bool Del(string uuid)
232232
return false;
233233
}
234234

235-
public bool DeleteCompletely(string uuid)
236-
{
235+
public bool DeleteCompletely(string uuid) {
237236
if (Del(uuid))
238237
{
239238
HotKeys.Remove(uuid);
240239
WeakReferenceMessenger.Default.Send("", "hotkey");
241240
return true;
242241
}
243-
else return false;
242+
243+
return false;
244244
}
245245

246246
public bool RequestUserModify(string uuid)

Core.Window/IconTools.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ internal partial class IconTools
2929
private static readonly ILogger Logger = LogManager.Logger.ForContext<IconTools>();
3030

3131
private static readonly ResiliencePipeline ResiliencePipeline = new ResiliencePipelineBuilder()
32-
.AddConcurrencyLimiter(new ConcurrencyLimiterOptions()
32+
.AddConcurrencyLimiter(new ConcurrencyLimiterOptions
3333
{
3434
PermitLimit = 1,
3535
QueueLimit = Int32.MaxValue
3636
})
3737
.AddRetry(
38-
new RetryStrategyOptions()
38+
new RetryStrategyOptions
3939
{
4040
ShouldHandle = new PredicateBuilder().Handle<Exception>(exception =>
4141
{
@@ -342,11 +342,9 @@ await Task.Run(() =>
342342
GetIcon(t.IconPath, t);
343343
break;
344344
}
345-
else
346-
{
347-
GetIcon(t.OnlyKey, t);
348-
break;
349-
}
345+
346+
GetIcon(t.OnlyKey, t);
347+
break;
350348
}
351349
}
352350

@@ -470,7 +468,7 @@ private struct Shfileinfo
470468

471469
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
472470
internal string szTypeName;
473-
};
471+
}
474472

475473
[GeneratedRegex(@"(.+),(-?\d+)(?:#.*)?")]
476474
private static partial Regex MyRegex();

Core.Window/ScreenCapture/ScreenCaptureByWGC.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private ComPtr<ID3D11Resource> CreateSharpDxTexture2D(IDirect3DSurface surface)
7070
[ComVisible(true)]
7171
private interface IDirect3DDxgiInterfaceAccess {
7272
IntPtr GetInterface([In] ref Guid iid);
73-
};
73+
}
7474

7575
public Stack<ScreenCaptureResult> CaptureAllScreenMat() {
7676
var screenCaptureResults = new Stack<ScreenCaptureResult>();
@@ -119,7 +119,7 @@ public List<ScreenCaptureInfo> GetAllScreenInfo() {
119119
return true;
120120
}
121121

122-
screenCaptureInfos.Add(new ScreenCaptureInfo() {
122+
screenCaptureInfos.Add(new ScreenCaptureInfo {
123123
HMonitor = arg1.DangerousGetHandle(),
124124
SdrWhiteLevelScale = DisplayConfigHelper.GetSdrWhiteLevel(arg1.DangerousGetHandle()),
125125
ScreenInfo = new Rect(arg3.left, arg3.top, arg3.right - arg3.left, arg3.bottom - arg3.top),
@@ -250,7 +250,7 @@ IDirect3DDevice CreateDirect3DDeviceFromSharpDxDevice(ID3D11Device* d3DDevice1)
250250
throw new Exception("Failed to map staging texture");
251251

252252
//更新窗口的Size数据
253-
return new ScreenCaptureResult() {
253+
return new ScreenCaptureResult {
254254
Info = screenCaptureInfo,
255255
Source = ConvertSubresourceToSdrMat(mappedSubresource, adapterForMonitor.Item2, ref screenCaptureInfo),
256256
};

Core.Window/ScreenCapture/ScreenCaptureInfoEx.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static IEnumerable<WindowInfo> GetAllWindowInfo() {
9191
RECT visibleRect = IntersectRects(clientRect, screenRect);
9292

9393
if (visibleRect.Width > 0 && visibleRect.Height > 0) {
94-
yield return new WindowInfo() {
94+
yield return new WindowInfo {
9595
Title = title,
9696
ModuleFileName = s,
9797
Hwnd = currentHwnd.DangerousGetHandle(),
@@ -119,7 +119,7 @@ private bool ValidScreenIntptr() {
119119

120120

121121
public void ThrowIfCantGetValidScreenIntptr() {
122-
if (ValidScreenIntptr(ref screenCaptureInfo)) {
122+
if (screenCaptureInfo.ValidScreenIntptr()) {
123123
return;
124124
}
125125

@@ -148,7 +148,7 @@ public void ThrowIfCantGetValidScreenIntptr() {
148148
screenCaptureInfo.SdrWhiteLevelScale=DisplayConfigHelper.GetSdrWhiteLevel(h);
149149
}
150150
public void ThrowIfCantGetValidWindowHandle() {
151-
ThrowIfCantGetValidScreenIntptr(ref screenCaptureInfo);
151+
screenCaptureInfo.ThrowIfCantGetValidScreenIntptr();
152152
_ = screenCaptureInfo.WindowInfo??throw new Exception("目标窗口不存在");
153153

154154

0 commit comments

Comments
 (0)