1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 06:00:45 +00:00
msfs-popout-panel-manager/WindowsAgent/WindowProcessManager.cs

76 lines
2.2 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using System;
2022-01-27 13:40:04 +00:00
using System.Diagnostics;
2024-02-28 02:44:21 +00:00
using System.Reflection;
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.WindowsAgent
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
public class WindowProcessManager
2022-01-27 13:40:04 +00:00
{
public static string GetApplicationVersion()
{
2024-02-28 02:44:21 +00:00
var assembly = Assembly.GetEntryAssembly();
2022-01-27 13:40:04 +00:00
2024-02-28 02:44:21 +00:00
if (assembly != null)
{
var assemblyName = assembly.GetName();
var systemAssemblyVersion = assemblyName.Version;
if (systemAssemblyVersion == null)
throw new ApplicationException("Unable to get application version number.");
var appVersion =
$"{systemAssemblyVersion.Major}.{systemAssemblyVersion.Minor}.{systemAssemblyVersion.Build}";
if (systemAssemblyVersion.Revision > 0)
appVersion += "." + systemAssemblyVersion.Revision.ToString("D4");
return appVersion;
}
throw new ApplicationException("Unable to get application version number.");
2022-01-27 13:40:04 +00:00
}
2023-07-12 22:41:31 +00:00
public static WindowProcess SimulatorProcess { get; private set; }
public static void GetSimulatorProcess()
2022-01-27 13:40:04 +00:00
{
2023-07-12 22:41:31 +00:00
SimulatorProcess = GetWindowProcess("FlightSimulator");
2022-01-27 13:40:04 +00:00
}
public static WindowProcess GetApplicationProcess()
{
2022-07-23 19:23:32 +00:00
return GetWindowProcess("MSFSPopoutPanelManager");
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private static WindowProcess GetWindowProcess(string processName)
2022-01-27 13:40:04 +00:00
{
foreach (var process in Process.GetProcesses())
{
if (process.ProcessName == processName)
{
return new WindowProcess()
{
ProcessId = process.Id,
ProcessName = process.ProcessName,
2024-02-28 02:44:21 +00:00
Handle = process.MainWindowHandle,
Modules = process.Modules
2022-01-27 13:40:04 +00:00
};
}
}
return null;
}
}
2022-07-23 19:23:32 +00:00
public class WindowProcess
{
public int ProcessId { get; set; }
public string ProcessName { get; set; }
public IntPtr Handle { get; set; }
2024-02-28 02:44:21 +00:00
public ProcessModuleCollection Modules { get; set; }
2022-07-23 19:23:32 +00:00
}
2022-01-27 13:40:04 +00:00
}