stringbuilder is faster than string but something is still off, most files dont have barely any content

This commit is contained in:
ti_mo
2026-02-22 00:52:43 +01:00
parent 1788f33c2f
commit 5671a7aac8
+18 -7
View File
@@ -24,7 +24,7 @@ static class DataExtractor
if (data.Length == 0) return; if (data.Length == 0) return;
var s = data.Split('|').ToList(); var s = data.Split('|').ToList();
if(s.Count < 3) return; if (s.Count < 3) return;
Data.Name = s[0]; Data.Name = s[0];
@@ -42,7 +42,7 @@ static class DataExtractor
static class DataHandler static class DataHandler
{ {
public const string OutputDir = "./output"; public const string OutputDir = "output";
public static void Parse(string data) public static void Parse(string data)
{ {
@@ -54,7 +54,16 @@ static class DataHandler
if (parsed.Name.Length == 0 || parsed.Length == 0 || parsed.Content.Length == 0) return; if (parsed.Name.Length == 0 || parsed.Length == 0 || parsed.Content.Length == 0) return;
var newPath = Path.Combine(OutputDir, parsed.Name); var processPath = Path.GetDirectoryName(Environment.ProcessPath);
if (processPath == null) return;
var outputDir = Path.Combine(processPath, OutputDir);
var newPath = Path.Combine(outputDir, parsed.Name);
if (newPath == parsed.Name)
{
newPath = outputDir + Path.DirectorySeparatorChar + parsed.Name.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
} // DO NOT WRITE SOMEWHERE ELSE THAN OUTPUT DIR
var fi = new FileInfo(newPath); var fi = new FileInfo(newPath);
var dir = Path.GetDirectoryName(newPath) ?? OutputDir; var dir = Path.GetDirectoryName(newPath) ?? OutputDir;
var di = new DirectoryInfo(dir); var di = new DirectoryInfo(dir);
@@ -94,12 +103,13 @@ internal class Server
{ {
if(!_listener.Pending()) continue; if(!_listener.Pending()) continue;
var peer = _listener.AcceptTcpClient(); using var peer = _listener.AcceptTcpClient();
var stream = peer.GetStream(); using var stream = peer.GetStream();
Console.WriteLine($"Connected to Peer: {peer.Client.RemoteEndPoint}"); Console.WriteLine($"Connected to Peer: {peer.Client.RemoteEndPoint}");
while (GetState(peer) == TcpState.Established) while (GetState(peer) == TcpState.Established)
{ {
StringBuilder sb = new();
var buffer = ""; var buffer = "";
try try
@@ -120,14 +130,15 @@ internal class Server
var recvCount = stream.Read(recvBytes); var recvCount = stream.Read(recvBytes);
if(recvCount <= 0) continue; if(recvCount <= 0) continue;
// TODO: for is to heavy // TODO: for and string are to heavy
for (var i = 0; i < recvCount; i++) buffer += (char)recvBytes[i]; sb.Append(Encoding.UTF8.GetString(recvBytes));
availableBytes -= recvCount; availableBytes -= recvCount;
} }
} }
} }
catch (Exception ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); }
buffer = sb.ToString();
if(buffer.Length == 0) continue; if(buffer.Length == 0) continue;
foreach (var b in buffer.Split("\r\n\r\n")) foreach (var b in buffer.Split("\r\n\r\n"))