forked from SmartlyDressedGames/Legally-Distinct-Missile
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathModule.cs
More file actions
106 lines (95 loc) · 4.1 KB
/
Copy pathModule.cs
File metadata and controls
106 lines (95 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Rocket.AutoInstaller.Installation;
using SDG.Framework.Modules;
using SDG.Unturned;
using UnityEngine;
using UnityObject = UnityEngine.Object;
namespace Rocket.AutoInstaller
{
public class Config
{
public bool? EnableCustomInstall { get; set; }
public string? CustomInstallPath { get; set; }
public bool BlockIfRocketInstalled { get; set; }
public bool AutoInstallRocketFromExtras { get; set; }
public bool EnableRetry { get; set; }
public bool EnableCaching { get; set; }
}
/// <summary>
/// This is needed to run Coroutines.
/// </summary>
internal class CoroutineRunner : MonoBehaviour;
[UsedImplicitly]
public class Module : IModuleNexus
{
private const string DiscordSupportURL = "https://discord.gg/z6VM7taWeG";
public void initialize()
{
var assembly = typeof(Module).Assembly;
var assemblyName = assembly.GetName();
CommandWindow.Log($"Loading {assemblyName.Name} {assemblyName.Version}...");
CommandWindow.Log($"Discord Support: {DiscordSupportURL}");
var modulesDirectory = Path.Combine(ReadWrite.PATH, "Modules");
const string autoInstallerDll = "Rocket.AutoInstaller.dll";
var workingDirectory = Path.GetDirectoryName(Directory
.GetFiles(modulesDirectory, autoInstallerDll, SearchOption.AllDirectories)
.FirstOrDefault() ?? throw new Exception($"Failed to find Rocket.AutoInstaller file: \"{autoInstallerDll}\", in: \"{modulesDirectory}\""))!;
var configPath = Path.Combine(workingDirectory, "config.json");
Config config;
if (File.Exists(configPath))
{
config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(configPath))!;
}
else
{
config = new Config
{
EnableCustomInstall = false,
CustomInstallPath = null,
BlockIfRocketInstalled = true,
AutoInstallRocketFromExtras = false,
EnableRetry = true,
EnableCaching = true,
};
File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
}
if (config.BlockIfRocketInstalled)
{
const string rocketUnturnedDll = "Rocket.Unturned.dll";
var rocketFiles = Directory.GetFiles(modulesDirectory, rocketUnturnedDll, SearchOption.AllDirectories);
var rocketPath = rocketFiles.FirstOrDefault();
if (rocketPath != null)
{
var rocketDirectory = Path.GetDirectoryName(rocketPath);
if (string.Equals(rocketDirectory, workingDirectory, StringComparison.OrdinalIgnoreCase))
{
CommandWindow.Log("Ignoring self-directory to prevent blocking");
}
else
{
CommandWindow.Log($"Rocket already installed: {rocketDirectory}");
if (config.BlockIfRocketInstalled)
{
CommandWindow.Log(
"Installation via Rocket.AutoInstaller has been stopped because Rocket is already installed. " +
"To proceed, either delete Rocket.Unturned from the Modules directory or set `BlockIfRocketInstalled` to `false` in the configuration."
);
return;
}
}
}
}
var instance = new GameObject();
UnityObject.DontDestroyOnLoad(instance);
var coroutineRunner = instance.AddComponent<CoroutineRunner>();
coroutineRunner.StartCoroutine(Installer.Install(config));
}
public void shutdown()
{
}
}
}