Skip to content

Commit

Permalink
Also log short summary of first two errors to player if /compile or /…
Browse files Browse the repository at this point in the history
…pcompile fails
  • Loading branch information
UnknownShadow200 committed Mar 5, 2020
1 parent 84cf737 commit 005f395
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Scripting/CmdCompile.cs
Expand Up @@ -44,7 +44,7 @@ public sealed class CmdCompile : Command2 {

if (!File.Exists(srcPath)) {
p.Message("File &9{0} %Snot found.", srcPath);
} else if (engine.Compile(srcPath, dstPath)) {
} else if (engine.Compile(srcPath, dstPath, p)) {
p.Message("Command compiled successfully.");
} else {
p.Message("%WCompilation error. See " + IScripting.ErrorPath + " for more information.");
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Scripting/CmdPlugin.cs
Expand Up @@ -61,7 +61,7 @@ public sealed class CmdPlugin : Command2 {

if (!File.Exists(srcPath)) {
p.Message("File &9{0} %Snot found.", srcPath);
} else if (engine.Compile(srcPath, dstPath)) {
} else if (engine.Compile(srcPath, dstPath, p)) {
p.Message("Plugin compiled successfully.");
} else {
p.Message("%WCompilation error. See " + IScripting.ErrorPath + " for more information.");
Expand Down
15 changes: 13 additions & 2 deletions MCGalaxy/Scripting/Scripting.cs
Expand Up @@ -72,7 +72,8 @@ public abstract class IScripting {
}
}

public bool Compile(string srcPath, string dstPath) {
const int maxLog = 2;
public bool Compile(string srcPath, string dstPath, Player p) {
CompilerParameters args = new CompilerParameters();
args.GenerateExecutable = false;
args.OutputAssembly = dstPath;
Expand Down Expand Up @@ -100,10 +101,20 @@ public abstract class IScripting {
sb.AppendLine();
}

int logged = 0;
foreach (CompilerError err in results.Errors) {
string type = err.IsWarning ? "Warning" : "Error";
p.Message("%W{0} #{1} on line {2} - {3}", type, err.ErrorNumber, err.Line, err.ErrorText);

logged++;
if (logged >= maxLog) break;
}
if (results.Errors.Count > maxLog) p.Message(" %W.. and {0} more", results.Errors.Count - maxLog);

using (StreamWriter w = new StreamWriter(ErrorPath, true)) {
w.Write(sb.ToString());
}
return !results.Errors.HasErrors;
return false;
}

List<string> ReadSource(string path, CompilerParameters args) {
Expand Down
3 changes: 3 additions & 0 deletions MCGalaxy/Server/Maintenance/Updater.cs
Expand Up @@ -90,6 +90,9 @@ public static class Updater {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) pl.save();

// Although Process.Start checks path exists, that won't work correctly when running from mono
// (since 'mono' exists but Updater.exe might not)
// So always explicitly check that Updater.exe exists here
string path = Path.Combine(Utils.FolderPath, "Updater.exe");
if (!File.Exists(path)) throw new FileNotFoundException("Unable to find " + path);

Expand Down

0 comments on commit 005f395

Please sign in to comment.