Skip to content

Commit fe1fabc

Browse files
committed
- Bug fix: Fixed an issue where the current user's profile data was overwritten when modifying another user's data.
- Bug fix: Fixed an empty message issue when the uninstall selection was cancelled. - Bug fix: Resolved folder mapping issues on download cards when a root directory was a subdirectory of another root. - Improvement: Downloads are now correctly restored when root directories are added or removed.
1 parent cc5253a commit fe1fabc

7 files changed

Lines changed: 57 additions & 6 deletions

gamevault/UserControls/DownloadsUserControl.xaml.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public async Task RestoreDownloadedGames()
5353
string gameId = dirName.Substring(2, dirName.IndexOf(')') - 2);
5454

5555
if (int.TryParse(gameId, out int id))
56-
foundPathsById.Add(id, SettingsViewModel.Instance.RootDirectories.First(x => dir.Contains(x.Uri)).Uri);
56+
foundPathsById.Add(id, SettingsViewModel.Instance.RootDirectories
57+
.Where(x => dir.Contains(x.Uri))
58+
.OrderByDescending(x => x.Uri.Length)
59+
.First().Uri);
60+
5761
}
5862
catch { continue; }
5963
}
@@ -107,9 +111,32 @@ public async Task RestoreDownloadedGames()
107111
if (games == null)
108112
return;
109113

110-
foreach (KeyValuePair<Game, string> game in games)
114+
var validGameIds = new HashSet<int>(games.Keys.Select(g => g.ID));
115+
// Remove controls not in the dictionary, unless they're downloading
116+
for (int i = DownloadsViewModel.Instance.DownloadedGames.Count - 1; i >= 0; i--)
111117
{
112-
DownloadsViewModel.Instance.DownloadedGames.Add(new GameDownloadUserControl(game.Key, game.Value, false));
118+
var control = DownloadsViewModel.Instance.DownloadedGames[i];
119+
int gameId = control.GetGameId();
120+
121+
bool existsInDict = validGameIds.Contains(gameId);
122+
123+
if (control.IsDownloading())
124+
{
125+
control.PauseDownload();
126+
}
127+
if (!existsInDict)
128+
{
129+
DownloadsViewModel.Instance.DownloadedGames.RemoveAt(i);
130+
}
131+
}
132+
var existingIds = new HashSet<int>(DownloadsViewModel.Instance.DownloadedGames.Select(c => c.GetGameId()));
133+
134+
foreach (var game in games)
135+
{
136+
if (!existingIds.Contains(game.Key.ID))
137+
{
138+
DownloadsViewModel.Instance.DownloadedGames.Add(new GameDownloadUserControl(game.Key, game.Value, false));
139+
}
113140
}
114141
}
115142
public void RefreshGame(Game game)

gamevault/UserControls/GameDownloadUserControl.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ private void PauseResume_Click(object sender, RoutedEventArgs e)
260260
ViewModel.State = "Download Paused";
261261
}
262262
}
263+
public void PauseDownload()
264+
{
265+
if (client == null || ViewModel.IsDownloadPaused || !IsDownloadActive)
266+
return;
267+
268+
ViewModel.IsDownloadPaused = true;
269+
client.Pause();
270+
IsDownloadActive = false;
271+
ViewModel.State = "Download Paused";
272+
}
263273
private void DownloadProgress(long totalFileSize, long currentBytesDownloaded, long totalBytesDownloaded, double? progressPercentage, long resumePosition)
264274
{
265275
App.Current.Dispatcher.Invoke((Action)delegate

gamevault/UserControls/GameSettingsUserControl.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ public async Task UninstallGame()
245245
}
246246
}
247247
}
248+
if (!File.Exists(selectedUninstallerExecutablePath))
249+
{
250+
MainWindowViewModel.Instance.AppBarText = "No valid uninstall executable selected";
251+
return;
252+
}
248253
Process uninstProcess = null;
249254
try
250255
{

gamevault/UserControls/SettingsUserControl.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ private async void AddRootDirectory_Click(object sender, RoutedEventArgs e)
640640
string result = string.Join(";", ViewModel.RootDirectories.Select(entry => entry.Uri));
641641
Preferences.Set(AppConfigKey.RootDirectories, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
642642
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
643+
await MainWindowViewModel.Instance.Downloads.RestoreDownloadedGames();
643644
}
644645
}
645646
catch (Exception ex)
@@ -661,6 +662,7 @@ private async void RemoveRootDirectory_Click(object sender, RoutedEventArgs e)
661662

662663
((FrameworkElement)sender).IsEnabled = false;//Disable the add button to block async restoring installed games
663664
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
665+
await MainWindowViewModel.Instance.Downloads.RestoreDownloadedGames();
664666
}
665667
}
666668
catch (Exception ex)

gamevault/UserControls/UserSettingsUserControl.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ private async void SaveUserDetails_Click(object sender, RoutedEventArgs e)
371371
}
372372
string result = await WebHelper.PutAsync(url, JsonSerializer.Serialize(selectedUser));
373373
ViewModel.OriginUser = JsonSerializer.Deserialize<User>(result);
374-
WebHelper.OverrideCredentials(selectedUser.Username, selectedUser.Password);
374+
if (LoginManager.Instance.GetCurrentUser().ID == ViewModel.OriginUser.ID)
375+
{
376+
WebHelper.OverrideCredentials(selectedUser.Username, selectedUser.Password);
377+
}
375378
MainWindowViewModel.Instance.AppBarText = "Successfully saved user changes";
376379
}
377380
catch (Exception ex)

gamevault/ViewModels/SettingsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public string Version
449449
{
450450
get
451451
{
452-
return Assembly.GetExecutingAssembly().GetName().Version.ToString() + "EA1";
452+
return Assembly.GetExecutingAssembly().GetName().Version.ToString() + "EA2";
453453
}
454454
}
455455
//DevMode

gamevault/Windows/LoginWindow.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
<StackPanel Background="Transparent">
6666
<Border Background="{DynamicResource MahApps.Brushes.ThemeBackground}" CornerRadius="5">
6767
<Grid Height="100" Width="100">
68-
<uc:CacheImage UseUriSource="True" ImageCacheType="UserAvatar" Data="{Binding UserCacheAvatar}" CornerRadius="5"/>
68+
<Grid>
69+
<uc:CacheImage UseUriSource="True" ImageCacheType="UserAvatar" Data="{Binding UserCacheAvatar}" CornerRadius="5"/>
70+
<Border x:Name="HoverBlur" Visibility="Hidden" Background="{DynamicResource GameVault.Brushes.Blur}" CornerRadius="5"/>
71+
</Grid>
6972
<Button x:Name="DeleteUserProfile" Style="{StaticResource ButtonWrapper}" Visibility="Hidden" Margin="0,0,0,3" Click="UserProfileContextMenu_Click">
7073
<Border Style="{StaticResource HoverEffect}" Background="Transparent" HorizontalAlignment="Right" VerticalAlignment="Bottom" CornerRadius="5">
7174
<Path Data="{StaticResource IconInstalledGamesSettings}" Fill="White" Margin="0,0,5,2"/>
@@ -96,6 +99,7 @@
9699
<Trigger Property="IsMouseOver" Value="True">
97100
<Setter TargetName="DeleteUserProfile" Property="Visibility" Value="Visible"/>
98101
<Setter TargetName="ProfileInfo" Property="Visibility" Value="Visible"/>
102+
<Setter TargetName="HoverBlur" Property="Visibility" Value="Visible"/>
99103
</Trigger>
100104
</ControlTemplate.Triggers>
101105
</ControlTemplate>

0 commit comments

Comments
 (0)