Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
83 changes: 51 additions & 32 deletions LuaSTGEditorSharp.Core/Execution/Execution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,65 @@ public virtual void Run(Logger logger, Action end)
CreateNoWindow = CreateNoWindow,
WorkingDirectory = WorkingDirectory,
RedirectStandardError = RedirectStandardError,
RedirectStandardOutput = RedirectStandardOutput
RedirectStandardOutput = RedirectStandardOutput,
StandardErrorEncoding = RedirectStandardError ? Encoding.UTF8 : null,
StandardOutputEncoding = RedirectStandardOutput ? Encoding.UTF8 : null,
}
};
LSTGInstance.EnableRaisingEvents = true;
LSTGInstance.Start();

logger("LuaSTG is Running.\n\n");

LSTGInstance.Exited += (s, e) => {
FileStream fs = null;
StreamReader sr = null;
StringBuilder sb = new StringBuilder();
try

if (RedirectStandardOutput)
{
LSTGInstance.OutputDataReceived += (s, e) => logger(e.Data);
LSTGInstance.Exited += (s, e) =>
{
fs = new FileStream(Path.GetFullPath(Path.Combine(
Path.GetDirectoryName(LuaSTGPath), LogFileName)), FileMode.Open);
sr = new StreamReader(fs);
int i = 0;
while (!sr.EndOfStream && i < 8192)
end();
logger("\nExited with code " + LSTGInstance.ExitCode + ".");
};
}
else
{
LSTGInstance.Exited += (s, e) => {
FileStream fs = null;
StreamReader sr = null;
StringBuilder sb = new StringBuilder();
try
{
fs = new FileStream(Path.GetFullPath(Path.Combine(
Path.GetDirectoryName(LuaSTGPath), LogFileName)), FileMode.Open);
sr = new StreamReader(fs);
int i = 0;
while (!sr.EndOfStream && i < 8192)
{
sb.Append(sr.ReadLine());
sb.Append("\n");
i++;
}
logger(sb.ToString());
end();
}
catch (System.Exception exc)
{
System.Windows.MessageBox.Show(exc.ToString());
}
finally
{
sb.Append(sr.ReadLine());
sb.Append("\n");
i++;
if (fs != null) fs.Close();
if (sr != null) sr.Close();
}
sb.Append("\nExited with code " + LSTGInstance.ExitCode + ".");
logger(sb.ToString());
end();
}
catch (System.Exception exc)
{
System.Windows.MessageBox.Show(exc.ToString());
}
finally
{
if (fs != null) fs.Close();
if (sr != null) sr.Close();
}
sb.Append("\nExited with code " + LSTGInstance.ExitCode + ".");
logger(sb.ToString());
};
};
}

LSTGInstance.Start();

logger("LuaSTG is Running.\n\n");

