Update project files and configurations for improved structure and maintainability
This commit is contained in:
@@ -201,6 +201,13 @@ namespace ResourceMonitorService.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
// First check configured game root folders
|
||||
var gameFromRootFolder = DetectGameFromRootFolders(filePath, process);
|
||||
if (gameFromRootFolder != null)
|
||||
{
|
||||
return gameFromRootFolder;
|
||||
}
|
||||
|
||||
// Check each configured game platform path
|
||||
foreach (var platformPath in _settings.GamePlatformPaths)
|
||||
{
|
||||
@@ -227,10 +234,28 @@ namespace ResourceMonitorService.Services
|
||||
|
||||
// Additional checks for common game launchers and executables
|
||||
var fileName = Path.GetFileNameWithoutExtension(filePath).ToLowerInvariant();
|
||||
|
||||
// Exclude known system processes and applications
|
||||
var systemExclusions = new[]
|
||||
{
|
||||
"officeclicktorun", "winword", "excel", "powerpoint", "outlook",
|
||||
"teams", "skype", "chrome", "firefox", "edge", "explorer",
|
||||
"notepad", "calculator", "cmd", "powershell", "taskmgr",
|
||||
"svchost", "dwm", "csrss", "winlogon", "lsass", "services",
|
||||
"wininit", "audiodg", "conhost", "rundll32", "msiexec",
|
||||
"setup", "installer", "update", "vshost", "devenv"
|
||||
};
|
||||
|
||||
// Skip if it's a known system process
|
||||
if (systemExclusions.Any(exclusion => fileName.Contains(exclusion)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var knownGameExecutables = new[]
|
||||
{
|
||||
"game", "launcher", "client", "main", "start", "run",
|
||||
// Add more common game executable patterns
|
||||
"game", "launcher", "client"
|
||||
// Removed generic terms like "main", "start", "run" that match too many system processes
|
||||
};
|
||||
|
||||
var gameIndicators = new[]
|
||||
@@ -240,8 +265,10 @@ namespace ResourceMonitorService.Services
|
||||
};
|
||||
|
||||
// Check if it's likely a game based on executable name or path
|
||||
if (knownGameExecutables.Any(exe => fileName.Contains(exe)) ||
|
||||
gameIndicators.Any(indicator => filePath.Contains(indicator, StringComparison.OrdinalIgnoreCase)))
|
||||
// Made the condition more restrictive to reduce false positives
|
||||
if ((knownGameExecutables.Any(exe => fileName.Equals(exe) || fileName.StartsWith(exe + ".")) ||
|
||||
gameIndicators.Any(indicator => filePath.Contains(indicator, StringComparison.OrdinalIgnoreCase))) &&
|
||||
!filePath.Contains("Program Files\\Common Files", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Try to determine platform and game name from other indicators
|
||||
var platform = DeterminePlatformFromProcess(process, filePath);
|
||||
@@ -394,6 +421,84 @@ namespace ResourceMonitorService.Services
|
||||
}
|
||||
}
|
||||
|
||||
private GameInfo? DetectGameFromRootFolders(string filePath, Process process)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var rootFolder in _settings.GameRootFolders)
|
||||
{
|
||||
if (filePath.StartsWith(rootFolder, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var gameName = ExtractGameNameFromRootFolder(filePath, rootFolder);
|
||||
|
||||
return new GameInfo
|
||||
{
|
||||
GameName = gameName,
|
||||
ExecutableName = Path.GetFileName(filePath),
|
||||
FullPath = filePath,
|
||||
ProcessId = process.Id,
|
||||
MemoryUsage = (ulong)process.WorkingSet64,
|
||||
CpuTime = process.TotalProcessorTime,
|
||||
StartTime = process.StartTime,
|
||||
Platform = "Standalone", // Games in root folders are typically standalone
|
||||
IsFullscreen = false, // Will be set by caller
|
||||
FPS = 0f // Will be set by caller
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error detecting game from root folders for path {FilePath}", filePath);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractGameNameFromRootFolder(string filePath, string rootFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Remove the root folder from the path to get the relative game path
|
||||
var relativePath = filePath.Substring(rootFolder.Length).TrimStart('\\', '/');
|
||||
|
||||
// Split by directory separator and take the first part as the game folder
|
||||
var pathParts = relativePath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (pathParts.Length > 0)
|
||||
{
|
||||
var gameFolder = pathParts[0];
|
||||
|
||||
// If the game folder name is reasonable, use it
|
||||
if (!string.IsNullOrEmpty(gameFolder) &&
|
||||
!gameFolder.Equals("bin", StringComparison.OrdinalIgnoreCase) &&
|
||||
!gameFolder.Equals("exe", StringComparison.OrdinalIgnoreCase) &&
|
||||
!gameFolder.Equals("data", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return gameFolder;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try to get the game name from file properties
|
||||
var versionInfo = FileVersionInfo.GetVersionInfo(filePath);
|
||||
if (!string.IsNullOrEmpty(versionInfo.ProductName) &&
|
||||
!versionInfo.ProductName.Equals(versionInfo.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return versionInfo.ProductName;
|
||||
}
|
||||
|
||||
// Last resort: use the executable name
|
||||
return Path.GetFileNameWithoutExtension(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Could not extract game name from root folder path {FilePath}", filePath);
|
||||
return Path.GetFileNameWithoutExtension(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetParentProcessId(int processId)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user