Make CLI be able to use non-interactive mode

pull/5/head
Miepee 4 years ago
parent 9ad9935fff
commit 4de05e2d61

@ -7,38 +7,64 @@ namespace AM2RPortHelper;
internal static class Program internal static class Program
{ {
private const string version = "1.3";
//TODO: add "-l" flag. transfer launcher mods to each other. //TODO: add "-l" flag. transfer launcher mods to each other.
private static int Main(string[] args) private static int Main(string[] args)
{ {
Console.WriteLine("AM2RPortHelperCLI v" + version); Console.WriteLine("AM2RPortHelperCLI v" + PortHelper.Version);
//TODO! //TODO!
var interactiveOption = new Option<bool>(new[] {"-i", "--interactive"}, "Use an interactive mode"); var interactiveOption = new Option<bool>(new[] { "-i", "--interactive" }, "Use an interactive mode. This will ignore all other options.");
var fileOption = new Option<FileInfo>(new[] { "-f", "--file" }, "The file path to the raw mod that should be ported. *REQUIRED*");
var linuxOption = new Option<FileInfo>(new[] { "-l", "--linux" }, "The output file path for the Linux mod. None given equals to no Linux port.");
var androidOption = new Option<FileInfo>(new[] { "-a", "--android" }, "The output file path for the Android mod. None given equals to no Android port.");
var macOption = new Option<FileInfo>(new[] { "-m", "--mac" }, "The output file path for the Mac mod. None given equals to no Mac port.");
var nameOption = new Option<string>(new[] { "-n", "--name" }, "The name used for the Mac mod. Required for the Mac option, has no effect on anything else.");
RootCommand rootCommand = new RootCommand(); RootCommand rootCommand = new RootCommand();
rootCommand.AddOption(interactiveOption); rootCommand.AddOption(interactiveOption);
rootCommand.SetHandler(RootMethod, interactiveOption); rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption, macOption, nameOption);
return rootCommand.Invoke(args); return rootCommand.Invoke(args);
/* /*
TODO: show this somewhere? maybe?
Console.WriteLine("\n**Make sure to replace the icon.png and splash.png with custom ones if you don't want to have placeholders**\n"); Console.WriteLine("\n**Make sure to replace the icon.png and splash.png with custom ones if you don't want to have placeholders**\n");
Console.WriteLine("THIS ONLY WORKS FOR MODS BASED ON THE COMMUNITY UPDATES! MODS BASED ON 1.1 WILL NOT WORK!"); Console.WriteLine("THIS ONLY WORKS FOR MODS BASED ON THE COMMUNITY UPDATES! MODS BASED ON 1.1 WILL NOT WORK!");
Console.WriteLine("To which platform do you want to port to?\n1 - Linux\n2 - Android\n3 - MacOS");
*/ */
} }
private static void RootMethod(bool interactive) private static void RootMethod(bool interactive, FileInfo inputModPath, FileInfo linuxPath, FileInfo androidPath, FileInfo macPath, string modName)
{ {
if (interactive) if (interactive)
{ {
RunInteractive(); RunInteractive();
return; return;
} }
var x = 0; if (!IsValidInputZip(inputModPath))
{
Console.Error.WriteLine("Input path does not exist, or does not point to a zip file!");
return;
}
if (linuxPath is not null)
{
PortHelper.PortWindowsToLinux(inputModPath.FullName, linuxPath.FullName);
}
if (androidPath is not null)
{
PortHelper.PortWindowsToAndroid(inputModPath.FullName, androidPath.FullName);
}
if (macPath is not null)
{
if (modName is null)
{
Console.Error.WriteLine("Mac option was chosen but mod name was not given!");
return;
}
PortHelper.PortWindowsToMac(inputModPath.FullName, macPath.FullName, modName);
}
Console.WriteLine("Done");
} }
private static void RunInteractive() private static void RunInteractive()
{ {
@ -50,7 +76,7 @@ internal static class Program
Console.WriteLine("Please provide the full path to the raw mod zip!"); Console.WriteLine("Please provide the full path to the raw mod zip!");
modZipPath = Console.ReadLine(); modZipPath = Console.ReadLine();
if (modZipPath == null || (!File.Exists(modZipPath) && Path.GetExtension(modZipPath).ToLower() != ".zip")) if (IsValidInputZip(modZipPath))
Console.WriteLine("Path does not exist, or does not point to a zip file!"); Console.WriteLine("Path does not exist, or does not point to a zip file!");
else else
invalidZip = false; invalidZip = false;
@ -88,6 +114,7 @@ internal static class Program
} }
} while (invalidOS); } while (invalidOS);
// Port everything
string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
string linuxPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_LINUX.zip"; string linuxPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_LINUX.zip";
string androidPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_ANDROID.apk"; string androidPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_ANDROID.apk";
@ -113,4 +140,14 @@ internal static class Program
Console.WriteLine("Successfully finished!"); Console.WriteLine("Successfully finished!");
} }
private static bool IsValidInputZip(string path)
{
return path == null || (!File.Exists(path) && Path.GetExtension(path).ToLower() != ".zip");
}
private static bool IsValidInputZip(FileInfo path)
{
return path is not null && IsValidInputZip(path.FullName);
}
} }

@ -13,7 +13,7 @@ public partial class MainForm : Form
{ {
public MainForm() public MainForm()
{ {
Title = "AM2RPortHelper"; Title = $"AM2RPortHelper - v{PortHelper.Version}";
MinimumSize = new Size(200, 200); MinimumSize = new Size(200, 200);

@ -7,7 +7,8 @@ using SixLabors.ImageSharp.Processing;
namespace AM2RPortHelperLib; namespace AM2RPortHelperLib;
public static class PortHelper public static class PortHelper
{ {
public const string Version = "1.3";
public delegate void OutputHandlerDelegate(string output); public delegate void OutputHandlerDelegate(string output);
private static OutputHandlerDelegate outputHandler; private static OutputHandlerDelegate outputHandler;
@ -167,6 +168,7 @@ public static class PortHelper
Directory.Delete(extractDirectory, true); Directory.Delete(extractDirectory, true);
} }
//TODO: try to figure out if its possible to extract the name from the data.win file? They do have a displayname option last time I checked...
public static void PortWindowsToMac(string inputRawZipPath, string outputRawZipPath, string modName, OutputHandlerDelegate outputDelegate = null) public static void PortWindowsToMac(string inputRawZipPath, string outputRawZipPath, string modName, OutputHandlerDelegate outputDelegate = null)
{ {
outputHandler = outputDelegate; outputHandler = outputDelegate;
@ -178,11 +180,6 @@ public static class PortHelper
// Get name from user // Get name from user
//TODO: handle error on special characters //TODO: handle error on special characters
//TODO: do not have input in lib!!!
// Rename the .app "file", makes it too difficult to use with modpacker so commented out.
//if (!String.IsNullOrWhiteSpace(input))
// appDirectory = appDirectory.Replace("AM2R", input);
// Check if temp folder exists, delete if yes, copy bare runner to there // Check if temp folder exists, delete if yes, copy bare runner to there
if (Directory.Exists(baseTempDirectory)) if (Directory.Exists(baseTempDirectory))

Loading…
Cancel
Save