Added method to delete userspeciffic logs.

This commit is contained in:
SCM6WE
2021-09-23 14:26:35 +02:00
committed by Felix Hartmann (PEA3-Fe-FI)
parent 9141efd55a
commit c3daaf8b00
2 changed files with 63 additions and 0 deletions

View File

@@ -93,8 +93,10 @@ namespace PolyChat
} }
else else
{ {
Debug.WriteLine("---- Added new Connection ----");//Todo show error!
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat)); Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
UIController.OnIncomingConnection(ForeignIp); UIController.OnIncomingConnection(ForeignIp);
fileManager.loadChats(ForeignIp);
} }
}); });
}); });

View File

@@ -21,6 +21,67 @@ namespace PolyChat.Models
UIController = uiController; UIController = uiController;
} }
/// <summary>
/// deletes chatlog of one speciffic user
/// </summary>
/// <param name="ip"></param>
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;
}
}
}
}
}
/// <summary>
/// loads one chatlog probably when someone tries to connect
/// </summary>
/// <param name="ip"></param>
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);
}
}
}
/// <summary> /// <summary>
/// sends chatlogs as json array to uiController wit corrosponding ip /// sends chatlogs as json array to uiController wit corrosponding ip
/// ///