Skip to content

Commit 6febf34

Browse files
committed
修复了在程序配置页面复制路径引发空引用异常;完善了右键菜单功能
1 parent 8bbe8e9 commit 6febf34

File tree

13 files changed

+157
-50
lines changed

13 files changed

+157
-50
lines changed

PreLaunchTaskr.Core/Services/Launcher.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using PreLaunchTaskr.Core.Repositories.Implementations;
66
using PreLaunchTaskr.Core.Repositories.Interfaces;
77

8+
using System;
89
using System.Collections.Generic;
910
using System.Diagnostics;
1011
using System.IO;
@@ -52,22 +53,49 @@ public static Launcher Init(string baseDirectory)
5253
new EnvironmentVariableRepositoryImpl(connection));
5354
}
5455

55-
public async Task<bool> Launch(int programId, string[] args)
56+
public bool Launch(int programId, string[] args)
5657
{
5758
ProgramInfo? programInfo = programRepository.GetById(programId);
5859
if (programInfo is null)
5960
return false;
6061

61-
return await Launch(programInfo, args, false, false);
62+
return Launch(programInfo, args, false, false);
6263
}
6364

64-
public async Task<bool> Launch(string path, string[] args)
65+
public bool Launch(string path, string[] args)
6566
{
6667
ProgramInfo? programInfo = programRepository.GetByPath(path);
6768
if (programInfo is null)
6869
return false;
6970

70-
return await Launch(programInfo, args, false, false);
71+
return Launch(programInfo, args, false, false);
72+
}
73+
74+
public bool Launch(
75+
int programId,
76+
string[] originArgs,
77+
bool asAdmin,
78+
bool waitForExit)
79+
{
80+
81+
ProgramInfo? programInfo = programRepository.GetById(programId);
82+
if (programInfo is null)
83+
return false;
84+
85+
return Launch(programInfo, originArgs, asAdmin, waitForExit);
86+
}
87+
88+
public bool Launch(
89+
string path,
90+
string[] originArgs,
91+
bool asAdmin,
92+
bool waitForExit)
93+
{
94+
ProgramInfo? programInfo = programRepository.GetByPath(path);
95+
if (programInfo is null)
96+
return false;
97+
98+
return Launch(programInfo, originArgs, asAdmin, waitForExit);
7199
}
72100

