diff --git a/AM2RModPacker/ModPacker.cs b/AM2RModPacker/ModPacker.cs index f696937..8517ff8 100644 --- a/AM2RModPacker/ModPacker.cs +++ b/AM2RModPacker/ModPacker.cs @@ -267,11 +267,15 @@ public partial class ModPacker : Form if (!output.ToLower().EndsWith(".zip")) output += ".zip"; LoadProfileParameters(ProfileOperatingSystems.Windows); - (successful, errorCode) = Core.CreateModPack(profile, originalPath, windowsPath, apkPath, output); - if (!successful) + try { - MessageBox.Show(errorCode, "Error", MessageBoxButtons.OK, MessageBoxType.Error); + Core.CreateModPack(profile, originalPath, windowsPath, apkPath, output); + } + catch (Exception exception) + { + MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxType.Error); AbortPatch(); + return; } } @@ -311,11 +315,15 @@ public partial class ModPacker : Form if (!output.ToLower().EndsWith(".zip")) output += ".zip"; LoadProfileParameters(ProfileOperatingSystems.Linux); - (successful, errorCode) = Core.CreateModPack(profile, originalPath, linuxPath, apkPath, output); - if (!successful) + try + { + Core.CreateModPack(profile, originalPath, linuxPath, apkPath, output); + } + catch (Exception exception) { - MessageBox.Show(errorCode, "Error", MessageBoxButtons.OK, MessageBoxType.Error); + MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxType.Error); AbortPatch(); + return; } } if (macCheckBox.Checked.Value) @@ -349,11 +357,15 @@ public partial class ModPacker : Form if (!output.ToLower().EndsWith(".zip")) output += ".zip"; LoadProfileParameters(ProfileOperatingSystems.Mac); - (successful, errorCode) = Core.CreateModPack(profile, originalPath, macPath, apkPath, output); - if (!successful) + try + { + Core.CreateModPack(profile, originalPath, macPath, apkPath, output); + } + catch (Exception exception) { - MessageBox.Show(errorCode, "Error", MessageBoxButtons.OK, MessageBoxType.Error); + MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxType.Error); AbortPatch(); + return; } } createLabel.Text = "Mod package(s) created!"; diff --git a/AM2RModPackerLib/Core.cs b/AM2RModPackerLib/Core.cs index 27c159a..44e5aa9 100644 --- a/AM2RModPackerLib/Core.cs +++ b/AM2RModPackerLib/Core.cs @@ -33,30 +33,18 @@ public static class Core private static readonly string localPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); // TODO: go over thhis and clean - public static (bool, string) CreateModPack(ModProfileXML profile, string originalZipPath, string modZipPath, string apkPath, string output) + public static void CreateModPack(ModProfileXML profile, string originalZipPath, string modZipPath, string apkPath, string output) { // Cleanup in case of previous errors if (Directory.Exists(Path.GetTempPath() + "/AM2RModPacker")) Directory.Delete(Path.GetTempPath() + "/AM2RModPacker", true); // Create temp work folders - string tempPath, - tempOriginalPath, - tempModPath, - tempProfilePath; + string tempPath = Directory.CreateDirectory(Path.GetTempPath() + "/AM2RModPacker").FullName; + string tempOriginalPath = Directory.CreateDirectory(tempPath + "/original").FullName; + string tempModPath = Directory.CreateDirectory(tempPath + "/mod").FullName; + string tempProfilePath = Directory.CreateDirectory(tempPath + "/profile").FullName; - // We might not have permission to access to the temp directory, so we need to catch the exception. - try - { - tempPath = Directory.CreateDirectory(Path.GetTempPath() + "/AM2RModPacker").FullName; - tempOriginalPath = Directory.CreateDirectory(tempPath + "/original").FullName; - tempModPath = Directory.CreateDirectory(tempPath + "/mod").FullName; - tempProfilePath = Directory.CreateDirectory(tempPath + "/profile").FullName; - } - catch (SecurityException) - { - return (false, "Could not create temp directory! Please run the application with administrator rights."); - } // Extract 1.1 and modded AM2R to their own directories in temp work ZipFile.ExtractToDirectory(originalZipPath, tempOriginalPath); @@ -227,7 +215,6 @@ public static class Core // Delete temp folder Directory.Delete(tempPath, true); - return (true, ""); }