forked from nxrighthere/UnrealCLR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.cs
163 lines (118 loc) · 6.37 KB
/
Install.cs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Diagnostics;
using System.IO;
public static class Install {
private static void Main(string[] arguments) {
Console.Title = "UnrealCLR Installation Tool";
using StreamReader consoleReader = new(Console.OpenStandardInput(8192), Console.InputEncoding, false, bufferSize: 1024);
Console.SetIn(consoleReader);
string projectPath = null;
bool? compileTestsOption = null;
bool? overwriteFilesOption = null;
for (int i = 0; i < arguments.Length; i++) {
if (arguments[i].Contains("--project-path", StringComparison.Ordinal))
projectPath = arguments[i + 1];
if (arguments[i].Contains("--compile-tests", StringComparison.Ordinal))
compileTestsOption = bool.Parse(arguments[i + 1]);
if (arguments[i].Contains("--overwrite-files", StringComparison.Ordinal))
overwriteFilesOption = true;
}
Console.WriteLine("Welcome to the UnrealCLR installation tool!");
if (String.IsNullOrEmpty(projectPath)) {
Console.Write(Environment.NewLine + "Please, set a path to an Unreal Engine project: ");
projectPath = @"" + Console.ReadLine();
}
projectPath = projectPath.Replace("\"", String.Empty, StringComparison.Ordinal).Replace("\'", String.Empty, StringComparison.Ordinal).TrimEnd(Path.DirectorySeparatorChar);
string sourcePath = Directory.GetCurrentDirectory() + "/..";
if (Directory.GetFiles(projectPath, "*.uproject", SearchOption.TopDirectoryOnly).Length != 0) {
Console.WriteLine($"Project file found in \"{ projectPath }\" folder!");
bool compileTests = false;
if (compileTestsOption != null) {
compileTests = compileTestsOption.GetValueOrDefault();
} else {
Console.Write(Environment.NewLine + "Do you want to compile and install tests? [y/n] ");
if (Console.ReadKey(false).Key == ConsoleKey.Y)
compileTests = true;
}
bool overwriteFiles = false;
if (overwriteFilesOption != null) {
overwriteFiles = overwriteFilesOption.GetValueOrDefault();
} else {
Console.Write(Environment.NewLine + "Installation will delete all previous files of the plugin" + (compileTests ? " and content of tests" : String.Empty) + ". Do you want to continue? [y/n] ");
if (Console.ReadKey(false).Key == ConsoleKey.Y)
overwriteFiles = true;
}
if (overwriteFiles) {
string nativeSource = sourcePath + "/Source/Native";
Console.WriteLine(Environment.NewLine + "Removing the previous plugin installation...");
if (Directory.Exists(projectPath + "/Plugins/UnrealCLR"))
Directory.Delete(projectPath + "/Plugins/UnrealCLR", true);
Console.WriteLine("Copying native source code and the runtime host of the plugin...");
foreach (string directoriesPath in Directory.GetDirectories(nativeSource, "*", SearchOption.AllDirectories)) {
Directory.CreateDirectory(directoriesPath.Replace(nativeSource, projectPath + "/Plugins/UnrealCLR", StringComparison.Ordinal));
}
foreach (string filesPath in Directory.GetFiles(nativeSource, "*.*", SearchOption.AllDirectories)) {
File.Copy(filesPath, filesPath.Replace(nativeSource, projectPath + "/Plugins/UnrealCLR", StringComparison.Ordinal), true);
}
Console.WriteLine("Launching compilation of the managed runtime...");
var runtimeCompilation = Process.Start(new ProcessStartInfo {
FileName = "dotnet",
Arguments = $"publish \"{ sourcePath }/Source/Managed/Runtime\" --configuration Release --framework net5.0 --output \"{ projectPath }/Plugins/UnrealCLR/Managed\"",
CreateNoWindow = false,
UseShellExecute = false
});
runtimeCompilation.WaitForExit();
if (runtimeCompilation.ExitCode != 0)
Error("Compilation of the runtime was finished with an error (Exit code: " + runtimeCompilation.ExitCode + ")!");
Console.WriteLine("Launching compilation of the framework...");
var frameworkCompilation = Process.Start(new ProcessStartInfo {
FileName = "dotnet",
Arguments = $"publish \"{ sourcePath }/Source/Managed/Framework\" --configuration Release --framework net5.0 --output \"{ sourcePath }/Source/Managed/Framework/bin/Release\"",
CreateNoWindow = false,
UseShellExecute = false
});
frameworkCompilation.WaitForExit();
if (frameworkCompilation.ExitCode != 0)
Error("Compilation of the framework was finished with an error (Exit code: " + frameworkCompilation.ExitCode + ")!");
if (compileTests) {
string contentPath = sourcePath + "/Content";
Console.WriteLine("Removing the previous content of the tests...");
if (Directory.Exists(projectPath + "/Content/Tests"))
Directory.Delete(projectPath + "/Content/Tests", true);
Console.WriteLine("Copying the content of the tests...");
foreach (string directoriesPath in Directory.GetDirectories(contentPath, "*", SearchOption.AllDirectories)) {
Directory.CreateDirectory(directoriesPath.Replace(contentPath, projectPath + "/Content", StringComparison.Ordinal));
}
foreach (string filesPath in Directory.GetFiles(contentPath, "*.*", SearchOption.AllDirectories)) {
File.Copy(filesPath, filesPath.Replace(contentPath, projectPath + "/Content", StringComparison.Ordinal), true);
}
Console.WriteLine("Launching compilation of the tests...");
var testsCompilation = Process.Start(new ProcessStartInfo {
FileName = "dotnet",
Arguments = $"publish \"{ sourcePath }/Source/Managed/Tests\" --configuration Release --framework net5.0 --output \"{ projectPath }/Managed/Tests\"",
CreateNoWindow = false,
UseShellExecute = false
});
testsCompilation.WaitForExit();
if (testsCompilation.ExitCode != 0)
Error("Compilation of the tests was finished with an error (Exit code: " + testsCompilation.ExitCode + ")!");
}
Console.Write("Done!");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(" Please, don't forget to recompile custom code with an updated framework!");
Console.ResetColor();
Environment.Exit(0);
} else {
Console.WriteLine(Environment.NewLine + "Installation canceled");
}
} else {
Error($"Project file not found in \"{ projectPath }\" folder!");
}
}
private static void Error(string message) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
Environment.Exit(-1);
}
}