Make right side scrollable + make creating win mods on non-win work

pull/9/head
Miepee 3 years ago
parent 08bf9f9876
commit 146ab72b69

@ -15,11 +15,12 @@ public partial class ModPacker : Form
// Currently broken as I don't know how to do this from Rider
//Icon = Icon.FromResource("icon64.ico");
MinimumSize = new Size(550, 430);
MinimumSize = new Size(550, 400);
var mainContent = new DynamicLayout() { Spacing = new Size(15, 15) };
var leftSide = new DynamicLayout() { Padding = 10, Spacing = new Size(5, 5) };
var rightSide = new DynamicLayout() { Padding = 10, Spacing = new Size(5, 5) };
var rightSide = new DynamicLayout() { Padding = 10, Spacing = new Size(5, 5), };
var rightSideScrollable = new Scrollable() { Border = BorderType.None};
// Left side
var modInfoPanel = new DynamicLayout() { Spacing = new Size(5, 5) };
@ -62,17 +63,19 @@ public partial class ModPacker : Form
resultPanel.AddRow(createLabel);
// Combine together
//TODO: add scrollbar pls
rightSide.AddRow(savePanel);
rightSide.AddRow(saveTextPanel);
rightSide.AddRow(miscOptionsPanel);
rightSide.AddRow(new Label() { Text = "I am a spacer!", TextColor = this.BackgroundColor });
rightSide.AddRow(loadZipsPanel);
rightSide.AddRow(resultPanel);
rightSideScrollable.Content = rightSide;
// Combine all into main panel and assign
Splitter splitter = new Splitter() {};
splitter.Panel1 = leftSide;
splitter.Panel2 = rightSide;
splitter.Panel2 = rightSideScrollable;
splitter.Panel1MinimumSize = 180;
splitter.Panel2MinimumSize = 320;
splitter.Orientation = Orientation.Horizontal;

