diff --git a/AM2RPortHelperCLI/Program.cs b/AM2RPortHelperCLI/Program.cs index 952c011..46aa76b 100644 --- a/AM2RPortHelperCLI/Program.cs +++ b/AM2RPortHelperCLI/Program.cs @@ -21,6 +21,7 @@ internal static class Program var androidOption = new Option(new[] { "-a", "--android" }, "The output file path for the Android mod. None given equals to no Android port."); var macOption = new Option(new[] { "-m", "--mac" }, "The output file path for the Mac mod. None given equals to no Mac port."); var nameOption = new Option(new[] { "-n", "--name" }, "The name used for the Mac or Android mod. Required for the Mac option, and optional for the Android version. Has no effect on anything else."); + var internetOption = new Option(new[] { "-w", "--internet" }, "Add internet usage permissions to the Android mod. Has no effect to other OS."); RootCommand rootCommand = new RootCommand { @@ -29,9 +30,10 @@ internal static class Program linuxOption, androidOption, macOption, - nameOption + nameOption, + internetOption }; - rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption, macOption, nameOption); + rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption, macOption, nameOption, internetOption); return rootCommand.Invoke(args); @@ -43,7 +45,7 @@ internal static class Program */ } - private static void RootMethod(bool interactive, FileInfo inputModPath, FileInfo linuxPath, FileInfo androidPath, FileInfo macPath, string modName) + private static void RootMethod(bool interactive, FileInfo inputModPath, FileInfo linuxPath, FileInfo androidPath, FileInfo macPath, string modName, bool usesInternet) { if (interactive) { @@ -62,7 +64,7 @@ internal static class Program } if (androidPath is not null) { - PortHelper.PortWindowsToAndroid(inputModPath.FullName, androidPath.FullName, string.IsNullOrWhiteSpace(modName) ? null : modName); + PortHelper.PortWindowsToAndroid(inputModPath.FullName, androidPath.FullName, string.IsNullOrWhiteSpace(modName) ? null : modName, usesInternet); } if (macPath is not null) { @@ -118,7 +120,7 @@ internal static class Program if (linuxSelected || androidSelected || macSelected) invalidOS = false; else - Console.WriteLine("You have to at least select one OS!"); + Console.WriteLine("You have to select at least one OS!"); break; } } while (invalidOS); @@ -138,8 +140,27 @@ internal static class Program if (linuxSelected) PortHelper.PortWindowsToLinux(modZipPath,linuxPath); - if (androidSelected) - PortHelper.PortWindowsToAndroid(modZipPath, androidPath); + + if (androidSelected) + { + // TODO: ask for modname + bool? internetSelected = null; + do + { + Console.WriteLine("Does your mod require internet access (y/n)?"); + var input = Console.ReadKey().Key; + switch (input) + { + case ConsoleKey.Y: internetSelected = true; break; + case ConsoleKey.N: internetSelected = false; break; + default: Console.WriteLine("Invalid input!"); break; + } + Console.WriteLine(); + } + while (internetSelected == null); + + PortHelper.PortWindowsToAndroid(modZipPath, androidPath, null, internetSelected.Value); + } if (macSelected) { Console.WriteLine("Mac requires a name! Please enter one (no special characters!):"); diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs index 99398be..c9d01b7 100644 --- a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs +++ b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs @@ -30,6 +30,10 @@ public partial class MainForm : Form mainLayout.AddSpace(); mainLayout.EndCentered(); mainLayout.BeginCentered(); + mainLayout.AddRow(checkboxAndroidRequiresInternet); + mainLayout.AddSpace(); + mainLayout.EndCentered(); + mainLayout.BeginCentered(); mainLayout.AddRow(labelModName, new Label { Width = 15 }, textboxModName); mainLayout.AddSpace(); mainLayout.EndCentered(); @@ -64,6 +68,7 @@ public partial class MainForm : Form // events checkboxAndroid.CheckedChanged += ShouldButtonPortBeEnabled; + checkboxAndroidRequiresInternet.CheckedChanged += ShouldButtonPortBeEnabled; checkboxLinux.CheckedChanged += ShouldButtonPortBeEnabled; checkboxMac.CheckedChanged += ShouldButtonPortBeEnabled; textboxModName.TextChanged += ShouldButtonPortBeEnabled; @@ -97,8 +102,8 @@ public partial class MainForm : Form string modName = null; if (!String.IsNullOrWhiteSpace(textboxModName.Text)) modName = textboxModName.Text; - - await Task.Run(() => PortHelper.PortWindowsToAndroid(modZipPath, androidPath, modName, OutputHandlerDelegate)); + bool useInternet = checkboxAndroidRequiresInternet.Checked.Value; + await Task.Run(() => PortHelper.PortWindowsToAndroid(modZipPath, androidPath, modName, useInternet, OutputHandlerDelegate)); } if (checkboxMac.Checked.Value) { @@ -141,6 +146,7 @@ public partial class MainForm : Form private void SetDisableStatusOfAllElements(bool disabled) { checkboxAndroid.Enabled = !disabled; + checkboxAndroidRequiresInternet.Enabled = !disabled; checkboxLinux.Enabled = !disabled; checkboxMac.Enabled = !disabled; filePicker.Enabled = !disabled; @@ -166,6 +172,10 @@ public partial class MainForm : Form { Text = "Android" }; + private readonly CheckBox checkboxAndroidRequiresInternet = new CheckBox + { + Text = "Requires internet (Android only)" + }; private readonly CheckBox checkboxMac = new CheckBox { Text = "Mac" diff --git a/AM2RPortHelperLib/PortHelper.cs b/AM2RPortHelperLib/PortHelper.cs index 187b20e..8b9f631 100644 --- a/AM2RPortHelperLib/PortHelper.cs +++ b/AM2RPortHelperLib/PortHelper.cs @@ -10,7 +10,7 @@ public static partial class PortHelper /// /// The current version of . /// - public const string Version = "1.3"; + public const string Version = "1.4"; public delegate void OutputHandlerDelegate(string output); private static OutputHandlerDelegate outputHandler; @@ -214,7 +214,7 @@ public static partial class PortHelper } // TODO: try to figure out if its possible to extract the name from the data.win file and then just offer a "use custom save directory" option that decides whether to use it or not. - public static void PortWindowsToAndroid(string inputRawZipPath, string outputRawApkPath, string modName = null, OutputHandlerDelegate outputDelegate = null) + public static void PortWindowsToAndroid(string inputRawZipPath, string outputRawApkPath, string modName = null, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null) { outputHandler = outputDelegate; string extractDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath); @@ -280,15 +280,27 @@ public static partial class PortHelper SaveAndroidIcon(orig, 144, resPath + "/drawable-xxhdpi-v4/icon.png"); SaveAndroidIcon(orig, 192, resPath + "/drawable-xxxhdpi-v4/icon.png"); - // If a custom name was given, replace it. - //TODO: handle errors - if (modName != null) + + // On certain occasions, we need to modify the manifest file. + if (modName != null || usesInternet) { string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml"); - manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", "com.companyname." + modName); + + // If a custom name was given, replace it. + //TODO: handle errors + if (modName != null) + manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", "com.companyname." + modName); + + // Add internet permission, keying off the Bluetooth permission. + if (usesInternet) + { + const string bluetoothPermission = ""; + const string internetPermission = ""; + manifestFile = manifestFile.Replace(bluetoothPermission, internetPermission + "\n " + bluetoothPermission); + } File.WriteAllText(apkDir + "/AndroidManifest.xml", manifestFile); } - + // Run APKTOOL and build the apk SendOutput("Rebuild apk..."); pStartInfo = new ProcessStartInfo