AI-optimized code

This commit is contained in:
2dust 2025-03-06 11:10:55 +08:00
parent d4a8787356
commit c3439c5abe
2 changed files with 7 additions and 3 deletions

View file

@ -15,7 +15,7 @@ namespace ServiceLib.Handler
public static async Task Start(string configPath, int httpPort, int pacPort) public static async Task Start(string configPath, int httpPort, int pacPort)
{ {
_needRestart = (configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning); _needRestart = configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning;
_configPath = configPath; _configPath = configPath;
_httpPort = httpPort; _httpPort = httpPort;
@ -70,7 +70,7 @@ namespace ServiceLib.Handler
} }
var client = await _tcpListener.AcceptTcpClientAsync(); var client = await _tcpListener.AcceptTcpClientAsync();
await Task.Run(() => { WriteContent(client); }); await Task.Run(() => WriteContent(client));
} }
catch catch
{ {
@ -90,7 +90,9 @@ namespace ServiceLib.Handler
public static void Stop() public static void Stop()
{ {
if (_tcpListener == null) if (_tcpListener == null)
{
return; return;
}
try try
{ {
_isRunning = false; _isRunning = false;

View file

@ -8,7 +8,7 @@ namespace ServiceLib.Handler
private static readonly Lazy<WebDavHandler> _instance = new(() => new()); private static readonly Lazy<WebDavHandler> _instance = new(() => new());
public static WebDavHandler Instance => _instance.Value; public static WebDavHandler Instance => _instance.Value;
private Config? _config; private readonly Config? _config;
private WebDavClient? _client; private WebDavClient? _client;
private string? _lastDescription; private string? _lastDescription;
private string _webDir = Global.AppName + "_backup"; private string _webDir = Global.AppName + "_backup";
@ -62,7 +62,9 @@ namespace ServiceLib.Handler
private async Task<bool> TryCreateDir() private async Task<bool> TryCreateDir()
{ {
if (_client is null) if (_client is null)
{
return false; return false;
}
try try
{ {
var result2 = await _client.Mkcol(_webDir); var result2 = await _client.Mkcol(_webDir);