Skip to content

Commit

Permalink
Steam shortcuts will now also be synced on install/uninstall trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelo420 committed Nov 29, 2024
1 parent 69993cb commit 22cc560
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
13 changes: 9 additions & 4 deletions gamevault/Helper/SteamHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using gamevault.Models;
using gamevault.ViewModels;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -231,6 +232,9 @@ internal static void SyncGamesWithSteamShortcuts(Dictionary<Game, string> games)
{
try
{
if (!SettingsViewModel.Instance.License.IsActive())
return;

string shortcutsDirectory = GetMostRecentUserUserDirectory();
if (!Directory.Exists(shortcutsDirectory))
return;
Expand Down Expand Up @@ -286,12 +290,13 @@ internal static void SyncGamesWithSteamShortcuts(Dictionary<Game, string> games)
}
internal static void RemoveGameVaultGamesFromSteamShortcuts()
{
string shortcutsDirectory = GetMostRecentUserUserDirectory();
if (!Directory.Exists(shortcutsDirectory))
return;

try
{
string shortcutsDirectory = GetMostRecentUserUserDirectory();
if (!Directory.Exists(shortcutsDirectory))
return;


string shortcutFile = Path.Combine(shortcutsDirectory, "shortcuts.vdf");
VdfMap shortcutFileMap = VdfUtilities.ReadVdf(File.ReadAllBytes(shortcutFile));
shortcutFileMap = TrimFirstOffsetEntry(shortcutFileMap);//Making sure to have a clean game list
Expand Down
3 changes: 2 additions & 1 deletion gamevault/Models/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public enum AppConfigKey
LastLibraryOrderBy,
SendAnonymousAnalytics,
LastCommunitySortBy,
ForcedInstallationType
ForcedInstallationType,
SyncSteamShortcuts
}
public static class AppFilePath
{
Expand Down
6 changes: 5 additions & 1 deletion gamevault/UserControls/InstallUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public static void PlayGame(int gameId)
}
private async void Settings_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
e.Handled = true;
try
{
int ID = ((KeyValuePair<Game, string>)((FrameworkElement)sender).DataContext).Key.ID;
Expand Down Expand Up @@ -422,6 +422,10 @@ private void Rows_ValueChanged(object sender, RoutedPropertyChangedEventArgs<dou
private void Collection_Updated(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
Rows_ValueChanged(null, null);
if (e.OldValue != null && e.OldValue != e.NewValue && SettingsViewModel.Instance.SyncSteamShortcuts)//Make sure that a game has really been added or removed
{
SteamHelper.SyncGamesWithSteamShortcuts(InstallViewModel.Instance.InstalledGames.ToDictionary(pair => pair.Key, pair => pair.Value));
}
}
}
}
2 changes: 1 addition & 1 deletion gamevault/UserControls/SettingsUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
<StackPanel Margin="30,0,0,0">
<StackPanel Margin="0,10,0,0">
<TextBlock Text="Steam" FontSize="20" FontWeight="Bold"/>
<mah:ToggleSwitch Header="Sync installed games with steam shortcuts (You need to restart Steam to see the changes)" Margin="10,10,0,0" Toggled="SyncSteamShortcuts_Toggled"/>
<mah:ToggleSwitch Header="Sync installed games with steam shortcuts (You need to restart Steam to see the changes)" Margin="10,10,0,0" IsOn="{Binding SyncSteamShortcuts}" Toggled="SyncSteamShortcuts_Toggled"/>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0">
<local:IconButton Text="Restore Backup" FontSize="15" Icon="{DynamicResource IconReload}" IconMargin="0,0,5,2" Width="135" Height="33" HorizontalAlignment="Right" Click="RestoreSteamShortcutBackup_Click"/>
</StackPanel>
Expand Down
3 changes: 3 additions & 0 deletions gamevault/UserControls/SettingsUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ private void IgnoredExecutablesSave_Click(object sender, RoutedEventArgs e)

private void SyncSteamShortcuts_Toggled(object sender, RoutedEventArgs e)
{
if (!this.loaded)//Make sure the toggle came from the ui
return;

if (((ToggleSwitch)sender).IsOn)
{
SteamHelper.SyncGamesWithSteamShortcuts(InstallViewModel.Instance.InstalledGames.ToDictionary(pair => pair.Key, pair => pair.Value));
Expand Down
13 changes: 12 additions & 1 deletion gamevault/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static SettingsViewModel Instance
private PhalcodeProduct license { get; set; }
private List<ThemeItem> themes { get; set; }
private bool showMappedTitle { get; set; }
private bool syncSteamShortcuts { get; set; }

#endregion

Expand All @@ -62,14 +63,16 @@ public SettingsViewModel()

string showMappedTitleString = Preferences.Get(AppConfigKey.ShowMappedTitle, AppFilePath.UserFile);
showMappedTitle = showMappedTitleString == "1" || showMappedTitleString == "";

//Setting the private members to avoid writing to the user config file over and over again
m_BackgroundStart = (Preferences.Get(AppConfigKey.BackgroundStart, AppFilePath.UserFile) == "1"); OnPropertyChanged(nameof(BackgroundStart));
m_AutoExtract = (Preferences.Get(AppConfigKey.AutoExtract, AppFilePath.UserFile) == "1"); OnPropertyChanged(nameof(AutoExtract));
autoDeletePortableGameFiles = Preferences.Get(AppConfigKey.AutoDeletePortable, AppFilePath.UserFile) == "1"; OnPropertyChanged(nameof(AutoDeletePortableGameFiles));
retainLibarySortByAndOrderBy = Preferences.Get(AppConfigKey.RetainLibarySortByAndOrderBy, AppFilePath.UserFile) == "1"; OnPropertyChanged(nameof(RetainLibarySortByAndOrderBy));

string analyticsPreference = Preferences.Get(AppConfigKey.SendAnonymousAnalytics, AppFilePath.UserFile);
sendAnonymousAnalytics = (analyticsPreference == "" || analyticsPreference == "1"); OnPropertyChanged(nameof(SendAnonymousAnalytics));

syncSteamShortcuts = Preferences.Get(AppConfigKey.SyncSteamShortcuts, AppFilePath.UserFile) == "1"; OnPropertyChanged(nameof(SyncSteamShortcuts));

string autoInstallPortableStr = Preferences.Get(AppConfigKey.AutoInstallPortable, AppFilePath.UserFile);
if (string.IsNullOrWhiteSpace(autoInstallPortableStr) || autoInstallPortableStr == "1")
Expand Down Expand Up @@ -287,6 +290,14 @@ public bool ShowMappedTitle
return showMappedTitle;
}
set { showMappedTitle = value; Preferences.Set(AppConfigKey.ShowMappedTitle, showMappedTitle ? "1" : "0", AppFilePath.UserFile); OnPropertyChanged(); }
}
public bool SyncSteamShortcuts
{
get
{
return syncSteamShortcuts;
}
set { syncSteamShortcuts = value; Preferences.Set(AppConfigKey.SyncSteamShortcuts, SyncSteamShortcuts ? "1" : "0", AppFilePath.UserFile); OnPropertyChanged(); }
}
public User RegistrationUser
{
Expand Down

0 comments on commit 22cc560

Please sign in to comment.