73101
/// <summary>
@@ -76,7 +104,7 @@ public async Task<bool> Launch(string path, string[] args)
76104
/// <param name="programInfo">添加的程序的信息</param>
77105
/// <param name="originArgs">原启动参数,不包含用户附加,不剔除用户屏蔽。</param>
78106
/// <returns></returns>
79-
public async Task<bool> Launch(
107+
public bool Launch(
80108
ProgramInfo programInfo,
81109
string[] originArgs,
82110
bool asAdmin,
@@ -85,7 +113,14 @@ public async Task<bool> Launch(
85113
string symlinkPath = GlobalProperties.SymbolicLinkPath(programInfo.Path);
86114
if (!File.Exists(symlinkPath))
87115
{
88-
File.CreateSymbolicLink(symlinkPath, programInfo.Path);
116+
try
117+
{
118+
File.CreateSymbolicLink(symlinkPath, programInfo.Path);
119+
}
120+
catch (Exception)
121+
{
122+
return false;
123+
}
89124
}
90125
ProcessStartInfo programStartInfo = new()
91126
{
@@ -180,7 +215,7 @@ public async Task<bool> Launch(
180215
}
181216
}
182217
taskProcess.Start();
183-
await taskProcess.WaitForExitAsync();
218+
taskProcess.WaitForExit();
184219
}
185220

186221
// 带上处理后的启动参数、专属环境变量,去启动程序
@@ -199,7 +234,7 @@ public async Task<bool> Launch(
199234
return false;
200235

201236
if (waitForExit)
202-
await programProcess.WaitForExitAsync();
237+
programProcess.WaitForExit();
203238

204239
return true;
205240
}
@@ -224,7 +259,7 @@ public async Task<bool> Launch(
224259
return false;
225260

226261
if (waitForExit)
227-
await programProcessAdmin.WaitForExitAsync();
262+
programProcessAdmin.WaitForExit();
228263

229264
return true;
230265
}

PreLaunchTaskr.GUI.WinUI3/PreLaunchTaskr.GUI.WinUI3.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
<ProjectReference Include="..\PreLaunchTaskr.Core\PreLaunchTaskr.Core.csproj" />
6868
<ProjectReference Include="..\PreLaunchTaskr.GUI.Common\PreLaunchTaskr.GUI.Common.csproj" />
6969
</ItemGroup>
70+
<ItemGroup>
71+
<Content Update="Assets\PreLaunchTaskrHome.jpg">
72+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+
</Content>
74+
</ItemGroup>
7075
<ItemGroup>
7176
<None Update="Assets\DefaultProgramIcon.png">
7277
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

PreLaunchTaskr.GUI.WinUI3/Views/AttachArgumentPage.xaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@
1818
<Border Padding="16" Style="{StaticResource CardBorderStyle}">
1919
<Border.ContextFlyout>
2020
<MenuFlyout>
21-
<MenuFlyoutItem DataContext="{x:Bind}" Text="复制">
21+
<MenuFlyoutItem
22+
Click="CopyArgument_Click"
23+
DataContext="{x:Bind}"
24+
Text="复制参数文本">
2225
<MenuFlyoutItem.Icon>
2326
<SymbolIcon Symbol="Copy" />
2427
</MenuFlyoutItem.Icon>
2528
</MenuFlyoutItem>
26-
<MenuFlyoutItem DataContext="{x:Bind}" Text="删除">
27-
<MenuFlyoutItem.Icon>
29+
<MenuFlyoutSubItem Foreground="Red" Text="删除">
30+
<MenuFlyoutSubItem.Icon>
2831
<SymbolIcon Symbol="Delete" />
29-
</MenuFlyoutItem.Icon>
30-
</MenuFlyoutItem>
32+
</MenuFlyoutSubItem.Icon>
33+
<MenuFlyoutItem
34+
Click="ConfirmDeleteArgument_Click"
35+
DataContext="{x:Bind}"
36+
Foreground="Red"
37+
Text="确认删除">
38+
<MenuFlyoutItem.Icon>
39+
<SymbolIcon Symbol="Delete" />
40+
</MenuFlyoutItem.Icon>
41+
</MenuFlyoutItem>
42+
</MenuFlyoutSubItem>
3143
</MenuFlyout>
3244
</Border.ContextFlyout>
3345

PreLaunchTaskr.GUI.WinUI3/Views/BlockArgumentPage.xaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,28 @@
1717
<Border Padding="16" Style="{StaticResource CardBorderStyle}">
1818
<Border.ContextFlyout>
1919
<MenuFlyout>
20-
<MenuFlyoutItem DataContext="{x:Bind}" Text="复制">
20+
<MenuFlyoutItem
21+
Click="CopyArgument_Click"
22+
DataContext="{x:Bind}"
23+
Text="复制参数文本">
2124
<MenuFlyoutItem.Icon>
2225
<SymbolIcon Symbol="Copy" />
2326
</MenuFlyoutItem.Icon>
2427
</MenuFlyoutItem>
25-
<MenuFlyoutItem DataContext="{x:Bind}" Text="删除">
26-
<MenuFlyoutItem.Icon>
28+
<MenuFlyoutSubItem Foreground="Red" Text="删除">
29+
<MenuFlyoutSubItem.Icon>
2730
<SymbolIcon Symbol="Delete" />
28-
</MenuFlyoutItem.Icon>
29-
</MenuFlyoutItem>
31+
</MenuFlyoutSubItem.Icon>
32+
<MenuFlyoutItem
33+
Click="ConfirmDeleteArgument_Click"
34+
DataContext="{x:Bind}"
35+
Foreground="Red"
36+
Text="确认删除">
37+
<MenuFlyoutItem.Icon>
38+
<SymbolIcon Symbol="Delete" />
39+
</MenuFlyoutItem.Icon>
40+
</MenuFlyoutItem>
41+
</MenuFlyoutSubItem>
3042
</MenuFlyout>
3143
</Border.ContextFlyout>
3244

PreLaunchTaskr.GUI.WinUI3/Views/EnvironmentVariablePage.xaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,36 @@
1717
<Border Padding="16" Style="{StaticResource CardBorderStyle}">
1818
<Border.ContextFlyout>
1919
<MenuFlyout>
20-
<MenuFlyoutItem DataContext="{x:Bind}" Text="复制">
20+
<MenuFlyoutItem
21+
Click="CopyName_Click"
22+
DataContext="{x:Bind}"
23+
Text="复制变量名">
2124
<MenuFlyoutItem.Icon>
2225
<SymbolIcon Symbol="Copy" />
2326
</MenuFlyoutItem.Icon>
2427
</MenuFlyoutItem>
25-
<MenuFlyoutItem DataContext="{x:Bind}" Text="删除">
28+
<MenuFlyoutItem
29+
Click="CopyValue_Click"
30+
DataContext="{x:Bind}"
31+
Text="复制变量值">
2632
<MenuFlyoutItem.Icon>
27-
<SymbolIcon Symbol="Delete" />
33+
<SymbolIcon Symbol="Copy" />
2834
</MenuFlyoutItem.Icon>
2935
</MenuFlyoutItem>
36+
<MenuFlyoutSubItem Foreground="Red" Text="删除">
37+
<MenuFlyoutSubItem.Icon>
38+
<SymbolIcon Symbol="Delete" />
39+
</MenuFlyoutSubItem.Icon>
40+
<MenuFlyoutItem
41+
Click="ConfirmDeleteEnvironmentVariable_Click"
42+
DataContext="{x:Bind}"
43+
Foreground="Red"
44+
Text="确认删除">
45+
<MenuFlyoutItem.Icon>
46+
<SymbolIcon Symbol="Delete" />
47+
</MenuFlyoutItem.Icon>
48+
</MenuFlyoutItem>
49+
</MenuFlyoutSubItem>
3050
</MenuFlyout>
3151
</Border.ContextFlyout>
3252

@@ -88,7 +108,7 @@
88108
<Button.Flyout>
89109
<MenuFlyout>
90110
<MenuFlyoutItem
91-
Click="ConfirmDeleteArgument_Click"
111+
Click="ConfirmDeleteEnvironmentVariable_Click"
92112
DataContext="{x:Bind}"
93113
Foreground="Red"
94114
Text="确认删除">

PreLaunchTaskr.GUI.WinUI3/Views/EnvironmentVariablePage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
2727
base.OnNavigatedTo(e);
2828
}
2929

30-
private void ConfirmDeleteArgument_Click(object sender, RoutedEventArgs e)
30+
private void ConfirmDeleteEnvironmentVariable_Click(object sender, RoutedEventArgs e)
3131
{
3232
EnvironmentVariableListItem item = DataContextHelper.GetDataContext<EnvironmentVariableListItem>(sender);
3333
viewModel.RemoveEnvironmentVariable(item);

PreLaunchTaskr.GUI.WinUI3/Views/MainPage.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@
6464
Click="RemoveProgram_Click"
6565
DataContext="{x:Bind}"
6666
Foreground="Red"
67-
Text="确定移除" />
67+
Text="确定移除">
68+
<MenuFlyoutItem.Icon>
69+
<SymbolIcon Symbol="Delete" />
70+
</MenuFlyoutItem.Icon>
71+
</MenuFlyoutItem>
6872
</MenuFlyoutSubItem>
6973

7074
<MenuFlyoutItem
7175
Click="CopyProgramPath_Click"
7276
DataContext="{x:Bind}"
73-
Text="复制程序所在位置">
77+
Text="复制程序所在路径">
7478
<MenuFlyoutItem.Icon>
7579
<SymbolIcon Symbol="Copy" />
7680
</MenuFlyoutItem.Icon>

PreLaunchTaskr.GUI.WinUI3/Views/PreLaunchTaskPage.xaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,28 @@
1717
<Border Padding="16" Style="{StaticResource CardBorderStyle}">
1818
<Border.ContextFlyout>
1919
<MenuFlyout>
20-
<MenuFlyoutItem DataContext="{x:Bind}" Text="复制">
20+
<MenuFlyoutItem
21+
Click="CopyPath_Click"
22+
DataContext="{x:Bind}"
23+
Text="复制路径">
2124
<MenuFlyoutItem.Icon>
2225
<SymbolIcon Symbol="Copy" />
2326
</MenuFlyoutItem.Icon>
2427
</MenuFlyoutItem>
25-
<MenuFlyoutItem DataContext="{x:Bind}" Text="删除">
26-
<MenuFlyoutItem.Icon>
27-
<SymbolIcon Symbol="Delete" />
28-
</MenuFlyoutItem.Icon>
29-
</MenuFlyoutItem>
28+
<MenuFlyoutSubItem Foreground="Red" Text="删除">
29+
<MenuFlyoutSubItem.Icon>
30+
<SymbolIcon Foreground="Red" Symbol="Delete" />
31+
</MenuFlyoutSubItem.Icon>
32+
<MenuFlyoutItem
33+
Click="ConfirmDeleteTask_Click"
34+
DataContext="{x:Bind}"
35+
Foreground="Red"
36+
Text="确认删除">
37+
<MenuFlyoutItem.Icon>
38+
<SymbolIcon Foreground="Red" Symbol="Delete" />
39+
</MenuFlyoutItem.Icon>
40+
</MenuFlyoutItem>
41+
</MenuFlyoutSubItem>
3042
</MenuFlyout>
3143
</Border.ContextFlyout>
3244

@@ -73,7 +85,7 @@
7385
<Button.Flyout>
7486
<MenuFlyout>
7587
<MenuFlyoutItem
76-
Click="ConfirmDeleteArgument_Click"
88+
Click="ConfirmDeleteTask_Click"
7789
DataContext="{x:Bind}"
7890
Foreground="Red"
7991
Text="确认删除">

PreLaunchTaskr.GUI.WinUI3/Views/PreLaunchTaskPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
2929
base.OnNavigatedTo(e);
3030
}
3131

32-
private void ConfirmDeleteArgument_Click(object sender, RoutedEventArgs e)
32+
private void ConfirmDeleteTask_Click(object sender, RoutedEventArgs e)
3333
{
3434
PreLaunchTaskListItem item = DataContextHelper.GetDataContext<PreLaunchTaskListItem>(sender);
3535
viewModel.RemoveTask(item);

PreLaunchTaskr.GUI.WinUI3/Views/ProgramConfigPage.xaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
<!--<Image.ContextFlyout>
3939
<MenuFlyout>
40-
<MenuFlyoutItem Text="保存图标" DataContext="{x:Bind}" Click="SaveIcon_Click">
40+
<MenuFlyoutItem Click="SaveIcon_Click" Text="保存图标">
4141
<MenuFlyoutItem.Icon>
4242
<SymbolIcon Symbol="Save" />
4343
</MenuFlyoutItem.Icon>
@@ -57,10 +57,7 @@
5757

5858
<TextBlock.ContextFlyout>
5959
<MenuFlyout>
60-
<MenuFlyoutItem
61-
Click="CopyFileName_Click"
62-
DataContext="{x:Bind}"
63-
Text="复制程序文件名">
60+
<MenuFlyoutItem Click="CopyFileName_Click" Text="复制程序文件名">
6461
<MenuFlyoutItem.Icon>
6562
<SymbolIcon Symbol="Copy" />
6663
</MenuFlyoutItem.Icon>
@@ -80,12 +77,18 @@
8077

8178
<TextBlock.ContextFlyout>
8279
<MenuFlyout>
80+
<MenuFlyoutItem Click="CopyFilePath_Click" Text="复制程序所在路径">
81+
<MenuFlyoutItem.Icon>
82+
<SymbolIcon Symbol="Copy" />
83+
</MenuFlyoutItem.Icon>
84+
</MenuFlyoutItem>
85+
8386
<MenuFlyoutItem
84-
Click="CopyFilePath_Click"
87+
Click="GoToFilePath_Click"
8588
DataContext="{x:Bind}"
86-
Text="复制程序所在路径">
89+
Text="打开程序所在位置">
8790
<MenuFlyoutItem.Icon>
88-
<SymbolIcon Symbol="Copy" />
91+
<SymbolIcon Symbol="Go" />
8992
</MenuFlyoutItem.Icon>
9093
</MenuFlyoutItem>
9194
</MenuFlyout>

0 commit comments

Comments
 (0)