This commit is contained in:
@@ -1,26 +1,50 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using PCL.Core.App.Essentials;
|
||||
using PCL.Core.App.IoC;
|
||||
using MRCC.Launcher;
|
||||
|
||||
namespace MRCC.Launcher;
|
||||
|
||||
public static class Program
|
||||
internal static class Program
|
||||
{
|
||||
public static bool IsDevMode;
|
||||
private static readonly object _logLock = new();
|
||||
private static readonly string LogPath = "redcircuit.log";
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool AllocConsole();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// 设置 WPF Application 加载委托
|
||||
ApplicationService.Loading = () =>
|
||||
IsDevMode = args.Any(a => string.Equals(a, "dev", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (IsDevMode)
|
||||
{
|
||||
var app = new App();
|
||||
return app;
|
||||
};
|
||||
AllocConsole();
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||
Log("=== RedCircuit 开发模式 ===");
|
||||
Log($"工作目录: {Environment.CurrentDirectory}");
|
||||
Log($"EXE目录: {AppContext.BaseDirectory}");
|
||||
Log("HTML5 世界直接运行于 WebView2 内,控制台用于查看日志。");
|
||||
}
|
||||
|
||||
// 设置主窗口加载委托
|
||||
MainWindowService.Loading = () => new MainWindow();
|
||||
// 启动器 UI:WebView2 加载 HTML5 世界
|
||||
var app = new App();
|
||||
app.Run(new MainWindow());
|
||||
}
|
||||
|
||||
// 启动生命周期
|
||||
Lifecycle.OnInitialize();
|
||||
public static void Log(string message)
|
||||
{
|
||||
var line = $"[{DateTime.Now:HH:mm:ss.fff}] {message}";
|
||||
lock (_logLock)
|
||||
{
|
||||
if (IsDevMode) Console.WriteLine(line);
|
||||
Debug.WriteLine(line);
|
||||
try { File.AppendAllText(LogPath, line + Environment.NewLine, Encoding.UTF8); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user