Skip to content

Commit

Permalink
Show warning when using launcher.exe as location
Browse files Browse the repository at this point in the history
  • Loading branch information
sabihoshi committed Sep 13, 2022
1 parent fabde6f commit 2e5ba64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject>GenshinLyreMidiPlayer.WPF.App</StartupObject>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
<ApplicationIcon>item_windsong_lyre.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<RepositoryUrl>https://github.com/sabihoshi/GenshinLyreMidiPlayer</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected override async void OnViewLoaded()
Navigation = ((MainWindowView) View).RootNavigation;
_theme.SetTheme(_theme.GetSystemTheme());

if (!SettingsView.TryGetLocation()) _ = SettingsView.LocationMissing();
if (!await SettingsView.TryGetLocationAsync()) _ = SettingsView.LocationMissing();
if (SettingsView.AutoCheckUpdates)
{
_ = SettingsView.CheckForUpdate()
Expand Down
33 changes: 26 additions & 7 deletions GenshinLyreMidiPlayer.WPF/ViewModels/SettingsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static string GenshinLocation

private PlaylistViewModel Playlist => _main.PlaylistView;

public bool TryGetLocation()
public async Task<bool> TryGetLocationAsync()
{
var locations = new[]
{
Expand All @@ -213,7 +213,13 @@ public bool TryGetLocation()
AppContext.BaseDirectory + "YuanShen.exe"
};

return locations.Any(TrySetLocation);
foreach (var location in locations)
{
if (await TrySetLocationAsync(location))
return true;
}

return false;
}

public async Task CheckForUpdate()
Expand Down Expand Up @@ -247,10 +253,10 @@ public async Task LocationMissing()
var dialog = new ContentDialog
{
Title = "Error",
Content = "Could not find Game's Location",
Content = "Could not find Game's Location, please find GenshinImpact.exe or YuanShen.exe",

PrimaryButtonText = "Find Manually...",
SecondaryButtonText = "Ignore",
SecondaryButtonText = "Ignore (Notes might not play)",
CloseButtonText = "Exit"
};

Expand Down Expand Up @@ -279,12 +285,12 @@ public async Task SetLocation()
{
Filter = "Executable|*.exe|All files (*.*)|*.*",
InitialDirectory = WindowHelper.InstallLocation is null
? string.Empty
? @"C:\Program Files\Genshin Impact\Genshin Impact Game\"
: Path.Combine(WindowHelper.InstallLocation, "Genshin Impact Game")
};

var success = openFileDialog.ShowDialog() == true;
var set = TrySetLocation(openFileDialog.FileName);
var set = await TrySetLocationAsync(openFileDialog.FileName);

if (!(success && set)) await LocationMissing();
}
Expand Down Expand Up @@ -332,9 +338,22 @@ protected override void OnActivate()
_ = CheckForUpdate();
}

private bool TrySetLocation(string? location)
private async Task<bool> TrySetLocationAsync(string? location)
{
if (!File.Exists(location)) return false;
if (Path.GetFileName(location).Equals("launcher.exe", StringComparison.OrdinalIgnoreCase))
{
var dialog = new ContentDialog
{
Title = "Incorrect Location",
Content = "launcher.exe is not the game, please find GenshinImpact.exe",

CloseButtonText = "Ok"
};

await dialog.ShowAsync();
return false;
}

Settings.GenshinLocation = location;
NotifyOfPropertyChange(() => Settings.GenshinLocation);
Expand Down

0 comments on commit 2e5ba64

Please sign in to comment.