From 80f7d54de91246197607ee4d3829bf6a54d63bca Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Thu, 3 Aug 2017 22:11:35 +1000 Subject: [PATCH] added save/load support (not enabled) to chat AI OnUnload() doesn't actually seem to get called, ever, so I added an ifdef'd out line to the message send function that would save the cache every single time the user sent a message. It works, but eugh... my poor SSD works hard. I want to give it a break. --- ShiftOS.Frontend/Apps/ChatClient.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ShiftOS.Frontend/Apps/ChatClient.cs b/ShiftOS.Frontend/Apps/ChatClient.cs index de9d80f..acb6b6f 100644 --- a/ShiftOS.Frontend/Apps/ChatClient.cs +++ b/ShiftOS.Frontend/Apps/ChatClient.cs @@ -93,7 +93,12 @@ namespace ShiftOS.Frontend.Apps //Let's try the AI stuff... :P if (!messagecache.Contains(_messages.Last().Message)) + { messagecache.Add(_messages.Last().Message); +#if RIP_USERS_SSD + SaveCache(); +#endif + } var rmsg = messagecache[rnd.Next(messagecache.Count)]; var split = new List(rmsg.Split(' ')); List nmsg = new List(); @@ -127,7 +132,7 @@ namespace ShiftOS.Frontend.Apps readonly string[] outcomes = new string[] { "ok", "sure", "yeah", "yes", "no", "nope", "alright" }; Random rnd = new Random(); - List messagecache = new List(); + private List messagecache = new List(); public void SendClientMessage(string nick, string message) { @@ -170,21 +175,30 @@ namespace ShiftOS.Frontend.Apps } gfx.DrawRectangle(vertSeparatorLeft, 0, 1, _bottomseparator, UIManager.SkinTextures["ControlTextColor"]); } - + public void OnLoad() { - + if (System.IO.File.Exists("aicache.dat")) + messagecache = System.IO.File.ReadAllLines("aicache.dat").ToList(); } public void OnSkinLoad() { } - + public bool OnUnload() { + // this doesn't get called... dammit + SaveCache(); return true; } + private void SaveCache() + { + // It's watching you... + System.IO.File.WriteAllLines("aicache.dat", messagecache); + } + public void OnUpgrade() { }