Skip to content

Commit

Permalink
fix: 先关闭游戏再关闭本程序将不会产生Textractor报错
Browse files Browse the repository at this point in the history
  • Loading branch information
imba-tjd committed Feb 11, 2023
1 parent 2d53e3a commit a6d982d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions MisakaTranslator-WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
[assembly : AssemblyCulture("")]
[assembly : ComVisible(false)]
[assembly : ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly : AssemblyVersion("2.12.1.0")]
[assembly : AssemblyFileVersion("2.12.1.0")]
[assembly : AssemblyVersion("2.12.2.0")]
[assembly : AssemblyFileVersion("2.12.2.0")]
5 changes: 5 additions & 0 deletions TextHookLibrary/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,10 @@ public static string FindProcessPath(int pid, bool isx64game = false)
catch (InvalidOperationException) { } // 进程已退出
return l;
}

/// <summary>
/// internal bool System.Diagnostics.ProcessManager.IsProcessRunning(int pid)
/// </summary>
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>));
}
}
7 changes: 5 additions & 2 deletions TextHookLibrary/TextHookHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public async Task AttachProcess(int pid) {
/// </summary>
/// <param name="pid"></param>
public async Task DetachProcess(int pid) {
if (!ProcessHelper.IsProcessRunning(pid))
return;
await ProcessTextractor.StandardInput.WriteLineAsync("detach -P" + pid);
await ProcessTextractor.StandardInput.FlushAsync();
}
Expand Down Expand Up @@ -213,13 +215,14 @@ public async Task DetachProcessByHookAddress(int pid, string HookAddress) {
/// </summary>
public async void CloseTextractor() {
if (ProcessTextractor != null && ProcessTextractor.HasExited == false) {
if (HandleMode == 1) {
if (HandleMode == 1 && ProcessHelper.IsProcessRunning(GamePID)) {
await DetachProcess(GamePID);
}
else if (HandleMode == 2) {
foreach (var item in PossibleGameProcessList.ToList())
if (PossibleGameProcessList[item.Key] == true) {
await DetachProcess(item.Key.Id);
if(ProcessHelper.IsProcessRunning(item.Key.Id))
await DetachProcess(item.Key.Id);
PossibleGameProcessList[item.Key] = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This is AutoUpdateCheck's Page.
LatestVersion[2.12.1.0]
LatestVersion[2.12.2.0]
DownloadPath[https://github.com/hanmin0822/MisakaTranslator/releases]

0 comments on commit a6d982d

Please sign in to comment.