Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions Commands/PluginManager/PluginManagerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ internal override async void Execute(string[] arguments)
{
ConsoleUtil.WriteLine(string.Empty);
ConsoleUtil.WriteLine("---- Plugin Manager Commands ----", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("p check [-igl] - checks for plugins updates.");
ConsoleUtil.WriteLine("p install [-igos] <plugin name> [version] - downloads and installs a plugin.");
ConsoleUtil.WriteLine("p list [-igls] - lists all installed plugins.");
ConsoleUtil.WriteLine("p maintenance [-igl] - runs a plugins maintenance.");
ConsoleUtil.WriteLine("p check [-i] - checks for plugins updates.");
ConsoleUtil.WriteLine("p install [-ios] <plugin name> [version] - downloads and installs a plugin.");
ConsoleUtil.WriteLine("p list [-is] - lists all installed plugins.");
ConsoleUtil.WriteLine("p maintenance [-i] - runs a plugins maintenance.");
ConsoleUtil.WriteLine("p paths [-pd] [path] - manages paths used for plugins and dependencies.");
ConsoleUtil.WriteLine("p refresh - refreshes list of plugin aliases.");
ConsoleUtil.WriteLine("p remove [-igs] <plugin name> - uninstalls a plugin.");
ConsoleUtil.WriteLine("p remove [-is] <plugin name> - uninstalls a plugin.");
ConsoleUtil.WriteLine("p token [GitHub PAT] - sets, clears or provides more info about GitHub Personal Authentication Token.");
ConsoleUtil.WriteLine("p update [-iglos] - updates all installed plugins.");
ConsoleUtil.WriteLine("p update [-ios] - updates all installed plugins.");
ConsoleUtil.WriteLine(string.Empty, ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("<required argument>, [optional argument] -g = global (all ports), -l = local (current port), -o = overwrite", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("<required argument>, [optional argument] -o = overwrite", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("-i = ignore locks (don't use unless you know what you are doing)", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("-s = skip checking for updates and refreshing list (don't use unless you know what you are doing)", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("-p = change used plugins path", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("-d = change used dependencies path", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("plugin name = GitHub repository author and name, eg. author-name/repo-name", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("If no version is specified then latest non-preview release is used.", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("If version is specified the plugin will be exempted from \"update\" command.", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("If both -g and -l arguments exist then by default (if unset) BOTH are used.", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("Use the same formatting for paths as in your LabAPI configuration.", ConsoleColor.DarkGray);

if (string.IsNullOrEmpty(Core.LocalAdmin.DataJson!.GitHubPersonalAccessToken))
{
Expand Down Expand Up @@ -109,6 +112,10 @@ internal override async void Execute(string[] arguments)
case "i" when args == null || args.Length is 0 or > 2 || string.IsNullOrEmpty(args[0]) || args[0].Count(x => x == '/') > 1:
case "install" when args == null || args.Length is 0 or > 2 || string.IsNullOrEmpty(args[0]) || args[0].Count(x => x == '/') > 1:

//Paths
case "paths" when args != null && args.Length > 1:
case "pth" when args != null && args.Length > 1:

//Remove
case "remove" when args is not { Length: 1 } || string.IsNullOrEmpty(args[0]) || args[0].Count(x => x == '/') > 1:
case "r" when args is not { Length: 1 } || string.IsNullOrEmpty(args[0]) || args[0].Count(x => x == '/') > 1:
Expand Down Expand Up @@ -141,6 +148,11 @@ internal override async void Execute(string[] arguments)
MaintenanceCommand.Maintenance(options);
break;

case "paths":
case "pth":
PathsCommand.ManagePaths(args, options);
break;

case "refresh":
case "ref":
case "rf":
Expand All @@ -153,7 +165,6 @@ internal override async void Execute(string[] arguments)
case "uninstall":
case "un":
_ = PluginInstaller.TryUninstallPlugin(args[0],
options.Contains('g', StringComparison.Ordinal) ? "global" : Core.LocalAdmin.GamePort.ToString(),
options.Contains('i', StringComparison.Ordinal),
options.Contains('s', StringComparison.Ordinal));
break;
Expand Down
28 changes: 1 addition & 27 deletions Commands/PluginManager/Subcommands/CheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,7 @@ internal static class CheckCommand
{
internal static async void Check(string options)
{
bool iSet = options.Contains('i', StringComparison.Ordinal),
gSet = options.Contains('g', StringComparison.Ordinal),
lSet = options.Contains('l', StringComparison.Ordinal);

bool local = false, global = false;

switch (gSet)
{
case false when !lSet:
case true when lSet:
local = global = true;
break;

case true:
global = true;
break;

default:
local = true;
break;
}

if (local)
await PluginUpdater.CheckForUpdates(Core.LocalAdmin.GamePort.ToString(), iSet);

if (global)
await PluginUpdater.CheckForUpdates("global", iSet);
await PluginUpdater.CheckForUpdates(options.Contains('i', StringComparison.Ordinal));

ConsoleUtil.WriteLine("[PLUGIN MANAGER] Checking for plugins update complete.", ConsoleColor.DarkGreen);
}
Expand Down
3 changes: 1 addition & 2 deletions Commands/PluginManager/Subcommands/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ internal static async void Install(string[] args, string options)
version = args[1];
}

await PluginInstaller.TryInstallPlugin(args[0], res.Result, version,
options.Contains('g', StringComparison.Ordinal) ? "global" : Core.LocalAdmin.GamePort.ToString(),
await PluginInstaller.TryInstallPlugin(args[0], res.Result, version, PluginPaths.PluginsFolder, PluginPaths.DependenciesFolder,
options.Contains('o', StringComparison.Ordinal),
options.Contains('i', StringComparison.Ordinal));
}
Expand Down
36 changes: 2 additions & 34 deletions Commands/PluginManager/Subcommands/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,11 @@ internal static class ListCommand
internal static async void List(string options)
{
bool iSet = options.Contains('i', StringComparison.Ordinal),
gSet = options.Contains('g', StringComparison.Ordinal),
lSet = options.Contains('l', StringComparison.Ordinal),
sSet = options.Contains('s', StringComparison.Ordinal);

bool local = false, global = false;

switch (gSet)
{
case false when !lSet:
case true when lSet:
local = global = true;
break;

case true:
global = true;
break;

default:
local = true;
break;
}

List<PluginStorage.PluginListEntry>? localPlugins = null, globalPlugins = null;

if (local)
localPlugins = await PluginStorage.ListPlugins(Core.LocalAdmin.GamePort.ToString(), iSet, sSet);

if (global)
globalPlugins = await PluginStorage.ListPlugins("global", iSet, sSet);

List<PluginStorage.PluginListEntry>? plugins = await PluginStorage.ListPlugins(iSet, sSet);
ConsoleUtil.WriteLine(null, ConsoleColor.Gray);

if (local)
PrintPlugins(Core.LocalAdmin.GamePort.ToString(), localPlugins);

if (global)
PrintPlugins("global", globalPlugins);
PrintPlugins(Core.LocalAdmin.GamePort.ToString(), plugins);
}

private static void PrintPlugins(string port, List<PluginStorage.PluginListEntry>? plugins)
Expand Down
28 changes: 1 addition & 27 deletions Commands/PluginManager/Subcommands/MaintenanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,7 @@ internal static class MaintenanceCommand
{
internal static async void Maintenance(string options)
{
bool iSet = options.Contains('i', StringComparison.Ordinal),
gSet = options.Contains('g', StringComparison.Ordinal),
lSet = options.Contains('l', StringComparison.Ordinal);

bool local = false, global = false;

switch (gSet)
{
case false when !lSet:
case true when lSet:
local = global = true;
break;

case true:
global = true;
break;

default:
local = true;
break;
}

if (local)
await PluginInstaller.PluginsMaintenance(Core.LocalAdmin.GamePort.ToString(), iSet);

if (global)
await PluginInstaller.PluginsMaintenance("global", iSet);
await PluginInstaller.PluginsMaintenance(options.Contains('i', StringComparison.Ordinal));

ConsoleUtil.WriteLine("[PLUGIN MANAGER] Plugins maintenance complete.", ConsoleColor.DarkGreen);
}
Expand Down
38 changes: 38 additions & 0 deletions Commands/PluginManager/Subcommands/PathsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using LocalAdmin.V2.IO;
using LocalAdmin.V2.PluginsManager;

namespace LocalAdmin.V2.Commands.PluginManager.Subcommands;

internal static class PathsCommand
{
internal static void ManagePaths(string[]? args, string options)
{
if (args is not null && args.Length > 0 && !string.IsNullOrEmpty(args[0]))
{
if (options.Contains('p', StringComparison.Ordinal))
{
var success = PluginPaths.SetPluginsFolder(args[0]);

if (!success)
{
ConsoleUtil.WriteLine("[PLUGIN MANAGER] Failed to change plugins path. Check your LabAPI configuration.", ConsoleColor.Yellow);
}
}

if (options.Contains('d', StringComparison.Ordinal))
{
var success = PluginPaths.SetDependenciesFolder(args[0]);

if (!success)
{
ConsoleUtil.WriteLine("[PLUGIN MANAGER] Failed to change dependencies path. Check your LabAPI configuration.", ConsoleColor.Yellow);
}
}
}

ConsoleUtil.WriteLine("[PLUGIN MANAGER] Current paths configuration used for plugins installation:", ConsoleColor.Green);
ConsoleUtil.WriteLine($"[PLUGIN MANAGER] Plugins path: {PluginPaths.PluginsFolder}", ConsoleColor.Green);
ConsoleUtil.WriteLine($"[PLUGIN MANAGER] Dependencies path: {PluginPaths.DependenciesFolder}", ConsoleColor.Green);
}
}
26 changes: 1 addition & 25 deletions Commands/PluginManager/Subcommands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,10 @@ internal static class UpdateCommand
internal static async void Update(string options)
{
bool iSet = options.Contains('i', StringComparison.Ordinal),
gSet = options.Contains('g', StringComparison.Ordinal),
lSet = options.Contains('l', StringComparison.Ordinal),
oSet = options.Contains('o', StringComparison.Ordinal),
sSet = options.Contains('s', StringComparison.Ordinal);

bool local = false, global = false;

switch (gSet)
{
case false when !lSet:
case true when lSet:
local = global = true;
break;

case true:
global = true;
break;

default:
local = true;
break;
}

if (local)
await PluginUpdater.UpdatePlugins(Core.LocalAdmin.GamePort.ToString(), iSet, oSet, sSet);

if (global)
await PluginUpdater.UpdatePlugins("global", iSet, oSet, sSet);
await PluginUpdater.UpdatePlugins(iSet, oSet, sSet);

ConsoleUtil.WriteLine("[PLUGIN MANAGER] Updating plugins update complete.", ConsoleColor.DarkGreen);
}
Expand Down
1 change: 1 addition & 0 deletions Core/LocalAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ private void RunScpsl()
};

_gameProcess!.EnableRaisingEvents = true;
PluginPaths.LoadLabApiConfig();
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions IO/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ internal static class PathManager
internal static readonly string GameUserDataRoot;
internal static readonly string ConfigPath;
internal static readonly string InternalJsonDataPath;
internal static readonly string LabApiRoot;
internal static readonly string PluginsPath;
internal static readonly string DependenciesPath;

internal static bool CorrectPathFound { get; private set; }

Expand All @@ -25,6 +28,12 @@ static PathManager()
ConfigPath = $"{GameUserDataRoot}config{Path.DirectorySeparatorChar}";

InternalJsonDataPath = ConfigPath + "localadmin_internal_data.json";

LabApiRoot = $"{GameUserDataRoot}LabAPI{Path.DirectorySeparatorChar}";

PluginsPath = $"{LabApiRoot}plugins{Path.DirectorySeparatorChar}";

DependenciesPath = $"{LabApiRoot}dependencies{Path.DirectorySeparatorChar}";
}

private static string GetSpecialFolderPath()
Expand Down
Loading
Loading