diff --git a/.gitignore b/.gitignore index 1e6cd00..72b2586 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ *.user #backups -.old*/ \ No newline at end of file +.old*/ diff --git a/DTLib.Dtsod/DTLib.Dtsod.csproj b/DTLib.Dtsod/DTLib.Dtsod.csproj index b3e5641..7164021 100644 --- a/DTLib.Dtsod/DTLib.Dtsod.csproj +++ b/DTLib.Dtsod/DTLib.Dtsod.csproj @@ -1,12 +1,13 @@ - net6.0 + net6.0;net48 preview disable disable - False true + False + embedded Debug;Release AnyCPU;x64;x86;arm64 diff --git a/DTLib.Network/DTLib.Network.csproj b/DTLib.Network/DTLib.Network.csproj index 04fcaa6..13a015d 100644 --- a/DTLib.Network/DTLib.Network.csproj +++ b/DTLib.Network/DTLib.Network.csproj @@ -1,11 +1,12 @@ - net6.0 - 10 + net6.0;net48 + preview disable disable False + embedded Debug;Release;Release-net48 AnyCPU;x64;x86;arm64 @@ -18,7 +19,6 @@ - diff --git a/DTLib.Tests/DTLib.Tests.csproj b/DTLib.Tests/DTLib.Tests.csproj index 301d7f1..cce9ae1 100644 --- a/DTLib.Tests/DTLib.Tests.csproj +++ b/DTLib.Tests/DTLib.Tests.csproj @@ -1,14 +1,14 @@  Exe - net6.0 + net6.0;net48 10 false disable True true False - DTLib.Tests + embedded Debug;Release;Release-net48 AnyCPU;x64;x86;arm64 @@ -29,10 +29,5 @@ - - - - - diff --git a/DTLib/ColoredConsole.cs b/DTLib/ColoredConsole.cs index ad55c8c..b23f61b 100644 --- a/DTLib/ColoredConsole.cs +++ b/DTLib/ColoredConsole.cs @@ -59,6 +59,14 @@ public static class ColoredConsole else throw new Exception("ColoredConsole.Write() error: every text string must have color string before"); } + public static void WriteLine() => Console.WriteLine(); + + public static void WriteLine(params string[] input) + { + Write(input); + WriteLine(); + } + // ввод цветного текста public static string Read(string color) { diff --git a/DTLib/DTLib.csproj b/DTLib/DTLib.csproj index 6813ad6..970d5b0 100644 --- a/DTLib/DTLib.csproj +++ b/DTLib/DTLib.csproj @@ -1,6 +1,6 @@  - net6.0 + net6.0;net48 preview disable disable @@ -8,6 +8,7 @@ False true + embedded False Debug;Release AnyCPU;x64;x86;arm64 diff --git a/DTLib/DependencyResolver.cs b/DTLib/DependencyResolver.cs index 560cff2..fc43bb2 100644 --- a/DTLib/DependencyResolver.cs +++ b/DTLib/DependencyResolver.cs @@ -9,7 +9,7 @@ public static class DependencyResolver public static void CopyLibs() { if(DepsCopied) return; - string depsdir = "Dependencies" + Путь.Разд; + string depsdir = $"Dependencies{Путь.Разд}"; depsdir += Environment.OSVersion.Platform switch { PlatformID.Unix => "linux", diff --git a/DTLib/Experimental/CompressedArray.cs b/DTLib/Experimental/CompressedArray.cs index 878e022..1385df9 100644 --- a/DTLib/Experimental/CompressedArray.cs +++ b/DTLib/Experimental/CompressedArray.cs @@ -38,7 +38,8 @@ namespace DTLib.Experimental } Memory = listMem.ToArray(); Description = listDesc.ToArray(); - ColoredConsole.Write("b", "listMem.Count: ", "c", listMem.Count.ToString(), "b", " listDesc.Count: ", "c", listDesc.Count + "\n"); + ColoredConsole.Write("b", "listMem.Count: ", "c", listMem.Count.ToString(), "b", " listDesc.Count: ", "c", + $"{listDesc.Count}\n"); for (short i = 0; i < listDesc.Count; i++) { ColoredConsole.Write("y", $"{Description[i]}:{Memory[i]}\n"); diff --git a/DTLib/Extensions/StringConverter.cs b/DTLib/Extensions/StringConverter.cs index 70ed1c1..a3ce624 100644 --- a/DTLib/Extensions/StringConverter.cs +++ b/DTLib/Extensions/StringConverter.cs @@ -2,7 +2,9 @@ public static class StringConverter { + public static ASCIIEncoding ASCII = new ASCIIEncoding(); public static Encoding UTF8 = new UTF8Encoding(false); + public static Encoding UTF8BOM = new UTF8Encoding(true); public static byte[] ToBytes(this string str) => UTF8.GetBytes(str); public static string BytesToString(this byte[] bytes) => UTF8.GetString(bytes); diff --git a/DTLib/Extensions/Unmanaged.cs b/DTLib/Extensions/Unmanaged.cs index eacd041..2eaff37 100644 --- a/DTLib/Extensions/Unmanaged.cs +++ b/DTLib/Extensions/Unmanaged.cs @@ -4,7 +4,7 @@ namespace DTLib.Extensions; public static class Unmanaged { - public static unsafe IntPtr ToHGlobalUTF8(this string s) + public static unsafe IntPtr StringToHGlobalUTF8(this string s) { byte[] buf = s.ToBytes(); int bl = buf.Length; @@ -15,5 +15,29 @@ public static class Unmanaged return (IntPtr) ptr; } - public static string ToStringUTF8(this IntPtr p) => Marshal.PtrToStringUTF8(p); + public static unsafe int ASCII_length(IntPtr asciiStr) + { + byte* str = (byte*)asciiStr; + while (*str != (byte)'\0') + str++; + long length = str - (byte*)asciiStr; + if (length > Int32.MaxValue) + throw new Exception($"ascii string length <{length}> > Int32.MaxValue"); + return (int)length; + } + + public static unsafe string HGlobalUTF8ToString(this IntPtr p) + { + return StringConverter.UTF8.GetString((byte*)p, ASCII_length(p)); + /*if (p == IntPtr.Zero) + throw new Exception("string pointer is null"); + int length = ASCII_length(p); + byte[] buf = new byte[length]; + for (int i = 0; i < length; i++) + buf[i] = ((byte*)p)[i]; + fixed(byte* bufptr=&buf[0]) + { + return StringConverter.UTF8.GetString(bufptr, length); + }*/ + } } \ No newline at end of file diff --git a/DTLib/Logging/FileLogger.cs b/DTLib/Logging/FileLogger.cs index f9ba6b0..3d65ee8 100644 --- a/DTLib/Logging/FileLogger.cs +++ b/DTLib/Logging/FileLogger.cs @@ -42,8 +42,12 @@ public class FileLogger : IDisposable public virtual void Dispose() { - LogfileStream?.Flush(); - LogfileStream?.Close(); + try + { + LogfileStream?.Flush(); + LogfileStream?.Close(); + } + catch (ObjectDisposedException) { } } ~FileLogger() => Dispose();