From 7c38bfc7559ba485e9d41604d709906b03fb6f40 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 14 Jun 2023 17:19:06 +1000 Subject: [PATCH] main: Move log if it is getting big --- FireWallet/MainForm.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index bd5f0bd..669df96 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -308,6 +308,18 @@ namespace FireWallet public void AddLog(string message) { if (message.Contains("Get Error: No connection could be made because the target machine actively refused it")) return; + + // If file size is over 1MB, rename it to old.log.txt + if (File.Exists(dir + "log.txt")) + { + FileInfo fi = new FileInfo(dir + "log.txt"); + if (fi.Length > 1000000) + { + if (File.Exists(dir + "old.log.txt")) File.Delete(dir + "old.log.txt"); // Delete old log file as it is super old + File.Move(dir + "log.txt", dir + "old.log.txt"); + } + } + StreamWriter sw = new StreamWriter(dir + "log.txt", true); sw.WriteLine(DateTime.Now.ToString() + ": " + message); sw.Dispose(); @@ -912,10 +924,7 @@ namespace FireWallet } JArray txs = JArray.Parse(TXGET["result"].ToString()); - if (toGet > txs.Count) - { - toGet = txs.Count; - } + if (toGet > txs.Count) toGet = txs.Count; // In case there are less TXs than expected (usually happens when the get TX's fails) Control[] tmpControls = new Control[toGet]; for (int i = 0; i < toGet; i++) {