using StgSharp.Geometries; using StgSharp.Graphics; using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Windows.Win32; using Windows.Win32.Foundation; namespace StgSharp { public enum LogType { Error, Warning, Info, InfoError, InfoWarning, } internal class LibHandle : SafeHandle { public LibHandle(IntPtr invalidHandleValue, bool ownsHandle) : base(invalidHandleValue, ownsHandle) { } public override bool IsInvalid => throw new NotImplementedException(); protected override bool ReleaseHandle() { return PInvoke.FreeLibrary(new HMODULE(handle)); } } internal static unsafe partial class InternalIO { internal static Dictionary GLtype = new Dictionary(); internal static IntPtr SSClibPtr = IntPtr.Zero; internal const string SS_errorlog = "SS_errorlog.log"; internal const string SSC_libname = "StgSharpC"; 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); } internal static T InternalLoadProc(LibHandle lib, string name) where T : Delegate { try { IntPtr procPtr = #if Windows PInvoke.GetProcAddress(lib, name); #elif Linux #endif T ret = Marshal.GetDelegateForFunctionPointer(procPtr); return ret; } 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 void InternalWriteLog(string beforeTime, string logLine, LogType logType) { 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); } } internal static void InternalWriteLog(string logLine, LogType logType) { 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); } } } }