diff --git a/Server/Client.cs b/Server/Client.cs index 9e1b2a9..9ff610e 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Net.Sockets; using System.Text; @@ -21,7 +22,7 @@ namespace Server public Client(Communication communication, TcpClient tcpClient) { - this.saveData = new SaveData(); + this.saveData = new SaveData(Directory.GetCurrentDirectory()+$"/test"); this.communication = communication; this.tcpClient = tcpClient; this.stream = this.tcpClient.GetStream(); @@ -77,12 +78,13 @@ namespace Server Array.Copy(message, 5, jsonArray, 0, message.Length - 5); dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonArray)); Console.WriteLine(json); - saveData.WriteData(Encoding.ASCII.GetString(jsonArray)); + saveData.WriteDataJSON(Encoding.ASCII.GetString(jsonArray)); } else if (message[4] == 0x02) { Console.WriteLine(message); + saveData.WriteDataRAW(Encoding.ASCII.GetString(message)); } diff --git a/Server/SaveData.cs b/Server/SaveData.cs index eddb8a9..640a862 100644 --- a/Server/SaveData.cs +++ b/Server/SaveData.cs @@ -7,13 +7,27 @@ namespace Server { class SaveData { - public SaveData() + private string path; + public SaveData(string path) { + this.path = path; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } } - public void WriteData(string data) + public void WriteDataJSON(string data) { - using (StreamWriter sw = File.AppendText(Directory.GetCurrentDirectory() + "/data.txt")) + using (StreamWriter sw = File.AppendText(this.path + "/dataJSON.txt")) + { + sw.WriteLine(data); + } + } + + public void WriteDataRAW(string data) + { + using (StreamWriter sw = File.AppendText(this.path + "/dataRAW.txt")) { sw.WriteLine(data); }