diff --git a/Color.cs b/Color.cs
deleted file mode 100644
index 6093917..0000000
--- a/Color.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-
-namespace DTLib
-{
- public abstract class Color
- {
- public record RGBA(byte R, byte G, byte B, byte A)
- {
- public RGBA(byte[] arrayRGBA) : this(arrayRGBA[0], arrayRGBA[1], arrayRGBA[2], arrayRGBA[3])
- {
- if (arrayRGBA.Length != 4)
- throw new Exception("Color.RGBA(byte[] arrayRGBA) error: arrayRGBA.Length != 4\n");
- }
- }
-
- public record RGB(byte R, byte G, byte B)
- {
- public RGB(byte[] arrayRGB) : this(arrayRGB[0], arrayRGB[1], arrayRGB[2])
- {
- if (arrayRGB.Length != 3)
- throw new Exception("Color.RGB(byte[] arrayRGB) error: arrayRGB.Length != 3\n");
- }
- }
- }
-
-}
diff --git a/ColoredConsole.cs b/ColoredConsole.cs
index 18b39ba..98b684e 100644
--- a/ColoredConsole.cs
+++ b/ColoredConsole.cs
@@ -26,8 +26,8 @@ namespace DTLib
"b" => ConsoleColor.Blue,
//case "cyan":
"c" => ConsoleColor.Cyan,
- //case "gray":
- "gray" => ConsoleColor.Gray,
+ //case "h":
+ "h" or "gray" => ConsoleColor.Gray,
//case "black":
"black" => ConsoleColor.Black,
_ => throw new Exception($"ColoredConsole.ParseColor({color}) error: incorrect color"),
diff --git a/DTLib.csproj b/DTLib.csproj
index ea97a15..1fde41c 100644
--- a/DTLib.csproj
+++ b/DTLib.csproj
@@ -32,9 +32,11 @@
-
+
+
+
@@ -59,7 +61,7 @@
-
+
diff --git a/DefaultLogger.cs b/DefaultLogger.cs
index 7072a2a..71a5f9f 100644
--- a/DefaultLogger.cs
+++ b/DefaultLogger.cs
@@ -1,6 +1,6 @@
-using System;
+using DTLib.Filesystem;
+using System;
using System.Text;
-using DTLib.Filesystem;
namespace DTLib
{
@@ -12,8 +12,13 @@ namespace DTLib
public string Logfile { get; set; }
+ private bool isEnabled=false;
+ public void Enable() { lock (Logfile) isEnabled = true; }
+ public void Disable() { lock (Logfile) isEnabled = false; }
+
public void Log(params string[] msg)
{
+ lock (Logfile) if (!isEnabled) return;
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1];
LogNoTime(msg);
@@ -21,17 +26,16 @@ namespace DTLib
public void LogNoTime(params string[] msg)
{
- lock (Logfile)
+ lock (Logfile) if (!isEnabled) return;
+ ColoredConsole.Write(msg);
+ if (msg.Length == 1)
+ lock (Logfile) File.AppendAllText(Logfile, msg[0]);
+ else
{
- ColoredConsole.Write(msg);
- if (msg.Length == 1) File.AppendAllText(Logfile, msg[0]);
- else
- {
- StringBuilder strB = new();
- for (ushort i = 0; i < msg.Length; i++)
- strB.Append(msg[++i]);
- File.AppendAllText(Logfile, strB.ToString());
- }
+ StringBuilder strB = new();
+ for (ushort i = 0; i < msg.Length; i++)
+ strB.Append(msg[++i]);
+ lock (Logfile) File.AppendAllText(Logfile, strB.ToString());
}
}
}
diff --git a/Dtsod/DtsodV21.cs b/Dtsod/DtsodV21.cs
index 499cab4..20c73e1 100644
--- a/Dtsod/DtsodV21.cs
+++ b/Dtsod/DtsodV21.cs
@@ -1,4 +1,5 @@
-using System;
+using DTLib.Extensions;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -29,6 +30,13 @@ namespace DTLib.Dtsod
foreach (KeyValuePair pair in Parse(text))
Add(pair.Key, pair.Value);
}
+ public DtsodV21(Dictionary rawDict)
+ {
+ Text = "";
+ foreach (KeyValuePair pair in rawDict)
+ Add(pair.Key, pair.Value);
+ }
+
// выдаёт Exception
public new dynamic this[string key]
@@ -89,14 +97,14 @@ namespace DTLib.Dtsod
// СЛОМАНО
/*void ReadCommentLine()
{
- for (; i < text.Length && text[i] != '\n'; i++) DebugNoTime("gray", text[i].ToString());
+ for (; i < text.Length && text[i] != '\n'; i++) DebugNoTime("h", text[i].ToString());
}*/
void ReadName()
{
bool isListElem = false;
- dynamic value = null;
+ dynamic value;
StringBuilder defaultNameBuilder = new();
DebugNoTime("m", "ReadName\n");
@@ -113,7 +121,8 @@ namespace DTLib.Dtsod
i++;
string name = defaultNameBuilder.ToString();
value = ReadValue();
- DebugNoTime("c", $"parsed.Add({name}, {value} { value.GetType() })\n");
+ // если value это null, эта строка выдавала ошибку
+ //DebugNoTime("c", $"parsed.Add({name}, {value} { value.GetType() })\n");
if (isListElem)
{
if (!parsed.ContainsKey(name))
@@ -158,11 +167,11 @@ namespace DTLib.Dtsod
valueBuilder.Append('"');
for (; text[i] != '"' || text[i - 1] == '\\'; i++)
{
- DebugNoTime("gray", text[i].ToString());
+ DebugNoTime("h", text[i].ToString());
valueBuilder.Append(text[i]);
}
valueBuilder.Append('"');
- DebugNoTime("gray", text[i].ToString());
+ DebugNoTime("h", text[i].ToString());
type = ValueType.String;
return valueBuilder.ToString();
}
diff --git a/Dtsod/DtsodV22.cs b/Dtsod/DtsodV22.cs
index 051201b..0755976 100644
--- a/Dtsod/DtsodV22.cs
+++ b/Dtsod/DtsodV22.cs
@@ -1,4 +1,5 @@
-using System;
+using DTLib.Extensions;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -35,12 +36,6 @@ namespace DTLib.Dtsod
Type = type;
IsList = isList;
}
- public ValueStruct(ValueTypes type, dynamic value)
- {
- Value = value;
- Type = type;
- IsList = false;
- }
}
public enum ValueTypes
@@ -122,14 +117,14 @@ namespace DTLib.Dtsod
// СЛОМАНО
/*void ReadCommentLine()
{
- for (; i < text.Length && text[i] != '\n'; i++) Debug("gray", text[i].ToString());
+ for (; i < text.Length && text[i] != '\n'; i++) Debug("h", text[i].ToString());
}*/
void ReadName()
{
bool isListElem = false;
- dynamic value = null;
+ dynamic value;
StringBuilder defaultNameBuilder = new();
DebugNoTime("m", "ReadName\n");
@@ -192,11 +187,11 @@ namespace DTLib.Dtsod
valueBuilder.Append('"');
for (; text[i] != '"' || text[i - 1] == '\\'; i++)
{
- DebugNoTime("gray", text[i].ToString());
+ DebugNoTime("h", text[i].ToString());
valueBuilder.Append(text[i]);
}
valueBuilder.Append('"');
- DebugNoTime("gray", text[i].ToString());
+ DebugNoTime("h", text[i].ToString());
type = ValueTypes.String;
return valueBuilder.ToString();
}
@@ -405,33 +400,34 @@ namespace DTLib.Dtsod
switch (value.Type)
{
case ValueTypes.List:
- outBuilder.Append("\"list deconstruction is'nt implemented yet\"");
+ outBuilder.Append('[').Append(ToStringConverter.MergeToString((IEnumerable