Check if output somehow isnt corrupted.

pull/9/head
Miepee 3 years ago
parent 15abb8016f
commit 84bf4631cd

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using GlennLib; using GlennLib;
@ -146,6 +147,21 @@ public partial class MainForm : Form
string iconPath = RawMods.GetProperPathToBuiltinIcons(nameof(ResourcesLib.icon), userIconPath); string iconPath = RawMods.GetProperPathToBuiltinIcons(nameof(ResourcesLib.icon), userIconPath);
string splashPath = RawMods.GetProperPathToBuiltinIcons(nameof(ResourcesLib.splash), userSplashPath); 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 // TODO: handle when porting methods throw exception
try try
{ {
@ -155,6 +171,11 @@ public partial class MainForm : Form
File.Delete(windowsPath); File.Delete(windowsPath);
await Task.Run(() => RawMods.PortToWindows(modZipPath, windowsPath, OutputHandlerDelegate)); 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) if (checkboxLinux.Checked.Value)
{ {
@ -162,6 +183,11 @@ public partial class MainForm : Form
File.Delete(linuxPath); File.Delete(linuxPath);
await Task.Run(() => RawMods.PortToLinux(modZipPath, linuxPath, iconPath, splashPath, OutputHandlerDelegate)); 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) if (checkboxAndroid.Checked.Value)
{ {
@ -178,6 +204,11 @@ public partial class MainForm : Form
File.Delete(macPath); File.Delete(macPath);
await Task.Run(() => RawMods.PortToMac(modZipPath, macPath, iconPath, splashPath, OutputHandlerDelegate)); 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!"; labelProgress.Text = "Done!";

Loading…
Cancel
Save