Skip to content

Commit

Permalink
Implement CLI options for a non-interactive installation
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed May 27, 2021
1 parent f067545 commit e955b7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
55 changes: 45 additions & 10 deletions Install/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,66 @@
using System.IO;

public static class Install {
private static void Main() {
private static void Main(string[] arguments) {
Console.Title = "UnrealCLR Installation Tool";

using StreamReader consoleReader = new StreamReader(Console.OpenStandardInput(8192), Console.InputEncoding, false, bufferSize: 1024);
using StreamReader consoleReader = new(Console.OpenStandardInput(8192), Console.InputEncoding, false, bufferSize: 1024);

Console.SetIn(consoleReader);

Console.WriteLine("Welcome to UnrealCLR installation tool!");
Console.Write(Environment.NewLine + "Please, set a path to an Unreal Engine project: ");
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 projectPath = @"" + Console.ReadLine().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!");
Console.Write(Environment.NewLine + "Do you want to compile and install the tests? [y/n] ");

bool compileTests = false;

if (Console.ReadKey(false).Key == ConsoleKey.Y)
compileTests = true;
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] ");

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 (Console.ReadKey(false).Key == ConsoleKey.Y) {
if (overwriteFiles) {
string nativeSource = sourcePath + "/Source/Native";

Console.WriteLine(Environment.NewLine + "Removing the previous plugin installation...");
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Create a new or use an existing Unreal Engine C++ or blueprints project. Clone t
#### Upgrading
Make sure that the Unreal Engine is not running. Re-run the installation process. Recompile custom code with an updated framework.

#### Command-line options
`--project-path <path>` Sets a path to the Unreal Engine project

`--compile-tests <true/false>` Indicates whether tests should be compiled

`--overwrite-files` Indicates whether all previous files of the plugin and content of tests should be overwritten

### Manual

#### Compilation
Expand Down

0 comments on commit e955b7c

Please sign in to comment.