Skip to content

Commit

Permalink
fix: remove stale shortctus
Browse files Browse the repository at this point in the history
feat: added option to open game details for unisntalled games
  • Loading branch information
felixkmh committed Jun 30, 2022
1 parent 6ca160e commit 8852b86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions source/ShortcutSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ShortcutSync : GenericPlugin
public static readonly ILogger logger = LogManager.GetLogger();
public static ShortcutSync Instance { get; private set; }
private TaskQueue backgroundTasks = new TaskQueue();
private ShortcutSyncSettings settings { get; set; }
internal ShortcutSyncSettings settings { get; set; }
public ShortcutSyncSettingsView settingsView { get; set; }
private Dictionary<string, IList<Guid>> shortcutNameToGameId { get; set; } = new Dictionary<string, IList<Guid>>();
private Dictionary<Guid, Shortcut<Game>> existingShortcuts { get; set; } = new Dictionary<Guid, Shortcut<Game>>();
Expand Down Expand Up @@ -404,7 +404,9 @@ private void Settings_OnSettingsChanged()
}
TiledShortcut.FadeTileEdge = settingsSnapshot.FadeBottom;
UpdateShortcutDicts(settingsSnapshot.ShortcutPath, settingsSnapshot);
UpdateShortcuts(PlayniteApi.Database.Games, settingsSnapshot, settingsSnapshot.FadeBottom != previousSettings.FadeBottom, true);
var forceUpdate = (settingsSnapshot.FadeBottom != previousSettings.FadeBottom) ||
(settingsSnapshot.OpenUninstalled != previousSettings.OpenUninstalled);
UpdateShortcuts(PlayniteApi.Database.Games, settingsSnapshot, forceUpdate, true);
previousSettings = settingsSnapshot;
});
}
Expand Down Expand Up @@ -900,6 +902,7 @@ public void UpdateShortcutDicts(string folderPath, ShortcutSyncSettings settings
if (!Directory.Exists(folderPath)) return;

var files = Directory.GetFiles(folderPath, shortcutName + "*.lnk", SearchOption.AllDirectories);
var stale = new List<Shortcut<Game>>();
foreach (var file in files)
{
var lnk = OpenLnk(file);
Expand All @@ -921,9 +924,18 @@ public void UpdateShortcutDicts(string folderPath, ShortcutSyncSettings settings
shortcutNameToGameId.Add(safeGameName, new List<Guid>());
}
shortcutNameToGameId[safeGameName].AddMissing(gameId);
} else
{
stale.Add(new TiledShortcut(new Game { Id = gameId }, file, GetLauncherScriptPath(), GetLauncherScriptIconsPath()));
}

}
}

foreach(var shortcut in stale)
{
shortcut.Remove();
}
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions source/ShortcutSyncSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class ShortcutSyncSettings : ISettings
public bool PrefixShortcutsPlay { get; set; } = false;
[QuickSearch.Attributes.GenericOption("LOC_SHS_PrefixShortcutsWithInstall")]
public bool PrefixShortcutsInstall { get; set; } = false;
[QuickSearch.Attributes.GenericOption("LOC_SHS_OpenUninstalledGames", Description = "LOC_SHS_OpenUninstalledGamesTooltip")]
public bool OpenUninstalled { get; set; } = false;

[Playnite.SDK.Data.DontSerialize]
public ShortcutSync.Prefix PrefixFlags =>
Expand Down
1 change: 1 addition & 0 deletions source/ShortcutSyncSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<CheckBox Content="{DynamicResource LOC_SHS_FadeEdges}" MinWidth="150" IsChecked="{Binding FadeBottom}" HorizontalAlignment="Left" Margin="0,2" ToolTip="{DynamicResource LOC_SHS_FadeEdgesTooltip}"/>
<CheckBox Content="{DynamicResource LOC_SHS_PrefixShortcutsWithPlay}" MinWidth="150" IsChecked="{Binding PrefixShortcutsPlay}" HorizontalAlignment="Left" Margin="0,2"/>
<CheckBox Content="{DynamicResource LOC_SHS_PrefixShortcutsWithInstall}" MinWidth="150" IsChecked="{Binding PrefixShortcutsInstall}" HorizontalAlignment="Left" Margin="0,2"/>
<CheckBox Content="{DynamicResource LOC_SHS_OpenUninstalledGames}" MinWidth="150" IsChecked="{Binding OpenUninstalled}" HorizontalAlignment="Left" Margin="0,2" ToolTip="{DynamicResource LOC_SHS_OpenUninstalledGamesTooltip}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel>
Expand Down
3 changes: 2 additions & 1 deletion source/TiledShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ protected string GetSourceName(Game game)
protected virtual string CreateVbsLauncher()
{
string fullPath = GetLauncherPath();
string action = (TargetObject.IsInstalled || !ShortcutSync.Instance.settings.OpenUninstalled) ? "start" : "showgame";
string script =
"Dim prefix, id\n" +

"prefix = \"playnite://playnite/start/\"\n" +
$"prefix = \"playnite://playnite/{action}/\"\n" +
$"id = \"{TargetObject.Id}\"\n" +

"Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n" +
Expand Down

0 comments on commit 8852b86

Please sign in to comment.