Skip to content

Commit

Permalink
InsertOrUpdateGameItem
Browse files Browse the repository at this point in the history
user should not be able to try and add a same game twice.
  • Loading branch information
Lesueur Benjamin committed Aug 20, 2020
1 parent 100eb6a commit 7b7ba57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
30 changes: 11 additions & 19 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static void UpdateFormIcons()
catch (Exception ex) { SendNotification("UpdateFormIcons: " + ex.Message, true); }
}

public void UpdateGameItem(DockerGame game, bool ForceUpdate = false)
public void InsertOrUpdateGameItem(DockerGame game)
{
exListBoxItem newitem = new exListBoxItem(game);

Expand All @@ -207,19 +207,6 @@ public void UpdateGameItem(DockerGame game, bool ForceUpdate = false)
GameList.Items.Add(newitem);
DatabaseManager.GameDB[game.GUID] = game;
}
else if (ForceUpdate)
{
for (int i = 0; i < GameList.Items.Count; i++)
{
exListBoxItem item = (exListBoxItem)GameList.Items[i];
if (item.Guid == game.GUID)
{
GameList.Items[i] = newitem;
DatabaseManager.GameDB[game.GUID] = game;
break;
}
}
}

// Update current title
string path_game = DockStatus ? VideoControllers[true].Name : VideoControllers[false].Name;
Expand Down Expand Up @@ -488,12 +475,12 @@ private void removeTheGameToolStripMenuItem_Click(object sender, EventArgs e)
if (dialogResult == DialogResult.Yes)
{
string filename = Path.Combine(path_database, game.FolderName + ".dat");

if (File.Exists(filename))
{
File.Delete(filename);
DatabaseManager.GameDB.TryRemove(item.Guid, out game);
GameList.Items.Remove(item);
}

DatabaseManager.GameDB.TryRemove(item.Guid, out game);
GameList.Items.Remove(item);
}
}
}
Expand All @@ -507,7 +494,7 @@ private void automaticDetectionToolStripMenuItem_Click(object sender, EventArgs
{
DockerGame thisGame = new DockerGame(uri);
thisGame.SanityCheck();
UpdateGameItem(thisGame);
InsertOrUpdateGameItem(thisGame);
}
}

Expand All @@ -518,6 +505,11 @@ private void findAGameToolStripMenuItem_Click(object sender, EventArgs e)
// only display the settings window when an executable has been picked.
if (currentSettings.GetIsReady())
currentSettings.Show();
{
DockerGame game = currentSettings.GetGame();
if (!DatabaseManager.GameDB.ContainsKey(game.GUID))
currentSettings.Show();
}
}

private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
7 changes: 6 additions & 1 deletion DockerForm/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public bool GetIsReady()
return IsReady;
}

public DockerGame GetGame()
{
return thisGame;
}

public void SetStartPos()
{
this.StartPosition = FormStartPosition.Manual;
Expand Down Expand Up @@ -118,7 +123,7 @@ private void Settings_Closing(object sender, FormClosingEventArgs e)
}

thisGame.SanityCheck();
thisForm.UpdateGameItem(thisGame, true);
thisForm.InsertOrUpdateGameItem(thisGame);
}

private bool PickAGame()
Expand Down

0 comments on commit 7b7ba57

Please sign in to comment.