Make Android name replacement not crash APK

mac
Miepee 4 years ago
parent 06a2538c3c
commit e520717e71

@ -19,7 +19,7 @@ internal static class Program
private static int Main(string[] args)
{
//PortHelper.PortLauncherMod("/home/narr/Downloads/Multitroid1_4_2VM_Linux.zip", "Windows", false, "./foo.zip");
//PortHelper.PortLauncherMod("/home/narr/Downloads/UnofficialMultitroidAPKTest1_6a.zip", "Linux", true, "./foo.zip");
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 IN NON-INTERACTIVE*");
@ -199,6 +199,7 @@ internal static class Program
Console.WriteLine("Successfully finished!");
}
// TODO: we should probably check for magic header instead of just file extension
private static bool IsValidInputZip(string path)
{
return path != null && (File.Exists(path) || Path.GetExtension(path).ToLower() == ".zip");

@ -283,10 +283,38 @@ public static partial class PortHelper
{
string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml");
// If a custom name was given, replace it.
//TODO: handle errors
// If a custom name was given, replace it everywhere.
//TODO: handle errors:
// A-Z, a-z, digits, underscore and needs to start with letters
if (modName != null)
manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", "com.companyname." + modName);
{
// first in the manifest
manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}");
// then in the rest
// TODO: create some sort of function for it to avoid copy paste
foreach (var file in Directory.GetFiles($"{apkDir}/smali/com/yoyogames/runner"))
{
var content = File.ReadAllText(file);
content = content.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}")
.Replace("com/companyname/AM2RWrapper", $"com/companyname/{modName}");
File.WriteAllText(file, content);
}
var am2rWrapperDir = new DirectoryInfo($"{apkDir}/smali/com/companyname/AM2RWrapper");
foreach (var file in am2rWrapperDir.GetFiles())
{
var content = File.ReadAllText(file.FullName);
content = content.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}")
.Replace("com/companyname/AM2RWrapper", $"com/companyname/{modName}")
.Replace("com$companyname$AM2RWrapper", $"com$companyname${modName}");
File.WriteAllText(file.FullName, content);
}
am2rWrapperDir.MoveTo($"{apkDir}/smali/com/companyname/{modName}");
var layoutContent = File.ReadAllText($"{apkDir}/res/layout/main.xml");
layoutContent = layoutContent.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}");
File.WriteAllText($"{apkDir}/res/layout/main.xml", layoutContent);
}
// Add internet permission, keying off the Bluetooth permission.
if (usesInternet)

Loading…
Cancel
Save