Fix up the title to be an iterated ID rather than PID
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace EveOPreview.Services.Implementation
|
namespace EveOPreview.Services.Implementation
|
||||||
{
|
{
|
||||||
@@ -91,8 +92,16 @@ namespace EveOPreview.Services.Implementation
|
|||||||
continue; // No need to monitor non-visual processes
|
continue; // No need to monitor non-visual processes
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append PID to the window title to make it unique
|
// Get all processes with same name and sort by PID
|
||||||
string mainWindowTitle = $"{process.MainWindowTitle} (PID: {process.Id})";
|
var sameNameProcesses = Process.GetProcessesByName(processName)
|
||||||
|
.Where(p => p.MainWindowHandle != IntPtr.Zero)
|
||||||
|
.OrderBy(p => p.Id)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Find index of current process in sorted list
|
||||||
|
int index = sameNameProcesses.FindIndex(p => p.Id == process.Id);
|
||||||
|
string mainWindowTitle = $"{process.MainWindowTitle} ({index + 1})";
|
||||||
|
|
||||||
this._processCache.TryGetValue(mainWindowHandle, out string cachedTitle);
|
this._processCache.TryGetValue(mainWindowHandle, out string cachedTitle);
|
||||||
|
|
||||||
if (cachedTitle == null)
|
if (cachedTitle == null)
|
||||||
@@ -109,9 +118,9 @@ namespace EveOPreview.Services.Implementation
|
|||||||
this._processCache[mainWindowHandle] = mainWindowTitle;
|
this._processCache[mainWindowHandle] = mainWindowTitle;
|
||||||
updatedProcesses.Add(new ProcessInfo(mainWindowHandle, mainWindowTitle));
|
updatedProcesses.Add(new ProcessInfo(mainWindowHandle, mainWindowTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
knownProcesses.Remove(mainWindowHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
knownProcesses.Remove(mainWindowHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (IntPtr index in knownProcesses)
|
foreach (IntPtr index in knownProcesses)
|
||||||
|
Reference in New Issue
Block a user