diff --git a/DockerForm/Form1.cs b/DockerForm/Form1.cs index cb8c5b0..3bccae1 100644 --- a/DockerForm/Form1.cs +++ b/DockerForm/Form1.cs @@ -405,27 +405,38 @@ public static void UpdateFormIcons() catch (Exception ex) { LogManager.UpdateLog("UpdateFormIcons: " + ex.Message, true); } } - public void InsertOrUpdateGameItem(DockerGame game, bool Update = true) + public void InsertOrUpdateGameItem(DockerGame game, bool auto) { + 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) + else { - exListBoxItem item = GameList.GetItemFromGuid(game.GUID); - if (item == null) + int idx = GameList.GetIndexFromGuid(game.GUID); + if (idx == -1) 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; + if (auto) + { + // automatic detection + list_game.Uri = game.Uri; + list_game.Version = game.Version; + list_game.LastCheck = DateTime.Now; + list_game.SanityCheck(); + } + else + { + // manually updated game + list_game = game; + GameList.Items[idx] = newitem; + } + + ((exListBoxItem)GameList.Items[idx]).Enabled = list_game.Enabled; LogManager.UpdateLog("[" + list_game.Name + "] profile has been updated"); } @@ -447,11 +458,11 @@ public void UpdateGameList() using (Stream reader = new FileStream(filename, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); - DockerGame game = (DockerGame)formatter.Deserialize(reader); - game.SanityCheck(); + DockerGame thisGame = (DockerGame)formatter.Deserialize(reader); + thisGame.SanityCheck(); - if (!DatabaseManager.GameDB.ContainsKey(game.GUID)) - DatabaseManager.GameDB.AddOrUpdate(game.GUID, game, (key, value) => game); + if (!DatabaseManager.GameDB.ContainsKey(thisGame.GUID)) + DatabaseManager.GameDB.AddOrUpdate(thisGame.GUID, thisGame, (key, value) => thisGame); reader.Dispose(); } diff --git a/DockerForm/Game.cs b/DockerForm/Game.cs index 00ca071..5c7255e 100644 --- a/DockerForm/Game.cs +++ b/DockerForm/Game.cs @@ -96,7 +96,7 @@ public void SanityCheck() else if (!HasFileSettings()) ErrorCode = ErrorCode.MissingSettings; - Enabled = (ErrorCode == ErrorCode.None ? true : false); + Enabled = ErrorCode == ErrorCode.None; } public string GetCrc() diff --git a/DockerForm/Settings.cs b/DockerForm/Settings.cs index 2ed10e4..ad48b08 100644 --- a/DockerForm/Settings.cs +++ b/DockerForm/Settings.cs @@ -131,7 +131,7 @@ private void Settings_Closing(object sender, FormClosingEventArgs e) } thisGame.SanityCheck(); - thisForm.InsertOrUpdateGameItem(thisGame); + thisForm.InsertOrUpdateGameItem(thisGame, false); } private bool PickAGame() diff --git a/DockerForm/exListBox.cs b/DockerForm/exListBox.cs index eda1af9..4a835b3 100644 --- a/DockerForm/exListBox.cs +++ b/DockerForm/exListBox.cs @@ -123,6 +123,17 @@ public exListBoxItem GetItemFromGuid(string guid) return null; } + public int GetIndexFromGuid(string guid) + { + for (int i = 0; i < Items.Count; i++) + { + exListBoxItem item = (exListBoxItem)Items[i]; + if (item.Guid == guid) + return i; + } + return -1; + } + public void Sort() { if (Items.Count > 1)