fixed bug with incorrect file.Remove()

This commit is contained in:
Timerix22 2024-01-06 01:07:28 +06:00
parent f30b7e1e4d
commit 4f7017e486
3 changed files with 25 additions and 20 deletions

View File

@ -122,17 +122,7 @@ internal static partial class Launcher
if (!offline)
{
ConnectToLauncherServer();
//обновление файлов клиента
Logger.LogInfo("Main", "updating client...");
DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
DownloadByManifest("sync_always", Directory.GetCurrent(), true);
var dirlistDtsod = new DtsodV23(Fsp
.DownloadFileToMemory(Path.Concat("sync_and_remove","dirlist.dtsod"))
.BytesToString());
foreach (string dir in dirlistDtsod["dirs"])
DownloadByManifest(Path.Concat("sync_and_remove", dir),
Path.Concat(Directory.GetCurrent(), dir), true, true);
Logger.LogInfo("Main", "client updated");
UpdateGame();
}
// запуск майнкрафта

View File

@ -21,7 +21,7 @@ public class Network
{
if (mainSocket.Connected)
{
Logger.LogInfo(nameof(ConnectToLauncherServer), "socket is connected already. disconnecting...");
Logger.LogInfo(nameof(Network), "socket is connected already. disconnecting...");
mainSocket.Shutdown(SocketShutdown.Both);
mainSocket.Close();
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@ -31,15 +31,15 @@ public class Network
while (true)
try
{
Logger.LogInfo(nameof(ConnectToLauncherServer), $"connecting to server {Config.ServerAddress}:{Config.ServerPort}");
Logger.LogInfo(nameof(Network), $"connecting to server {Config.ServerAddress}:{Config.ServerPort}");
var ip = Dns.GetHostAddresses(Config.ServerAddress)[0];
mainSocket.Connect(new IPEndPoint(ip, Config.ServerPort));
Logger.LogInfo(nameof(ConnectToLauncherServer), $"connected to server {ip}");
Logger.LogInfo(nameof(Network), $"connected to server {ip}");
break;
}
catch (SocketException ex)
{
Logger.LogError(nameof(ConnectToLauncherServer), ex);
Logger.LogError(nameof(Network), ex);
Thread.Sleep(2000);
}
@ -53,7 +53,7 @@ public class Network
public static void DownloadByManifest(IOPath dirOnServer, IOPath dirOnClient, bool overwrite = false, bool delete_excess = false)
{
var manifestPath = Path.Concat(dirOnServer, "manifest.dtsod");
Logger.LogDebug(nameof(DownloadByManifest), manifestPath);
Logger.LogDebug(nameof(Network), manifestPath);
string manifestContent = Fsp.DownloadFileToMemory(manifestPath).BytesToString();
var manifest = new DtsodV23(manifestContent);
var hasher = new Hasher();
@ -73,4 +73,19 @@ public class Network
}
}
}
public static void UpdateGame()
{
//обновление файлов клиента
Logger.LogInfo(nameof(Network), "updating client...");
DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
DownloadByManifest("sync_always", Directory.GetCurrent(), true);
var dirlistDtsod = new DtsodV23(Fsp
.DownloadFileToMemory(Path.Concat("sync_and_remove","dirlist.dtsod"))
.BytesToString());
foreach (string dir in dirlistDtsod["dirs"])
DownloadByManifest(Path.Concat("sync_and_remove", dir),
Path.Concat(Directory.GetCurrent(), dir), true, true);
Logger.LogInfo(nameof(Network), "client updated");
}
}

View File

@ -24,12 +24,12 @@ public static class Manifests
var manifestPath = Path.Concat(dir, "manifest.dtsod");
if (Directory.GetFiles(dir).Contains(manifestPath))
File.Delete(manifestPath);
foreach (var _file in Directory.GetAllFiles(dir))
foreach (var fileInDir in Directory.GetAllFiles(dir))
{
var file = _file.Remove(0, dir.Length);
manifestBuilder.Append(file);
var fileRelative = fileInDir.RemoveBase(dir);
manifestBuilder.Append(fileRelative);
manifestBuilder.Append(": \"");
byte[] hash = hasher.HashFile(Path.Concat(dir, file));
byte[] hash = hasher.HashFile(Path.Concat(fileInDir));
manifestBuilder.Append(hash.HashToString());
manifestBuilder.Append("\";\n");
}