Add internet support for Android (#5)

* Add internet support for Android

- Add logic to PortWindowsToAndroid
- Modify GUI, CLI, and CLI interactive to take in the new argument
- Bump version number to 1.4

* Fix lobster moments

* Fix crash when porting to android

Co-authored-by: Miepee <janbidler00@protonmail.com>
mac
Lojemiru 4 years ago committed by GitHub
parent 8105ae36c3
commit b582e0fcbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,7 @@ internal static class Program
var androidOption = new Option<FileInfo>(new[] { "-a", "--android" }, "The output file path for the Android mod. None given equals to no Android 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 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 or Android mod. Required for the Mac option, and optional for the Android version. Has no effect on anything else."); var nameOption = new Option<string>(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<bool>(new[] { "-w", "--internet" }, "Add internet usage permissions to the Android mod. Has no effect to other OS.");
RootCommand rootCommand = new RootCommand RootCommand rootCommand = new RootCommand
{ {
@ -29,9 +30,10 @@ internal static class Program
linuxOption, linuxOption,
androidOption, androidOption,
macOption, 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); 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) if (interactive)
{ {
@ -62,7 +64,7 @@ internal static class Program
} }
if (androidPath is not null) 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) if (macPath is not null)
{ {
@ -118,7 +120,7 @@ internal static class Program
if (linuxSelected || androidSelected || macSelected) if (linuxSelected || androidSelected || macSelected)
invalidOS = false; invalidOS = false;
else else
Console.WriteLine("You have to at least select one OS!"); Console.WriteLine("You have to select at least one OS!");
break; break;
} }
} while (invalidOS); } while (invalidOS);
@ -138,8 +140,27 @@ internal static class Program
if (linuxSelected) if (linuxSelected)
PortHelper.PortWindowsToLinux(modZipPath,linuxPath); 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) if (macSelected)
{ {
Console.WriteLine("Mac requires a name! Please enter one (no special characters!):"); Console.WriteLine("Mac requires a name! Please enter one (no special characters!):");

@ -30,6 +30,10 @@ public partial class MainForm : Form
mainLayout.AddSpace(); mainLayout.AddSpace();
mainLayout.EndCentered(); mainLayout.EndCentered();
mainLayout.BeginCentered(); mainLayout.BeginCentered();
mainLayout.AddRow(checkboxAndroidRequiresInternet);
mainLayout.AddSpace();
mainLayout.EndCentered();
mainLayout.BeginCentered();
mainLayout.AddRow(labelModName, new Label { Width = 15 }, textboxModName); mainLayout.AddRow(labelModName, new Label { Width = 15 }, textboxModName);
mainLayout.AddSpace(); mainLayout.AddSpace();
mainLayout.EndCentered(); mainLayout.EndCentered();
@ -64,6 +68,7 @@ public partial class MainForm : Form
// events // events
checkboxAndroid.CheckedChanged += ShouldButtonPortBeEnabled; checkboxAndroid.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxAndroidRequiresInternet.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxLinux.CheckedChanged += ShouldButtonPortBeEnabled; checkboxLinux.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxMac.CheckedChanged += ShouldButtonPortBeEnabled; checkboxMac.CheckedChanged += ShouldButtonPortBeEnabled;
textboxModName.TextChanged += ShouldButtonPortBeEnabled; textboxModName.TextChanged += ShouldButtonPortBeEnabled;
@ -97,8 +102,8 @@ public partial class MainForm : Form
string modName = null; string modName = null;
if (!String.IsNullOrWhiteSpace(textboxModName.Text)) modName = textboxModName.Text; if (!String.IsNullOrWhiteSpace(textboxModName.Text)) modName = textboxModName.Text;
bool useInternet = checkboxAndroidRequiresInternet.Checked.Value;
await Task.Run(() => PortHelper.PortWindowsToAndroid(modZipPath, androidPath, modName, OutputHandlerDelegate)); await Task.Run(() => PortHelper.PortWindowsToAndroid(modZipPath, androidPath, modName, useInternet, OutputHandlerDelegate));
} }
if (checkboxMac.Checked.Value) if (checkboxMac.Checked.Value)
{ {
@ -141,6 +146,7 @@ public partial class MainForm : Form
private void SetDisableStatusOfAllElements(bool disabled) private void SetDisableStatusOfAllElements(bool disabled)
{ {
checkboxAndroid.Enabled = !disabled; checkboxAndroid.Enabled = !disabled;
checkboxAndroidRequiresInternet.Enabled = !disabled;
checkboxLinux.Enabled = !disabled; checkboxLinux.Enabled = !disabled;
checkboxMac.Enabled = !disabled; checkboxMac.Enabled = !disabled;
filePicker.Enabled = !disabled; filePicker.Enabled = !disabled;
@ -166,6 +172,10 @@ public partial class MainForm : Form
{ {
Text = "Android" Text = "Android"
}; };
private readonly CheckBox checkboxAndroidRequiresInternet = new CheckBox
{
Text = "Requires internet (Android only)"
};
private readonly CheckBox checkboxMac = new CheckBox private readonly CheckBox checkboxMac = new CheckBox
{ {
Text = "Mac" Text = "Mac"

@ -10,7 +10,7 @@ public static partial class PortHelper
/// <summary> /// <summary>
/// The current version of <see cref="AM2RPortHelperLib"/>. /// The current version of <see cref="AM2RPortHelperLib"/>.
/// </summary> /// </summary>
public const string Version = "1.3"; public const string Version = "1.4";
public delegate void OutputHandlerDelegate(string output); public delegate void OutputHandlerDelegate(string output);
private static OutputHandlerDelegate outputHandler; 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. // 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; outputHandler = outputDelegate;
string extractDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath); 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, 144, resPath + "/drawable-xxhdpi-v4/icon.png");
SaveAndroidIcon(orig, 192, resPath + "/drawable-xxxhdpi-v4/icon.png"); SaveAndroidIcon(orig, 192, resPath + "/drawable-xxxhdpi-v4/icon.png");
// If a custom name was given, replace it.
//TODO: handle errors // On certain occasions, we need to modify the manifest file.
if (modName != null) if (modName != null || usesInternet)
{ {
string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml"); 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 = "<uses-permission android:name=\"android.permission.BLUETOOTH\"/>";
const string internetPermission = "<uses-permission android:name=\"android.permission.INTERNET\"/>";
manifestFile = manifestFile.Replace(bluetoothPermission, internetPermission + "\n " + bluetoothPermission);
}
File.WriteAllText(apkDir + "/AndroidManifest.xml", manifestFile); File.WriteAllText(apkDir + "/AndroidManifest.xml", manifestFile);
} }
// Run APKTOOL and build the apk // Run APKTOOL and build the apk
SendOutput("Rebuild apk..."); SendOutput("Rebuild apk...");
pStartInfo = new ProcessStartInfo pStartInfo = new ProcessStartInfo

Loading…
Cancel
Save