2023-04-08 00:09:00 +00:00
|
|
|
|
using LANCommander.SDK.Enums;
|
2023-11-16 05:58:55 +00:00
|
|
|
|
using LANCommander.SDK.Helpers;
|
|
|
|
|
using LANCommander.SDK.PowerShell;
|
2023-08-21 23:44:20 +00:00
|
|
|
|
using Playnite.SDK;
|
2023-01-07 18:46:26 +00:00
|
|
|
|
using Playnite.SDK.Models;
|
|
|
|
|
using Playnite.SDK.Plugins;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2023-01-08 18:09:57 +00:00
|
|
|
|
namespace LANCommander.PlaynitePlugin
|
2023-01-07 18:46:26 +00:00
|
|
|
|
{
|
|
|
|
|
public class LANCommanderUninstallController : UninstallController
|
|
|
|
|
{
|
2023-08-21 23:44:20 +00:00
|
|
|
|
public static readonly ILogger Logger = LogManager.GetLogger();
|
|
|
|
|
|
2023-01-14 21:15:31 +00:00
|
|
|
|
private LANCommanderLibraryPlugin Plugin;
|
2023-01-07 18:46:26 +00:00
|
|
|
|
|
2023-01-14 21:15:31 +00:00
|
|
|
|
public LANCommanderUninstallController(LANCommanderLibraryPlugin plugin, Game game) : base(game)
|
2023-01-07 18:46:26 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "Uninstall LANCommander Game";
|
|
|
|
|
Plugin = plugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Uninstall(UninstallActionArgs args)
|
|
|
|
|
{
|
2023-01-15 07:19:03 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-11-11 03:36:35 +00:00
|
|
|
|
var gameManager = new LANCommander.SDK.GameManager(Plugin.LANCommanderClient, Plugin.Settings.InstallDirectory);
|
2023-08-21 23:44:20 +00:00
|
|
|
|
|
2023-11-16 05:58:55 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var scriptPath = ScriptHelper.GetScriptFilePath(Game.InstallDirectory, SDK.Enums.ScriptType.Uninstall);
|
|
|
|
|
|
2023-11-16 20:06:40 +00:00
|
|
|
|
if (!String.IsNullOrEmpty(scriptPath) && File.Exists(scriptPath))
|
2023-11-16 05:58:55 +00:00
|
|
|
|
{
|
|
|
|
|
var manifest = ManifestHelper.Read(Game.InstallDirectory);
|
|
|
|
|
var script = new PowerShellScript();
|
|
|
|
|
|
|
|
|
|
script.AddVariable("InstallDirectory", Game.InstallDirectory);
|
|
|
|
|
script.AddVariable("GameManifest", manifest);
|
|
|
|
|
script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory);
|
|
|
|
|
script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress);
|
|
|
|
|
|
|
|
|
|
script.UseFile(scriptPath);
|
|
|
|
|
|
|
|
|
|
script.Execute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "There was an error running the uninstall script");
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 06:29:16 +00:00
|
|
|
|
gameManager.Uninstall(Game.InstallDirectory);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-11-16 05:58:55 +00:00
|
|
|
|
Logger.Error(ex, "There was an error uninstalling the game");
|
2023-11-10 06:29:16 +00:00
|
|
|
|
}
|
2023-08-21 23:44:20 +00:00
|
|
|
|
|
2023-01-07 18:46:26 +00:00
|
|
|
|
InvokeOnUninstalled(new GameUninstalledEventArgs());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|