@ -208,6 +208,27 @@ public partial class ModPacker : Form
if (windowsCheckBox.Checked.Value)
{
var windowsZip = ZipFile.Open(windowsPath, ZipArchiveMode.Read);
if (windowsZip.Entries.All(f => f.FullName != "AM2R.exe"))
{
var result = MessageBox.Show("Modded game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return;
}
}
if (windowsZip.Entries.Any(f => f.Name == "profile.xml"))
{
var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return;
}
}
using (var saveFile = new SaveFileDialog { Title = "Save Windows mod profile", Filters = { zipFileFilter } })
{
if (saveFile.ShowDialog(this) == DialogResult.Ok)
@ -229,6 +250,29 @@ public partial class ModPacker : Form
if (linuxCheckBox.Checked.Value)
{
/*
if (!File.Exists(tempModPath + "/" + runnerName))
{ //TODO: put this onto the outer method
var result = MessageBox.Show("Modded Linux game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}
}
if (File.Exists(tempModPath + "profile.xml"))
{
//TODO: put this onto the outer method
/* var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}
}*/
using (var saveFile = new SaveFileDialog { Title = "Save Linux mod profile", Filters = { zipFileFilter } })
{
if (saveFile.ShowDialog(this) == DialogResult.Ok)
@ -249,6 +293,20 @@ public partial class ModPacker : Form
}
if (macCheckBox.Checked.Value)
{
/*if (!File.Exists(tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner"))
{
var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
if (File.Exists(tempModPath + "profile.xml"))
{
/*var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}*/
using (SaveFileDialog saveFile = new SaveFileDialog { Title = "Save Mac mod profile", Filters = { zipFileFilter } })
{
if (saveFile.ShowDialog(this) == DialogResult.Ok)

@ -14,4 +14,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="6.0.0-preview.5.21301.5" />
</ItemGroup>
</Project>

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.ComponentModel;
using System.Diagnostics;
using System.IO.Compression;
using System.Security;
using System.Security.Cryptography;
@ -22,7 +23,7 @@ public static class Core
private static readonly string localPath = Directory.GetCurrentDirectory();
// TODO: go over thhis and clean
public static (bool, string) CreateModPack(ModProfileXML profile, string input, string originalPath, string apkPath, string output)
public static (bool, string) CreateModPack(ModProfileXML profile, string originalZipPath, string modZipPath, string apkPath, string output)
{
// Cleanup in case of previous errors
if (Directory.Exists(Path.GetTempPath() + "/AM2RModPacker"))
@ -48,8 +49,8 @@ public static class Core
}
// Extract 1.1 and modded AM2R to their own directories in temp work
ZipFile.ExtractToDirectory(originalPath, tempOriginalPath);
ZipFile.ExtractToDirectory(input, tempModPath);
ZipFile.ExtractToDirectory(originalZipPath, tempOriginalPath);
ZipFile.ExtractToDirectory(modZipPath, tempModPath);
if (Directory.Exists(tempModPath + "/AM2R"))
tempModPath += "/AM2R";
@ -73,28 +74,6 @@ public static class Core
// Create AM2R.exe and data.win patches
case "Windows":
{
if (!File.Exists(tempModPath + "/AM2R.exe"))
{ //TODO: put this onto the outer method
/*
var result = MessageBox.Show("Modded game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}*/
}
if (File.Exists(tempModPath + "profile.xml"))
{
//TODO: put this onto the outer method
/*var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}*/
}
if (profile.UsesYYC)
{
CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/AM2R.exe", tempProfilePath + "/AM2R.xdelta");
@ -109,49 +88,12 @@ public static class Core
case "Linux":
{
string runnerName = File.Exists(tempModPath + "/" + "AM2R") ? "AM2R" : "runner";
if (!File.Exists(tempModPath + "/" + runnerName))
{ //TODO: put this onto the outer method
/*
var result = MessageBox.Show("Modded Linux game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}*/
}
if (File.Exists(tempModPath + "profile.xml"))
{
//TODO: put this onto the outer method
/* var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
if (result != DialogResult.Yes)
{
AbortPatch();
return (false, "");
}*/
}
CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/assets/game.unx", tempProfilePath + "/game.xdelta");
CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/" + runnerName, tempProfilePath + "/AM2R.xdelta");
break;
}
case "Mac":
{
if (!File.Exists(tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner"))
{
/*var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();*/
}
if (File.Exists(tempModPath + "profile.xml"))
{
/*var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();*/
}
CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/AM2R.app/Contents/Resources/game.ios", tempProfilePath + "/game.xdelta");
CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner", tempProfilePath + "/AM2R.xdelta");
@ -297,18 +239,24 @@ public static class Core
// Specify process start info
var parameters = new ProcessStartInfo
{
// TODO: deal with linux/mac
FileName = localPath + "/utilities/xdelta/xdelta3.exe",
FileName = OS.IsWindows ? localPath + "/utilities/xdelta/xdelta3.exe" : "xdelta3",
WorkingDirectory = localPath,
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "-f -e -s \"" + original + "\" \"" + modified + "\" \"" + output + "\""
};
// Launch process and wait for exit. using statement automatically disposes the object for us!
using var proc = new Process { StartInfo = parameters };
proc.Start();
proc.WaitForExit();
// Launch process and wait for exit.
try
{
using var proc = new Process { StartInfo = parameters };
proc.Start();
proc.WaitForExit();
}
catch (Win32Exception e)
{
throw new Exception("Xdelta3 could not be found! For Windows, make sure that the utilities folder exists, for other OS make sure it is installed and in PATH.");
}
}
public static string CalculateMD5(string filename)

@ -0,0 +1,87 @@
using System.Runtime.InteropServices;
namespace AM2RModPackerLib;
/// <summary>
/// Class that has information about the current running operating system.
/// </summary>
public static class OS
{
/// <summary>
/// Determines if the current OS is Windows.
/// </summary>
public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
/// <summary>
/// Determines if the current OS is Linux.
/// </summary>
public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
/// <summary>
/// Determines if the current OS is Mac.
/// </summary>
public static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
/// <summary>
/// Determines if the current OS is a unix based system (Mac or Linux).
/// </summary>
public static readonly bool IsUnix = IsLinux || IsMac;
/// <summary>
/// Gets a string representation of the current OS.
/// </summary>
public static readonly string Name = DetermineOsName();
/// <summary>
/// Generates a string representation of the current OS
/// </summary>
private static string DetermineOsName()
{
if (IsWindows)
return "Windows";
if (IsLinux)
return "Linux";
if (IsMac)
return "Mac";
return "Unknown OS";
}
/// <summary>
/// Checks if this is run via WINE.
/// </summary>
public static readonly bool IsThisRunningFromWINE = CheckIfRunFromWINE();
/// <summary>
/// Checks if this is run via Flatpak.
/// </summary>
public static readonly bool IsThisRunningFromFlatpak = CheckIfRunFromFlatpak();
/// <summary>
/// Checks if the Launcher is ran from WINE.
/// </summary>
/// <returns><see langword="true"/> if run from WINE, <see langword="false"/> if not.</returns>
private static bool CheckIfRunFromWINE()
{
// We check for wine by seeing if a reg entry exists.
// Not the best way, and could be removed from the future, but good enough for our purposes.
if (IsWindows && (Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null))
return true;
return false;
}
/// <summary>
/// Checks if the Launcher is ran from a Flatpak.
/// </summary>
/// <returns>see langword="true"/> if run from a Flatpak, <see langword="false"/> if not.</returns>
private static bool CheckIfRunFromFlatpak()
{
if (!IsLinux) return false;
// This file is present in all flatpaks
if (File.Exists("/.flatpak-info"))
return true;
return false;
}
}
Loading…
Cancel
Save