mirror of
https://github.com/LBPUnion/UnionPatcher.git
synced 2025-04-28 23:39:03 +00:00
Move patch delegate to function
This commit is contained in:
parent
281ddc2117
commit
a90da4e7b3
1 changed files with 62 additions and 55 deletions
|
@ -7,6 +7,7 @@ using Eto.Forms;
|
||||||
|
|
||||||
namespace LBPUnion.UnionPatcher.Gui {
|
namespace LBPUnion.UnionPatcher.Gui {
|
||||||
public class MainForm : Form {
|
public class MainForm : Form {
|
||||||
|
#region UI
|
||||||
private readonly FilePicker filePicker;
|
private readonly FilePicker filePicker;
|
||||||
private readonly TextBox serverUrl;
|
private readonly TextBox serverUrl;
|
||||||
private readonly FilePicker outputFileName;
|
private readonly FilePicker outputFileName;
|
||||||
|
@ -52,61 +53,7 @@ namespace LBPUnion.UnionPatcher.Gui {
|
||||||
TabIndex = tabIndex,
|
TabIndex = tabIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
control.Click += delegate {
|
control.Click += Patch;
|
||||||
if(string.IsNullOrWhiteSpace(this.filePicker.FilePath)) {
|
|
||||||
this.CreateOkDialog("Form Error", "No file specified!").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(this.serverUrl.Text)) {
|
|
||||||
this.CreateOkDialog("Form Error", "No server URL specified!").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(this.outputFileName.FilePath)) {
|
|
||||||
this.CreateOkDialog("Form Error", "No output file specified!").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ElfFile eboot = new(this.filePicker.FilePath);
|
|
||||||
|
|
||||||
if(eboot.IsValid == false) {
|
|
||||||
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)\nThe EBOOT must be decrypted before using this tool").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(eboot.Is64Bit == null) {
|
|
||||||
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
|
||||||
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filePicker.FilePath == this.outputFileName.FilePath)
|
|
||||||
{
|
|
||||||
this.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();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Uri.TryCreate(this.serverUrl.Text, UriKind.Absolute, out _))
|
|
||||||
{
|
|
||||||
this.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL.").ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath);
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
this.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text).ShowModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
@ -154,5 +101,65 @@ namespace LBPUnion.UnionPatcher.Gui {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
private void Patch(object sender, EventArgs e) {
|
||||||
|
this.Patch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Patch() {
|
||||||
|
if(string.IsNullOrWhiteSpace(this.filePicker.FilePath)) {
|
||||||
|
this.CreateOkDialog("Form Error", "No file specified!").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(this.serverUrl.Text)) {
|
||||||
|
this.CreateOkDialog("Form Error", "No server URL specified!").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(this.outputFileName.FilePath)) {
|
||||||
|
this.CreateOkDialog("Form Error", "No output file specified!").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.filePicker.FilePath == this.outputFileName.FilePath) {
|
||||||
|
this.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();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Uri.TryCreate(this.serverUrl.Text, UriKind.Absolute, out _)) {
|
||||||
|
this.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL.").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate EBOOT after validating form; more expensive
|
||||||
|
|
||||||
|
ElfFile eboot = new(this.filePicker.FilePath);
|
||||||
|
|
||||||
|
if(eboot.IsValid == false) {
|
||||||
|
this.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();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(eboot.Is64Bit == null) {
|
||||||
|
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
|
||||||
|
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
this.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text).ShowModal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue