Skip to content

Commit

Permalink
Check if output somehow isnt corrupted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miepee committed Jan 1, 2024
1 parent 15abb80 commit 84bf463
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions GlennGUI/GlennGUI/MainForm.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -155,13 +171,23 @@ 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)
{
if (File.Exists(linuxPath))
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)
{
Expand All @@ -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!";
Expand Down

0 comments on commit 84bf463

Please sign in to comment.