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 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 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
{
@ -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);
{
// 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!):");

@ -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"

@ -10,7 +10,7 @@ public static partial class PortHelper
/// <summary>
/// The current version of <see cref="AM2RPortHelperLib"/>.
/// </summary>
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,12 +280,24 @@ public static partial class PortHelper
SaveAndroidIcon(orig, 144, resPath + "/drawable-xxhdpi-v4/icon.png");
SaveAndroidIcon(orig, 192, resPath + "/drawable-xxxhdpi-v4/icon.png");
// On certain occasions, we need to modify the manifest file.
if (modName != null || usesInternet)
{
string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml");
// If a custom name was given, replace it.
//TODO: handle errors
if (modName != null)
{
string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml");
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);
}

Loading…
Cancel
Save