Skip to content

Commit

Permalink
Handle cancelling out of game selection
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 29, 2021
1 parent 4391cc9 commit a6e0bec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Core/GameInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public GameInstance AddInstance(string path, string name, IUser user)
{
var game = DetermineGame(new DirectoryInfo(path), user);
if (game == null)
throw new NotKSPDirKraken(path);
return null;

return AddInstance(new GameInstance(game, path, name, user));
}
Expand Down Expand Up @@ -608,14 +608,15 @@ public static bool IsGameInstanceDir(DirectoryInfo path)
/// </summary>
/// <param name="path">A DirectoryInfo of the path to check</param>
/// <param name="user">IUser object for interaction</param>
/// <returns>An instance of the matching game, or null if none could be found</returns>
/// <returns>An instance of the matching game or null if the user cancelled</returns>
/// <exception cref="NotKSPDirKraken">Thrown when no games found</exception>
public IGame DetermineGame(DirectoryInfo path, IUser user)
{
var matchingGames = knownGames.Where(g => g.GameInFolder(path)).ToList();
switch (matchingGames.Count)
{
case 0:
return null;
throw new NotKSPDirKraken(path.FullName);

case 1:
return matchingGames.First();
Expand Down
11 changes: 6 additions & 5 deletions GUI/Dialogs/CloneFakeGameDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ private async void buttonOK_Click(object sender, EventArgs e)
try
{
IGame guessedGame = manager.DetermineGame(new DirectoryInfo(existingPath), user);
if (guessedGame == null)
{
// User cancelled, let them try again
reactivateDialog();
return;
}
await Task.Run(() =>
{
if (guessedGame == null)
{
throw new NotKSPDirKraken(existingPath);
}
GameInstance instanceToClone = new GameInstance(
guessedGame,
existingPath,
Expand Down

0 comments on commit a6e0bec

Please sign in to comment.