Skip to content

Commit a6d982d

Browse files
committed
fix: 先关闭游戏再关闭本程序将不会产生Textractor报错
1 parent 2d53e3a commit a6d982d

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

MisakaTranslator-WPF/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
[assembly : AssemblyCulture("")]
1313
[assembly : ComVisible(false)]
1414
[assembly : ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
15-
[assembly : AssemblyVersion("2.12.1.0")]
16-
[assembly : AssemblyFileVersion("2.12.1.0")]
15+
[assembly : AssemblyVersion("2.12.2.0")]
16+
[assembly : AssemblyFileVersion("2.12.2.0")]

TextHookLibrary/ProcessHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,10 @@ public static string FindProcessPath(int pid, bool isx64game = false)
116116
catch (InvalidOperationException) { } // 进程已退出
117117
return l;
118118
}
119+
120+
/// <summary>
121+
/// internal bool System.Diagnostics.ProcessManager.IsProcessRunning(int pid)
122+
/// </summary>
123+
public static Func<int, bool> IsProcessRunning = (Func<int, bool>)typeof(Process).Assembly.GetType("System.Diagnostics.ProcessManager").GetMethod("IsProcessRunning", new[] { typeof(int) }).CreateDelegate(typeof(Func<int, bool>));
119124
}
120125
}

TextHookLibrary/TextHookHandle.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public async Task AttachProcess(int pid) {
182182
/// </summary>
183183
/// <param name="pid"></param>
184184
public async Task DetachProcess(int pid) {
185+
if (!ProcessHelper.IsProcessRunning(pid))
186+
return;
185187
await ProcessTextractor.StandardInput.WriteLineAsync("detach -P" + pid);
186188
await ProcessTextractor.StandardInput.FlushAsync();
187189
}
@@ -213,13 +215,14 @@ public async Task DetachProcessByHookAddress(int pid, string HookAddress) {
213215
/// </summary>
214216
public async void CloseTextractor() {
215217
if (ProcessTextractor != null && ProcessTextractor.HasExited == false) {
216-
if (HandleMode == 1) {
218+
if (HandleMode == 1 && ProcessHelper.IsProcessRunning(GamePID)) {
217219
await DetachProcess(GamePID);
218220
}
219221
else if (HandleMode == 2) {
220222
foreach (var item in PossibleGameProcessList.ToList())
221223
if (PossibleGameProcessList[item.Key] == true) {
222-
await DetachProcess(item.Key.Id);
224+
if(ProcessHelper.IsProcessRunning(item.Key.Id))
225+
await DetachProcess(item.Key.Id);
223226
PossibleGameProcessList[item.Key] = false;
224227
}
225228
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
This is AutoUpdateCheck's Page.
2-
LatestVersion[2.12.1.0]
2+
LatestVersion[2.12.2.0]
33
DownloadPath[https://github.com/hanmin0822/MisakaTranslator/releases]

0 commit comments

Comments
 (0)