load chatlogs on newly created chat
This commit is contained in:
committed by
Felix Hartmann (PEA3-Fe-FI)
parent
c3daaf8b00
commit
5ce1316245
@@ -93,10 +93,10 @@ namespace PolyChat
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("---- Added new Connection ----");//Todo show error!
|
Debug.WriteLine("---- Added new Connection ----");
|
||||||
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);
|
fileManager.loadChat(ForeignIp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace PolyChat.Models
|
|||||||
{
|
{
|
||||||
foreach (String path in filepaths)
|
foreach (String path in filepaths)
|
||||||
{
|
{
|
||||||
if(Path.GetFileName(path).Equals(ip))
|
if (Path.GetFileName(path).Equals(ip))
|
||||||
{
|
{
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
return;
|
return;
|
||||||
@@ -50,32 +50,15 @@ namespace PolyChat.Models
|
|||||||
/// loads one chatlog probably when someone tries to connect
|
/// loads one chatlog probably when someone tries to connect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip"></param>
|
/// <param name="ip"></param>
|
||||||
public void loadChats()
|
public void loadChat(String ip)
|
||||||
{
|
{
|
||||||
//load dir and create if non existant
|
//load dir and create if non existant
|
||||||
if (Directory.Exists("U:\\PolyChat\\Saves"))
|
if (Directory.Exists("U:\\PolyChat\\Saves"))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--Path exists.--");
|
Debug.WriteLine("--Path exists.--");
|
||||||
}
|
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
||||||
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($"U:\\PolyChat\\Saves\\{ip}.txt"));
|
||||||
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.OnIncomingConnection(ip);
|
||||||
UIController.OnIncomingMessages(ip, jsonArr);
|
UIController.OnIncomingMessages(ip, jsonArr);
|
||||||
}
|
}
|
||||||
@@ -180,9 +163,9 @@ namespace PolyChat.Models
|
|||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
//security
|
//security
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
private void genKeys()
|
private void genKeys()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,7 +176,8 @@ namespace PolyChat.Models
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static String encrypt(String toEncrypt)
|
public static String encrypt(String toEncrypt)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
string textToEncrypt = toEncrypt;
|
string textToEncrypt = toEncrypt;
|
||||||
string ToReturn = "";
|
string ToReturn = "";
|
||||||
string publickey = "santhosh";
|
string publickey = "santhosh";
|
||||||
@@ -214,7 +198,8 @@ namespace PolyChat.Models
|
|||||||
ToReturn = Convert.ToBase64String(ms.ToArray());
|
ToReturn = Convert.ToBase64String(ms.ToArray());
|
||||||
}
|
}
|
||||||
return ToReturn;
|
return ToReturn;
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new Exception(ex.Message, ex.InnerException);
|
throw new Exception(ex.Message, ex.InnerException);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user