Compare commits

..

No commits in common. "a6479fe0d06876232336dcd73b1489c9486aa46f" and "5ae58e6a980f0d21ca8f11dad2492840262bcaab" have entirely different histories.

5 changed files with 62 additions and 44 deletions

View file

@ -29,11 +29,6 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Build - name: Build
run: | run: |
cd v2rayN cd v2rayN

View file

@ -196,26 +196,5 @@ 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
}
}
} }
} }

View file

@ -25,6 +25,36 @@ 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) public static void SaveLog(string strContent)
{ {
if (!LogManager.IsLoggingEnabled()) return; if (!LogManager.IsLoggingEnabled()) return;

View file

@ -79,8 +79,8 @@
{ {
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}"); Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
Logging.LoggingEnabled(_config.GuiItem.EnableLog); Logging.LoggingEnabled(_config.GuiItem.EnableLog);
Logging.ClearLogs();
ClearExpiredFiles(); ClearTemps();
return true; return true;
} }
@ -92,12 +92,33 @@
return true; return true;
} }
private void ClearExpiredFiles() private void ClearTemps()
{ {
Task.Run(() => Task.Run(() =>
{ {
FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1)); try
FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1)); {
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
}
}); });
} }

View file

@ -63,8 +63,6 @@ namespace ServiceLib.ViewModels
#endregion Menu #endregion Menu
private bool _hasNextReloadJob = false;
#region Init #region Init
public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
@ -536,12 +534,14 @@ namespace ServiceLib.ViewModels
#region core job #region core job
public async Task Reload() public async Task Reload(int times = 0)
{ {
//If there are unfinished reload job, marked with next job. //If there are unfinished reload job, wait a few seconds and exec again.
if (!BlReloadEnabled) if (!BlReloadEnabled)
{ {
_hasNextReloadJob = true; await Task.Delay(3000);
if (times > 3) return;
await Reload(++times);
return; return;
} }
@ -552,19 +552,12 @@ namespace ServiceLib.ViewModels
await SysProxyHandler.UpdateSysProxy(_config, false); await SysProxyHandler.UpdateSysProxy(_config, false);
_updateView?.Invoke(EViewAction.DispatcherReload, null); _updateView?.Invoke(EViewAction.DispatcherReload, null);
BlReloadEnabled = true;
if (_hasNextReloadJob)
{
_hasNextReloadJob = false;
await Reload();
}
} }
public void ReloadResult() public void ReloadResult()
{ {
// BlReloadEnabled = true;
//Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false); //Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
BlReloadEnabled = true;
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box); ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (ShowClashUI) if (ShowClashUI)
{ {