Skip to content

Commit e658ad7

Browse files
Explicit error messages, attempt to fix branching issue.
1 parent 41d88af commit e658ad7

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

Handlers/MessageHandler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public static void errorMessage(string title, string caption) {
1414
Style = Style.None
1515
}).Show();
1616
}
17+
18+
public static void warnMessage(string title, string caption) {
19+
MessageBoxManager.GetMessageBoxStandardWindow(new MessageBoxStandardParams {
20+
ButtonDefinitions = ButtonEnum.Ok,
21+
ContentTitle = $"Warning: {title}",
22+
ContentMessage = caption,
23+
Icon = Icon.Warning,
24+
Style = Style.None
25+
}).Show();
26+
}
1727

1828
public static Task<ButtonResult> yesNoMessage(string title, string caption) {
1929
return MessageBoxManager.GetMessageBoxStandardWindow(new MessageBoxStandardParams {

Util.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Runtime.InteropServices;
56
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
@@ -21,7 +22,7 @@ public static void initializePatcher(string baseROMConfigurationPath, string con
2122
gameInfo = GameInformation.getGameConfiguration(patcher.getGameCode());
2223
try {
2324
if (!CommandUpdateHandler.fetchScriptCommands()) {
24-
throw new Exception("Something is wrong!");
25+
throw new Exception("Something went wrong when fetching commands!");
2526
}
2627
}
2728
catch (Exception e) {
@@ -45,7 +46,7 @@ public static void scriptToAssembler(string path, string game, string script, in
4546
}
4647
}
4748

48-
private static void subprocess(string program, string args) {
49+
private static string subprocess(string program, string args) {
4950
var proc = new Process();
5051
proc.StartInfo = new ProcessStartInfo {
5152
FileName = program,
@@ -55,21 +56,29 @@ private static void subprocess(string program, string args) {
5556
CreateNoWindow = true
5657
};
5758

58-
proc.Start();
59+
if (!proc.Start()) {
60+
return
61+
$"Error: Program \"{program}\" was not found.\n" +
62+
"If this is one of the arm executables and you are not on Windows, make sure you have arm-none-eabi-binutils installed (and in your path), and try again.\n" +
63+
"If this is one of the arm executables and you are a Windows user, make sure arm-none-eabi-as and arm-none-eabi-objcopy are in the same folder as SwissArmyKnife, or in a location referred to by your system path.";
64+
}
65+
66+
StringBuilder Str = new StringBuilder();
67+
while (!proc.StandardOutput.EndOfStream) {
68+
Str.Append(proc.StandardOutput.ReadLine());
69+
}
70+
5971
proc.WaitForExit();
6072

61-
var errorOutput = proc.StandardError.ReadToEnd();
62-
63-
if (proc.ExitCode != 0)
64-
throw new Exception(errorOutput);
73+
return Str.ToString();
6574
}
6675

67-
public static void assembler(string path, string output) {
68-
subprocess("arm-none-eabi-as", $"-mthumb -c \"{path}\" -o \"{output}\"");
76+
public static string assembler(string path, string output) {
77+
return subprocess("arm-none-eabi-as", $"-mthumb -c \"{path}\" -o \"{output}\"");
6978
}
7079

71-
public static void objectCopy(string path, string output) {
72-
subprocess("arm-none-eabi-objcopy", $"-O binary \"{path}\" \"{output}\"");
80+
public static string objectCopy(string path, string output) {
81+
return subprocess("arm-none-eabi-objcopy", $"-O binary \"{path}\" \"{output}\"");
7382
}
7483

7584
private static async Task<string> handleFolderFileChoice(bool saving, bool isFile, Window parentInstance,
@@ -83,7 +92,7 @@ private static async Task<string> handleFolderFileChoice(bool saving, bool isFil
8392
string[] resultArray =
8493
await new OpenFileDialog {Filters = dialogFilter, AllowMultiple = false}.ShowAsync(
8594
parentInstance);
86-
result = resultArray.Length != 0 ? resultArray[0] : null;
95+
result = resultArray != null && resultArray.Length != 0 ? resultArray[0] : null;
8796
}
8897
}
8998
else {

ViewModels/Editors/ScriptEditorViewModel.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using BeaterLibrary;
66
using BeaterLibrary.Formats.Scripts;
77
using ReactiveUI;
8+
using SwissArmyKnife.Avalonia.Handlers;
89
using SwissArmyKnife.Avalonia.Utils;
910

1011
namespace SwissArmyKnife.Avalonia.ViewModels.Editors {
@@ -46,7 +47,7 @@ private void changeScript(int index) {
4647
));
4748
}
4849
catch (Exception ex) {
49-
textDoc.Text = "Something went wrong when decompiling this script.";
50+
textDoc.Text = "Something went wrong when decompiling this script.\n" + ex;
5051
}
5152
}
5253

@@ -65,10 +66,21 @@ public override void onSaveChanges() {
6566
_selectedIndex,
6667
x => {
6768
UI.patcher.saveToNarcFolder(UI.gameInfo.scripts, selectedIndex, x => {
68-
UI.scriptToAssembler("Temp.s", UI.gameInfo.title, textDoc.Text,
69-
UI.gameInfo.getScriptPluginsByScrId(selectedIndex));
70-
UI.assembler("Temp.s", "Temp.o");
71-
UI.objectCopy("Temp.o", x);
69+
UI.scriptToAssembler("Temp.s", UI.gameInfo.title, textDoc.Text, UI.gameInfo.getScriptPluginsByScrId(selectedIndex));
70+
71+
// Hacky way to detect errors.
72+
string ASResult = UI.assembler("Temp.s", "Temp.o");
73+
MessageHandler.warnMessage("Assembler output", $"If you see any errors here, there was a compilation error, and the file was not created.\nThe output is as follows:\n\n{ASResult}");
74+
if (ASResult.Contains("Error")) {
75+
return;
76+
}
77+
78+
string OBJResult = UI.objectCopy("Temp.o", x);
79+
MessageHandler.warnMessage("Objcopy output", $"If you see any errors here, there was a linking error, and the file was not created.\nThe output is as follows:\n\n{OBJResult}");
80+
if (OBJResult.Contains("Error")) {
81+
return;
82+
}
83+
7284
File.Delete("Temp.s");
7385
File.Delete("Temp.o");
7486
});

ViewModels/Editors/WildPokemonViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void changeWildContainer(int index) {
115115
}
116116
}
117117
catch (Exception ex) {
118-
MessageHandler.errorMessage("Invalid wild encounter container", "This file is invalid.");
118+
MessageHandler.errorMessage("Invalid wild encounter container", "This file is invalid.\n" + ex.ToString());
119119
}
120120
}
121121

ViewModels/Editors/ZoneEntitiesViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public override void onSaveChanges() {
156156
currentZoneEntities.triggers = new List<Trigger>(triggers);
157157
currentZoneEntities.initializationScripts = new List<InitializationScript>(initScripts);
158158
currentZoneEntities.triggerRelatedEntries = new List<TriggerRelated>(triggerRelated);
159+
// currentZoneEntities.serialize();
159160
}
160161
}
161162
}

ViewModels/NewProjectViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public NewProjectViewModel(baseROMConfiguration baseROMs, Window instance) {
6565
UI.patcher.handleROM(false);
6666
}
6767
catch (Exception ex) {
68-
MessageHandler.errorMessage("Initialization Error", ex.Message);
68+
MessageHandler.errorMessage("Initialization Error", ex.ToString());
6969
}
7070
}
7171
}
@@ -112,7 +112,7 @@ private bool createProjectStructure() {
112112
return true;
113113
}
114114
catch (Exception e) {
115-
MessageHandler.errorMessage("Project Creation", $"Failed to create project. \"{e.Message}\"");
115+
MessageHandler.errorMessage("Project Creation", $"Failed to create project. \"{e}\"");
116116
return false;
117117
}
118118
}

0 commit comments

Comments
 (0)