2023-11-10 00:29:16 -06:00
|
|
|
|
using LANCommander.SDK;
|
|
|
|
|
using LANCommander.SDK.Helpers;
|
2023-04-07 19:09:00 -05:00
|
|
|
|
using LANCommander.SDK.Models;
|
|
|
|
|
using Playnite.SDK;
|
|
|
|
|
using Playnite.SDK.Models;
|
|
|
|
|
using Playnite.SDK.Plugins;
|
2023-01-06 22:12:03 -06:00
|
|
|
|
using System;
|
|
|
|
|
|
2023-01-08 12:09:57 -06:00
|
|
|
|
namespace LANCommander.PlaynitePlugin
|
2023-01-06 22:12:03 -06:00
|
|
|
|
{
|
|
|
|
|
public class LANCommanderInstallController : InstallController
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
public static readonly ILogger Logger = LogManager.GetLogger();
|
|
|
|
|
|
2023-01-14 15:15:31 -06:00
|
|
|
|
private LANCommanderLibraryPlugin Plugin;
|
2023-01-06 22:12:03 -06:00
|
|
|
|
|
2023-01-15 04:29:47 -06:00
|
|
|
|
public LANCommanderInstallController(LANCommanderLibraryPlugin plugin, Playnite.SDK.Models.Game game) : base(game)
|
2023-01-06 22:12:03 -06:00
|
|
|
|
{
|
|
|
|
|
Name = "Install using LANCommander";
|
|
|
|
|
Plugin = plugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Install(InstallActionArgs args)
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("Game install triggered, checking connection...");
|
|
|
|
|
|
2023-03-17 02:07:25 -05:00
|
|
|
|
while (!Plugin.ValidateConnection())
|
|
|
|
|
{
|
2023-08-21 18:44:20 -05:00
|
|
|
|
Logger.Trace("User not authenticated. Opening auth window...");
|
|
|
|
|
|
2023-03-17 02:07:25 -05:00
|
|
|
|
Plugin.ShowAuthenticationWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 22:12:03 -06:00
|
|
|
|
var gameId = Guid.Parse(Game.GameId);
|
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
string installDirectory = null;
|
2023-08-21 18:44:20 -05:00
|
|
|
|
|
2023-09-16 15:13:55 -05:00
|
|
|
|
var result = Plugin.PlayniteApi.Dialogs.ActivateGlobalProgress(progress =>
|
2023-04-07 20:08:03 -05:00
|
|
|
|
{
|
2023-11-10 21:36:35 -06:00
|
|
|
|
var gameManager = new GameManager(Plugin.LANCommanderClient, Plugin.Settings.InstallDirectory);
|
2023-10-24 19:11:50 -05:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
gameManager.OnArchiveExtractionProgress += (long pos, long len) =>
|
2023-10-24 19:11:50 -05:00
|
|
|
|
{
|
2023-11-10 00:29:16 -06:00
|
|
|
|
progress.ProgressMaxValue = len;
|
|
|
|
|
progress.CurrentProgressValue = pos;
|
|
|
|
|
};
|
2023-10-24 19:11:50 -05:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
gameManager.OnArchiveEntryExtractionProgress += (object sender, ArchiveEntryExtractionProgressArgs e) =>
|
2023-10-24 19:11:50 -05:00
|
|
|
|
{
|
|
|
|
|
if (progress.CancelToken != null && progress.CancelToken.IsCancellationRequested)
|
|
|
|
|
{
|
2023-11-10 00:29:16 -06:00
|
|
|
|
e.Reader.Cancel();
|
|
|
|
|
e.Reader.Dispose();
|
|
|
|
|
e.Stream.Dispose();
|
2023-10-24 19:11:50 -05:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
progress.IsIndeterminate = true;
|
2023-10-24 19:11:50 -05:00
|
|
|
|
}
|
2023-11-10 00:29:16 -06:00
|
|
|
|
};
|
2023-10-24 19:11:50 -05:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
installDirectory = gameManager.Install(gameId);
|
2023-10-24 19:11:50 -05:00
|
|
|
|
},
|
2023-11-10 00:29:16 -06:00
|
|
|
|
new GlobalProgressOptions($"Downloading {Game.Name}...")
|
2023-10-24 19:11:50 -05:00
|
|
|
|
{
|
2023-11-10 00:29:16 -06:00
|
|
|
|
IsIndeterminate = true,
|
2023-10-24 19:11:50 -05:00
|
|
|
|
Cancelable = true,
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
if (!result.Canceled && result.Error == null && !String.IsNullOrWhiteSpace(installDirectory))
|
2023-10-24 19:11:50 -05:00
|
|
|
|
{
|
2023-11-10 00:29:16 -06:00
|
|
|
|
var manifest = ManifestHelper.Read(installDirectory);
|
2023-01-06 22:12:03 -06:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
Plugin.UpdateGame(manifest);
|
2023-01-06 22:12:03 -06:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
var installInfo = new GameInstallationData
|
2023-01-06 22:12:03 -06:00
|
|
|
|
{
|
2023-11-10 00:29:16 -06:00
|
|
|
|
InstallDirectory = installDirectory,
|
|
|
|
|
};
|
2023-01-06 22:12:03 -06:00
|
|
|
|
|
2023-11-10 00:29:16 -06:00
|
|
|
|
InvokeOnInstalled(new GameInstalledEventArgs(installInfo));
|
2023-01-06 22:12:03 -06:00
|
|
|
|
}
|
2023-01-15 04:29:47 -06:00
|
|
|
|
}
|
2023-01-06 22:12:03 -06:00
|
|
|
|
}
|
|
|
|
|
}
|