From 9e74f95e53e1ee8fa529a675047314c50220ef46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=92=80=E5=A2=83=E7=9F=B3?= Date: Wed, 31 Dec 2025 21:15:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=82=E9=85=8D=20LuaSTG=20Sub=20v0.21.1?= =?UTF-8?q?18=20stdout=20=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaSTGEditorSharp.Core/Execution/Execution.cs | 83 ++++++++++++------- LuaSTGEditorSharp/MainWindow.xaml.cs | 71 +--------------- .../Windows/SettingsWindow.xaml.cs | 2 + LuaSTGPlusLib/LSTGEXPlusExecution.cs | 4 +- LuaSTGSubLib/LSTGSubExecution.cs | 4 +- 5 files changed, 59 insertions(+), 105 deletions(-) diff --git a/LuaSTGEditorSharp.Core/Execution/Execution.cs b/LuaSTGEditorSharp.Core/Execution/Execution.cs index fd172ba..d04ae99 100644 --- a/LuaSTGEditorSharp.Core/Execution/Execution.cs +++ b/LuaSTGEditorSharp.Core/Execution/Execution.cs @@ -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 { diff --git a/LuaSTGEditorSharp/MainWindow.xaml.cs b/LuaSTGEditorSharp/MainWindow.xaml.cs index 0d30034..be0931c 100644 --- a/LuaSTGEditorSharp/MainWindow.xaml.cs +++ b/LuaSTGEditorSharp/MainWindow.xaml.cs @@ -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())); } diff --git a/LuaSTGEditorSharp/Windows/SettingsWindow.xaml.cs b/LuaSTGEditorSharp/Windows/SettingsWindow.xaml.cs index 1675afa..a5a834c 100644 --- a/LuaSTGEditorSharp/Windows/SettingsWindow.xaml.cs +++ b/LuaSTGEditorSharp/Windows/SettingsWindow.xaml.cs @@ -470,6 +470,7 @@ private void WriteSettings() PluginPathSettings = PluginPath; TempPathSettings = TempPath; ZipExecutablePathSettings = ZipExecutablePath; + DynamicDebugReportingSettings = DynamicDebugReporting; SpaceIndentationSettings = SpaceIndentation; IndentationSpaceLengthSettings = IndentationSpaceLength; TabDisplayWidthSettings = TabDisplayWidth; @@ -503,6 +504,7 @@ private void ReadSettings() PluginPath = PluginPathSettings; TempPath = TempPathSettings; ZipExecutablePath = ZipExecutablePathSettings; + DynamicDebugReporting = DynamicDebugReportingSettings; SpaceIndentation = SpaceIndentationSettings; IndentationSpaceLength = IndentationSpaceLengthSettings; TabDisplayWidth = TabDisplayWidthSettings; diff --git a/LuaSTGPlusLib/LSTGEXPlusExecution.cs b/LuaSTGPlusLib/LSTGEXPlusExecution.cs index e74696c..144d989 100644 --- a/LuaSTGPlusLib/LSTGEXPlusExecution.cs +++ b/LuaSTGPlusLib/LSTGEXPlusExecution.cs @@ -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"; diff --git a/LuaSTGSubLib/LSTGSubExecution.cs b/LuaSTGSubLib/LSTGSubExecution.cs index e7f1a03..5462da9 100644 --- a/LuaSTGSubLib/LSTGSubExecution.cs +++ b/LuaSTGSubLib/LSTGSubExecution.cs @@ -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"; From eff5452b94328b11de64c66fe095410d5b3be650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=92=80=E5=A2=83=E7=9F=B3?= Date: Wed, 31 Dec 2025 21:19:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?LuaSTG-x=E5=BA=94=E8=AF=A5=E4=B9=9F?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81stdout=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaSTGXLib.Legacy/LSTGXExecution.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LuaSTGXLib.Legacy/LSTGXExecution.cs b/LuaSTGXLib.Legacy/LSTGXExecution.cs index 8795c4b..0c79569 100644 --- a/LuaSTGXLib.Legacy/LSTGXExecution.cs +++ b/LuaSTGXLib.Legacy/LSTGXExecution.cs @@ -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";