Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Honorbuddy/HonorbuddyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void CloseBotProcess()
if (!_isExiting && BotProcess != null && !BotProcess.HasExitedSafe())
{
_isExiting = true;
Task.Run(async () => await Utility.CloseBotProcessAsync(BotProcess, Profile))
Task.Run(async () => await Utility.CloseBotProcessAsync(BotProcess, Profile, "Honorbuddy"))
.ContinueWith(o =>
{
_isExiting = false;
Expand Down
1 change: 1 addition & 0 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ public enum SystemMetric : int

public enum Message : uint
{
CLOSE = (0x0010),
NCHITTEST = (0x0084),
KEY_DOWN = (0x0100), //Key down
KEY_UP = (0x0101), //Key Up
Expand Down
23 changes: 21 additions & 2 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,31 @@ public static void RestoreForegroundWindowAndMouse()

#endregion

public static async Task CloseBotProcessAsync(Process proc, CharacterProfile profile)
public static async Task CloseBotProcessAsync(Process proc, CharacterProfile profile, String windowText = "")
{
var procName = proc.ProcessName;
profile.Log("Attempting to close {0}", procName);

proc.CloseMainWindow();
// If a specific window name was given, close that window instead of main window.
// StartsWith() is used instead of Equals() because Honorbuddy appends " - attached to ..." in title
if( !String.IsNullOrEmpty(windowText))
{
IntPtr wHnd = NativeMethods.EnumerateProcessWindowHandles(proc.Id)
.FirstOrDefault((p => NativeMethods.GetWindowText(p).StartsWith(windowText)));
if( wHnd != IntPtr.Zero )
{
NativeMethods.PostMessage(wHnd, (uint)NativeMethods.Message.CLOSE, IntPtr.Zero, UIntPtr.Zero);
}
else
{
proc.CloseMainWindow();
}
}
else
{
proc.CloseMainWindow();
}

if (await WaitForProcessToExitAsync(proc, TimeSpan.FromSeconds(10)))
{
profile.Log("Successfully closed {0} gracefully", procName);
Expand Down