Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ウィンドウを移動する条件にパス追加 #36

Merged
merged 1 commit into from
Apr 2, 2024
Merged
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
1 change: 1 addition & 0 deletions VdLabel/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum WindowMatchType
{
CommandLine,
Title,
Path,
}

enum WindowPatternType
Expand Down
19 changes: 17 additions & 2 deletions VdLabel/WindowMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PInvoke;
using System.Diagnostics;
using System.Management;
using System.Text.RegularExpressions;
using WindowsDesktop;
Expand Down Expand Up @@ -88,6 +89,19 @@ private void CheckProcesses()
{
return true;
}
string path;
try
{
using var process = Process.GetProcessById(processId);
using var module = process.MainModule;
path = module?.FileName ?? string.Empty;
}
catch (Exception)
{
// プロセスが終了している場合がある
windows.Remove(hWnd);
return true;
}
var commandLine = GetCommandLine(processId);
string windowTitle;
try
Expand All @@ -104,7 +118,7 @@ private void CheckProcesses()
{
return true;
}
if (this.targetWindows.FirstOrDefault(t => t.Regex.IsMatch(GetCheckText(t.MatchType, commandLine, windowTitle))) is not { } target)
if (this.targetWindows.FirstOrDefault(t => t.Regex.IsMatch(GetCheckText(t.MatchType, path, commandLine, windowTitle))) is not { } target)
{
return true;
}
Expand Down Expand Up @@ -139,11 +153,12 @@ private void CheckProcesses()
this.logger.LogDebug("プロセスチェック終了");
}

private static string GetCheckText(WindowMatchType type, string commandLine, string windowTitle)
private static string GetCheckText(WindowMatchType type, string path, string commandLine, string windowTitle)
=> type switch
{
WindowMatchType.CommandLine => commandLine,
WindowMatchType.Title => windowTitle,
WindowMatchType.Path => path,
_ => string.Empty,
};

Expand Down