diff --git a/BetterGenshinImpact/Genshin/Paths/RegistryGameLocator.cs b/BetterGenshinImpact/Genshin/Paths/RegistryGameLocator.cs index 1faadeec..f0b4f5b6 100644 --- a/BetterGenshinImpact/Genshin/Paths/RegistryGameLocator.cs +++ b/BetterGenshinImpact/Genshin/Paths/RegistryGameLocator.cs @@ -18,25 +18,38 @@ public class RegistryGameLocator var cn = Registry.GetValue($@"HKEY_CURRENT_USER\Software\miHoYo\HYP\1_1\hk4e_cn", "GameInstallPath", null) as string; if (!string.IsNullOrEmpty(cn)) { - return Path.Combine(cn, "YuanShen.exe"); + var filePath = Path.Combine(cn, "YuanShen.exe"); + if (File.Exists(filePath)) + { + return filePath; + } } var global = Registry.GetValue($@"HKEY_CURRENT_USER\Software\Cognosphere\HYP\1_0\hk4e_global", "GameInstallPath", null) as string; if (!string.IsNullOrEmpty(global)) { - return Path.Combine(global, "GenshinImpact.exe"); + var filePath = Path.Combine(global, "GenshinImpact.exe"); + if (File.Exists(filePath)) + { + return filePath; + } } var bilibili = Registry.GetValue($@"HKEY_CURRENT_USER\Software\miHoYo\HYP\standalone\14_0\hk4e_cn\umfgRO5gh5\hk4e_cn", "GameInstallPath", null) as string; if (!string.IsNullOrEmpty(bilibili)) { - return Path.Combine(bilibili, "YuanShen.exe"); + var filePath = Path.Combine(bilibili, "YuanShen.exe"); + if (File.Exists(filePath)) + { + return filePath; + } } } catch (Exception e) { - TaskControl.Logger.LogDebug(e, "Failed to locate game path."); + TaskControl.Logger.LogDebug(e, "Failed to locate game path from HYP."); } + return null; } } \ No newline at end of file diff --git a/BetterGenshinImpact/Genshin/Paths/UnityLogGameLocator.cs b/BetterGenshinImpact/Genshin/Paths/UnityLogGameLocator.cs index a31501d4..55939921 100644 --- a/BetterGenshinImpact/Genshin/Paths/UnityLogGameLocator.cs +++ b/BetterGenshinImpact/Genshin/Paths/UnityLogGameLocator.cs @@ -23,15 +23,29 @@ public partial class UnityLogGameLocator string logFilePathOversea = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\Genshin Impact\output_log.txt"); string logFilePathChinese = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\原神\output_log.txt"); - // Fallback to the CN server. - string logFilePath = File.Exists(logFilePathChinese) ? logFilePathChinese : logFilePathOversea; - return await LocateGamePathAsync(logFilePath).ConfigureAwait(false); + if (File.Exists(logFilePathChinese)) + { + var p1 = await LocateGamePathAsync(logFilePathChinese).ConfigureAwait(false); + if (p1 is not null && File.Exists(p1)) + { + return p1; + } + } + + if (File.Exists(logFilePathOversea)) + { + var p2 = await LocateGamePathAsync(logFilePathOversea).ConfigureAwait(false); + if (p2 is not null && File.Exists(p2)) + { + return p2; + } + } } catch (Exception e) { TaskControl.Logger.LogDebug(e, "Failed to locate game path."); - return null; } + return null; } private static async ValueTask LocateGamePathAsync(string logFilePath) diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs index 47888dfb..604cfed6 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs @@ -337,14 +337,14 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi { Task.Run(async () => { - var p1 = await UnityLogGameLocator.LocateSingleGamePathAsync(); + var p1 = RegistryGameLocator.GetDefaultGameInstallPath(); if (!string.IsNullOrEmpty(p1)) { Config.GenshinStartConfig.InstallPath = p1; } else { - var p2 = RegistryGameLocator.GetDefaultGameInstallPath(); + var p2 = await UnityLogGameLocator.LocateSingleGamePathAsync(); if (!string.IsNullOrEmpty(p2)) { Config.GenshinStartConfig.InstallPath = p2;