Skip to content

Commit

Permalink
fixed database update
Browse files Browse the repository at this point in the history
- now has a better support when games are automatically updated.
- fixed and issue where game list would only be visually updated after a software restart.
  • Loading branch information
Lesueur Benjamin committed Feb 11, 2021
1 parent a7dfddb commit 3a63c19
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
39 changes: 25 additions & 14 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion DockerForm/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion DockerForm/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void Settings_Closing(object sender, FormClosingEventArgs e)
}

thisGame.SanityCheck();
thisForm.InsertOrUpdateGameItem(thisGame);
thisForm.InsertOrUpdateGameItem(thisGame, false);
}

private bool PickAGame()
Expand Down
11 changes: 11 additions & 0 deletions DockerForm/exListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3a63c19

Please sign in to comment.