Read Mac and Android Display name from data file directly

mac
Miepee 3 years ago
parent 81f5594c84
commit 7e1392c94e

@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AM2RPortHelperGUI.Mac", "AM
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AM2RPortHelperGUI.Wpf", "AM2RPortHelperGUI\AM2RPortHelperGUI.Wpf\AM2RPortHelperGUI.Wpf.csproj", "{4C4043B0-38AB-479A-A4B3-D3F7F39092F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UndertaleModLib", "UndertaleModTool\UndertaleModLib\UndertaleModLib.csproj", "{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -49,6 +51,10 @@ Global
{3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Release|Any CPU.Build.0 = Release|Any CPU
{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10</LangVersion>
<PackageVersion>1.8.0</PackageVersion>
@ -23,4 +23,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UndertaleModTool\UndertaleModLib\UndertaleModLib.csproj" />
</ItemGroup>
</Project>

@ -2,6 +2,7 @@ using System.Diagnostics;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using UndertaleModLib;
using static AM2RPortHelperLib.Core;
namespace AM2RPortHelperLib;
@ -11,6 +12,7 @@ public abstract class RawMods : IMods
// For completionist sake, it should be possible to also port raw APKs to win/lin/mac
// But until some person actually shows up that needs this feature, I'm too lazy to implement it
// TODO: documentation
public static ModOS GetModOSOfRawZip(string inputRawZipPath)
{
@ -95,8 +97,7 @@ public abstract class RawMods : IMods
Directory.Delete(assetsDir, true);
}
// 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 PortToAndroid(string inputRawZipPath, string outputRawApkPath, string modName = null, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null)
public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, bool useCustomSaveDirectory = false, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null)
{
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
SendOutput("Zip Recognized as " + currentOS);
@ -185,17 +186,26 @@ public abstract class RawMods : IMods
// TODO: Hermite probably best as image upscaler, but we'll see
// On certain occasions, we need to modify the manifest file.
if (modName != null || usesInternet)
if (useCustomSaveDirectory || usesInternet)
{
string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml");
// If a custom name was given, replace it everywhere.
if (modName != null)
if (useCustomSaveDirectory)
{
string modName;
FileInfo datafile = new FileInfo(extractDirectory + "/game.ios");
using (FileStream fs = datafile.OpenRead())
{
UndertaleData gmData = UndertaleIO.Read(fs, SendOutput, SendOutput);
modName = gmData.GeneralInfo.DisplayName.Content;
}
modName = modName.Replace(" ", "").Replace(":", "");
// rules for name: A-Z, a-z, digits, underscore and needs to start with letters
Regex nameReg = new Regex(@"^[a-zA-Z][a-zA-Z0-9_]*$");
if (!nameReg.Match(modName).Success)
throw new InvalidDataException("The display name " + modName + " is invalid! The name has to start with letters (a-z), and can only contain letters, digits and underscore!");
throw new InvalidDataException("The display name " + modName + " is invalid! The name has to start with letters (a-z), and can only contain letters, digits, space, colon and underscore!");
// first in the manifest
manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}");
@ -268,8 +278,7 @@ public abstract class RawMods : IMods
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 PortToMac(string inputRawZipPath, string outputRawZipPath, string modName, OutputHandlerDelegate outputDelegate = null)
public static void PortToMac(string inputRawZipPath, string outputRawZipPath, OutputHandlerDelegate outputDelegate = null)
{
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
SendOutput("Zip Recognized as " + currentOS);
@ -334,6 +343,7 @@ public abstract class RawMods : IMods
string bin;
string args;
// TODO: replace this via built-in lib
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
bin = "\"" + utilDir + "/UTMTCli/UndertaleModCli.exe\"";
@ -364,7 +374,15 @@ public abstract class RawMods : IMods
HelperMethods.DirectoryCopy(extractDirectory, assetsDir);
// Edit config and plist to change display name
//TODO: handle error on special characters
string modName;
FileInfo datafile = new FileInfo(extractDirectory + "/game.ios");
using (FileStream fs = datafile.OpenRead())
{
UndertaleData gmData = UndertaleIO.Read(fs, SendOutput, SendOutput);
modName = gmData.GeneralInfo.DisplayName.Content;
}
//TODO: handle error on special characters, but need to know which characters are invalid in the first place
//if (modName.Contains())
SendOutput("Editing Runner references to AM2R...");
string textFile = File.ReadAllText(assetsDir + "/yoyorunner.config");
textFile = textFile.Replace("YoYo Runner", modName);

@ -1 +1 @@
Subproject commit ad5a84bdfbf3a58079c3e2a60ce487b3438a0bce
Subproject commit 79704260e15ab8c7ffdbc7effb3cbe366f480a00
Loading…
Cancel
Save