Skip to content

Commit

Permalink
improved Game profile update process
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesueur Benjamin committed Feb 9, 2021
1 parent feba97c commit a7dfddb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
27 changes: 13 additions & 14 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,27 +407,26 @@ public static void UpdateFormIcons()

public void InsertOrUpdateGameItem(DockerGame game, bool Update = true)
{
exListBoxItem newitem = new exListBoxItem(game);

if (!DatabaseManager.GameDB.ContainsKey(game.GUID))
{
exListBoxItem newitem = new exListBoxItem(game);
GameList.Items.Add(newitem);
DatabaseManager.GameDB[game.GUID] = game;
LogManager.UpdateLog("[" + game.Name + "] profile has been added to the database");
}
else if (Update)
{
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;
LogManager.UpdateLog("[" + game.Name + "] profile has been updated");
break;
}
}
exListBoxItem item = GameList.GetItemFromGuid(game.GUID);
if (item == null)
return;

DockerGame list_game = DatabaseManager.GameDB[game.GUID];
list_game.Uri = game.Uri;
list_game.Version = game.Version;
list_game.LastCheck = game.LastCheck;
list_game.SanityCheck();
item.Enabled = list_game.Enabled;
LogManager.UpdateLog("[" + list_game.Name + "] profile has been updated");
}

// Update current title
Expand Down Expand Up @@ -833,7 +832,7 @@ private void automaticDetectionToolStripMenuItem_Click(object sender, EventArgs
{
DialogResult dialogResult = MessageBox.Show("Do you want to add [" + game.Name + "] to your Database ? ", "(Beta) Automatic Detection", MessageBoxButtons.YesNoCancel);
if (dialogResult == DialogResult.Yes)
InsertOrUpdateGameItem(game, false);
InsertOrUpdateGameItem(game, true);
else if (dialogResult == DialogResult.No)
{
// Properties.Settings.Default.Blacklist.Add(game.Name);
Expand Down
11 changes: 11 additions & 0 deletions DockerForm/exListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ protected override void OnDrawItem(DrawItemEventArgs e)
catch (Exception) { }
}

public exListBoxItem GetItemFromGuid(string guid)
{
for (int i = 0; i < Items.Count; i++)
{
exListBoxItem item = (exListBoxItem)Items[i];
if (item.Guid == guid)
return item;
}
return null;
}

public void Sort()
{
if (Items.Count > 1)
Expand Down

0 comments on commit a7dfddb

Please sign in to comment.