diff --git a/GlennGUI/GlennGUI/MainForm.cs b/GlennGUI/GlennGUI/MainForm.cs index 975a256..bf526d0 100644 --- a/GlennGUI/GlennGUI/MainForm.cs +++ b/GlennGUI/GlennGUI/MainForm.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Runtime.InteropServices; using System.Threading.Tasks; using GlennLib; @@ -146,6 +147,21 @@ private async void ButtonPortOnClick(object sender, EventArgs e) string iconPath = RawMods.GetProperPathToBuiltinIcons(nameof(ResourcesLib.icon), userIconPath); string splashPath = RawMods.GetProperPathToBuiltinIcons(nameof(ResourcesLib.splash), userSplashPath); + bool checkIfOutputIsValid(string pathToZip) + { + bool errorThrown = false; + try + { + ZipFile.OpenRead(pathToZip); + } + catch (Exception) + { + errorThrown = true; + } + + return errorThrown; + } + // TODO: handle when porting methods throw exception try { @@ -155,6 +171,11 @@ private async void ButtonPortOnClick(object sender, EventArgs e) File.Delete(windowsPath); await Task.Run(() => RawMods.PortToWindows(modZipPath, windowsPath, OutputHandlerDelegate)); + if (!checkIfOutputIsValid(windowsPath)) + { + MessageBox.Show(this, "The Windows port output somehow got corrupted. Deleting file.", "Error", MessageBoxType.Error); + File.Delete(windowsPath); + } } if (checkboxLinux.Checked.Value) { @@ -162,6 +183,11 @@ private async void ButtonPortOnClick(object sender, EventArgs e) File.Delete(linuxPath); await Task.Run(() => RawMods.PortToLinux(modZipPath, linuxPath, iconPath, splashPath, OutputHandlerDelegate)); + if (!checkIfOutputIsValid(linuxPath)) + { + MessageBox.Show(this, "The Linux port output somehow got corrupted. Deleting file.", "Error", MessageBoxType.Error); + File.Delete(windowsPath); + } } if (checkboxAndroid.Checked.Value) { @@ -178,6 +204,11 @@ private async void ButtonPortOnClick(object sender, EventArgs e) File.Delete(macPath); await Task.Run(() => RawMods.PortToMac(modZipPath, macPath, iconPath, splashPath, OutputHandlerDelegate)); + if (!checkIfOutputIsValid(macPath)) + { + MessageBox.Show(this, "The Mac port output somehow got corrupted. Deleting file.", "Error", MessageBoxType.Error); + File.Delete(windowsPath); + } } labelProgress.Text = "Done!";