Files
stgsharp/源代码/StgSharp/Control/IO/InternalIO.cs
T

122 lines
3.4 KiB
C#

using StgSharp.Geometries;
using StgSharp.Graphics;
using System.Threading;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if Windows
#endif
namespace StgSharp
{
public enum LogType
{
Error,
Warning,
Info,
InfoError,
InfoWarning,
}
internal static unsafe partial class InternalIO
{
internal static Dictionary<TypeCode, uint> GLtype =
new Dictionary<TypeCode, uint>();
internal static IntPtr SSClibPtr = IntPtr.Zero;
internal const string SS_errorlog =
"SS_errorlog.log";
internal const string SSC_libname =
"StgSharpC";
internal static readonly GCHandle ssc_logHandle =
GCHandle.Alloc(new byte[512], GCHandleType.Pinned);
static InternalIO()
{
GLtype.Add(TypeCode.Single, GLconst.FLOAT);
GLtype.Add(TypeCode.Int32, GLconst.INT);
GLtype.Add(TypeCode.UInt32, GLconst.UNSIGNED_INT);
GLtype.Add(TypeCode.Int16, GLconst.SHORT);
GLtype.Add(TypeCode.UInt16, GLconst.UNSIGNED_SHORT);
GLtype.Add(TypeCode.SByte, GLconst.BYTE);
GLtype.Add(TypeCode.Byte, GLconst.UNSIGNED_BYTE);
}
[Obsolete("Not completed", true)]
internal static IntPtr InternalLoadProc<T>(IntPtr lib, string name) where T : Delegate
{
try
{
IntPtr procPtr =
#if Windows
IntPtr.Zero;
#elif Linux
#endif
return procPtr;
}
catch (Exception)
{
throw;
}
}
internal static void InternalAppendLog(string log)
{
if (!File.Exists(SS_errorlog))
{
FileStream stream = File.Create(SS_errorlog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorlog))
{
logStream.WriteLine(log);
}
}
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
{
logSyncSemaphore.Wait();
if (!File.Exists(InternalIO.SS_errorlog))
{
FileStream stream = File.Create(InternalIO.SS_errorlog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorlog))
{
logStream.WriteLine(beforeTime);
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
}
internal static void InternalWriteLog(string logLine, LogType logType)
{
logSyncSemaphore.Wait();
if (!File.Exists(SS_errorlog))
{
FileStream stream = File.Create(SS_errorlog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorlog))
{
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
}
}
}