diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs
index f9c8131..d7a2d6f 100644
--- a/PolyChat/Controller.cs
+++ b/PolyChat/Controller.cs
@@ -93,8 +93,10 @@ namespace PolyChat
}
else
{
+ Debug.WriteLine("---- Added new Connection ----");//Todo show error!
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
UIController.OnIncomingConnection(ForeignIp);
+ fileManager.loadChats(ForeignIp);
}
});
});
diff --git a/PolyChat/Models/FileManager.cs b/PolyChat/Models/FileManager.cs
index 3702fd5..ec1485f 100644
--- a/PolyChat/Models/FileManager.cs
+++ b/PolyChat/Models/FileManager.cs
@@ -21,6 +21,67 @@ namespace PolyChat.Models
UIController = uiController;
}
+ ///
+ /// deletes chatlog of one speciffic user
+ ///
+ ///
+ public void deleteChat(String ip)
+ {
+ if (Directory.Exists("U:\\PolyChat\\Saves"))
+ {
+ Debug.WriteLine("--Path exists.--");
+ //go through all files and send ip and json array to ui
+ String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves");
+ if (filepaths.Length > 0)
+ {
+ foreach (String path in filepaths)
+ {
+ if(Path.GetFileName(path).Equals(ip))
+ {
+ File.Delete(path);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// loads one chatlog probably when someone tries to connect
+ ///
+ ///
+ public void loadChats()
+ {
+ //load dir and create if non existant
+ if (Directory.Exists("U:\\PolyChat\\Saves"))
+ {
+ Debug.WriteLine("--Path exists.--");
+ }
+ else
+ {
+ Directory.CreateDirectory("U:\\PolyChat\\Saves");
+ Debug.WriteLine("--Path Created--.");
+ }
+
+ //go through all files and send ip and json array to ui
+ String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves");
+ if (filepaths.Length > 0)
+ {
+ Debug.WriteLine("---Loading Saves");
+ foreach (String path in filepaths)
+ {
+ Debug.WriteLine($"--{path}");
+ String jsonArr = decrypt(File.ReadAllText(path));
+ String ip = Path.GetFileName(path);
+ ip = ip.Substring(0, ip.Length - 4);
+ Debug.WriteLine($"-{ip}");
+ Debug.WriteLine(jsonArr);
+ UIController.OnIncomingConnection(ip);
+ UIController.OnIncomingMessages(ip, jsonArr);
+ }
+ }
+ }
+
///
/// sends chatlogs as json array to uiController wit corrosponding ip
///