2023-04-07 19:09:00 -05:00
|
|
|
|
using LANCommander.PlaynitePlugin.Extensions;
|
2023-11-16 00:46:20 -06:00
|
|
|
|
using LANCommander.SDK.Helpers;
|
|
|
|
|
|
using LANCommander.SDK.PowerShell;
|
2023-12-26 18:11:09 -06:00
|
|
|
|
using LANCommander.SDK.Extensions;
|
2023-01-07 12:34:12 -06:00
|
|
|
|
using Playnite.SDK;
|
2023-01-25 21:08:05 -06:00
|
|
|
|
using Playnite.SDK.Events;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
using Playnite.SDK.Models;
|
|
|
|
|
|
using Playnite.SDK.Plugins;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-01-07 12:34:12 -06:00
|
|
|
|
using System.IO;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
using System.Linq;
|
2023-10-28 13:56:54 -05:00
|
|
|
|
using System.Web;
|
2023-01-15 13:33:04 -06:00
|
|
|
|
using System.Windows;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
using System.Windows.Controls;
|
2023-01-19 20:02:34 -06:00
|
|
|
|
using System.Windows.Media;
|
2024-01-14 23:48:52 -06:00
|
|
|
|
using LANCommander.SDK;
|
2024-01-23 18:54:44 -06:00
|
|
|
|
using LANCommander.PlaynitePlugin.Controls;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-02-06 01:43:40 -06:00
|
|
|
|
using System.Net;
|
2024-05-07 01:47:00 -05:00
|
|
|
|
using Windows.System;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
|
2023-01-08 12:09:57 -06:00
|
|
|
|
namespace LANCommander.PlaynitePlugin
|
2023-01-04 19:23:32 -06:00
|
|
|
|
{
|
2023-01-14 15:15:31 -06:00
|
|
|
|
public class LANCommanderLibraryPlugin : LibraryPlugin
|
2023-01-04 19:23:32 -06:00
|
|
|
|
{
|
2024-02-16 01:06:13 -06:00
|
|
|
|
public override Guid Id { get; } = Guid.Parse("48e1bac7-e0a0-45d7-ba83-36f5e9e959fc");
|
|
|
|
|
|
public override string Name => "LANCommander";
|
|
|
|
|
|
|
2023-01-04 19:23:32 -06:00
|
|
|
|
public static readonly ILogger Logger = LogManager.GetLogger();
|
2024-02-18 15:53:32 -06:00
|
|
|
|
internal SettingsViewModel Settings { get; set; }
|
2024-02-18 15:59:28 -06:00
|
|
|
|
internal Client LANCommanderClient { get; set; }
|
2023-01-04 19:23:32 -06:00
|
|
|
|
|
2024-02-16 01:06:13 -06:00
|
|
|
|
internal LANCommanderSaveController SaveController { get; set; }
|
|
|
|
|
|
internal ImportController ImportController { get; set; }
|
2024-01-20 21:02:41 -06:00
|
|
|
|
public DownloadQueueController DownloadQueue { get; set; }
|
2024-02-16 01:06:13 -06:00
|
|
|
|
|
2024-01-21 12:52:12 -06:00
|
|
|
|
public SidebarItem DownloadQueueSidebarItem { get; set; }
|
2023-03-20 18:37:12 -05:00
|
|
|
|
|
2024-01-19 05:15:01 -06:00
|
|
|
|
public TopPanelItem OfflineModeTopPanelItem { get; set; }
|
2024-01-19 05:33:33 -06:00
|
|
|
|
public TopPanelItem ProfileTopPanelItem { get; set; }
|
2024-01-19 05:15:01 -06:00
|
|
|
|
|
2023-01-14 15:15:31 -06:00
|
|
|
|
public LANCommanderLibraryPlugin(IPlayniteAPI api) : base(api)
|
2023-01-04 19:23:32 -06:00
|
|
|
|
{
|
|
|
|
|
|
Properties = new LibraryPluginProperties
|
|
|
|
|
|
{
|
|
|
|
|
|
HasSettings = true,
|
2024-02-16 00:22:01 -06:00
|
|
|
|
HasCustomizedGameImport = true,
|
2023-01-04 19:23:32 -06:00
|
|
|
|
};
|
2023-01-07 12:34:12 -06:00
|
|
|
|
|
2024-02-18 15:53:32 -06:00
|
|
|
|
Settings = new SettingsViewModel(this);
|
2024-01-02 02:34:58 -06:00
|
|
|
|
LANCommanderClient = new SDK.Client(Settings.ServerAddress, Settings.InstallDirectory, new PlayniteLogger(Logger));
|
2023-11-10 00:29:16 -06:00
|
|
|
|
LANCommanderClient.UseToken(new SDK.Models.AuthToken()
|
2023-01-11 20:48:39 -06:00
|
|
|
|
{
|
|
|
|
|
|
AccessToken = Settings.AccessToken,
|
|
|
|
|
|
RefreshToken = Settings.RefreshToken,
|
2023-11-09 19:40:38 -06:00
|
|
|
|
});
|
2023-03-29 20:49:31 -05:00
|
|
|
|
|
2024-01-23 18:54:44 -06:00
|
|
|
|
#region Initialize Top Bar Items
|
|
|
|
|
|
OfflineModeTopPanelItem = new TopPanelItem
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Title = ResourceProvider.GetString("LOCLANCommanderGoOnline"),
|
2024-01-23 18:54:44 -06:00
|
|
|
|
Icon = new TextBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = char.ConvertFromUtf32(0xef3e),
|
|
|
|
|
|
FontSize = 16,
|
|
|
|
|
|
FontFamily = ResourceProvider.GetResource("FontIcoFont") as FontFamily,
|
|
|
|
|
|
Padding = new Thickness(10, 0, 10, 0),
|
|
|
|
|
|
Foreground = (SolidColorBrush)new BrushConverter().ConvertFrom("#ff6b6b"),
|
|
|
|
|
|
},
|
|
|
|
|
|
Visible = Settings.OfflineModeEnabled,
|
|
|
|
|
|
Activated = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowAuthenticationWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-01-23 18:57:15 -06:00
|
|
|
|
ProfileTopPanelItem = new TopPanelItem
|
2024-01-23 18:54:44 -06:00
|
|
|
|
{
|
2024-01-24 00:35:34 -06:00
|
|
|
|
Icon = new ProfileTopPanelItem(this)
|
2024-01-23 18:54:44 -06:00
|
|
|
|
};
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-01-27 11:25:59 -08:00
|
|
|
|
ValidateConnection();
|
|
|
|
|
|
|
2024-01-24 00:35:34 -06:00
|
|
|
|
Settings.Load();
|
2024-01-23 18:54:44 -06:00
|
|
|
|
|
2024-02-16 01:06:13 -06:00
|
|
|
|
ImportController = new ImportController(this);
|
2024-01-20 21:02:41 -06:00
|
|
|
|
DownloadQueue = new DownloadQueueController(this);
|
|
|
|
|
|
|
2023-09-03 15:55:04 -05:00
|
|
|
|
api.UriHandler.RegisterSource("lancommander", args =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Arguments.Length == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
Guid gameId;
|
|
|
|
|
|
|
|
|
|
|
|
switch (args.Arguments[0].ToLower())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "install":
|
|
|
|
|
|
if (args.Arguments.Length == 1)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
if (Guid.TryParse(args.Arguments[1], out gameId))
|
|
|
|
|
|
PlayniteApi.InstallGame(gameId);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "run":
|
|
|
|
|
|
if (args.Arguments.Length == 1)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
if (Guid.TryParse(args.Arguments[1], out gameId))
|
|
|
|
|
|
PlayniteApi.StartGame(gameId);
|
|
|
|
|
|
break;
|
2023-10-28 13:56:54 -05:00
|
|
|
|
|
|
|
|
|
|
case "connect":
|
|
|
|
|
|
if (args.Arguments.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowAuthenticationWindow();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowAuthenticationWindow(HttpUtility.UrlDecode(args.Arguments[1]));
|
|
|
|
|
|
break;
|
2023-09-03 15:55:04 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2023-01-04 19:23:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-14 23:48:52 -06:00
|
|
|
|
public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
Migrate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-17 02:07:25 -05:00
|
|
|
|
public bool ValidateConnection()
|
|
|
|
|
|
{
|
2024-01-23 18:01:12 -06:00
|
|
|
|
LANCommanderClient.ValidateToken();
|
2024-01-19 05:33:33 -06:00
|
|
|
|
|
2024-01-23 18:01:12 -06:00
|
|
|
|
if (LANCommanderClient.IsConnected())
|
2024-01-19 05:33:33 -06:00
|
|
|
|
{
|
|
|
|
|
|
OfflineModeTopPanelItem.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-23 18:01:12 -06:00
|
|
|
|
return LANCommanderClient.IsConnected();
|
2023-03-17 02:07:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-23 18:54:44 -06:00
|
|
|
|
public async Task Logout()
|
|
|
|
|
|
{
|
|
|
|
|
|
await LANCommanderClient.LogoutAsync();
|
|
|
|
|
|
|
|
|
|
|
|
Settings.AccessToken = null;
|
|
|
|
|
|
Settings.RefreshToken = null;
|
|
|
|
|
|
Settings.PlayerAlias = null;
|
|
|
|
|
|
Settings.PlayerName = null;
|
|
|
|
|
|
Settings.PlayerAvatarUrl = null;
|
|
|
|
|
|
|
|
|
|
|
|
SavePluginSettings(Settings);
|
|
|
|
|
|
|
|
|
|
|
|
ShowAuthenticationWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 00:22:01 -06:00
|
|
|
|
public override IEnumerable<Game> ImportGames(LibraryImportGamesArgs args)
|
2023-01-04 19:23:32 -06:00
|
|
|
|
{
|
2024-01-18 23:22:46 -06:00
|
|
|
|
if (!ValidateConnection() && !Settings.OfflineModeEnabled)
|
2023-01-15 14:18:26 -06:00
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("Authentication invalid, showing auth window...");
|
2023-03-17 02:07:25 -05:00
|
|
|
|
ShowAuthenticationWindow();
|
2023-09-15 17:36:45 -05:00
|
|
|
|
|
2024-01-18 23:22:46 -06:00
|
|
|
|
if (!ValidateConnection() && !Settings.OfflineModeEnabled)
|
2023-09-15 17:36:45 -05:00
|
|
|
|
{
|
|
|
|
|
|
Logger.Trace("User cancelled authentication.");
|
|
|
|
|
|
|
2024-02-18 17:24:45 -06:00
|
|
|
|
throw new Exception(ResourceProvider.GetString("LOCLANCommanderImportGamesAuthenticationInvalidNotification"));
|
2023-09-15 17:36:45 -05:00
|
|
|
|
}
|
2023-01-15 14:18:26 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-18 23:22:46 -06:00
|
|
|
|
if (Settings.OfflineModeEnabled)
|
2024-02-16 01:06:13 -06:00
|
|
|
|
return new List<Game>();
|
2024-01-05 18:27:52 -06:00
|
|
|
|
|
2024-02-16 01:06:13 -06:00
|
|
|
|
return ImportController.ImportGames();
|
2024-02-16 00:22:01 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 22:12:03 -06:00
|
|
|
|
public override IEnumerable<InstallController> GetInstallActions(GetInstallActionsArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Game.PluginId != Id)
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
2024-01-18 23:22:46 -06:00
|
|
|
|
if (Settings.OfflineModeEnabled)
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString("LOCLANCommanderOfflineModeInstallWarningMessage"), ResourceProvider.GetString("LOCLANCommanderOfflineModeInstallWarningCaption"));
|
2024-01-18 23:22:46 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 22:12:03 -06:00
|
|
|
|
yield return new LANCommanderInstallController(this, args.Game);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-07 12:46:26 -06:00
|
|
|
|
public override IEnumerable<UninstallController> GetUninstallActions(GetUninstallActionsArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Game.PluginId != Id)
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
|
|
yield return new LANCommanderUninstallController(this, args.Game);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-02 20:46:28 -06:00
|
|
|
|
public override IEnumerable<PlayController> GetPlayActions(GetPlayActionsArgs args)
|
|
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
var manifests = GetGameManifests(args.Game);
|
2024-02-16 01:23:26 -06:00
|
|
|
|
var primaryDisplay = System.Windows.Forms.Screen.AllScreens.FirstOrDefault(s => s.Primary);
|
2024-01-02 21:21:06 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
LANCommanderClient.Actions.AddVariable("DisplayWidth", primaryDisplay.Bounds.Width.ToString());
|
|
|
|
|
|
LANCommanderClient.Actions.AddVariable("DisplayHeight", primaryDisplay.Bounds.Height.ToString());
|
2024-01-02 20:46:28 -06:00
|
|
|
|
|
2024-05-10 20:50:37 -05:00
|
|
|
|
foreach (var manifest in manifests.Where(m => m != null && m.Actions != null))
|
2024-02-16 01:23:26 -06:00
|
|
|
|
{
|
2024-05-28 21:08:30 -05:00
|
|
|
|
foreach (var action in manifest.Actions.Where(a => a.IsPrimaryAction).OrderBy(a => a.SortOrder))
|
2024-03-10 19:51:42 -05:00
|
|
|
|
{
|
2024-05-06 22:55:25 -05:00
|
|
|
|
AutomaticPlayController automaticPlayController = null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2024-03-10 19:51:42 -05:00
|
|
|
|
{
|
2024-05-06 22:55:25 -05:00
|
|
|
|
automaticPlayController = new AutomaticPlayController(args.Game)
|
|
|
|
|
|
{
|
|
|
|
|
|
Arguments = LANCommanderClient.Actions.ExpandVariables(action.Arguments, args.Game.InstallDirectory, skipSlashes: true),
|
|
|
|
|
|
Name = action.Name,
|
|
|
|
|
|
Path = LANCommanderClient.Actions.ExpandVariables(action.Path, args.Game.InstallDirectory),
|
|
|
|
|
|
TrackingMode = TrackingMode.Default,
|
|
|
|
|
|
Type = AutomaticPlayActionType.File,
|
|
|
|
|
|
WorkingDir = LANCommanderClient.Actions.ExpandVariables(action.WorkingDirectory, args.Game.InstallDirectory)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, "Could not yield primary action");
|
|
|
|
|
|
}
|
2024-03-10 19:51:42 -05:00
|
|
|
|
|
2024-05-06 22:55:25 -05:00
|
|
|
|
if (automaticPlayController != null)
|
|
|
|
|
|
yield return automaticPlayController;
|
|
|
|
|
|
}
|
2024-02-16 01:23:26 -06:00
|
|
|
|
}
|
2024-01-18 01:27:03 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
if (!Settings.OfflineModeEnabled)
|
|
|
|
|
|
{
|
2024-05-19 17:34:32 -05:00
|
|
|
|
SDK.Models.Game game = null;
|
2024-01-18 01:27:03 -06:00
|
|
|
|
|
2024-05-19 17:34:32 -05:00
|
|
|
|
game = LANCommanderClient.Games.Get(args.Game.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if (game != null && game.Servers != null)
|
2024-02-16 01:23:26 -06:00
|
|
|
|
foreach (var server in game.Servers.Where(s => s.Actions != null))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var action in server.Actions)
|
2024-01-18 19:36:20 -06:00
|
|
|
|
{
|
2024-03-10 19:51:42 -05:00
|
|
|
|
AutomaticPlayController automaticPlayController = null;
|
2024-02-06 01:43:40 -06:00
|
|
|
|
|
2024-03-10 19:51:42 -05:00
|
|
|
|
try
|
2024-02-16 01:23:26 -06:00
|
|
|
|
{
|
2024-03-10 19:51:42 -05:00
|
|
|
|
var serverHost = String.IsNullOrWhiteSpace(server.Host) ? new Uri(Settings.ServerAddress).Host : server.Host;
|
|
|
|
|
|
|
|
|
|
|
|
var variables = new Dictionary<string, string>()
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "ServerHost", serverHost },
|
|
|
|
|
|
{ "ServerPort", server.Port.ToString() }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-23 11:47:21 -05:00
|
|
|
|
if (!IPAddress.TryParse(serverHost, out var parsedAddress))
|
|
|
|
|
|
{
|
|
|
|
|
|
var serverIp = Dns.GetHostEntry(serverHost).AddressList.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (serverIp != null)
|
|
|
|
|
|
variables["ServerIP"] = serverIp.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
variables["ServerIP"] = serverHost;
|
|
|
|
|
|
}
|
2024-03-10 19:51:42 -05:00
|
|
|
|
|
|
|
|
|
|
automaticPlayController = new AutomaticPlayController(args.Game)
|
|
|
|
|
|
{
|
|
|
|
|
|
Arguments = LANCommanderClient.Actions.ExpandVariables(action.Arguments, args.Game.InstallDirectory, variables, true),
|
|
|
|
|
|
Name = action.Name,
|
|
|
|
|
|
Path = LANCommanderClient.Actions.ExpandVariables(action.Path, args.Game.InstallDirectory, variables),
|
|
|
|
|
|
TrackingMode = TrackingMode.Default,
|
|
|
|
|
|
Type = AutomaticPlayActionType.File,
|
|
|
|
|
|
WorkingDir = LANCommanderClient.Actions.ExpandVariables(action.WorkingDirectory, args.Game.InstallDirectory, variables)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
2024-02-16 01:23:26 -06:00
|
|
|
|
{
|
2024-03-10 19:51:42 -05:00
|
|
|
|
Logger?.Error(ex, "Could not yield server action");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (automaticPlayController != null)
|
|
|
|
|
|
yield return automaticPlayController;
|
2024-01-18 19:36:20 -06:00
|
|
|
|
}
|
2024-01-18 23:22:46 -06:00
|
|
|
|
}
|
2024-01-02 20:46:28 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
internal IEnumerable<GameManifest> GetGameManifests(Game game)
|
|
|
|
|
|
{
|
|
|
|
|
|
var manifests = new List<GameManifest>();
|
|
|
|
|
|
|
|
|
|
|
|
var mainManifest = ManifestHelper.Read(game.InstallDirectory, game.Id);
|
|
|
|
|
|
|
|
|
|
|
|
manifests.Add(mainManifest);
|
|
|
|
|
|
|
|
|
|
|
|
if (mainManifest.DependentGames != null)
|
|
|
|
|
|
foreach (var dependentGameId in mainManifest.DependentGames)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var dependentGameManifest = ManifestHelper.Read(game.InstallDirectory, dependentGameId);
|
|
|
|
|
|
|
|
|
|
|
|
if (dependentGameManifest.Type == SDK.Enums.GameType.Expansion || dependentGameManifest.Type == SDK.Enums.GameType.Mod)
|
|
|
|
|
|
manifests.Add(dependentGameManifest);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, $"Could not load manifest from dependent game {dependentGameId}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return manifests;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-15 04:56:56 -06:00
|
|
|
|
public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
|
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("Populating game menu items...");
|
|
|
|
|
|
|
2024-01-20 21:02:41 -06:00
|
|
|
|
yield return new GameMenuItem
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Description = ResourceProvider.GetString("LOCLANCommanderAddToDownloadQueue"),
|
2024-01-20 21:02:41 -06:00
|
|
|
|
Action = (args2) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var game in args2.Games)
|
2024-01-21 14:44:36 -06:00
|
|
|
|
DownloadQueue.Add(game);
|
2024-01-20 21:02:41 -06:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-01-15 04:56:56 -06:00
|
|
|
|
if (args.Games.Count == 1 && args.Games.First().IsInstalled && !String.IsNullOrWhiteSpace(args.Games.First().InstallDirectory))
|
|
|
|
|
|
{
|
2024-01-09 01:22:56 -06:00
|
|
|
|
var game = args.Games.First();
|
|
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
var nameChangeScriptPath = ScriptHelper.GetScriptFilePath(game.InstallDirectory, game.Id, SDK.Enums.ScriptType.NameChange);
|
|
|
|
|
|
var keyChangeScriptPath = ScriptHelper.GetScriptFilePath(game.InstallDirectory, game.Id, SDK.Enums.ScriptType.KeyChange);
|
|
|
|
|
|
var installScriptPath = ScriptHelper.GetScriptFilePath(game.InstallDirectory, game.Id, SDK.Enums.ScriptType.Install);
|
2023-01-15 04:56:56 -06:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(nameChangeScriptPath))
|
2023-08-21 18:44:20 -05:00
|
|
|
|
{
|
|
|
|
|
|
Logger.Trace($"Name change script found at path {nameChangeScriptPath}");
|
|
|
|
|
|
|
2023-01-15 04:56:56 -06:00
|
|
|
|
yield return new GameMenuItem
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Description = ResourceProvider.GetString("LOCLANCommanderChangeNameContextMenuItem"),
|
2023-01-15 04:56:56 -06:00
|
|
|
|
Action = (nameChangeArgs) =>
|
|
|
|
|
|
{
|
2024-01-27 11:10:33 -08:00
|
|
|
|
var oldName = Settings.DisplayName;
|
2023-03-17 02:08:04 -05:00
|
|
|
|
|
2024-02-18 17:24:45 -06:00
|
|
|
|
var result = PlayniteApi.Dialogs.SelectString(ResourceProvider.GetString("LOCLANCommanderChangePlayerNameDialogMessage"), ResourceProvider.GetString("LOCLANCommanderChangePlayerNameDialogCaption"), oldName);
|
2023-01-16 11:31:38 -06:00
|
|
|
|
|
|
|
|
|
|
if (result.Result == true)
|
2023-10-16 20:48:12 -05:00
|
|
|
|
{
|
2024-01-09 01:22:56 -06:00
|
|
|
|
var nameChangeGame = nameChangeArgs.Games.First();
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
RunNameChangeScript(nameChangeGame.InstallDirectory, game.Id, oldName, result.SelectedString);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
var alias = LANCommanderClient.Profile.ChangeAlias(result.SelectedString);
|
2024-01-15 20:39:04 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
Settings.DisplayName = alias;
|
2024-01-15 20:39:04 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
SavePluginSettings(Settings);
|
2023-10-16 20:48:12 -05:00
|
|
|
|
}
|
2023-01-15 04:56:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-08-21 18:44:20 -05:00
|
|
|
|
}
|
2023-01-15 04:56:56 -06:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(keyChangeScriptPath))
|
2023-08-21 18:44:20 -05:00
|
|
|
|
{
|
|
|
|
|
|
Logger.Trace($"Key change script found at path {keyChangeScriptPath}");
|
|
|
|
|
|
|
2023-01-15 04:56:56 -06:00
|
|
|
|
yield return new GameMenuItem
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Description = ResourceProvider.GetString("LOCLANCommanderChangeGameKeyContextMenuItem"),
|
2023-01-15 04:56:56 -06:00
|
|
|
|
Action = (keyChangeArgs) =>
|
|
|
|
|
|
{
|
2024-02-16 01:23:26 -06:00
|
|
|
|
// NUKIEEEE
|
|
|
|
|
|
var newKey = LANCommanderClient.Games.GetNewKey(keyChangeArgs.Games.First().Id);
|
2023-01-15 20:45:37 -06:00
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
if (String.IsNullOrEmpty(newKey))
|
2024-02-18 17:24:45 -06:00
|
|
|
|
PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString("LOCLANCommanderNoKeysAvailableMessage"), ResourceProvider.GetString("LOCLANCommanderNoKeysAvailableTitle"));
|
2023-01-15 20:45:37 -06:00
|
|
|
|
else
|
2024-02-16 01:23:26 -06:00
|
|
|
|
RunKeyChangeScript(keyChangeArgs.Games.First().InstallDirectory, keyChangeArgs.Games.First().Id, newKey);
|
2023-01-15 04:56:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-08-21 18:44:20 -05:00
|
|
|
|
}
|
2023-03-28 21:30:29 -05:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(installScriptPath))
|
2023-08-21 18:44:20 -05:00
|
|
|
|
{
|
|
|
|
|
|
Logger.Trace($"Install script found at path {installScriptPath}");
|
|
|
|
|
|
|
2023-03-28 21:30:29 -05:00
|
|
|
|
yield return new GameMenuItem
|
|
|
|
|
|
{
|
2024-02-18 17:53:40 -06:00
|
|
|
|
Description = ResourceProvider.GetString("LOCLANCommanderManageRunInstallScriptContextMenuItem"),
|
2023-03-28 21:30:29 -05:00
|
|
|
|
Action = (installArgs) =>
|
|
|
|
|
|
{
|
2024-02-16 01:23:26 -06:00
|
|
|
|
RunInstallScript(installArgs.Games.First().InstallDirectory, installArgs.Games.First().Id);
|
2023-03-28 21:30:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-08-21 18:44:20 -05:00
|
|
|
|
}
|
2024-02-17 17:30:14 -06:00
|
|
|
|
|
|
|
|
|
|
yield return new GameMenuItem
|
|
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Description = ResourceProvider.GetString("LOCLANCommanderManageSavesContextMenuItem"),
|
2024-02-17 17:30:14 -06:00
|
|
|
|
Action = (args2) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowSaveManagerWindow(game);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-01-15 04:56:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-28 23:10:18 -05:00
|
|
|
|
public override void OnGameStarting(OnGameStartingEventArgs args)
|
|
|
|
|
|
{
|
2024-01-19 00:25:38 -06:00
|
|
|
|
if (args.Game.PluginId == Id)
|
2023-11-17 02:28:46 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
var manifests = GetGameManifests(args.Game);
|
2024-02-03 18:32:42 -06:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
LANCommanderClient.Games.StartPlaySession(args.Game.Id);
|
2024-02-03 18:32:42 -06:00
|
|
|
|
|
|
|
|
|
|
if (!Settings.OfflineModeEnabled && LANCommanderClient.IsConnected())
|
2023-11-20 19:33:48 -06:00
|
|
|
|
{
|
2024-02-12 17:32:50 -06:00
|
|
|
|
// This would be better served by some metadata
|
2024-02-18 17:24:45 -06:00
|
|
|
|
if (args.Game.Name.EndsWith(ResourceProvider.GetString("LOCLANCommanderUpdateAvailableSuffix")))
|
2024-02-12 17:32:50 -06:00
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
var title = args.Game.Name.Replace(ResourceProvider.GetString("LOCLANCommanderUpdateAvailableSuffix"), "");
|
|
|
|
|
|
var updateMessage = ResourceProvider.GetString("LOCLANCommanderUpdateAvailableMessage").Replace("{Title}", title);
|
|
|
|
|
|
var result = PlayniteApi.Dialogs.ShowMessage(updateMessage, ResourceProvider.GetString("LOCLANCommanderUpdateAvailableCaption"), MessageBoxButton.YesNo);
|
2024-02-12 17:32:50 -06:00
|
|
|
|
|
|
|
|
|
|
if (result == MessageBoxResult.Yes)
|
|
|
|
|
|
{
|
|
|
|
|
|
args.CancelStartup = true;
|
|
|
|
|
|
|
|
|
|
|
|
PlayniteApi.InstallGame(args.Game.Id);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-07 01:47:00 -05:00
|
|
|
|
}
|
2024-02-12 17:32:50 -06:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
foreach (var manifest in manifests)
|
|
|
|
|
|
{
|
|
|
|
|
|
var currentGamePlayerAlias = GameService.GetPlayerAlias(args.Game.InstallDirectory, manifest.Id);
|
|
|
|
|
|
var currentGameKey = GameService.GetCurrentKey(args.Game.InstallDirectory, manifest.Id);
|
2024-01-19 00:25:38 -06:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
if (currentGamePlayerAlias != Settings.DisplayName)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nameChangeScriptPath = ScriptHelper.GetScriptFilePath(args.Game.InstallDirectory, manifest.Id, SDK.Enums.ScriptType.NameChange);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(nameChangeScriptPath))
|
|
|
|
|
|
RunNameChangeScript(args.Game.InstallDirectory, manifest.Id, currentGamePlayerAlias, Settings.DisplayName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Settings.OfflineModeEnabled && LANCommanderClient.IsConnected())
|
2024-01-19 00:25:38 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
var keyChangeScriptPath = ScriptHelper.GetScriptFilePath(args.Game.InstallDirectory, manifest.Id, SDK.Enums.ScriptType.KeyChange);
|
2024-02-06 19:36:55 -06:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
if (File.Exists(keyChangeScriptPath))
|
2024-02-06 19:36:55 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
var allocatedKey = LANCommanderClient.Games.GetAllocatedKey(manifest.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentGameKey != allocatedKey)
|
|
|
|
|
|
RunKeyChangeScript(args.Game.InstallDirectory, manifest.Id, allocatedKey);
|
2024-02-06 19:36:55 -06:00
|
|
|
|
}
|
2024-01-19 00:25:38 -06:00
|
|
|
|
}
|
2024-05-07 01:47:00 -05:00
|
|
|
|
|
|
|
|
|
|
// Download saves for main game + mods/expansions
|
|
|
|
|
|
if (!Settings.OfflineModeEnabled && LANCommanderClient.IsConnected())
|
2024-01-19 00:25:38 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var latestSave = LANCommanderClient.Saves.GetLatest(manifest.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if (latestSave == null || (latestSave.CreatedOn > args.Game.LastActivity && latestSave.CreatedOn > args.Game.Added))
|
|
|
|
|
|
{
|
|
|
|
|
|
SaveController = new LANCommanderSaveController(this, args.Game);
|
|
|
|
|
|
SaveController.Download(manifest.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, "Could not download save");
|
|
|
|
|
|
}
|
2024-01-19 00:25:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var beforeStartScriptPath = ScriptHelper.GetScriptFilePath(args.Game.InstallDirectory, manifest.Id, SDK.Enums.ScriptType.BeforeStart);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(beforeStartScriptPath))
|
|
|
|
|
|
RunBeforeStartScript(args.Game.InstallDirectory, manifest.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, "Ran into an unexpected error when attempting to run an Before Start script");
|
|
|
|
|
|
}
|
2024-03-13 17:16:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-28 23:10:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-28 21:30:29 -05:00
|
|
|
|
public override void OnGameStopped(OnGameStoppedEventArgs args)
|
|
|
|
|
|
{
|
2024-01-18 23:22:46 -06:00
|
|
|
|
if (args.Game.PluginId == Id && !Settings.OfflineModeEnabled)
|
2023-11-17 02:28:46 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
var manifests = GetGameManifests(args.Game);
|
|
|
|
|
|
|
2024-02-16 01:23:26 -06:00
|
|
|
|
LANCommanderClient.Games.EndPlaySession(args.Game.Id);
|
2023-11-20 19:33:48 -06:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
foreach (var manifest in manifests)
|
2023-11-20 19:33:48 -06:00
|
|
|
|
{
|
2024-05-07 01:47:00 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
SaveController = new LANCommanderSaveController(this, args.Game);
|
|
|
|
|
|
SaveController.Upload(manifest.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, "Could not upload save");
|
|
|
|
|
|
}
|
2024-03-13 17:16:24 -05:00
|
|
|
|
|
2024-05-07 01:47:00 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var afterStopScriptPath = ScriptHelper.GetScriptFilePath(args.Game.InstallDirectory, manifest.Id, SDK.Enums.ScriptType.AfterStop);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(afterStopScriptPath))
|
|
|
|
|
|
RunAfterStopScript(args.Game.InstallDirectory, args.Game.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error(ex, "Ran into an unexpected error when attempting to run an After Stop script");
|
|
|
|
|
|
}
|
2024-03-13 17:16:24 -05:00
|
|
|
|
}
|
2023-11-17 02:28:46 -06:00
|
|
|
|
}
|
2023-03-28 23:10:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-19 20:02:34 -06:00
|
|
|
|
public override IEnumerable<TopPanelItem> GetTopPanelItems()
|
|
|
|
|
|
{
|
2024-01-19 05:15:01 -06:00
|
|
|
|
yield return OfflineModeTopPanelItem;
|
2024-01-19 05:33:33 -06:00
|
|
|
|
yield return ProfileTopPanelItem;
|
2023-01-15 04:56:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-20 21:02:41 -06:00
|
|
|
|
public override IEnumerable<SidebarItem> GetSidebarItems()
|
|
|
|
|
|
{
|
2024-01-21 12:52:12 -06:00
|
|
|
|
DownloadQueueSidebarItem = new SidebarItem
|
2024-01-20 21:02:41 -06:00
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
Title = ResourceProvider.GetString("LOCLANCommanderDownloadQueueSidebarTitle"),
|
2024-01-20 21:02:41 -06:00
|
|
|
|
Icon = new TextBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = char.ConvertFromUtf32(0xef08),
|
|
|
|
|
|
FontFamily = ResourceProvider.GetResource("FontIcoFont") as FontFamily,
|
|
|
|
|
|
},
|
|
|
|
|
|
Type = SiderbarItemType.View,
|
|
|
|
|
|
Opened = () =>
|
|
|
|
|
|
{
|
2024-02-18 15:52:41 -06:00
|
|
|
|
var view = new Views.DownloadQueueView(this);
|
2024-01-20 21:02:41 -06:00
|
|
|
|
|
|
|
|
|
|
view.DataContext = DownloadQueue;
|
|
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2024-01-21 12:52:12 -06:00
|
|
|
|
|
|
|
|
|
|
yield return DownloadQueueSidebarItem;
|
2024-01-20 21:02:41 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-04 19:23:32 -06:00
|
|
|
|
public override ISettings GetSettings(bool firstRunSettings)
|
|
|
|
|
|
{
|
2023-01-05 01:07:17 -06:00
|
|
|
|
return Settings;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override UserControl GetSettingsView(bool firstRunView)
|
|
|
|
|
|
{
|
2024-02-18 15:50:25 -06:00
|
|
|
|
return new SettingsView(this);
|
2023-01-05 01:07:17 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-19 20:02:34 -06:00
|
|
|
|
public void ShowNameChangeWindow()
|
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("Showing name change dialog!");
|
|
|
|
|
|
|
2024-01-27 11:10:33 -08:00
|
|
|
|
var oldName = Settings.DisplayName;
|
2024-01-15 20:39:04 -06:00
|
|
|
|
|
2024-02-18 17:24:45 -06:00
|
|
|
|
var result = PlayniteApi.Dialogs.SelectString(ResourceProvider.GetString("LOCLANCommanderChangePlayerNameDialogMessage"), ResourceProvider.GetString("LOCLANCommanderChangePlayerNameDialogCaption"), oldName);
|
2023-01-19 20:02:34 -06:00
|
|
|
|
|
|
|
|
|
|
if (result.Result == true)
|
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace($"New name entered was \"{result.SelectedString}\"");
|
|
|
|
|
|
|
2023-01-19 20:02:34 -06:00
|
|
|
|
// Check to make sure they're staying in ASCII encoding
|
2023-01-20 00:21:51 -06:00
|
|
|
|
if (String.IsNullOrEmpty(result.SelectedString) || result.SelectedString.Any(c => c > sbyte.MaxValue))
|
2023-01-19 20:02:34 -06:00
|
|
|
|
{
|
2024-02-18 17:24:45 -06:00
|
|
|
|
PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString("LOCLANCommanderChangePlayerNameDialogInvalidMessage"));
|
2023-01-19 20:02:34 -06:00
|
|
|
|
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("An invalid name was specified. Showing the name dialog again...");
|
|
|
|
|
|
|
2023-01-19 20:02:34 -06:00
|
|
|
|
ShowNameChangeWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-01-27 11:10:33 -08:00
|
|
|
|
Settings.DisplayName = result.SelectedString;
|
2023-01-19 20:02:34 -06:00
|
|
|
|
|
2024-01-27 11:10:33 -08:00
|
|
|
|
Logger.Trace($"New player name of \"{Settings.DisplayName}\" has been set!");
|
2023-08-21 18:44:20 -05:00
|
|
|
|
|
|
|
|
|
|
Logger.Trace("Saving plugin settings!");
|
2023-01-19 20:02:34 -06:00
|
|
|
|
SavePluginSettings(Settings);
|
|
|
|
|
|
|
|
|
|
|
|
var games = PlayniteApi.Database.Games.Where(g => g.IsInstalled).ToList();
|
|
|
|
|
|
|
2024-01-02 02:34:58 -06:00
|
|
|
|
LANCommanderClient.Profile.ChangeAlias(result.SelectedString);
|
2023-01-19 20:02:34 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-08-21 18:44:20 -05:00
|
|
|
|
else
|
|
|
|
|
|
Logger.Trace("Name change was cancelled");
|
2023-01-19 20:02:34 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-20 17:35:11 -06:00
|
|
|
|
public Window ShowAuthenticationWindow(string serverAddress = null, EventHandler onClose = null)
|
2023-01-05 01:07:17 -06:00
|
|
|
|
{
|
2023-01-15 13:33:04 -06:00
|
|
|
|
Window window = null;
|
2024-01-02 21:41:52 -06:00
|
|
|
|
Application.Current.Dispatcher.Invoke((Action)delegate
|
2023-01-05 01:07:17 -06:00
|
|
|
|
{
|
2023-01-15 13:33:04 -06:00
|
|
|
|
window = PlayniteApi.Dialogs.CreateWindow(new WindowCreationOptions()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowMinimizeButton = false,
|
|
|
|
|
|
});
|
2023-01-05 01:07:17 -06:00
|
|
|
|
|
2024-02-18 17:24:45 -06:00
|
|
|
|
window.Title = ResourceProvider.GetString("LOCLANCommanderAuthenticationWindowTitle");
|
2024-02-13 23:24:42 -06:00
|
|
|
|
window.SizeToContent = SizeToContent.WidthAndHeight;
|
|
|
|
|
|
window.MinWidth = 400;
|
2024-02-18 15:52:08 -06:00
|
|
|
|
window.Content = new Views.AuthenticationView(this);
|
2024-02-18 15:54:39 -06:00
|
|
|
|
window.DataContext = new ViewModels.AuthenticationViewModel()
|
2023-01-15 13:33:04 -06:00
|
|
|
|
{
|
2023-10-28 13:56:54 -05:00
|
|
|
|
ServerAddress = serverAddress ?? Settings?.ServerAddress
|
2023-01-15 13:33:04 -06:00
|
|
|
|
};
|
2023-01-05 01:07:17 -06:00
|
|
|
|
|
2023-01-15 13:33:04 -06:00
|
|
|
|
window.Owner = PlayniteApi.Dialogs.GetCurrentAppWindow();
|
2023-03-14 02:31:42 -05:00
|
|
|
|
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
|
|
|
|
window.ResizeMode = ResizeMode.NoResize;
|
2023-11-20 17:35:11 -06:00
|
|
|
|
|
|
|
|
|
|
if (onClose != null)
|
|
|
|
|
|
window.Closed += onClose;
|
|
|
|
|
|
|
2023-01-15 13:33:04 -06:00
|
|
|
|
window.ShowDialog();
|
|
|
|
|
|
});
|
2023-01-06 02:39:00 -06:00
|
|
|
|
|
|
|
|
|
|
return window;
|
2023-01-04 19:23:32 -06:00
|
|
|
|
}
|
2023-01-07 12:34:12 -06:00
|
|
|
|
|
2024-02-17 17:30:14 -06:00
|
|
|
|
public Window ShowSaveManagerWindow(Game game)
|
|
|
|
|
|
{
|
|
|
|
|
|
Window window = null;
|
|
|
|
|
|
|
|
|
|
|
|
Application.Current.Dispatcher.Invoke((Action)delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
window = PlayniteApi.Dialogs.CreateWindow(new WindowCreationOptions()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowMinimizeButton = false,
|
|
|
|
|
|
ShowMaximizeButton = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-02-18 17:24:45 -06:00
|
|
|
|
window.Title = ResourceProvider.GetString("LOCLANCommanderSaveManagerWindowTitle") + $" - {game.Name}";
|
2024-02-17 17:30:14 -06:00
|
|
|
|
window.SizeToContent = SizeToContent.WidthAndHeight;
|
|
|
|
|
|
window.MinWidth = 300;
|
2024-02-18 15:51:02 -06:00
|
|
|
|
window.Content = new Views.SaveManagerView(this, game);
|
2024-02-17 17:30:14 -06:00
|
|
|
|
window.Owner = PlayniteApi.Dialogs.GetCurrentAppWindow();
|
|
|
|
|
|
window.ResizeMode = ResizeMode.CanResizeWithGrip;
|
|
|
|
|
|
|
|
|
|
|
|
window.ShowDialog();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-13 17:16:24 -05:00
|
|
|
|
private int RunBeforeStartScript(string installDirectory, Guid gameId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory, gameId);
|
|
|
|
|
|
var path = ScriptHelper.GetScriptFilePath(installDirectory, gameId, SDK.Enums.ScriptType.BeforeStart);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var script = new PowerShellScript();
|
|
|
|
|
|
|
|
|
|
|
|
script.AddVariable("InstallDirectory", installDirectory);
|
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory);
|
|
|
|
|
|
script.AddVariable("ServerAddress", Settings.ServerAddress);
|
|
|
|
|
|
script.AddVariable("PlayerAlias", Settings.DisplayName);
|
|
|
|
|
|
|
|
|
|
|
|
script.UseFile(path);
|
|
|
|
|
|
|
|
|
|
|
|
return script.Execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int RunAfterStopScript(string installDirectory, Guid gameId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory, gameId);
|
|
|
|
|
|
var path = ScriptHelper.GetScriptFilePath(installDirectory, gameId, SDK.Enums.ScriptType.AfterStop);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var script = new PowerShellScript();
|
|
|
|
|
|
|
|
|
|
|
|
script.AddVariable("InstallDirectory", installDirectory);
|
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory);
|
|
|
|
|
|
script.AddVariable("ServerAddress", Settings.ServerAddress);
|
|
|
|
|
|
script.AddVariable("PlayerAlias", Settings.DisplayName);
|
|
|
|
|
|
|
|
|
|
|
|
script.UseFile(path);
|
|
|
|
|
|
|
|
|
|
|
|
return script.Execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-09 01:22:56 -06:00
|
|
|
|
private int RunInstallScript(string installDirectory, Guid gameId)
|
2023-11-16 00:46:20 -06:00
|
|
|
|
{
|
2024-01-09 01:22:56 -06:00
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory, gameId);
|
|
|
|
|
|
var path = ScriptHelper.GetScriptFilePath(installDirectory, gameId, SDK.Enums.ScriptType.Install);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var script = new PowerShellScript();
|
|
|
|
|
|
|
|
|
|
|
|
script.AddVariable("InstallDirectory", installDirectory);
|
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory);
|
|
|
|
|
|
script.AddVariable("ServerAddress", Settings.ServerAddress);
|
|
|
|
|
|
|
|
|
|
|
|
script.UseFile(path);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
return script.Execute();
|
|
|
|
|
|
}
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
return 0;
|
2023-11-16 00:46:20 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-09 01:22:56 -06:00
|
|
|
|
private int RunNameChangeScript(string installDirectory, Guid gameId, string oldPlayerAlias, string newPlayerAlias)
|
2023-11-16 00:46:20 -06:00
|
|
|
|
{
|
2024-01-09 01:22:56 -06:00
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory, gameId);
|
|
|
|
|
|
var path = ScriptHelper.GetScriptFilePath(installDirectory, gameId, SDK.Enums.ScriptType.NameChange);
|
2023-11-16 14:06:40 -06:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var script = new PowerShellScript();
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
script.AddVariable("InstallDirectory", installDirectory);
|
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory);
|
|
|
|
|
|
script.AddVariable("ServerAddress", Settings.ServerAddress);
|
|
|
|
|
|
script.AddVariable("OldPlayerAlias", oldPlayerAlias);
|
|
|
|
|
|
script.AddVariable("NewPlayerAlias", newPlayerAlias);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
script.UseFile(path);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2024-01-19 00:25:38 -06:00
|
|
|
|
GameService.UpdatePlayerAlias(installDirectory, gameId, newPlayerAlias);
|
|
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
return script.Execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
2023-11-16 00:46:20 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-09 01:22:56 -06:00
|
|
|
|
private int RunKeyChangeScript(string installDirectory, Guid gameId, string key = "")
|
2023-11-16 00:46:20 -06:00
|
|
|
|
{
|
2024-01-09 01:22:56 -06:00
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory, gameId);
|
|
|
|
|
|
var path = ScriptHelper.GetScriptFilePath(installDirectory, gameId, SDK.Enums.ScriptType.KeyChange);
|
2023-11-16 14:06:40 -06:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var script = new PowerShellScript();
|
|
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(key))
|
2024-01-02 02:34:58 -06:00
|
|
|
|
key = LANCommanderClient.Games.GetAllocatedKey(manifest.Id);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
script.AddVariable("InstallDirectory", installDirectory);
|
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory);
|
|
|
|
|
|
script.AddVariable("ServerAddress", Settings.ServerAddress);
|
|
|
|
|
|
script.AddVariable("AllocatedKey", key);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
script.UseFile(path);
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2024-02-03 18:32:42 -06:00
|
|
|
|
GameService.UpdateCurrentKey(installDirectory, gameId, key);
|
|
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
return script.Execute();
|
|
|
|
|
|
}
|
2023-11-16 00:46:20 -06:00
|
|
|
|
|
2023-11-16 14:06:40 -06:00
|
|
|
|
return 0;
|
2023-11-16 00:46:20 -06:00
|
|
|
|
}
|
2024-01-14 23:48:52 -06:00
|
|
|
|
|
|
|
|
|
|
void Migrate()
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Old Manifest Locations
|
2024-01-20 21:02:41 -06:00
|
|
|
|
var installedGames = PlayniteApi.Database.Games.Where(g => g.IsInstalled && !String.IsNullOrWhiteSpace(g.InstallDirectory) && g.PluginId == Id).ToList();
|
2024-01-14 23:48:52 -06:00
|
|
|
|
|
|
|
|
|
|
foreach (var game in installedGames)
|
|
|
|
|
|
{
|
2024-02-16 01:23:26 -06:00
|
|
|
|
if (!Directory.Exists(GameService.GetMetadataDirectoryPath(game.InstallDirectory, game.Id)))
|
|
|
|
|
|
Directory.CreateDirectory(GameService.GetMetadataDirectoryPath(game.InstallDirectory, game.Id));
|
2024-01-14 23:48:52 -06:00
|
|
|
|
|
|
|
|
|
|
var metaFiles = new Dictionary<string, string>()
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "_manifest.yml", "Manifest.yml" },
|
|
|
|
|
|
{ "_install.ps1", "Install.ps1" },
|
|
|
|
|
|
{ "_uninstall.ps1", "Uninstall.ps1" },
|
|
|
|
|
|
{ "_changename.ps1", "ChangeName.ps1" },
|
|
|
|
|
|
{ "_changekey.ps1", "ChangeKey.ps1" },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-02-18 19:00:09 -06:00
|
|
|
|
// Move any old file names to the .lancommander metadata directory
|
2024-01-14 23:48:52 -06:00
|
|
|
|
foreach (var file in metaFiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
var originalPath = Path.Combine(game.InstallDirectory, file.Key);
|
2024-02-16 01:23:26 -06:00
|
|
|
|
var destinationPath = GameService.GetMetadataFilePath(game.InstallDirectory, game.Id, file.Value);
|
2024-01-14 23:48:52 -06:00
|
|
|
|
|
2024-01-22 01:50:30 -06:00
|
|
|
|
if (File.Exists(originalPath) && !File.Exists(destinationPath))
|
|
|
|
|
|
File.Move(originalPath, destinationPath);
|
2024-01-14 23:48:52 -06:00
|
|
|
|
}
|
2024-02-18 19:00:09 -06:00
|
|
|
|
|
|
|
|
|
|
// Change the ID of any game installed pre-0.6.0 to match the GameId
|
|
|
|
|
|
if (game.Id.ToString() != game.GameId)
|
|
|
|
|
|
{
|
2024-02-18 19:06:06 -06:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-02-22 17:19:45 -06:00
|
|
|
|
var originalId = game.Id;
|
|
|
|
|
|
|
2024-02-18 19:06:06 -06:00
|
|
|
|
game.Id = Guid.Parse(game.GameId);
|
2024-02-18 19:00:09 -06:00
|
|
|
|
|
2024-02-22 17:19:45 -06:00
|
|
|
|
PlayniteApi.Database.Games.Remove(originalId);
|
|
|
|
|
|
PlayniteApi.Database.Games.Add(game);
|
2024-02-18 19:06:06 -06:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.Error($"Could not migrate ID for game {game.Name}");
|
|
|
|
|
|
}
|
2024-02-18 19:00:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the current version of the game as recorded in the manifest
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(game.Version))
|
|
|
|
|
|
{
|
|
|
|
|
|
var manifest = ManifestHelper.Read(game.InstallDirectory, game.Id);
|
|
|
|
|
|
|
|
|
|
|
|
game.Version = manifest.Version;
|
|
|
|
|
|
|
|
|
|
|
|
PlayniteApi.Database.Games.Update(game);
|
|
|
|
|
|
}
|
2024-01-14 23:48:52 -06:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
2023-01-04 19:23:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|