From 7d77decf179f16e01893190b19194aecbb55fe60 Mon Sep 17 00:00:00 2001 From: Dagg <32235163+daggintosh@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:26:15 -0700 Subject: [PATCH] Swap out the custom message boxes with the stock Eto MessageBox (#29) * Use regex to discover existing server urls - Supports LBP PSP and PS3 - Hardcoded length limit, will fix soonTM * Get maximum length for server URL from EBOOT * Potential fix for LBP3 - Matches all but NULL instead of just all * Potentially extend maximum length Thanks slendy * Leave a NULL character of padding * Use stock eto message boxes instead of custom. * Use Information message box type Ding may be strange but this process takes a while sometimes --- UnionPatcher.Gui/Forms/FilePatchForm.cs | 29 ++++++++++------ UnionPatcher.Gui/Forms/RemotePatchForm.cs | 20 ++++++------ UnionPatcher.Gui/Gui.cs | 40 ++++------------------- 3 files changed, 35 insertions(+), 54 deletions(-) diff --git a/UnionPatcher.Gui/Forms/FilePatchForm.cs b/UnionPatcher.Gui/Forms/FilePatchForm.cs index 27e9fa8..e5ea839 100644 --- a/UnionPatcher.Gui/Forms/FilePatchForm.cs +++ b/UnionPatcher.Gui/Forms/FilePatchForm.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Text.RegularExpressions; using Eto; using Eto.Drawing; using Eto.Forms; @@ -73,46 +74,54 @@ public class FilePatchForm : Form { private void Patch() { if(string.IsNullOrWhiteSpace(this.filePicker.FilePath)) { - Gui.CreateOkDialog("Form Error", "No file specified!").ShowModal(); + Gui.CreateOkDialog("Form Error", "No file specified!"); return; } if(string.IsNullOrWhiteSpace(this.serverUrl.Text)) { - Gui.CreateOkDialog("Form Error", "No server URL specified!").ShowModal(); + Gui.CreateOkDialog("Form Error", "No server URL specified!"); return; } if(string.IsNullOrWhiteSpace(this.outputFileName.FilePath)) { - Gui.CreateOkDialog("Form Error", "No output file specified!").ShowModal(); + Gui.CreateOkDialog("Form Error", "No output file specified!"); return; } if(this.filePicker.FilePath == this.outputFileName.FilePath) { - Gui.CreateOkDialog("Form Error", "Input and output filename are the same! Please save the patched file with a different name so you have a backup of your the original EBOOT.ELF.").ShowModal(); + Gui.CreateOkDialog("Form Error", "Input and output filename are the same! Please save the patched file with a different name so you have a backup of your the original EBOOT.ELF."); return; } if(!Uri.TryCreate(this.serverUrl.Text, UriKind.Absolute, out _)) { - Gui.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL.").ShowModal(); + Gui.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL."); return; } + + if(!Regex.IsMatch(this.serverUrl.Text, "LITTLEBIGPLANETPS3_XML")) { + bool userCertain = Gui.CreateConfirmationDialog("URL Mistype", $"Server URL {this.serverUrl.Text} does not match LITTLEBIGPLANETPS3_XML, are you sure you want to use this?"); + if (!userCertain) { + return; + } + // else, godspeed, captain + } // Validate EBOOT after validating form; more expensive ElfFile eboot = new(this.filePicker.FilePath); if(eboot.IsValid == false) { - Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)\n" + "The EBOOT must be decrypted before using this tool").ShowModal(); + Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)\n" + "The EBOOT must be decrypted before using this tool"); return; } if(eboot.Is64Bit == null) { - Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system").ShowModal(); + Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system"); return; } if(string.IsNullOrWhiteSpace(eboot.Architecture)) { - Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal(); + Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)"); return; } @@ -120,10 +129,10 @@ public class FilePatchForm : Form { Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath); } catch(Exception e) { - Gui.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal(); + Gui.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e); return; } - Gui.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text).ShowModal(); + Gui.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text); } } \ No newline at end of file diff --git a/UnionPatcher.Gui/Forms/RemotePatchForm.cs b/UnionPatcher.Gui/Forms/RemotePatchForm.cs index 1e84400..7354ea9 100644 --- a/UnionPatcher.Gui/Forms/RemotePatchForm.cs +++ b/UnionPatcher.Gui/Forms/RemotePatchForm.cs @@ -34,25 +34,25 @@ public class RemotePatchForm : Form control.Click += delegate { if (string.IsNullOrEmpty(this.ps3LocalIP.Text)) { - Gui.CreateOkDialog("Error", "No PS3 IP address specified!").ShowModal(); + Gui.CreateOkDialog("Error", "No PS3 IP address specified!"); return; } if (string.IsNullOrEmpty(this.lbpGameID.Text)) { - Gui.CreateOkDialog("Error", "No title ID specified!").ShowModal(); + Gui.CreateOkDialog("Error", "No title ID specified!"); return; } if (string.IsNullOrEmpty(this.serverUrl.Text)) { - Gui.CreateOkDialog("Error", "No server URL specified!").ShowModal(); + Gui.CreateOkDialog("Error", "No server URL specified!"); return; } if (!Uri.TryCreate(this.serverUrl.Text, UriKind.Absolute, out _)) { - Gui.CreateOkDialog("Error", "Server URL is invalid! Please enter a valid URL.").ShowModal(); + Gui.CreateOkDialog("Error", "Server URL is invalid! Please enter a valid URL."); return; } @@ -69,11 +69,11 @@ public class RemotePatchForm : Form } catch (Exception e) { - Gui.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal(); + Gui.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e); return; } - Gui.CreateOkDialog("Success!", $"The Server URL for {this.lbpGameID.Text} on the PS3 at {this.ps3LocalIP.Text} has been patched to {this.serverUrl.Text}").ShowModal(); + Gui.CreateOkDialog("Success!", $"The Server URL for {this.lbpGameID.Text} on the PS3 at {this.ps3LocalIP.Text} has been patched to {this.serverUrl.Text}"); }; return control; @@ -91,13 +91,13 @@ public class RemotePatchForm : Form control.Click += delegate { if (string.IsNullOrEmpty(this.ps3LocalIP.Text)) { - Gui.CreateOkDialog("Form Error", "No PS3 IP address specified!").ShowModal(); + Gui.CreateOkDialog("Form Error", "No PS3 IP address specified!"); return; } if (string.IsNullOrEmpty(this.lbpGameID.Text)) { - Gui.CreateOkDialog("Form Error", "No game ID specified!").ShowModal(); + Gui.CreateOkDialog("Form Error", "No game ID specified!"); return; } @@ -107,11 +107,11 @@ public class RemotePatchForm : Form } catch (Exception e) { - Gui.CreateOkDialog("Error occurred while reverting EBOOT", "An error occured while patching:\n" + e).ShowModal(); + Gui.CreateOkDialog("Error occurred while reverting EBOOT", "An error occured while patching:\n" + e); return; } - Gui.CreateOkDialog("Success!", $"UnionRemotePatcher reverted your the EBOOT for {this.lbpGameID.Text} to stock. You're ready to patch your EBOOT again.").ShowModal(); + Gui.CreateOkDialog("Success!", $"UnionRemotePatcher reverted your the EBOOT for {this.lbpGameID.Text} to stock. You're ready to patch your EBOOT again."); }; return control; diff --git a/UnionPatcher.Gui/Gui.cs b/UnionPatcher.Gui/Gui.cs index 9a62e51..808094f 100644 --- a/UnionPatcher.Gui/Gui.cs +++ b/UnionPatcher.Gui/Gui.cs @@ -9,39 +9,11 @@ public static class Gui { new Application().Run(new ModeSelectionForm()); } - public static Dialog CreateOkDialog(string title, string errorMessage) { - DynamicLayout layout = new(); - Button button; - - layout.Spacing = new Size(5, 5); - layout.MinimumSize = new Size(350, 100); - - layout.BeginHorizontal(); - layout.Add(new Label { - Text = errorMessage, - }); - - layout.BeginHorizontal(); - layout.BeginVertical(); - layout.Add(null); - layout.Add(button = new Button { - Text = "OK", - }); - - layout.EndVertical(); - layout.EndHorizontal(); - layout.EndHorizontal(); - - Dialog dialog = new() { - Content = layout, - Padding = new Padding(10, 10, 10, 10), - Title = title, - }; - - button.Click += delegate { - dialog.Close(); - }; - - return dialog; + public static void CreateOkDialog(string title, string errorMessage) { + MessageBox.Show(errorMessage, title, MessageBoxButtons.OK, MessageBoxType.Information); + } + public static bool CreateConfirmationDialog(string title, string errorMessage) { + DialogResult result = MessageBox.Show(errorMessage, title, MessageBoxButtons.YesNo, MessageBoxType.Question); + return result == DialogResult.Yes; } } \ No newline at end of file