Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some exceptions not being caught when they should #193

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/KKManager.Core/Data/Zipmods/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ internal static bool TryLoadFromZip(IArchive zip, out Manifest manifest)
manifest = LoadFromZip(zip);
return true;
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine($"Cannot load {zip} - {ex.Message}.");
if (!(ex is OperationCanceledException))
Expand All @@ -239,25 +239,19 @@ internal static bool TryLoadFromZip(IArchive zip, out Manifest manifest)
}
}

internal static Manifest LoadFromZip(ZipArchive zip)
internal static Manifest LoadFromZip(IArchive zip)
{
var entry = zip.Entries.FirstOrDefault(x => !x.IsDirectory && string.Equals(x.Key, "manifest.xml", StringComparison.OrdinalIgnoreCase));

return LoadFromZipInt(entry?.OpenEntryStream());
}

internal static Manifest LoadFromZip(IArchive zip)
{
var entry = zip.Entries.FirstOrDefault(x => !x.IsDirectory && x.Key == "manifest.xml");
if (entry == null)
throw new InvalidDataException("Manifest.xml is missing, make sure this is a zipmod");

return LoadFromZipInt(entry?.OpenEntryStream());
var entryStream = entry.OpenEntryStream();
return LoadFromZipInt(entryStream);
}

private static Manifest LoadFromZipInt(Stream entry)
{
if (entry == null)
throw new InvalidDataException("Manifest.xml is missing, make sure this is a zipmod");

var manifest = new Manifest(entry);

if (manifest.GUID == null)
Expand Down
2 changes: 1 addition & 1 deletion src/KKManager.Core/Data/Zipmods/SideloaderModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static SideloaderModInfo LoadFromFile(string filename)
}
}
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine($"Failed to load image \"{imgName}\" from mod archive \"{location.Name}\" with error: {ex.Message}");
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/KKManager.Core/Functions/ModInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static void InstallPlugin(string fileName)
{
newPlugs = PluginLoader.LoadFromFile(fileName).ToList();
}
catch (SystemException ex)
catch (Exception ex)
{
throw new InvalidDataException("The file is not a plugin or is broken - " + ex.Message, ex);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ private static void InstallZipmod(string fileName)
{
throw;
}
catch (SystemException ex)
catch (Exception ex)
{
throw new InvalidDataException("The file is not a zipmod or is broken - " + ex.Message, ex);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private static void InstallZipmod(string fileName)
Directory.CreateDirectory(installModDir);
newMod.Location.CopyTo(Path.Combine(installModDir, newMod.Location.Name));
}
catch (SystemException e)
catch (Exception e)
{
Console.WriteLine(e);
throw new InvalidOperationException("Failed to install zipmod file - " + e.Message, e);
Expand Down
6 changes: 5 additions & 1 deletion src/KKManager.Core/Functions/ZipmodTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static void SideloaderCleanupByManifest(IEnumerable<string> allMods)
{
mods.Add(SideloaderModLoader.LoadFromFile(mod));
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine($"Deleting zipmod file: {mod} | Reason: {ex.Message}");
// Kill it with fire
Expand Down Expand Up @@ -128,6 +128,10 @@ private static void SafeFileDelete(string file)
{
// Nom nom nom
}
catch (Exception e)
{
Console.WriteLine($"Unexpected Exception when trying to delete file: {file}\n{e.ToStringDemystified()}");
}
}
}
}
2 changes: 1 addition & 1 deletion src/KKManager.Core/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static IEnumerable<CultureInfo> GetSupportedLanguages()
{
return x.GetFiles("KKManager.resources.dll", SearchOption.TopDirectoryOnly).Any();
}
catch (SystemException e)
catch (Exception e)
{
Console.WriteLine(e);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/KKManager.Core/Util/ListTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void FastAutoResizeColumns(this ObjectListView olv)
{
olv.EndUpdate();
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine(ex);
}
Expand Down
6 changes: 6 additions & 0 deletions src/KKManager.Core/Util/ProcessTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public static Process SafeStartProcess(ProcessStartInfo startInfo, bool elevated
MessageBox.Show(ex.Message, Resources.FailedToStartApplicationMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show(ex.ToStringDemystified(), Resources.FailedToStartApplicationMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
ManlyMarco marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
}

public static Process SafeStartProcess(string filename, bool elevated = false)
Expand Down
8 changes: 7 additions & 1 deletion src/KKManager/Windows/Content/CardWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public bool TryOpenCardDirectory(string path)
OpenCardDirectory(new DirectoryInfo(path));
return true;
}
catch (SystemException ex)
catch (Exception ex)
{
ShowFailedToLoadDirError(ex);
return false;
Expand Down Expand Up @@ -334,6 +334,11 @@ private void RefreshThumbnails(bool additive = false, CharacterRange refreshRang
{
return false;
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
});
}

Expand Down Expand Up @@ -415,6 +420,7 @@ private void SetupImageLists()
}
}
catch (SystemException) { }
catch (Exception e) { Console.WriteLine(e); }
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions src/KKManager/Windows/Content/PluginsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void SetPluginsEnabled(IList<PluginInfo> plugins, bool enabled)
{
plug.SetEnabled(enabled);
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Failed to toggle active state of " + plug.Name + "\n\n" + ex.Message, "Enable/Disable plugins", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down Expand Up @@ -207,7 +207,7 @@ private void toolStripButtonOpenDir_Click(object sender, EventArgs e)
{
Process.Start(InstallDirectoryHelper.PluginPath.FullName);
}
catch (SystemException ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Failed to start application", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/KKManager/Windows/Content/SideloaderModsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void SetZipmodEnabled(bool enabled, IEnumerable<SideloaderModInfo> toCha
{
obj.SetEnabled(enabled);
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Failed to toggle active state of " + obj.Name + "\n\n" + ex.Message, "Enable/Disable zipmods", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down Expand Up @@ -148,7 +148,7 @@ private async void toolStripButtonDelete_Click(object sender, EventArgs e)
await obj.Location.SafeDelete();
objectListView1.RemoveObject(obj);
}
catch (SystemException ex)
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Failed to delete " + obj.Name + "\n\n" + ex.Message, "Delete zipmods", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand All @@ -162,7 +162,7 @@ private void toolStripButtonOpenModsDir_Click(object sender, EventArgs e)
{
Process.Start(InstallDirectoryHelper.ModsPath.FullName);
}
catch (SystemException ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Failed to start application", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Expand Down
5 changes: 3 additions & 2 deletions src/KKManager/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed partial class MainWindow : Form
{
private UpdateSourceBase[] _updateSources;
public UpdateSourceBase[] GetUpdateSources() => _updateSources ?? (_updateSources = UpdateSourceManager.FindUpdateSources(Program.ProgramLocation));

public MainWindow()
{
Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
Expand Down Expand Up @@ -111,9 +111,10 @@ private static DirectoryInfo GetGameDirectory()
try
{
path = Registry.CurrentUser.OpenSubKey(@"Software\Illusion\Koikatu\koikatu")
?.GetValue("INSTALLDIR") as string;
?.GetValue("INSTALLDIR") as string;
ManlyMarco marked this conversation as resolved.
Show resolved Hide resolved
}
catch (SystemException) { }
catch (Exception ex) { ex.ToStringDemystified(); }
}

path = ShowInstallDirectoryDialog(path);
Expand Down
Loading