daily update on 20241226 by nitload youmu

This commit is contained in:
Nitload
2024-12-26 03:09:46 +08:00
parent 7c8d462ca5
commit 592ad55d57
94 changed files with 3767 additions and 1484 deletions
@@ -29,6 +29,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -36,6 +37,9 @@ using System.IO.Pipes;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Windows.Win32.UI.WindowsAndMessaging;
namespace StgSharp
{
@@ -44,7 +48,58 @@ namespace StgSharp
private static Process? _dialogueProcess;
private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe;
private static ConcurrentBag<string> msgCache = new ConcurrentBag<string>(
);
private static int _readAndWriteThreadId;
private static ProcessStartInfo _dialogueProcessInfo;
private static StreamReader _dr;
private static StreamWriter _dw;
public static bool NeedShowWhenStartup
{
get;
set;
}
public static void SetReadAndWriteThread(Thread thread)
{
_readAndWriteThreadId = thread.ManagedThreadId;
}
private static void AssertThread()
{
if (_readAndWriteThreadId != Thread.CurrentThread.ManagedThreadId)
{
throw new InvalidOperationException("Communication with dialogue can only call from certain thread.");
}
}
internal static void CreateDialogueProcessIfNotExist()
{
if( _dialogueProcess != null ) {
return;
}
if (!File.Exists(_dialogueProcessInfo.FileName))
{
}
_dialogueProcess = Process.Start( _dialogueProcessInfo );
_dr = new StreamReader(_dialogueClientPipe);
_dw = new StreamWriter(_dialogueServerPipe);
_dialogueProcess!.Exited += DialogueProcessExitCallback;
_dialogueServerPipe.DisposeLocalCopyOfClientHandle();
_dialogueClientPipe.DisposeLocalCopyOfClientHandle();
}
private static void DialogueProcessExitCallback(object? sender, EventArgs e)
{
_dialogueProcess = null;
_dr.Close();
_dw.Close();
}
internal static void LoadDialogue()
{
@@ -67,20 +122,36 @@ namespace StgSharp
throw new PlatformNotSupportedException( "Unknown OS platform" );
}
string consoleRoute = $"{path}{Path.DirectorySeparatorChar}StgSharpErrorConsole{exeName}";
string consoleRoute = $"{path}{Path.DirectorySeparatorChar}StgSharpTerminalDialogue{Path.DirectorySeparatorChar}StgSharpTerminalDialogue{exeName}";
ProcessStartInfo info = new ProcessStartInfo
_dialogueProcessInfo = new ProcessStartInfo
{
FileName = path,
Arguments = _dialogueServerPipe.GetClientHandleAsString() + " " + _dialogueClientPipe.GetClientHandleAsString(),
FileName = consoleRoute,
Arguments = $"{_dialogueServerPipe.GetClientHandleAsString()} {_dialogueClientPipe.GetClientHandleAsString()}",
UseShellExecute = true,
RedirectStandardOutput = false,
};
}
internal static void PostMessage(
string instruction,
params string[] operands ) { }
params string[] operands)
{
CreateDialogueProcessIfNotExist();
_dw.WriteLine($"{instruction} {operands}");
}
public static void PostError(Exception ex)
{
CreateDialogueProcessIfNotExist();
_dw.WriteLine($"posterror {ex.Message}");
_dialogueProcess!.Exited -= DialogueProcessExitCallback;
}
internal static void UnloadDialogue()
{
@@ -93,20 +164,23 @@ namespace StgSharp
_dialogueClientPipe.Dispose();
}
private static void CreateDialogueProcessIfNotExist()
internal static string WaitCertainReturn( string target )
{
if( _dialogueProcess != null ) {
return;
if( _dialogueProcess == null ) {
return string.Empty;
}
_dialogueProcess = Process.Start( _dialogueProcessInfo );
_dialogueProcess.Exited += ( sender, e ) => {
_dialogueProcess = null;
_dialogueProcess = null;
};
string temp = string .Empty;
do {
temp = _dr.ReadLine();
temp = temp ?? string.Empty;
if( !temp!.StartsWith( target ) ) {
break;
}
} while (true);
_dialogueServerPipe.DisposeLocalCopyOfClientHandle();
_dialogueClientPipe.DisposeLocalCopyOfClientHandle();
int index = temp.IndexOf( ' ' );
return index != -1 ? temp.Substring( index + 1 ) : string.Empty;
}
}
@@ -33,6 +33,8 @@
// using StgSharp.Graphics;
// using StgSharp.Math;
using StgSharp.Data.Intrinsic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -82,7 +84,7 @@ namespace StgSharp
private static uint markCount = 0;
internal static GraphicAPI API = default;
public static void Init()
public static unsafe void Init()
{
mainTimeProvider = new StgSharpTime();
MainTimeProvider.StartProvidingTime();
@@ -92,6 +94,15 @@ namespace StgSharp
$"Program {Assembly.GetEntryAssembly()!.FullName} Started.",
LogType.Info );
_mainThreadID = Environment.CurrentManagedThreadId;
Dialogue.LoadDialogue();
if (Dialogue.NeedShowWhenStartup)
{
Dialogue.CreateDialogueProcessIfNotExist();
}
InternalIO.InitIntrinsicContext();
}
public static void LogError( Exception ex )