This commit is contained in:
Timerix 2021-09-13 17:04:23 +03:00
parent ef6a55b385
commit 65ccd57136
7 changed files with 62 additions and 20 deletions

View File

@ -22,7 +22,7 @@ namespace DTLib.ConsoleGUI
void ParseLayoutFile(string layout_file) void ParseLayoutFile(string layout_file)
{ {
DtsodV22 layout = new(File.ReadAllText(layout_file)); DtsodV23 layout = new(File.ReadAllText(layout_file));
AnchorPoint = (layout[Name]["anchor"][0], layout[Name]["anchor"][1]); AnchorPoint = (layout[Name]["anchor"][0], layout[Name]["anchor"][1]);
Width = layout[Name]["width"]; Width = layout[Name]["width"];
Height = layout[Name]["height"]; Height = layout[Name]["height"];

View File

@ -40,6 +40,7 @@
<Compile Include="ConsoleGUI\Window.cs" /> <Compile Include="ConsoleGUI\Window.cs" />
<Compile Include="ConsoleGUI\WindowOld.cs" /> <Compile Include="ConsoleGUI\WindowOld.cs" />
<Compile Include="Dtsod\DtsodV22.cs" /> <Compile Include="Dtsod\DtsodV22.cs" />
<Compile Include="Dtsod\DtsodV23.cs" />
<Compile Include="Dtsod\DtsodV21.cs" /> <Compile Include="Dtsod\DtsodV21.cs" />
<Compile Include="cs9somefix.cs" /> <Compile Include="cs9somefix.cs" />
<Compile Include="Dtsod\ValueTypes.cs" /> <Compile Include="Dtsod\ValueTypes.cs" />
@ -53,6 +54,7 @@
<Compile Include="Network\OldNetwork.cs" /> <Compile Include="Network\OldNetwork.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Hasher.cs" /> <Compile Include="Hasher.cs" />
<Compile Include="SafeMutex.cs" />
<Compile Include="SecureRandom.cs" /> <Compile Include="SecureRandom.cs" />
<Compile Include="SimpleConverter.cs" /> <Compile Include="SimpleConverter.cs" />
<Compile Include="TImer.cs" /> <Compile Include="TImer.cs" />

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using static System.Net.Mime.MediaTypeNames;
namespace DTLib.Dtsod namespace DTLib.Dtsod
{ {

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using static System.Net.Mime.MediaTypeNames;
namespace DTLib.Dtsod namespace DTLib.Dtsod
{ {

View File

@ -1,6 +1,5 @@
using DTLib.Dtsod; using DTLib.Dtsod;
using DTLib.Filesystem; using DTLib.Filesystem;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
@ -130,7 +129,7 @@ namespace DTLib.Network
var fileHash = new Hasher().HashFile(filePath); var fileHash = new Hasher().HashFile(filePath);
mainSocket.SendPackage(Filesize.ToString().ToBytes()); mainSocket.SendPackage(Filesize.ToString().ToBytes());
mainSocket.SendPackage(fileHash); mainSocket.SendPackage(fileHash);
if (mainSocket.GetPackage().ToStr() != "ready") throw new Exception("user socket isn't ready"); mainSocket.GetAnswer("ready");
byte[] buffer = new byte[5120]; byte[] buffer = new byte[5120];
var hashstr = fileHash.HashToString(); var hashstr = fileHash.HashToString();
int packagesCount = 0; int packagesCount = 0;
@ -163,6 +162,52 @@ namespace DTLib.Network
Debug(new string[] { "g", $" uploaded {BytesUploaded} of {Filesize} bytes\n" }); Debug(new string[] { "g", $" uploaded {BytesUploaded} of {Filesize} bytes\n" });
} }
/*public void DownloadByManifest(string manifestString, string dirOnClient, bool overwrite = false, bool delete_excess = false)
{
if (!dirOnClient.EndsWith("\\")) dirOnClient += "\\";
var manifest = new DtsodV23(manifestString);
Debug("g", $"found {manifest.Values.Count} files in manifest\n");
var hasher = new Hasher();
foreach (string fileOnServer in manifest.Keys)
{
string fileOnClient = dirOnClient + fileOnServer;
Debug("b", "file <", "c", fileOnClient, "b", ">... ");
if (!File.Exists(fileOnClient))
{
DebugNoTime("y", "doesn't exist\n");
DownloadFile(fileOnServer, fileOnClient);
}
else if (overwrite && hasher.HashFile(fileOnClient).HashToString() != manifest[fileOnServer])
{
DebugNoTime("y", "outdated\n");
DownloadFile(fileOnServer, fileOnClient);
}
else DebugNoTime("g", "without changes\n");
}
// удаление лишних файлов
if (delete_excess)
{
List<string> dirs = new();
foreach (string file in Directory.GetAllFiles(dirOnClient, ref dirs))
{
if (!manifest.ContainsKey(file.Remove(0, dirOnClient.Length)))
{
Debug("y", $"deleting excess file: {file}\n");
File.Delete(file);
}
}
// удаление пустых папок
/*foreach (string dir in dirs)
{
if (Directory.Exists(dir) && Directory.GetAllFiles(dir).Count == 0)
{
Debug("y", $"deleting empty dir: {dir}\n");
Directory.Delete(dir);
}
}*/
/*}
}*/
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 += "\\";
@ -190,8 +235,7 @@ namespace DTLib.Network
// удаление лишних файлов // удаление лишних файлов
if (delete_excess) if (delete_excess)
{ {
List<string> dirs = new(); foreach (string file in Directory.GetAllFiles(dirOnClient))
foreach (string file in Directory.GetAllFiles(dirOnClient, ref dirs))
{ {
if (!manifest.ContainsKey(file.Remove(0, dirOnClient.Length))) if (!manifest.ContainsKey(file.Remove(0, dirOnClient.Length)))
{ {
@ -199,15 +243,6 @@ namespace DTLib.Network
File.Delete(file); File.Delete(file);
} }
} }
// удаление пустых папок
/*foreach (string dir in dirs)
{
if (Directory.Exists(dir) && Directory.GetAllFiles(dir).Count == 0)
{
Debug("y", $"deleting empty dir: {dir}\n");
Directory.Delete(dir);
}
}*/
} }
} }
@ -227,15 +262,15 @@ namespace DTLib.Network
manifestBuilder.Append(hash.HashToString()); manifestBuilder.Append(hash.HashToString());
manifestBuilder.Append("\";\n"); manifestBuilder.Append("\";\n");
} }
Debug($"g", $" manifest of {dir} created\n");
File.WriteAllText(dir + "manifest.dtsod", manifestBuilder.ToString()); File.WriteAllText(dir + "manifest.dtsod", manifestBuilder.ToString());
Log($"g", $" manifest of {dir} created\n");
} }
void Debug(params string[] msg) static void Debug(params string[] msg)
{ {
if (debug) Log(msg); if (debug) Log(msg);
} }
void DebugNoTime(params string[] msg) static void DebugNoTime(params string[] msg)
{ {
if (debug) LogNoTime(msg); if (debug) LogNoTime(msg);
} }

View File

@ -53,5 +53,11 @@ namespace DTLib.Network
var rec = socket.GetPackage().ToStr(); var rec = socket.GetPackage().ToStr();
if (rec != answer) throw new Exception($"GetAnswer() error: invalid answer: <{rec}>"); if (rec != answer) throw new Exception($"GetAnswer() error: invalid answer: <{rec}>");
} }
public static byte[] RequestPackage(this Socket socket, byte[] request)
{
socket.SendPackage(request);
return socket.GetPackage();
}
} }
} }

View File

@ -23,9 +23,10 @@ namespace DTLib
method(); method();
} while (Repeat); } while (Repeat);
}); });
TimerThread.Start();
} }
public void Start() => TimerThread.Start();
// завершение потока // завершение потока
public void Stop() public void Stop()
{ {