few fixes
This commit is contained in:
parent
7adb98c9a6
commit
5d77e4cfd3
2
Color.cs
2
Color.cs
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace DTLib
|
namespace DTLib
|
||||||
{
|
{
|
||||||
public class Color
|
public abstract class Color
|
||||||
{
|
{
|
||||||
public record RGBA(byte R, byte G, byte B, byte A)
|
public record RGBA(byte R, byte G, byte B, byte A)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Color.cs" />
|
||||||
<Compile Include="CompressedArray.cs" />
|
<Compile Include="CompressedArray.cs" />
|
||||||
<Compile Include="ConsoleGUI\Container.cs" />
|
<Compile Include="ConsoleGUI\Container.cs" />
|
||||||
<Compile Include="ConsoleGUI\Control.cs" />
|
<Compile Include="ConsoleGUI\Control.cs" />
|
||||||
|
|||||||
@ -95,13 +95,13 @@ namespace DTLib.Dtsod
|
|||||||
Dictionary<string, dynamic> parsed = new();
|
Dictionary<string, dynamic> parsed = new();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < text.Length; i++) ReadName();
|
for (; i < text.Length; i++) ReadName();
|
||||||
if (debug) LogNoTime("g", $"Parse returns {parsed.Keys.Count} keys\n");
|
DebugNoTime("g", $"Parse returns {parsed.Keys.Count} keys\n");
|
||||||
return parsed;
|
return parsed;
|
||||||
|
|
||||||
// СЛОМАНО
|
// СЛОМАНО
|
||||||
/*void ReadCommentLine()
|
/*void ReadCommentLine()
|
||||||
{
|
{
|
||||||
for (; i < text.Length && text[i] != '\n'; i++) if (debug) LogNoTime("gray", text[i].ToString());
|
for (; i < text.Length && text[i] != '\n'; i++) DebugNoTime("gray", text[i].ToString());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void ReadName()
|
void ReadName()
|
||||||
@ -111,7 +111,7 @@ namespace DTLib.Dtsod
|
|||||||
dynamic value = null;
|
dynamic value = null;
|
||||||
StringBuilder defaultNameBuilder = new();
|
StringBuilder defaultNameBuilder = new();
|
||||||
|
|
||||||
if (debug) LogNoTime("m", "ReadName\n");
|
DebugNoTime("m", "ReadName\n");
|
||||||
for (; i < text.Length; i++)
|
for (; i < text.Length; i++)
|
||||||
{
|
{
|
||||||
switch (text[i])
|
switch (text[i])
|
||||||
@ -125,7 +125,7 @@ namespace DTLib.Dtsod
|
|||||||
i++;
|
i++;
|
||||||
string name = defaultNameBuilder.ToString();
|
string name = defaultNameBuilder.ToString();
|
||||||
value = ReadValue();
|
value = ReadValue();
|
||||||
if (debug) LogNoTime("c", $"parsed.Add({name}, {value} { value.GetType() })\n");
|
DebugNoTime("c", $"parsed.Add({name}, {value} { value.GetType() })\n");
|
||||||
if (isListElem)
|
if (isListElem)
|
||||||
{
|
{
|
||||||
if (!parsed.ContainsKey(name)) parsed.Add(name, new List<dynamic>());
|
if (!parsed.ContainsKey(name)) parsed.Add(name, new List<dynamic>());
|
||||||
@ -141,14 +141,14 @@ namespace DTLib.Dtsod
|
|||||||
throw new Exception("Parse.ReadName() error: unexpected '}' at " + i + " char");
|
throw new Exception("Parse.ReadName() error: unexpected '}' at " + i + " char");
|
||||||
// если $ перед названием параметра поставить, значение value добавится в лист с названием name
|
// если $ перед названием параметра поставить, значение value добавится в лист с названием name
|
||||||
case '$':
|
case '$':
|
||||||
if (debug) LogNoTime("w", text[i].ToString());
|
DebugNoTime("w", text[i].ToString());
|
||||||
if (defaultNameBuilder.ToString().Length != 0) throw new Exception("Parse.ReadName() error: unexpected '$' at " + i + " char");
|
if (defaultNameBuilder.ToString().Length != 0) throw new Exception("Parse.ReadName() error: unexpected '$' at " + i + " char");
|
||||||
isListElem = true;
|
isListElem = true;
|
||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
throw new Exception("Parse.ReadName() error: unexpected ';' at " + i + " char");
|
throw new Exception("Parse.ReadName() error: unexpected ';' at " + i + " char");
|
||||||
default:
|
default:
|
||||||
if (debug) LogNoTime("w", text[i].ToString());
|
DebugNoTime("w", text[i].ToString());
|
||||||
defaultNameBuilder.Append(text[i]);
|
defaultNameBuilder.Append(text[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -167,11 +167,11 @@ namespace DTLib.Dtsod
|
|||||||
valueBuilder.Append('"');
|
valueBuilder.Append('"');
|
||||||
for (; text[i] != '"' || text[i - 1] == '\\'; i++)
|
for (; text[i] != '"' || text[i - 1] == '\\'; i++)
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("gray", text[i].ToString());
|
DebugNoTime("gray", text[i].ToString());
|
||||||
valueBuilder.Append(text[i]);
|
valueBuilder.Append(text[i]);
|
||||||
}
|
}
|
||||||
valueBuilder.Append('"');
|
valueBuilder.Append('"');
|
||||||
if (debug) LogNoTime("gray", text[i].ToString());
|
DebugNoTime("gray", text[i].ToString());
|
||||||
type = ValueType.String;
|
type = ValueType.String;
|
||||||
return valueBuilder.ToString();
|
return valueBuilder.ToString();
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ namespace DTLib.Dtsod
|
|||||||
StringBuilder valueBuilder = new();
|
StringBuilder valueBuilder = new();
|
||||||
for (; text[i] != ']'; i++)
|
for (; text[i] != ']'; i++)
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("c", text[i].ToString());
|
DebugNoTime("c", text[i].ToString());
|
||||||
switch (text[i])
|
switch (text[i])
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
@ -206,7 +206,7 @@ namespace DTLib.Dtsod
|
|||||||
ParseValueToRightType(valueBuilder.ToString());
|
ParseValueToRightType(valueBuilder.ToString());
|
||||||
output.Add(value);
|
output.Add(value);
|
||||||
}
|
}
|
||||||
if (debug) LogNoTime("c", text[i].ToString());
|
DebugNoTime("c", text[i].ToString());
|
||||||
type = ValueType.List;
|
type = ValueType.List;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ namespace DTLib.Dtsod
|
|||||||
i++;
|
i++;
|
||||||
for (; balance != 0; i++)
|
for (; balance != 0; i++)
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("y", text[i].ToString());
|
DebugNoTime("y", text[i].ToString());
|
||||||
switch (text[i])
|
switch (text[i])
|
||||||
{
|
{
|
||||||
case '"':
|
case '"':
|
||||||
@ -226,12 +226,12 @@ namespace DTLib.Dtsod
|
|||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
balance--;
|
balance--;
|
||||||
if (debug) LogNoTime("b", $"\nbalance -- = {balance}\n");
|
DebugNoTime("b", $"\nbalance -- = {balance}\n");
|
||||||
if (balance != 0) valueBuilder.Append(text[i]);
|
if (balance != 0) valueBuilder.Append(text[i]);
|
||||||
break;
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
balance++;
|
balance++;
|
||||||
if (debug) LogNoTime("b", $"\nbalance ++ = {balance}\n");
|
DebugNoTime("b", $"\nbalance ++ = {balance}\n");
|
||||||
valueBuilder.Append(text[i]);
|
valueBuilder.Append(text[i]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -247,7 +247,7 @@ namespace DTLib.Dtsod
|
|||||||
void ParseValueToRightType(string stringValue)
|
void ParseValueToRightType(string stringValue)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (debug) LogNoTime("b", $"\nParseValueToRightType({stringValue})\n");
|
DebugNoTime("b", $"\nParseValueToRightType({stringValue})\n");
|
||||||
switch (stringValue)
|
switch (stringValue)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -300,10 +300,10 @@ namespace DTLib.Dtsod
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder defaultValueBuilder = new();
|
StringBuilder defaultValueBuilder = new();
|
||||||
if (debug) LogNoTime("m", "\nReadValue\n");
|
DebugNoTime("m", "\nReadValue\n");
|
||||||
for (; i < text.Length; i++)
|
for (; i < text.Length; i++)
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("b", text[i].ToString());
|
DebugNoTime("b", text[i].ToString());
|
||||||
switch (text[i])
|
switch (text[i])
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
@ -343,5 +343,15 @@ namespace DTLib.Dtsod
|
|||||||
throw new Exception("Dtsod.Parse.ReadValue error: wtf it's the end of function");
|
throw new Exception("Dtsod.Parse.ReadValue error: wtf it's the end of function");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Debug(params string[] msg)
|
||||||
|
{
|
||||||
|
if (debug) Log(msg);
|
||||||
|
}
|
||||||
|
void DebugNoTime(params string[] msg)
|
||||||
|
{
|
||||||
|
if (debug) LogNoTime(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace DTLib.Network
|
|||||||
public class FSP
|
public class FSP
|
||||||
{
|
{
|
||||||
Socket mainSocket;
|
Socket mainSocket;
|
||||||
public bool debug = false;
|
static public bool debug = false;
|
||||||
public FSP(Socket _mainSocket) => mainSocket = _mainSocket;
|
public FSP(Socket _mainSocket) => mainSocket = _mainSocket;
|
||||||
|
|
||||||
public uint BytesDownloaded = 0;
|
public uint BytesDownloaded = 0;
|
||||||
@ -28,7 +28,7 @@ namespace DTLib.Network
|
|||||||
// скачивает файл с помощью FSP протокола
|
// скачивает файл с помощью FSP протокола
|
||||||
public void DownloadFile(string filePath_server, string filePath_client)
|
public void DownloadFile(string filePath_server, string filePath_client)
|
||||||
{
|
{
|
||||||
if (debug) Log("b", $"requesting file download: {filePath_server}\n");
|
Debug("b", $"requesting file download: {filePath_server}\n");
|
||||||
mainSocket.SendPackage("requesting file download".ToBytes());
|
mainSocket.SendPackage("requesting file download".ToBytes());
|
||||||
mainSocket.SendPackage(filePath_server.ToBytes());
|
mainSocket.SendPackage(filePath_server.ToBytes());
|
||||||
DownloadFile(filePath_client);
|
DownloadFile(filePath_client);
|
||||||
@ -76,13 +76,13 @@ namespace DTLib.Network
|
|||||||
//speedCounter.Stop();
|
//speedCounter.Stop();
|
||||||
fileStream.Flush();
|
fileStream.Flush();
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
if (debug) Log(new string[] { "g", $" downloaded {BytesDownloaded} of {Filesize} bytes\n" });
|
Debug(new string[] { "g", $" downloaded {BytesDownloaded} of {Filesize} bytes\n" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] DownloadFileToMemory(string filePath_server)
|
public byte[] DownloadFileToMemory(string filePath_server)
|
||||||
{
|
{
|
||||||
BytesDownloaded = 0;
|
BytesDownloaded = 0;
|
||||||
if (debug) Log("b", $"requesting file download: {filePath_server}\n");
|
Debug("b", $"requesting file download: {filePath_server}\n");
|
||||||
mainSocket.SendPackage("requesting file download".ToBytes());
|
mainSocket.SendPackage("requesting file download".ToBytes());
|
||||||
mainSocket.SendPackage(filePath_server.ToBytes());
|
mainSocket.SendPackage(filePath_server.ToBytes());
|
||||||
using var fileStream = new System.IO.MemoryStream();
|
using var fileStream = new System.IO.MemoryStream();
|
||||||
@ -117,14 +117,14 @@ namespace DTLib.Network
|
|||||||
//speedCounter.Stop();
|
//speedCounter.Stop();
|
||||||
byte[] output = fileStream.GetBuffer();
|
byte[] output = fileStream.GetBuffer();
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
if (debug) Log(new string[] { "g", $" downloaded {BytesDownloaded} of {Filesize} bytes\n" });
|
Debug(new string[] { "g", $" downloaded {BytesDownloaded} of {Filesize} bytes\n" });
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
// отдаёт файл с помощью FSP протокола
|
// отдаёт файл с помощью FSP протокола
|
||||||
public void UploadFile(string filePath)
|
public void UploadFile(string filePath)
|
||||||
{
|
{
|
||||||
if (debug) Log("b", $"uploading file {filePath}\n");
|
Debug("b", $"uploading file {filePath}\n");
|
||||||
using var fileStream = File.OpenRead(filePath);
|
using var fileStream = File.OpenRead(filePath);
|
||||||
Filesize = File.GetSize(filePath).ToUInt();
|
Filesize = File.GetSize(filePath).ToUInt();
|
||||||
var fileHash = new Hasher().HashFile(filePath);
|
var fileHash = new Hasher().HashFile(filePath);
|
||||||
@ -160,32 +160,32 @@ namespace DTLib.Network
|
|||||||
}
|
}
|
||||||
//speedCounter.Stop();
|
//speedCounter.Stop();
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
if (debug) Log(new string[] { "g", $" uploaded {BytesUploaded} of {Filesize} bytes\n" });
|
Debug(new string[] { "g", $" uploaded {BytesUploaded} of {Filesize} bytes\n" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadByManifest(string dirOnServer, string dirOnClient, bool overwrite = false, bool delete_excess = false)
|
public void DownloadByManifest(string dirOnServer, string dirOnClient, bool overwrite = false, bool delete_excess = false)
|
||||||
{
|
{
|
||||||
if (!dirOnClient.EndsWith("\\")) dirOnClient += "\\";
|
if (!dirOnClient.EndsWith("\\")) dirOnClient += "\\";
|
||||||
if (!dirOnServer.EndsWith("\\")) dirOnServer += "\\";
|
if (!dirOnServer.EndsWith("\\")) dirOnServer += "\\";
|
||||||
if (debug) Log("b", "downloading manifest <", "c", dirOnServer + "manifest.dtsod", "b", ">\n");
|
Debug("b", "downloading manifest <", "c", dirOnServer + "manifest.dtsod", "b", ">\n");
|
||||||
var manifest = new DtsodV22(DownloadFileToMemory(dirOnServer + "manifest.dtsod").ToStr());
|
var manifest = new DtsodV22(DownloadFileToMemory(dirOnServer + "manifest.dtsod").ToStr());
|
||||||
if (debug) Log("g", $"found {manifest.Values.Count} files in manifest\n");
|
Debug("g", $"found {manifest.Values.Count} files in manifest\n");
|
||||||
var hasher = new Hasher();
|
var hasher = new Hasher();
|
||||||
foreach (string fileOnServer in manifest.Keys)
|
foreach (string fileOnServer in manifest.Keys)
|
||||||
{
|
{
|
||||||
string fileOnClient = dirOnClient + fileOnServer;
|
string fileOnClient = dirOnClient + fileOnServer;
|
||||||
if (debug) Log("b", "file <", "c", fileOnClient, "b", ">... ");
|
Debug("b", "file <", "c", fileOnClient, "b", ">... ");
|
||||||
if (!File.Exists(fileOnClient))
|
if (!File.Exists(fileOnClient))
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("y", "doesn't exist\n");
|
DebugNoTime("y", "doesn't exist\n");
|
||||||
DownloadFile(dirOnServer + fileOnServer, fileOnClient);
|
DownloadFile(dirOnServer + fileOnServer, fileOnClient);
|
||||||
}
|
}
|
||||||
else if (overwrite && hasher.HashFile(fileOnClient).HashToString() != manifest[fileOnServer])
|
else if (overwrite && hasher.HashFile(fileOnClient).HashToString() != manifest[fileOnServer])
|
||||||
{
|
{
|
||||||
if (debug) LogNoTime("y", "outdated\n");
|
DebugNoTime("y", "outdated\n");
|
||||||
DownloadFile(dirOnServer + fileOnServer, fileOnClient);
|
DownloadFile(dirOnServer + fileOnServer, fileOnClient);
|
||||||
}
|
}
|
||||||
else if (debug) LogNoTime("g", "without changes\n");
|
else DebugNoTime("g", "without changes\n");
|
||||||
}
|
}
|
||||||
// удаление лишних файлов
|
// удаление лишних файлов
|
||||||
if (delete_excess)
|
if (delete_excess)
|
||||||
@ -195,7 +195,7 @@ namespace DTLib.Network
|
|||||||
{
|
{
|
||||||
if (!manifest.ContainsKey(file.Remove(0, dirOnClient.Length)))
|
if (!manifest.ContainsKey(file.Remove(0, dirOnClient.Length)))
|
||||||
{
|
{
|
||||||
if (debug) Log("y", $"deleting excess file: {file}\n");
|
Debug("y", $"deleting excess file: {file}\n");
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ namespace DTLib.Network
|
|||||||
{
|
{
|
||||||
if (Directory.Exists(dir) && Directory.GetAllFiles(dir).Count == 0)
|
if (Directory.Exists(dir) && Directory.GetAllFiles(dir).Count == 0)
|
||||||
{
|
{
|
||||||
if (debug) Log("y", $"deleting empty dir: {dir}\n");
|
Debug("y", $"deleting empty dir: {dir}\n");
|
||||||
Directory.Delete(dir);
|
Directory.Delete(dir);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
@ -230,5 +230,14 @@ namespace DTLib.Network
|
|||||||
File.WriteAllText(dir + "manifest.dtsod", manifestBuilder.ToString());
|
File.WriteAllText(dir + "manifest.dtsod", manifestBuilder.ToString());
|
||||||
Log($"g", $" manifest of {dir} created\n");
|
Log($"g", $" manifest of {dir} created\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Debug(params string[] msg)
|
||||||
|
{
|
||||||
|
if (debug) Log(msg);
|
||||||
|
}
|
||||||
|
void DebugNoTime(params string[] msg)
|
||||||
|
{
|
||||||
|
if (debug) LogNoTime(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user