Compare commits

..

3 commits

Author SHA1 Message Date
2dust
a6479fe0d0 Update build-windows.yml
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release macOS / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run
2025-01-14 18:15:45 +08:00
2dust
4ad4e27dc1 Improve reload function 2025-01-14 17:05:13 +08:00
2dust
7370684985 Improve delete expired files 2025-01-14 17:04:43 +08:00
5 changed files with 44 additions and 62 deletions

View file

@ -29,6 +29,11 @@ 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,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
}
}
} }
} }

View file

@ -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) 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();
ClearTemps(); ClearExpiredFiles();
return true; return true;
} }
@ -92,33 +92,12 @@
return true; return true;
} }
private void ClearTemps() private void ClearExpiredFiles()
{ {
Task.Run(() => Task.Run(() =>
{ {
try FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1));
{ 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,6 +63,8 @@ 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)
@ -534,14 +536,12 @@ namespace ServiceLib.ViewModels
#region core job #region core job
public async Task Reload(int times = 0) public async Task Reload()
{ {
//If there are unfinished reload job, wait a few seconds and exec again. //If there are unfinished reload job, marked with next job.
if (!BlReloadEnabled) if (!BlReloadEnabled)
{ {
await Task.Delay(3000); _hasNextReloadJob = true;
if (times > 3) return;
await Reload(++times);
return; return;
} }
@ -552,12 +552,19 @@ 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)
{ {