diff --git a/LANCommander.Playnite.Extension/InstallController.cs b/LANCommander.Playnite.Extension/InstallController.cs index 5d9053b..37e163a 100644 --- a/LANCommander.Playnite.Extension/InstallController.cs +++ b/LANCommander.Playnite.Extension/InstallController.cs @@ -22,7 +22,6 @@ namespace LANCommander.PlaynitePlugin { Name = "Install using LANCommander"; Plugin = plugin; - } public override void Install(InstallActionArgs args) @@ -88,7 +87,7 @@ namespace LANCommander.PlaynitePlugin private string Extract(LANCommander.SDK.Models.Game game, string archivePath) { - var destination = $"C:\\Games\\{game.Title.SanitizeFilename()}"; + var destination = Path.Combine(Plugin.Settings.InstallDirectory, game.Title.SanitizeFilename()); Plugin.PlayniteApi.Dialogs.ActivateGlobalProgress(progress => { diff --git a/LANCommander.Playnite.Extension/PlayniteLibraryPlugin.cs b/LANCommander.Playnite.Extension/PlayniteLibraryPlugin.cs index 443274d..1f53f1b 100644 --- a/LANCommander.Playnite.Extension/PlayniteLibraryPlugin.cs +++ b/LANCommander.Playnite.Extension/PlayniteLibraryPlugin.cs @@ -32,7 +32,13 @@ namespace LANCommander.PlaynitePlugin HasSettings = true, }; - LoadSettings(); + Settings = new PlayniteSettingsViewModel(this); + LANCommander = new LANCommanderClient(Settings.ServerAddress); + LANCommander.Token = new SDK.Models.AuthToken() + { + AccessToken = Settings.AccessToken, + RefreshToken = Settings.RefreshToken, + }; } public override IEnumerable GetGames(LibraryGetGamesArgs args) @@ -100,52 +106,6 @@ namespace LANCommander.PlaynitePlugin return new PlayniteSettingsView(this); } - public void LoadSettings() - { - Settings = LoadPluginSettings(); - - try - { - if (LANCommander == null) - LANCommander = new LANCommanderClient(Settings.ServerAddress); - - LANCommander.Client.BaseUrl = new Uri(Settings.ServerAddress); - - var token = new SDK.Models.AuthToken() - { - AccessToken = Settings.AccessToken, - RefreshToken = Settings.RefreshToken, - }; - - LANCommander.Token = token; - } - catch - { - - } - } - - public void SaveSettings() - { - SavePluginSettings(Settings); - - if (LANCommander == null) - LANCommander = new LANCommanderClient(Settings.ServerAddress); - - if (Settings.ServerAddress != LANCommander.Client.BaseUrl.ToString()) - { - LANCommander.Client.BaseUrl = new Uri(Settings.ServerAddress); - - var token = new SDK.Models.AuthToken() - { - AccessToken = Settings.AccessToken, - RefreshToken = Settings.RefreshToken, - }; - - LANCommander.Token = token; - } - } - public System.Windows.Window ShowAuthenticationWindow() { var window = PlayniteApi.Dialogs.CreateWindow(new WindowCreationOptions() @@ -188,6 +148,7 @@ namespace LANCommander.PlaynitePlugin var manifest = deserializer.Deserialize(manifestContents); + #region Actions if (game.GameActions == null) game.GameActions = new System.Collections.ObjectModel.ObservableCollection(); @@ -195,15 +156,73 @@ namespace LANCommander.PlaynitePlugin { bool isFirstAction = !manifest.Actions.Any(a => a.IsPrimaryAction) && manifest.Actions.First().Name == action.Name; + foreach (var existingAction in game.GameActions) + if (action.Name == existingAction.Name) + game.GameActions.Remove(existingAction); + game.GameActions.AddMissing(new PN.SDK.Models.GameAction() { Name = action.Name, Arguments = action.Arguments, - Path = PlayniteApi.ExpandGameVariables(game, action.Path), - WorkingDir = action.WorkingDirectory.Replace('/', Path.DirectorySeparatorChar) ?? game.InstallDirectory, + Path = PlayniteApi.ExpandGameVariables(game, action.Path?.Replace('/', Path.DirectorySeparatorChar)), + WorkingDir = action.WorkingDirectory?.Replace('/', Path.DirectorySeparatorChar) ?? game.InstallDirectory, IsPlayAction = action.IsPrimaryAction || isFirstAction }); } + #endregion + + #region Features + var singlePlayerFeature = PlayniteApi.Database.Features.FirstOrDefault(f => f.Name == "Single Player"); + + if (manifest.LanMultiplayer != null) + { + var multiplayerInfo = manifest.LanMultiplayer; + + string playerCount = multiplayerInfo.MinPlayers == multiplayerInfo.MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)"; + string featureName = $"LAN Multiplayer {playerCount}"; + + if (PlayniteApi.Database.Features.Any(f => f.Name == featureName)) + { + game.Features.Add(PlayniteApi.Database.Features.FirstOrDefault(f => f.Name == featureName)); + } + else + { + PlayniteApi.Database.Features.Add(new PN.SDK.Models.GameFeature() + { + Name = featureName + }); + + game.Features.Add(new PN.SDK.Models.GameFeature() + { + Name = $"LAN Multiplayer {playerCount}" + }); + } + } + + if (manifest.LocalMultiplayer != null) + { + var multiplayerInfo = manifest.LocalMultiplayer; + + string playerCount = multiplayerInfo.MinPlayers == multiplayerInfo.MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)"; + + game.Features.Add(new PN.SDK.Models.GameFeature() + { + Name = $"Local Multiplayer {playerCount}" + }); + } + + if (manifest.OnlineMultiplayer != null) + { + var multiplayerInfo = manifest.OnlineMultiplayer; + + string playerCount = multiplayerInfo.MinPlayers == multiplayerInfo.MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)"; + + game.Features.Add(new PN.SDK.Models.GameFeature() + { + Name = $"Online Multiplayer {playerCount}" + }); + } + #endregion PlayniteApi.Database.Games.Update(game); } diff --git a/LANCommander.Playnite.Extension/PlayniteSettings.cs b/LANCommander.Playnite.Extension/PlayniteSettings.cs index 3ce2e26..76518d5 100644 --- a/LANCommander.Playnite.Extension/PlayniteSettings.cs +++ b/LANCommander.Playnite.Extension/PlayniteSettings.cs @@ -15,43 +15,45 @@ namespace LANCommander.PlaynitePlugin public string ServerAddress { get; set; } = String.Empty; public string AccessToken { get; set; } = String.Empty; public string RefreshToken { get; set; } = String.Empty; + public string InstallDirectory { get; set; } = String.Empty; - public PlayniteSettingsViewModel() - { - - } + public PlayniteSettingsViewModel() { } public PlayniteSettingsViewModel(PlayniteLibraryPlugin plugin) { Plugin = plugin; - ServerAddress = Plugin.Settings.ServerAddress; - AccessToken = Plugin.Settings.AccessToken; - RefreshToken = Plugin.Settings.RefreshToken; + var settings = Plugin.LoadPluginSettings(); + + ServerAddress = settings.ServerAddress; + AccessToken = settings.AccessToken; + RefreshToken = settings.RefreshToken; + InstallDirectory = settings.InstallDirectory; } public void BeginEdit() { - + } public void CancelEdit() { - + } public void EndEdit() { - Plugin.Settings.ServerAddress = ServerAddress; - - Plugin.SaveSettings(); + Plugin.SavePluginSettings(this); } public bool VerifySettings(out List errors) { errors = new List(); - return true; + if (String.IsNullOrWhiteSpace(InstallDirectory)) + errors.Add("An install directory needs to be set!"); + + return errors.Count == 0; } } } diff --git a/LANCommander.Playnite.Extension/PlayniteSettingsView.xaml b/LANCommander.Playnite.Extension/PlayniteSettingsView.xaml index c9659d6..6d109da 100644 --- a/LANCommander.Playnite.Extension/PlayniteSettingsView.xaml +++ b/LANCommander.Playnite.Extension/PlayniteSettingsView.xaml @@ -3,17 +3,41 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:sys="clr-namespace:System;assembly=mscorlib" - mc:Ignorable="d" + xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:playniteplugin="clr-namespace:LANCommander.PlaynitePlugin" d:DataContext="{d:DesignInstance Type=playniteplugin:PlayniteSettingsViewModel}" + mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600"> - - - - - + + + + + + + + + + + + + + +