diff --git a/v2rayN/ServiceLib/Common/FileManager.cs b/v2rayN/ServiceLib/Common/FileManager.cs index b7bc3a8f..11d03eb0 100644 --- a/v2rayN/ServiceLib/Common/FileManager.cs +++ b/v2rayN/ServiceLib/Common/FileManager.cs @@ -196,5 +196,26 @@ namespace ServiceLib.Common } } } + + public static void DeleteExpiredFiles(string sourceDir, DateTime dtLine) + { + try + { + var files = Directory.GetFiles(sourceDir, "*.*"); + foreach (var filePath in files) + { + var file = new FileInfo(filePath); + if (file.CreationTime >= dtLine) + { + continue; + } + file.Delete(); + } + } + catch + { + // ignored + } + } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Common/Logging.cs b/v2rayN/ServiceLib/Common/Logging.cs index c8b07053..7031260f 100644 --- a/v2rayN/ServiceLib/Common/Logging.cs +++ b/v2rayN/ServiceLib/Common/Logging.cs @@ -25,36 +25,6 @@ namespace ServiceLib.Common } } - public static void ClearLogs() - { - Task.Run(() => - { - try - { - var now = DateTime.Now.AddMonths(-1); - var dir = Utils.GetLogPath(); - var files = Directory.GetFiles(dir, "*.txt"); - foreach (var filePath in files) - { - var file = new FileInfo(filePath); - if (file.CreationTime >= now) continue; - try - { - file.Delete(); - } - catch - { - // ignored - } - } - } - catch - { - // ignored - } - }); - } - public static void SaveLog(string strContent) { if (!LogManager.IsLoggingEnabled()) return; diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 0a3a2815..087918f9 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -79,8 +79,8 @@ { Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}"); Logging.LoggingEnabled(_config.GuiItem.EnableLog); - Logging.ClearLogs(); - ClearTemps(); + + ClearExpiredFiles(); return true; } @@ -92,33 +92,12 @@ return true; } - private void ClearTemps() + private void ClearExpiredFiles() { Task.Run(() => { - try - { - var now = DateTime.Now.AddMonths(-1); - var dir = Utils.GetTempPath(); - var files = Directory.GetFiles(dir, "*.*"); - foreach (var filePath in files) - { - var file = new FileInfo(filePath); - if (file.CreationTime >= now) continue; - try - { - file.Delete(); - } - catch - { - // ignored - } - } - } - catch - { - // ignored - } + FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1)); + FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1)); }); }