diff --git a/AM2RPortHelperCLI/Program.cs b/AM2RPortHelperCLI/Program.cs
index 3f48416..7200187 100644
--- a/AM2RPortHelperCLI/Program.cs
+++ b/AM2RPortHelperCLI/Program.cs
@@ -34,7 +34,7 @@ internal static class Program
androidOption,
macOption,
nameOption,
- internetOption,
+ internetOption
};
rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption,
macOption, nameOption, internetOption, verboseOption);
@@ -64,16 +64,16 @@ internal static class Program
if (linuxPath is not null)
{
- RawMods.PortToLinux(inputModPath.FullName, linuxPath.FullName, beVerbose ? OutputHandlerDelegate : null);
+ RawModsBase.PortToLinux(inputModPath.FullName, linuxPath.FullName, beVerbose ? OutputHandlerDelegate : null);
}
if (androidPath is not null)
{
- RawMods.PortToAndroid(inputModPath.FullName, androidPath.FullName,
+ RawModsBase.PortToAndroid(inputModPath.FullName, androidPath.FullName,
useCustomSave, usesInternet, beVerbose ? OutputHandlerDelegate : null);
}
if (macPath is not null)
{
- RawMods.PortToMac(inputModPath.FullName, macPath.FullName, beVerbose ? OutputHandlerDelegate : null);
+ RawModsBase.PortToMac(inputModPath.FullName, macPath.FullName, beVerbose ? OutputHandlerDelegate : null);
}
if (beVerbose)
Console.WriteLine("Done.");
@@ -142,7 +142,7 @@ internal static class Program
if (File.Exists(linuxPath))
File.Delete(linuxPath);
- RawMods.PortToLinux(modZipPath, linuxPath, OutputHandlerDelegate);
+ RawModsBase.PortToLinux(modZipPath, linuxPath, OutputHandlerDelegate);
}
if (androidSelected)
@@ -181,16 +181,14 @@ internal static class Program
}
while (customSaveSelected == null);
- RawMods.PortToAndroid(modZipPath, androidPath, customSaveSelected.Value, customSaveSelected.Value, OutputHandlerDelegate);
+ RawModsBase.PortToAndroid(modZipPath, androidPath, customSaveSelected.Value, customSaveSelected.Value, OutputHandlerDelegate);
}
if (macSelected)
{
if (File.Exists(macPath))
File.Delete(macPath);
- Console.WriteLine("Mac requires a name! Please enter one (no special characters!):");
- string modName = Console.ReadLine();
- RawMods.PortToMac(modZipPath, macPath, OutputHandlerDelegate);
+ RawModsBase.PortToMac(modZipPath, macPath, OutputHandlerDelegate);
}
Console.WriteLine("Successfully finished!");
@@ -199,10 +197,10 @@ internal static class Program
// We want people to also provide zips that don't end in .zip. If it turns out to not be a zip, it'll still throw later.
private static bool IsValidInputZip(string path)
{
- return path != null && (File.Exists(path));
+ return path != null && File.Exists(path);
}
- private static bool IsValidInputZip(FileInfo path)
+ private static bool IsValidInputZip(FileSystemInfo path)
{
return IsValidInputZip(path?.FullName);
}
diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs
index 745962e..0c3d766 100644
--- a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs
+++ b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs
@@ -40,7 +40,7 @@ public partial class MainForm : Form
mainLayout.BeginCentered();
mainLayout.AddRow(checkboxAndroidRequiresInternet);
mainLayout.EndCentered();
- mainLayout.AddRow(new Label() { Height = 5 });
+ mainLayout.AddRow(new Label { Height = 5 });
mainLayout.BeginCentered();
mainLayout.AddRow(checkboxUseCustomSave);
mainLayout.EndCentered();
@@ -101,7 +101,7 @@ public partial class MainForm : Form
if (File.Exists(linuxPath))
File.Delete(linuxPath);
- await Task.Run(() => RawMods.PortToLinux(modZipPath, linuxPath, OutputHandlerDelegate));
+ await Task.Run(() => RawModsBase.PortToLinux(modZipPath, linuxPath, OutputHandlerDelegate));
}
if (checkboxAndroid.Checked.Value)
{
@@ -110,7 +110,7 @@ public partial class MainForm : Form
bool useCustomSave = checkboxUseCustomSave.Checked.Value;
bool useInternet = checkboxAndroidRequiresInternet.Checked.Value;
- await Task.Run(() => RawMods.PortToAndroid(modZipPath, androidPath, useCustomSave, useInternet, OutputHandlerDelegate));
+ await Task.Run(() => RawModsBase.PortToAndroid(modZipPath, androidPath, useCustomSave, useInternet, OutputHandlerDelegate));
}
if (checkboxMac.Checked.Value)
{
@@ -118,7 +118,7 @@ public partial class MainForm : Form
File.Delete(macPath);
string modName = checkboxUseCustomSave.Text;
- await Task.Run(() => RawMods.PortToMac(modZipPath, macPath, OutputHandlerDelegate));
+ await Task.Run(() => RawModsBase.PortToMac(modZipPath, macPath, OutputHandlerDelegate));
}
labelProgress.Text = "Done!";
@@ -139,12 +139,9 @@ public partial class MainForm : Form
private void ShouldButtonPortBeEnabled(object sender, EventArgs e)
{
- // there needs to be a selected mod + any checkbox (if mac, then there needs to be a name)
- if ((!String.IsNullOrWhiteSpace(filePicker.FilePath)
- && ((checkboxAndroid.Checked.Value && !checkboxMac.Checked.Value))
- || (checkboxLinux.Checked.Value && !checkboxMac.Checked.Value)
- || (checkboxMac.Checked.Value && !String.IsNullOrWhiteSpace(checkboxUseCustomSave.Text))))
-
+ // there needs to be a selected mod + any checkbox
+ if (!String.IsNullOrWhiteSpace(filePicker.FilePath) &&
+ (checkboxAndroid.Checked.Value || checkboxLinux.Checked.Value || checkboxMac.Checked.Value))
buttonPort.Enabled = true;
else
buttonPort.Enabled = false;
diff --git a/AM2RPortHelperLib/Core.cs b/AM2RPortHelperLib/Core.cs
index 27fdb4d..837061a 100644
--- a/AM2RPortHelperLib/Core.cs
+++ b/AM2RPortHelperLib/Core.cs
@@ -1,7 +1,20 @@
namespace AM2RPortHelperLib;
-public class Core
+public static class Core
{
+ private static string ReturnAndCreateConfigDir()
+ {
+ string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create) + "/PortHelper/";
+ Console.WriteLine(path);
+ Directory.CreateDirectory(path);
+ return path;
+ }
+
+ ///
+ /// The full path to the PortHelper's place in Configuration Application Data.
+ ///
+ internal static readonly string ConfigDir = ReturnAndCreateConfigDir();
+
///
/// The current version of .
///
diff --git a/AM2RPortHelperLib/HelperMethods.cs b/AM2RPortHelperLib/HelperMethods.cs
index 3ea96f7..5eec737 100644
--- a/AM2RPortHelperLib/HelperMethods.cs
+++ b/AM2RPortHelperLib/HelperMethods.cs
@@ -61,7 +61,7 @@ public static class HelperMethods
foreach (DirectoryInfo subDir in dirs)
{
string tempPath = Path.Combine(destDirName, subDir.Name);
- DirectoryCopy(subDir.FullName, tempPath, true);
+ DirectoryCopy(subDir.FullName, tempPath);
}
}
diff --git a/AM2RPortHelperLib/LauncherMods.cs b/AM2RPortHelperLib/LauncherModsBase.cs
similarity index 94%
rename from AM2RPortHelperLib/LauncherMods.cs
rename to AM2RPortHelperLib/LauncherModsBase.cs
index 4ae6d79..3bb4719 100644
--- a/AM2RPortHelperLib/LauncherMods.cs
+++ b/AM2RPortHelperLib/LauncherModsBase.cs
@@ -2,7 +2,7 @@
namespace AM2RPortHelperLib;
-public abstract class LauncherMods : IMods
+public abstract class LauncherModsBase : ModsBase
{
///
/// Ports a Mod zip intended to be installed via the AM2RLauncher to other operating systems.
@@ -17,8 +17,8 @@ public abstract class LauncherMods : IMods
/// TODO: other exceptions
public static void PortLauncherMod(string inputLauncherZipPath, Core.ModOS modTarget, bool includeAndroid, string outputLauncherZipPath, string am2r11ZipPath = null, OutputHandlerDelegate outputDelegate = null)
{
- outputHandler = outputDelegate;
- string extractDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputLauncherZipPath);
+ OutputHandler = outputDelegate;
+ string extractDirectory = TempDir + "/" + Path.GetFileNameWithoutExtension(inputLauncherZipPath);
string filesToCopyDir = extractDirectory + "/files_to_copy";
// Check if temp folder exists, delete if yes, extract zip to there
@@ -62,7 +62,7 @@ public abstract class LauncherMods : IMods
// get proper runner
File.Delete(extractDirectory + "/AM2R.xdelta");
- File.Copy(utilDir + "/windowsRunner.xdelta", extractDirectory + "/AM2R.xdelta");
+ File.Copy(UtilDir + "/windowsRunner.xdelta", extractDirectory + "/AM2R.xdelta");
// Windows doesn't care about capitalization and because I can't predict how it originally was, I'm going to ignore it.
@@ -91,7 +91,7 @@ public abstract class LauncherMods : IMods
// get proper runner
File.Delete(extractDirectory + "/AM2R.xdelta");
- File.Copy(utilDir + "/linuxRunner.xdelta", extractDirectory + "/AM2R.xdelta");
+ File.Copy(UtilDir + "/linuxRunner.xdelta", extractDirectory + "/AM2R.xdelta");
// Linux needs everything lowercased. Only needed if we're coming from Windows
if (currentOS == "Windows")
@@ -99,9 +99,9 @@ public abstract class LauncherMods : IMods
// Windows doesn't have icon/splash, so we copy them over from here
if (!File.Exists(filesToCopyDir + "/icon.png"))
- File.Copy(utilDir + "/icon.png", filesToCopyDir + "/icon.png");
+ File.Copy(UtilDir + "/icon.png", filesToCopyDir + "/icon.png");
if (!File.Exists(filesToCopyDir + "/splash.png"))
- File.Copy(utilDir + "/splash.png", filesToCopyDir + "/splash.png");
+ File.Copy(UtilDir + "/splash.png", filesToCopyDir + "/splash.png");
// Properly set profile.xml variables
profile.OperatingSystem = "Linux";
diff --git a/AM2RPortHelperLib/IMods.cs b/AM2RPortHelperLib/ModsBase.cs
similarity index 59%
rename from AM2RPortHelperLib/IMods.cs
rename to AM2RPortHelperLib/ModsBase.cs
index 5d1955b..4c30549 100644
--- a/AM2RPortHelperLib/IMods.cs
+++ b/AM2RPortHelperLib/ModsBase.cs
@@ -1,28 +1,28 @@
namespace AM2RPortHelperLib;
-public abstract class IMods
+public abstract class ModsBase
{
public delegate void OutputHandlerDelegate(string output);
- protected static OutputHandlerDelegate outputHandler;
+ protected static OutputHandlerDelegate OutputHandler;
protected static void SendOutput(string output)
{
- outputHandler?.Invoke(output);
+ OutputHandler?.Invoke(output);
}
///
/// A temporary directory
///
- protected static readonly string tmp = Path.GetTempPath() + "/PortHelper/";
+ protected static readonly string TempDir = Path.GetTempPath() + "/PortHelper/";
///
/// The current directory of the AM2RPortHelper program.
///
- protected static readonly string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
+ protected static readonly string CurrentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
///
/// The "utils" folder that's shipped with the AM2RPortHelper.
///
- protected static readonly string utilDir = currentDir + "/utils";
+ protected static readonly string UtilDir = CurrentDir + "/utils";
}
\ No newline at end of file
diff --git a/AM2RPortHelperLib/RawMods.cs b/AM2RPortHelperLib/RawModsBase.cs
similarity index 90%
rename from AM2RPortHelperLib/RawMods.cs
rename to AM2RPortHelperLib/RawModsBase.cs
index eba67d8..c591c3f 100644
--- a/AM2RPortHelperLib/RawMods.cs
+++ b/AM2RPortHelperLib/RawModsBase.cs
@@ -9,7 +9,7 @@ using static AM2RPortHelperLib.Core;
namespace AM2RPortHelperLib;
-public abstract class RawMods : IMods
+public abstract class RawModsBase : ModsBase
{
// 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
@@ -34,10 +34,9 @@ public abstract class RawMods : IMods
private static string GetProperPathToBuiltinIcons(string nameOfResource)
{
- string subCaseFunction(string resource)
+ string SubCaseFunction(string resource)
{
- // TODO: default path should be in XDG_CONFIG
- string origPath = utilDir + "/" + resource;
+ string origPath = ConfigDir + "/" + resource;
if (File.Exists(origPath))
return origPath;
@@ -49,19 +48,19 @@ public abstract class RawMods : IMods
_ => throw new InvalidDataException("SubCaseFunction was called with an improper resource!")
};
- Image.Load(byteArray).SaveAsPng(tmp + "/" + resource);
- origPath = tmp + "/" + resource;
+ Image.Load(byteArray).SaveAsPng(TempDir + "/" + resource);
+ origPath = TempDir + "/" + resource;
return origPath;
}
switch (nameOfResource)
{
case nameof(Resources.icon):
- return subCaseFunction(nameof(Resources.icon) + ".png");
+ return SubCaseFunction(nameof(Resources.icon) + ".png");
case nameof(Resources.splash):
- return subCaseFunction(nameof(Resources.splash) + ".png");
+ return SubCaseFunction(nameof(Resources.splash) + ".png");
case nameof(Resources.splashAndroid):
- return subCaseFunction(nameof(Resources.splashAndroid) + ".png");
+ return SubCaseFunction(nameof(Resources.splashAndroid) + ".png");
default: throw new InvalidDataException(nameOfResource + " is an unknown Icon!");
}
}
@@ -84,8 +83,8 @@ public abstract class RawMods : IMods
return;
}
- outputHandler = outputDelegate;
- string extractDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
+ OutputHandler = outputDelegate;
+ string extractDirectory = TempDir + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
string assetsDir = extractDirectory + "/assets";
// Check if temp folder exists, delete if yes, extract zip to there
@@ -116,7 +115,7 @@ public abstract class RawMods : IMods
default: throw new NotSupportedException("The OS of the mod zip is unknown and thus not supported");
}
- File.Copy(utilDir + "/runner", extractDirectory + "/runner");
+ File.Copy(UtilDir + "/runner", extractDirectory + "/runner");
if (!File.Exists(assetsDir + "/icon.png"))
File.Copy(GetProperPathToBuiltinIcons(nameof(Resources.icon)), assetsDir + "/icon.png");
if (!File.Exists(assetsDir + "/splash.png"))
@@ -130,7 +129,7 @@ public abstract class RawMods : IMods
ZipFile.CreateFromDirectory(extractDirectory, outputRawZipPath);
// Clean up
- Directory.Delete(tmp, true);
+ Directory.Delete(TempDir, true);
}
public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, bool useCustomSaveDirectory = false, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null)
@@ -138,14 +137,14 @@ public abstract class RawMods : IMods
ModOS currentOS = GetModOSOfRawZip(inputRawZipPath);
SendOutput("Zip Recognized as " + currentOS);
- outputHandler = outputDelegate;
- string extractDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
+ OutputHandler = outputDelegate;
+ string extractDirectory = TempDir + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
string apkDir = extractDirectory + "/apk";
string apkAssetsDir = apkDir + "/assets";
string bin = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "cmd.exe" : "java";
string args = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "/C java -jar " : "-jar ";
- string apktool = currentDir + "/utils/apktool.jar";
- string signer = currentDir + "/utils/uber-apk-signer.jar";
+ string apktool = CurrentDir + "/utils/apktool.jar";
+ string signer = CurrentDir + "/utils/uber-apk-signer.jar";
string finalApkBuild = extractDirectory + "/build-aligned-debugSigned.apk";
// Check if temp folder exists, delete if yes, extract zip to there
@@ -158,7 +157,7 @@ public abstract class RawMods : IMods
ProcessStartInfo pStartInfo = new ProcessStartInfo
{
FileName = bin,
- Arguments = args + "\"" + apktool + "\" d -f -o \"" + apkDir + "\" \"" + currentDir + "/utils/AM2RWrapper.apk" + "\"",
+ Arguments = args + "\"" + apktool + "\" d -f -o \"" + apkDir + "\" \"" + UtilDir + "/AM2RWrapper.apk" + "\"",
CreateNoWindow = true
};
Process p = new Process { StartInfo = pStartInfo };
@@ -244,7 +243,7 @@ public abstract class RawMods : IMods
manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}");
// then in the rest
- string AndroidIDReplace(string content, string name)
+ string AndroidIdReplace(string content)
{
return content.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}")
.Replace("com/companyname/AM2RWrapper", $"com/companyname/{modName}")
@@ -253,20 +252,20 @@ public abstract class RawMods : IMods
foreach (var file in Directory.GetFiles($"{apkDir}/smali/com/yoyogames/runner"))
{
var content = File.ReadAllText(file);
- content = AndroidIDReplace(content, modName);
+ content = AndroidIdReplace(content);
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 = AndroidIDReplace(content, modName);
+ content = AndroidIdReplace(content);
File.WriteAllText(file.FullName, content);
}
am2rWrapperDir.MoveTo($"{apkDir}/smali/com/companyname/{modName}");
var layoutContent = File.ReadAllText($"{apkDir}/res/layout/main.xml");
- layoutContent = AndroidIDReplace(layoutContent, modName);
+ layoutContent = AndroidIdReplace(layoutContent);
File.WriteAllText($"{apkDir}/res/layout/main.xml", layoutContent);
}
@@ -308,7 +307,7 @@ public abstract class RawMods : IMods
File.Move(finalApkBuild, outputRawApkPath);
// Clean up
- Directory.Delete(tmp, true);
+ Directory.Delete(TempDir, true);
}
public static void PortToMac(string inputRawZipPath, string outputRawZipPath, OutputHandlerDelegate outputDelegate = null)
@@ -323,8 +322,8 @@ public abstract class RawMods : IMods
return;
}
- outputHandler = outputDelegate;
- string baseTempDirectory = tmp + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
+ OutputHandler = outputDelegate;
+ string baseTempDirectory = TempDir + "/" + Path.GetFileNameWithoutExtension(inputRawZipPath);
string extractDirectory = baseTempDirectory + "/extract";
string appDirectory = baseTempDirectory + "/AM2R.app";
string contentsDir = baseTempDirectory + "/Contents";
@@ -333,9 +332,9 @@ public abstract class RawMods : IMods
// Check if temp folder exists, delete if yes, copy bare runner to there
if (Directory.Exists(baseTempDirectory))
Directory.Delete(baseTempDirectory, true);
- SendOutput("Copying Runner...");
+ SendOutput("Copying Mac Runner...");
Directory.CreateDirectory(contentsDir);
- HelperMethods.DirectoryCopy(utilDir + "/Contents", contentsDir, true);
+ HelperMethods.DirectoryCopy(UtilDir + "/Contents", contentsDir);
// Extract mod to temp location
SendOutput("Extracting Mac...");
@@ -380,15 +379,15 @@ public abstract class RawMods : IMods
// TODO: replace this via built-in lib
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- bin = "\"" + utilDir + "/UTMTCli/UndertaleModCli.exe\"";
+ bin = "\"" + UtilDir + "/UTMTCli/UndertaleModCli.exe\"";
args = "";
}
else
{
// First chmod the file, just in case
- Process.Start("chmod", "+x \"" + utilDir + "/UTMTCli/UndertaleModCli.dll\"");
+ Process.Start("chmod", "+x \"" + UtilDir + "/UTMTCli/UndertaleModCli.dll\"");
bin = "dotnet";
- args = "\"" + utilDir + "/UTMTCli/UndertaleModCli.dll\" ";
+ args = "\"" + UtilDir + "/UTMTCli/UndertaleModCli.dll\" ";
// Also chmod the runner. Just in case.
Process.Start("chmod", "+x \"" + contentsDir + "/MacOS/Mac_Runner");
}
@@ -396,7 +395,7 @@ public abstract class RawMods : IMods
ProcessStartInfo pStartInfo = new ProcessStartInfo
{
FileName = bin,
- Arguments = args + "load \"" + extractDirectory + "/game.ios\" -s \"" + utilDir + "/bc16AndRemoveFunctions.csx\" -o \"" + extractDirectory + "/game.ios\"",
+ Arguments = args + "load \"" + extractDirectory + "/game.ios\" -s \"" + UtilDir + "/bc16AndRemoveFunctions.csx\" -o \"" + extractDirectory + "/game.ios\"",
CreateNoWindow = false
};
Process p = new Process { StartInfo = pStartInfo };
@@ -437,6 +436,6 @@ public abstract class RawMods : IMods
ZipFile.CreateFromDirectory(baseTempDirectory, outputRawZipPath);
// Clean up
- Directory.Delete(tmp, true);
+ Directory.Delete(TempDir, true);
}
}
\ No newline at end of file
diff --git a/AM2RPortHelperLib/Serializer.cs b/AM2RPortHelperLib/Serializer.cs
index 4aa0d9a..5a630c1 100644
--- a/AM2RPortHelperLib/Serializer.cs
+++ b/AM2RPortHelperLib/Serializer.cs
@@ -26,7 +26,6 @@ public static class Serializer
memStream.Flush();
memStream.Close();
memStream.Dispose();
- memStream = null;
return xml;
}