Skip to content

Commit 3c398a5

Browse files
committed
- Bug fix: Installed games were sometimes not displayed if they were deleted from the server.
- Bug fix: Completed downloads were sometimes displayed as paused after a restart.
1 parent 6fc8a6a commit 3c398a5

4 files changed

Lines changed: 51 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# GameVault App Changelog
22

3+
## 1.17.3
4+
Recommended Gamevault Server Version: `v16.1.1`
5+
### Changes
6+
- Bug fix: Installed games were sometimes not displayed if they were deleted from the server.
7+
- Bug fix: Completed downloads were sometimes displayed as paused after a restart.
8+
39
## 1.17.2
410
Recommended Gamevault Server Version: `v15.0.2`
511
### Changes

gamevault/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//(used if a resource is not found in the page,
1212
// app, or any theme specific resource dictionaries)
1313
)]
14-
[assembly: AssemblyVersion("1.17.2.0")]
14+
[assembly: AssemblyVersion("1.17.3.0")]
1515
[assembly: AssemblyCopyright("© Phalcode™. All Rights Reserved.")]
1616
#if DEBUG
1717
[assembly: XmlnsDefinition("debug-mode", "Namespace")]

gamevault/Helper/Web/HttpClientDownloadWithProgress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private void TriggerProgressChanged(long totalDownloadSize, long currentBytesRea
190190
return;
191191

192192
totalDownloadSize = PreResumeSize == -1 ? totalDownloadSize : PreResumeSize;
193-
double progressPercentage = Math.Round((double)totalBytesRead / totalDownloadSize * 100, 0);
193+
double progressPercentage = (double)totalBytesRead / totalDownloadSize * 100;
194194
ProgressChanged(totalDownloadSize, currentBytesRead, totalBytesRead, progressPercentage, ResumePosition);
195195
}
196196
public void Cancel()

gamevault/UserControls/InstallUserControl.xaml.cs

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,33 @@ private async void UserControl_Loaded(object sender, RoutedEventArgs e)
4040
InstallViewModel.Instance.InstalledGamesFilter = CollectionViewSource.GetDefaultView(InstallViewModel.Instance.InstalledGames);
4141
}
4242
}
43+
private List<Game> GetGamesFromOfflineCache(Dictionary<int, string> games)
44+
{
45+
List<Game> offlineCacheGames = new List<Game>();
46+
foreach (KeyValuePair<int, string> entry in games)
47+
{
48+
string objectFromFile = Preferences.Get(entry.Key.ToString(), LoginManager.Instance.GetUserProfile().OfflineCache);
49+
if (objectFromFile != string.Empty)
50+
{
51+
try
52+
{
53+
string decompressedObject = StringCompressor.DecompressString(objectFromFile);
54+
Game? deserializedObject = JsonSerializer.Deserialize<Game>(decompressedObject);
55+
if (deserializedObject != null)
56+
{
57+
offlineCacheGames.Add(deserializedObject);
58+
}
59+
}
60+
catch (FormatException exFormat) { }
61+
}
62+
else
63+
{
64+
string gameTitle = Path.GetFileName(entry.Value);
65+
offlineCacheGames.Add(new Game() { ID = entry.Key, Title = gameTitle.Substring(gameTitle.IndexOf(')') + 1) });
66+
}
67+
}
68+
return offlineCacheGames;
69+
}
4370
public async Task RestoreInstalledGames(bool fromCLI = false)
4471
{
4572
if (gamesRestored)
@@ -98,33 +125,26 @@ public async Task RestoreInstalledGames(bool fromCLI = false)
98125
if (LoginManager.Instance.IsLoggedIn())
99126
{
100127
string gameList = await WebHelper.GetAsync(@$"{SettingsViewModel.Instance.ServerUrl}/api/games?filter.id=$in:{gameIds}&limit=-1");
101-
return JsonSerializer.Deserialize<PaginatedData<Game>>(gameList).Data;
102-
}
103-
else
104-
{
105-
List<Game> offlineCacheGames = new List<Game>();
106-
foreach (KeyValuePair<int, string> entry in foundGames)
128+
Game[] serverGames = JsonSerializer.Deserialize<PaginatedData<Game>>(gameList)!.Data;
129+
130+
var serverGameIds = new HashSet<int>(serverGames.Select(g => g.ID));
131+
var missingGames = foundGames.Where(kvp => !serverGameIds.Contains(kvp.Key))
132+
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
133+
134+
//Make sure to display installed games that are already deleted on the server
135+
if (missingGames.Count > 0)
107136
{
108-
string objectFromFile = Preferences.Get(entry.Key.ToString(), LoginManager.Instance.GetUserProfile().OfflineCache);
109-
if (objectFromFile != string.Empty)
110-
{
111-
try
112-
{
113-
string decompressedObject = StringCompressor.DecompressString(objectFromFile);
114-
Game? deserializedObject = JsonSerializer.Deserialize<Game>(decompressedObject);
115-
if (deserializedObject != null)
116-
{
117-
offlineCacheGames.Add(deserializedObject);
118-
}
119-
}
120-
catch (FormatException exFormat) { }
121-
}
122-
else
137+
List<Game> offlineCacheGames = GetGamesFromOfflineCache(foundGames);
138+
if (offlineCacheGames.Count > 0)
123139
{
124-
string gameTitle = Path.GetFileName(entry.Value);
125-
offlineCacheGames.Add(new Game() { ID = entry.Key, Title = gameTitle.Substring(gameTitle.IndexOf(')') + 1) });
140+
serverGames = serverGames.Concat(offlineCacheGames).ToArray();
126141
}
127142
}
143+
return serverGames;
144+
}
145+
else
146+
{
147+
List<Game> offlineCacheGames = GetGamesFromOfflineCache(foundGames);
128148
return offlineCacheGames.ToArray();
129149
}
130150
}

0 commit comments

Comments
 (0)