@ -4,16 +4,15 @@ using System.IO.Compression;
using System.Linq ;
using System.Text.RegularExpressions ;
using AM2RModPackerLib ;
using AM2RModPackerLib.XML ;
using Eto.Forms ;
namespace AM2RModPacker ;
public partial class ModPacker : Form
{
private static readonly string version = Core . Version ;
private const string version = Core . Version ;
private ModCreationInfo mod i nfo = new ModCreationInfo ( ) ;
private ModCreationInfo mod I nfo = new ModCreationInfo ( ) ;
private readonly FileFilter zipFileFilter = new FileFilter ( "zip archives (*.zip)" , ".zip" ) ;
private readonly FileFilter apkFileFilter = new FileFilter ( "Android application packages (*.apk)" , ".apk" ) ;
@ -44,6 +43,7 @@ public partial class ModPacker : Form
initialDir = $@"{home}/Library/Application Support/" ;
dialog . Directory = initialDir ;
string saveFolderPath = null ;
while ( ! wasSuccessful )
{
if ( dialog . ShowDialog ( this ) = = DialogResult . Ok )
@ -61,31 +61,28 @@ public partial class ModPacker : Form
else
{
wasSuccessful = true ;
string saveFile Path = dialog . Directory . Replace ( match . Value , "%localappdata%/" ) ;
saveFolder Path = dialog . Directory . Replace ( match . Value , "%localappdata%/" ) ;
// If we don't do this, custom save locations are going to fail on Linux
if ( OS . IsWindows )
saveF ilePath = saveFile Path. Replace ( "\\" , "/" ) ;
saveF olderPath = saveFolder Path. Replace ( "\\" , "/" ) ;
// On Mac, we need to adjust the path
if ( OS . IsMac )
saveF ilePath = saveFile Path. Replace ( "com.yoyogames.am2r" , "AM2R" ) ;
saveF olderPath = saveFolder Path. Replace ( "com.yoyogames.am2r" , "AM2R" ) ;
// if someone has a custom save path inside of am2r and creates these whithin game maker, they will always be lower case
// we need to adjust them here to lowercase as well, as otherwise launcher gets problems on nix systems
const string vanillaPrefix = "%localappdata%/AM2R/" ;
if ( saveFilePath . Contains ( vanillaPrefix ) )
saveFilePath = vanillaPrefix + saveFilePath . Substring ( vanillaPrefix . Length ) . ToLower ( ) ;
modinfo . SaveFolderPath = saveFilePath ;
if ( saveFolderPath . Contains ( vanillaPrefix ) )
saveFolderPath = vanillaPrefix + saveFolderPath . Substring ( vanillaPrefix . Length ) . ToLower ( ) ;
}
}
else
{
wasSuccessful = true ;
modinfo . SaveFolderPath = null ;
}
}
customSaveTextBox . Text = modinfo. S aveFolderPath;
customSaveTextBox . Text = s aveFolderPath;
}
private void YYCCheckBox_CheckedChanged ( object sender , EventArgs e )
@ -97,9 +94,10 @@ public partial class ModPacker : Form
macCheckBox . Checked = false ;
macLabel . Visible = false ;
macButton . Enabled = false ;
mod i nfo. MacModPath = null ;
mod I nfo. MacModPath = null ;
}
// TODO: replace checked changed and click with a generic method to avoid copy paste
private void WindowsCheckBox_CheckedChanged ( object sender , EventArgs e )
{
windowsButton . Enabled = windowsCheckBox . Checked . Value ;
@ -107,7 +105,7 @@ public partial class ModPacker : Form
if ( ! windowsCheckBox . Checked . Value )
{
windowsLabel . Visible = false ;
mod i nfo. WindowsModPath = null ;
mod I nfo. WindowsModPath = null ;
}
UpdateCreateButton ( ) ;
}
@ -115,8 +113,8 @@ public partial class ModPacker : Form
private void WindowsButton_Click ( object sender , EventArgs e )
{
// Open window to select modded Linux .zip
mod i nfo. WindowsModPath = SelectFile ( "Please select your custom Windows AM2R .zip" , zipFileFilter ) ;
windowsLabel . Visible = mod i nfo. IsWindowsModLoaded ;
mod I nfo. WindowsModPath = SelectFile ( "Please select your custom Windows AM2R .zip" , zipFileFilter ) ;
windowsLabel . Visible = mod I nfo. IsWindowsModLoaded ;
UpdateCreateButton ( ) ;
}
@ -127,7 +125,7 @@ public partial class ModPacker : Form
if ( ! apkCheckBox . Checked . Value )
{
apkLabel . Visible = false ;
mod i nfo. ApkModPath = null ;
mod I nfo. ApkModPath = null ;
}
UpdateCreateButton ( ) ;
}
@ -135,8 +133,8 @@ public partial class ModPacker : Form
private void ApkButton_Click ( object sender , EventArgs e )
{
// Open window to select modded AM2R APK
mod i nfo. ApkModPath = SelectFile ( "Please select your custom AM2R .apk" , apkFileFilter ) ;
apkLabel . Visible = mod i nfo. IsApkModLoaded ;
mod I nfo. ApkModPath = SelectFile ( "Please select your custom AM2R .apk" , apkFileFilter ) ;
apkLabel . Visible = mod I nfo. IsApkModLoaded ;
UpdateCreateButton ( ) ;
}
@ -147,7 +145,7 @@ public partial class ModPacker : Form
if ( ! linuxCheckBox . Checked . Value )
{
linuxLabel . Visible = false ;
mod i nfo. LinuxModPath = null ;
mod I nfo. LinuxModPath = null ;
}
UpdateCreateButton ( ) ;
}
@ -155,8 +153,8 @@ public partial class ModPacker : Form
private void LinuxButton_Click ( object sender , EventArgs e )
{
// Open window to select modded Linux .zip
mod i nfo. LinuxModPath = SelectFile ( "Please select your custom Linux AM2R .zip" , zipFileFilter ) ;
linuxLabel . Visible = mod i nfo. IsLinuxModLoaded ;
mod I nfo. LinuxModPath = SelectFile ( "Please select your custom Linux AM2R .zip" , zipFileFilter ) ;
linuxLabel . Visible = mod I nfo. IsLinuxModLoaded ;
UpdateCreateButton ( ) ;
}
@ -169,7 +167,7 @@ public partial class ModPacker : Form
if ( ! macCheckBox . Checked . Value )
{
macLabel . Visible = false ;
mod i nfo. MacModPath = null ;
mod I nfo. MacModPath = null ;
}
UpdateCreateButton ( ) ;
}
@ -183,16 +181,16 @@ public partial class ModPacker : Form
private void macButton_Click ( object sender , EventArgs e )
{
// Open window to select modded Mac .zip
mod i nfo. MacModPath = SelectFile ( "Please select your custom Mac AM2R .zip" , zipFileFilter ) ;
macLabel . Visible = mod i nfo. IsMacModLoaded ;
mod I nfo. MacModPath = SelectFile ( "Please select your custom Mac AM2R .zip" , zipFileFilter ) ;
macLabel . Visible = mod I nfo. IsMacModLoaded ;
UpdateCreateButton ( ) ;
}
private void OriginalZipButton_Click ( object sender , EventArgs e )
{
// Open window to select AM2R 1.1
mod i nfo. AM2R11Path = SelectFile ( "Please select AM2R_11.zip" , zipFileFilter ) ;
originalZipLabel . Visible = mod i nfo. IsAM2R11Loaded ;
mod I nfo. AM2R11Path = SelectFile ( "Please select AM2R_11.zip" , zipFileFilter ) ;
originalZipLabel . Visible = mod I nfo. IsAM2R11Loaded ;
UpdateCreateButton ( ) ;
}
@ -211,7 +209,7 @@ public partial class ModPacker : Form
}
// Verify 1.1
var result11 = Core . CheckIfZipIsAM2R11 ( mod i nfo. AM2R11Path ) ;
var result11 = Core . CheckIfZipIsAM2R11 ( mod I nfo. AM2R11Path ) ;
if ( result11 ! = IsZipAM2R11ReturnCodes . Successful )
{
MessageBox . Show ( "AM2R 1.1 zip is invalid! Error code: " + result11 ) ;
@ -226,9 +224,9 @@ public partial class ModPacker : Form
{
string modZipPath = os switch
{
ProfileOperatingSystems . Windows = > mod i nfo. WindowsModPath ,
ProfileOperatingSystems . Linux = > mod i nfo. LinuxModPath ,
ProfileOperatingSystems . Mac = > mod i nfo. MacModPath ,
ProfileOperatingSystems . Windows = > mod I nfo. WindowsModPath ,
ProfileOperatingSystems . Linux = > mod I nfo. LinuxModPath ,
ProfileOperatingSystems . Mac = > mod I nfo. MacModPath ,
_ = > null
} ;
string output ;
@ -249,7 +247,7 @@ public partial class ModPacker : Form
LoadProfileParameters ( os ) ;
try
{
Core . CreateModPack ( mod info. Profile , modinfo . AM2R11Path , modZipPath , modi nfo. ApkModPath , output ) ;
Core . CreateModPack ( mod Info. Profile , modInfo . AM2R11Path , modZipPath , modI nfo. ApkModPath , output ) ;
}
catch ( Exception exception )
{
@ -273,7 +271,7 @@ public partial class ModPacker : Form
if ( windowsCheckBox . Checked . Value )
{
var windowsZip = ZipFile . Open ( mod i nfo. WindowsModPath , ZipArchiveMode . Read ) ;
var windowsZip = ZipFile . Open ( mod I nfo. WindowsModPath , 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 ) ;
@ -293,7 +291,7 @@ public partial class ModPacker : Form
if ( linuxCheckBox . Checked . Value )
{
var linuxZip = ZipFile . Open ( mod i nfo. LinuxModPath , ZipArchiveMode . Read ) ;
var linuxZip = ZipFile . Open ( mod I nfo. LinuxModPath , ZipArchiveMode . Read ) ;
if ( linuxZip . Entries . All ( f = > f . FullName ! = "AM2R" ) & & linuxZip . Entries . All ( f = > f . FullName ! = "runner" ) )
{
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 ) ;
@ -312,7 +310,7 @@ public partial class ModPacker : Form
}
if ( macCheckBox . Checked . Value )
{
var macZip = ZipFile . Open ( mod i nfo. MacModPath , ZipArchiveMode . Read ) ;
var macZip = ZipFile . Open ( mod I nfo. MacModPath , ZipArchiveMode . Read ) ;
if ( macZip . Entries . All ( f = > f . Name ! = "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 , MessageBoxType . Warning ) ;
@ -332,26 +330,26 @@ public partial class ModPacker : Form
private void LoadProfileParameters ( ProfileOperatingSystems operatingSystem )
{
mod i nfo. Profile . Name = nameTextBox . Text ;
mod i nfo. Profile . Author = authorTextBox . Text ;
mod i nfo. Profile . Version = versionTextBox . Text ;
mod i nfo. Profile . UsesCustomMusic = musicCheckBox . Checked . Value ;
mod i nfo. Profile . UsesYYC = yycCheckBox . Checked . Value ;
mod i nfo. Profile . SupportsAndroid = apkCheckBox . Checked . Value ;
mod i nfo. Profile . ProfileNotes = modNotesTextBox . Text ;
mod i nfo. Profile . OperatingSystem = operatingSystem . ToString ( ) ;
if ( customSaveCheckBox . Checked . Value & & customSaveTextBox . Text ! = "" )
mod i nfo. Profile . SaveLocation = customSaveTextBox . Text ;
mod I nfo. Profile . Name = nameTextBox . Text ;
mod I nfo. Profile . Author = authorTextBox . Text ;
mod I nfo. Profile . Version = versionTextBox . Text ;
mod I nfo. Profile . UsesCustomMusic = musicCheckBox . Checked . Value ;
mod I nfo. Profile . UsesYYC = yycCheckBox . Checked . Value ;
mod I nfo. Profile . SupportsAndroid = apkCheckBox . Checked . Value ;
mod I nfo. Profile . ProfileNotes = modNotesTextBox . Text ;
mod I nfo. Profile . OperatingSystem = operatingSystem . ToString ( ) ;
if ( customSaveCheckBox . Checked . Value & & ! String . IsNullOrWhiteSpace ( customSaveTextBox . Text ) )
mod I nfo. Profile . SaveLocation = customSaveTextBox . Text ;
else
mod i nfo. Profile . SaveLocation = "%localappdata%/AM2R" ;
mod I nfo. Profile . SaveLocation = "%localappdata%/AM2R" ;
if ( operatingSystem = = ProfileOperatingSystems . Linux )
mod info. Profile . SaveLocation = modi nfo. Profile . SaveLocation . Replace ( "%localappdata%" , "~/.config" ) ;
mod Info. Profile . SaveLocation = modI nfo. Profile . SaveLocation . Replace ( "%localappdata%" , "~/.config" ) ;
else if ( operatingSystem = = ProfileOperatingSystems . Mac )
{
if ( mod i nfo. Profile . SaveLocation . Contains ( "%localappdata%/AM2R" ) )
mod info. Profile . SaveLocation = modi nfo. Profile . SaveLocation . Replace ( "%localappdata%/AM2R" , "~/Library/Application Support/com.yoyogames.am2r" ) ;
if ( mod I nfo. Profile . SaveLocation . Contains ( "%localappdata%/AM2R" ) )
mod Info. Profile . SaveLocation = modI nfo. Profile . SaveLocation . Replace ( "%localappdata%/AM2R" , "~/Library/Application Support/com.yoyogames.am2r" ) ;
else
mod i nfo. Profile . SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo ( mod i nfo. Profile . SaveLocation ) . Name . ToLower ( ) ;
mod I nfo. Profile . SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo ( mod I nfo. Profile . SaveLocation ) . Name . ToLower ( ) ;
}
}
@ -367,12 +365,12 @@ public partial class ModPacker : Form
private void UpdateCreateButton ( )
{
if ( mod i nfo. IsAM2R11Loaded & & // AM2R_11 zip must be provided
( ! windowsCheckBox . Checked . Value | | mod i nfo. IsWindowsModLoaded ) & & // either Windows is disabled OR windows is provided
( ! apkCheckBox . Checked . Value | | mod i nfo. IsApkModLoaded ) & & // either APK is disabled OR APK is provided
( ! linuxCheckBox . Checked . Value | | mod i nfo. IsLinuxModLoaded ) & & // either Linux is disabled OR linux is provided
( ! macCheckBox . Checked . Value | | mod i nfo. IsMacModLoaded ) & & // either Mac is disabled OR mac is provided
( mod info. IsWindowsModLoaded | | modinfo . IsLinuxModLoaded | | modi nfo. IsMacModLoaded ) & & // one desktop OS has to be selected
if ( mod I nfo. IsAM2R11Loaded & & // AM2R_11 zip must be provided
( ! windowsCheckBox . Checked . Value | | mod I nfo. IsWindowsModLoaded ) & & // either Windows is disabled OR windows is provided
( ! apkCheckBox . Checked . Value | | mod I nfo. IsApkModLoaded ) & & // either APK is disabled OR APK is provided
( ! linuxCheckBox . Checked . Value | | mod I nfo. IsLinuxModLoaded ) & & // either Linux is disabled OR linux is provided
( ! macCheckBox . Checked . Value | | mod I nfo. IsMacModLoaded ) & & // either Mac is disabled OR mac is provided
( mod Info. IsWindowsModLoaded | | modInfo . IsLinuxModLoaded | | modI nfo. IsMacModLoaded ) & & // one desktop OS has to be selected
( ! customSaveCheckBox . Checked . Value | | customSaveTextBox . Text ! = "" ) ) // either custom saves are disabled OR custom save is provided
createButton . Enabled = true ;
else