Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit 2c50658

Browse files
committed
Force support for NugetInstallJob
1 parent 76ac249 commit 2c50658

8 files changed

Lines changed: 35 additions & 19 deletions

src/Commands/CommandOpenMod.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CommandOpenMod : IRocketCommand
1414
private static readonly List<IJob> s_Jobs = new List<IJob>();
1515
private static readonly List<CommandWindowInputted> s_RocketModComandWindowsDelegates = new List<CommandWindowInputted>();
1616
private static CommandStep s_CurrentStep;
17-
17+
private static string[] s_Args;
1818
public void Execute(IRocketPlayer caller, string[] command)
1919
{
2020
if (command.Length < 1)
@@ -37,6 +37,8 @@ public void Execute(IRocketPlayer caller, string[] command)
3737
}
3838

3939
Reset();
40+
41+
s_Args = command;
4042
Logger.Log("Starting OpenMod installation..", ConsoleColor.DarkCyan);
4143
Logger.Log("Visit https://openmod.github.io/openmod-docs for information.", ConsoleColor.DarkCyan);
4244
Logger.Log("Type \"cancel\" to cancel.", ConsoleColor.Cyan);
@@ -111,7 +113,7 @@ private void PerformMigration()
111113
{
112114
try
113115
{
114-
JobsExecutor.Execute(s_Jobs);
116+
JobsExecutor.Execute(s_Jobs, s_Args);
115117
}
116118
finally
117119
{
@@ -175,6 +177,7 @@ private void Reset()
175177
s_CurrentStep = null;
176178
s_Jobs.Clear();
177179
UnbindCommandInput();
180+
s_Args = null;
178181
}
179182

180183
// Some really shitty state machine

src/Jobs/IJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public interface IJob
44
{
5-
void ExecuteMigration();
5+
void ExecuteMigration(string[] args);
66
}
77
}

src/Jobs/JobsExecutor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace OpenMod.Installer.RocketMod.Jobs
66
{
77
public static class JobsExecutor
88
{
9-
public static bool Execute(List<IJob> jobsToExecute)
9+
public static bool Execute(List<IJob> jobsToExecute, string[] args)
1010
{
1111
var executedJobs = new List<IJob>();
1212

@@ -19,7 +19,7 @@ public static bool Execute(List<IJob> jobsToExecute)
1919
try
2020
{
2121
executedJobs.Add(job);
22-
job.ExecuteMigration();
22+
job.ExecuteMigration(args);
2323
}
2424
catch (Exception e)
2525
{

src/Jobs/MigrateEconomyJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace OpenMod.Installer.RocketMod.Jobs
44
{
55
public class MigrateEconomyJob : IJob
66
{
7-
public void ExecuteMigration()
7+
public void ExecuteMigration(string[] args)
88
{
99
Logger.Log("Adding economy migration job to autoexec.yaml...");
1010
//todo check if job exists

src/Jobs/MigratePermissionsJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace OpenMod.Installer.RocketMod.Jobs
1414
{
1515
public class MigratePermissionsJob : IReversibleJob
1616
{
17-
public void ExecuteMigration()
17+
public void ExecuteMigration(string[] args)
1818
{
1919
Logger.Log("Importing RocketMod permissions to OpenMod...");
2020

src/Jobs/NuGetInstallJob.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Rocket.Core.Logging;
44
using System;
55
using System.IO;
6+
using System.Linq;
67
using System.Threading.Tasks;
78

89
namespace OpenMod.Installer.RocketMod.Jobs
@@ -17,29 +18,35 @@ protected NuGetInstallJob(string packageId)
1718
m_PackageId = packageId;
1819
}
1920

20-
public void ExecuteMigration()
21+
public void ExecuteMigration(string[] args)
2122
{
22-
AsyncHelperEx.RunSync(DownloadPackage);
23+
AsyncHelperEx.RunSync(() => DownloadPackage(args.Contains("--force") || args.Contains("-f")));
2324
}
2425

25-
private async Task DownloadPackage()
26+
private async Task DownloadPackage(bool force)
2627
{
2728
Logger.Log($"Installing package \"{m_PackageId}\"...");
2829
var nuGetPackageManager = NuGetHelper.GetNuGetPackageManager();
2930

3031
const bool c_AllowPreReleaseVersion = false;
3132

3233
var oldIdentity = await nuGetPackageManager.GetLatestPackageIdentityAsync(m_PackageId);
33-
if (oldIdentity != null)
34+
if (!force && oldIdentity != null)
3435
{
35-
Logger.Log($"Package \"{m_PackageId}\" is already installed.");
36+
Logger.LogWarning($"Package \"{m_PackageId}\" is already installed, skipping. Use \"openmod install -f\" to install anyway.");
3637
return;
3738
}
3839

3940
var package = await nuGetPackageManager.QueryPackageExactAsync(m_PackageId, null, c_AllowPreReleaseVersion);
4041
if (package?.Identity == null)
4142
{
42-
Logger.Log($"Downloading has failed for {m_PackageId}: {NuGetInstallCode.PackageOrVersionNotFound}");
43+
Logger.LogError($"Downloading has failed for {m_PackageId}: {NuGetInstallCode.PackageOrVersionNotFound}");
44+
return;
45+
}
46+
47+
if (oldIdentity?.Version == package.Identity.Version && package.Identity.HasVersion)
48+
{
49+
Logger.LogError($"Latest version of {package.Identity.Id} is already installed.");
4350
return;
4451
}
4552

src/Jobs/OpenModAssemblyLoadJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class OpenModAssemblyLoadJob : IReversibleJob
1313
private static readonly Dictionary<string, Assembly> s_LoadedAssemblies = new Dictionary<string, Assembly>();
1414
private static readonly Regex s_VersionRegex = new Regex("Version=(?<version>.+?), ", RegexOptions.Compiled);
1515

16-
public void ExecuteMigration()
16+
public void ExecuteMigration(string[] args)
1717
{
1818
Logger.Log("Loading OpenMod assemblies. Ignore the message spam below.");
1919
var aviEvents = new List<AssemblyLoadEventHandler>();

src/Jobs/OpenModModuleInstallJob.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class OpenModModuleInstallJob : IReversibleJob
1212
{
1313
private bool m_OpenModInstalledAlready;
1414

15-
public void ExecuteMigration()
15+
public void ExecuteMigration(string[] args)
1616
{
1717
Logger.Log("Downloading and installing the OpenMod module.");
1818

@@ -66,13 +66,19 @@ public void ExtractArchive(byte[] archive, string directory)
6666
}
6767

6868
var path = Path.Combine(directory, Path.GetFileName(file.FilenameInZip));
69+
try
70+
{
71+
if (File.Exists(path))
72+
{
73+
File.Delete(path);
74+
}
6975

70-
if (File.Exists(path))
76+
zip.ExtractFile(file, path);
77+
}
78+
catch (Exception ex)
7179
{
72-
File.Delete(path);
80+
Logger.LogWarning($"Failed to extract {file.FilenameInZip}: {ex.Message}.");
7381
}
74-
75-
zip.ExtractFile(file, path);
7682
}
7783
}
7884

0 commit comments

Comments
 (0)