if (RedirectStandardOutput)
{
LSTGInstance.BeginOutputReadLine();
}
}
else
{
Expand Down
71 changes: 2 additions & 69 deletions LuaSTGEditorSharp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,81 +720,14 @@ private void FinishPackaging(object sender, RunWorkerCompletedEventArgs args)

private void RunLuaSTG(App currentApp, CompileProcess process)
{
/*
string LuaSTGparam = "\"" +
"start_game=true is_debug=true setting.nosplash=true setting.windowed="
+ currentApp.DebugWindowed.ToString().ToLower() + " setting.resx=" + currentApp.DebugResolutionX +
" setting.resy=" + currentApp.DebugResolutionY + " cheat=" + currentApp.DebugCheat.ToString().ToLower() +
" updatelib=" + currentApp.DebugUpdateLib.ToString().ToLower() + " setting.mod=\'"
+ process.projName + "\'\"";
try
{
if (lstgInstance == null || lstgInstance.HasExited)
{
lstgInstance = new Process
{
StartInfo = new ProcessStartInfo(process.luaSTGExePath, LuaSTGparam)
{
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = process.luaSTGFolder,
RedirectStandardError = true,
RedirectStandardOutput = true
}
};
lstgInstance.Start();
DebugString += "LuaSTG is Running.\n\n";
*/
/*
* what it should be like:
*
lstg.OutputDataReceived += (s, e) => DebugString += e.Data;
lstg.ErrorDataReceived += (s, e) => DebugString += e.Data;
*
* what it actually is:
*/
/*
lstgInstance.Exited += (s, e) => {
FileStream fs = null;
StreamReader sr = null;
try
{
fs = new FileStream(Path.GetFullPath(Path.Combine(
Path.GetDirectoryName(process.luaSTGExePath), "log.txt")), FileMode.Open);
sr = new StreamReader(fs);
DebugString += sr.ReadToEnd();
//debugOutput.ScrollToEnd();
}
finally
{
if (fs != null) fs.Close();
if (sr != null) sr.Close();
}
DebugString += "\nExited with code " + lstgInstance.ExitCode + ".";
};
lstgInstance.EnableRaisingEvents = true;
lstgInstance.BeginOutputReadLine();
lstgInstance.BeginErrorReadLine();
//lstg.WaitForExit();
}
else
{
MessageBox.Show("LuaSTG is already running, please exit first."
, "LuaSTG Editor Sharp", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
catch (Win32Exception)
{
throw new EXEPathNotSetException();
}
*/
PluginHandler.Plugin.Execution.BeforeRun(new ExecutionConfig()
{
ModName = process.projName
});
DebugString = "";
PluginHandler.Plugin.Execution.Run((s) =>
{
DebugString = s;
DebugString += s + "\n";
}
, () => App.Current.Dispatcher.Invoke(() => debugOutput.ScrollToEnd()));
}
Expand Down
2 changes: 2 additions & 0 deletions LuaSTGEditorSharp/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ private void WriteSettings()
PluginPathSettings = PluginPath;
TempPathSettings = TempPath;
ZipExecutablePathSettings = ZipExecutablePath;
DynamicDebugReportingSettings = DynamicDebugReporting;
SpaceIndentationSettings = SpaceIndentation;
IndentationSpaceLengthSettings = IndentationSpaceLength;
TabDisplayWidthSettings = TabDisplayWidth;
Expand Down Expand Up @@ -503,6 +504,7 @@ private void ReadSettings()
PluginPath = PluginPathSettings;
TempPath = TempPathSettings;
ZipExecutablePath = ZipExecutablePathSettings;
DynamicDebugReporting = DynamicDebugReportingSettings;
SpaceIndentation = SpaceIndentationSettings;
IndentationSpaceLength = IndentationSpaceLengthSettings;
TabDisplayWidth = TabDisplayWidthSettings;
Expand Down
4 changes: 2 additions & 2 deletions LuaSTGPlusLib/LSTGEXPlusExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override void BeforeRun(ExecutionConfig config)
+ config.ModName + "\'\"";
UseShellExecute = false;
CreateNoWindow = true;
RedirectStandardError = true;
RedirectStandardOutput = true;
RedirectStandardError = false;
RedirectStandardOutput = false;
}

protected override string LogFileName => "log.txt";
Expand Down
4 changes: 2 additions & 2 deletions LuaSTGSubLib/LSTGSubExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override void BeforeRun(ExecutionConfig config)
+ config.ModName + "\'\"";
UseShellExecute = false;
CreateNoWindow = true;
RedirectStandardError = true;
RedirectStandardOutput = true;
RedirectStandardError = false;
RedirectStandardOutput = currentApp.DynamicDebugReporting; // LuaSTG Sub v0.21.118+ supports stdout redirect
}

protected override string LogFileName => "engine.log";
Expand Down
4 changes: 2 additions & 2 deletions LuaSTGXLib.Legacy/LSTGXExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override void BeforeRun(ExecutionConfig config)
+ config.ModName + "\'\"";
UseShellExecute = false;
CreateNoWindow = true;
RedirectStandardError = true;
RedirectStandardOutput = true;
RedirectStandardError = false;
RedirectStandardOutput = false;
}

protected override string LogFileName => "lstg_log.txt";
Expand Down
Loading