dont make createModPack function return error msgs

pull/9/head
Miepee 4 years ago
parent b5e611fd3f
commit d3c5e9da58

@ -267,11 +267,15 @@ public partial class ModPacker : Form
if (!output.ToLower().EndsWith(".zip")) if (!output.ToLower().EndsWith(".zip"))
output += ".zip"; output += ".zip";
LoadProfileParameters(ProfileOperatingSystems.Windows); LoadProfileParameters(ProfileOperatingSystems.Windows);
(successful, errorCode) = Core.CreateModPack(profile, originalPath, windowsPath, apkPath, output); try
if (!successful)
{ {
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(); AbortPatch();
return;
} }
} }
@ -311,11 +315,15 @@ public partial class ModPacker : Form
if (!output.ToLower().EndsWith(".zip")) if (!output.ToLower().EndsWith(".zip"))
output += ".zip"; output += ".zip";
LoadProfileParameters(ProfileOperatingSystems.Linux); LoadProfileParameters(ProfileOperatingSystems.Linux);
(successful, errorCode) = Core.CreateModPack(profile, originalPath, linuxPath, apkPath, output); try
if (!successful) {
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(); AbortPatch();
return;
} }
} }
if (macCheckBox.Checked.Value) if (macCheckBox.Checked.Value)
@ -349,11 +357,15 @@ public partial class ModPacker : Form
if (!output.ToLower().EndsWith(".zip")) if (!output.ToLower().EndsWith(".zip"))
output += ".zip"; output += ".zip";
LoadProfileParameters(ProfileOperatingSystems.Mac); LoadProfileParameters(ProfileOperatingSystems.Mac);
(successful, errorCode) = Core.CreateModPack(profile, originalPath, macPath, apkPath, output); try
if (!successful) {
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(); AbortPatch();
return;
} }
} }
createLabel.Text = "Mod package(s) created!"; createLabel.Text = "Mod package(s) created!";

@ -33,30 +33,18 @@ public static class Core
private static readonly string localPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); private static readonly string localPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
// TODO: go over thhis and clean // 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 // Cleanup in case of previous errors
if (Directory.Exists(Path.GetTempPath() + "/AM2RModPacker")) if (Directory.Exists(Path.GetTempPath() + "/AM2RModPacker"))
Directory.Delete(Path.GetTempPath() + "/AM2RModPacker", true); Directory.Delete(Path.GetTempPath() + "/AM2RModPacker", true);
// Create temp work folders // Create temp work folders
string tempPath, string tempPath = Directory.CreateDirectory(Path.GetTempPath() + "/AM2RModPacker").FullName;
tempOriginalPath, string tempOriginalPath = Directory.CreateDirectory(tempPath + "/original").FullName;
tempModPath, string tempModPath = Directory.CreateDirectory(tempPath + "/mod").FullName;
tempProfilePath; 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 // Extract 1.1 and modded AM2R to their own directories in temp work
ZipFile.ExtractToDirectory(originalZipPath, tempOriginalPath); ZipFile.ExtractToDirectory(originalZipPath, tempOriginalPath);
@ -227,7 +215,6 @@ public static class Core
// Delete temp folder // Delete temp folder
Directory.Delete(tempPath, true); Directory.Delete(tempPath, true);
return (true, "");
} }

Loading…
Cancel
Save