Skip to content

Commit cf6a8d6

Browse files
authored
Merge pull request #30 from Aynshe/feature/case-insensitive-retrobat-search
Make RetroBat executable search case-insensitive
2 parents ffc18a9 + 04fd0a5 commit cf6a8d6

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

RetroBatService.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,22 @@ public string GetRetrobatPath()
2727
private void InitializeRetrobatPath()
2828
{
2929
_logger.Log("Searching for RetroBat path");
30+
string? registryPath = null;
3031
try
3132
{
3233
using var key = Registry.CurrentUser.OpenSubKey(@"Software\RetroBat");
3334
if (key != null)
3435
{
35-
var path = key.GetValue("LatestKnownInstallPath") as string;
36-
if (!string.IsNullOrEmpty(path))
36+
registryPath = key.GetValue("LatestKnownInstallPath") as string;
37+
if (!string.IsNullOrEmpty(registryPath) && Directory.Exists(registryPath))
3738
{
38-
_retrobatPath = Path.Combine(path, "retrobat.exe");
39-
_logger.Log($"RetroBat path found in registry: {_retrobatPath}");
40-
return;
39+
var exePath = Directory.EnumerateFiles(registryPath, "retrobat.exe", new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive }).FirstOrDefault();
40+
if (!string.IsNullOrEmpty(exePath))
41+
{
42+
_retrobatPath = exePath;
43+
_logger.Log($"RetroBat path found in registry: {_retrobatPath}");
44+
return;
45+
}
4146
}
4247
}
4348
}
@@ -46,14 +51,29 @@ private void InitializeRetrobatPath()
4651
_logger.LogError("Error reading registry", ex);
4752
}
4853

49-
_retrobatPath = @"C:\Retrobat\retrobat.exe"; // Default path
50-
_logger.Log($"Using default path: {_retrobatPath}");
54+
var defaultDir = @"C:\Retrobat";
55+
if (Directory.Exists(defaultDir))
56+
{
57+
var defaultExePath = Directory.EnumerateFiles(defaultDir, "retrobat.exe", new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive }).FirstOrDefault();
58+
if (!string.IsNullOrEmpty(defaultExePath))
59+
{
60+
_retrobatPath = defaultExePath;
61+
_logger.Log($"Using default path: {_retrobatPath}");
62+
return;
63+
}
64+
}
5165

52-
if (!File.Exists(_retrobatPath))
66+
_retrobatPath = Path.Combine(defaultDir, "retrobat.exe");
67+
var errorMessage = "Unable to find retrobat.exe.";
68+
if (!string.IsNullOrEmpty(registryPath))
69+
{
70+
errorMessage += $" Searched in registry path '{registryPath}' and default path '{defaultDir}'.";
71+
}
72+
else
5373
{
54-
var error = $"Unable to find RetroBat at {_retrobatPath}";
55-
_logger.LogError(error);
74+
errorMessage += $" Searched in default path '{defaultDir}'.";
5675
}
76+
_logger.LogError(errorMessage);
5777
}
5878

5979
public bool IsEmulationStationRunning()

0 commit comments

Comments
 (0)