fix bug
This commit is contained in:
parent
582d9504ef
commit
001c6dddf7
@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.0.3-Smooth_Switching_IPAddress</Version>
|
<Version>2.0.3</Version>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Description>github加速神器</Description>
|
<Description>github加速神器</Description>
|
||||||
<Copyright>https://github.com/dotnetcore/FastGithub</Copyright>
|
<Copyright>https://github.com/dotnetcore/FastGithub</Copyright>
|
||||||
|
|||||||
@ -48,6 +48,7 @@ namespace FastGithub.Http
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async void StartCleanup()
|
private async void StartCleanup()
|
||||||
{
|
{
|
||||||
|
await Task.Yield();
|
||||||
while (this.Cleanup() == false)
|
while (this.Cleanup() == false)
|
||||||
{
|
{
|
||||||
await Task.Delay(this.CleanupInterval);
|
await Task.Delay(this.CleanupInterval);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using FastGithub.Configuration;
|
using FastGithub.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
@ -15,14 +16,19 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
sealed class HostsConflictSolver : IDnsConflictSolver
|
sealed class HostsConflictSolver : IDnsConflictSolver
|
||||||
{
|
{
|
||||||
private readonly FastGithubConfig fastGithubConfig;
|
private readonly FastGithubConfig fastGithubConfig;
|
||||||
|
private readonly ILogger<HostsConflictSolver> logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// host文件冲解决者
|
/// host文件冲解决者
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fastGithubConfig"></param>
|
/// <param name="fastGithubConfig"></param>
|
||||||
public HostsConflictSolver(FastGithubConfig fastGithubConfig)
|
/// <param name="logger"></param>
|
||||||
|
public HostsConflictSolver(
|
||||||
|
FastGithubConfig fastGithubConfig,
|
||||||
|
ILogger<HostsConflictSolver> logger)
|
||||||
{
|
{
|
||||||
this.fastGithubConfig = fastGithubConfig;
|
this.fastGithubConfig = fastGithubConfig;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -56,8 +62,15 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
|
|
||||||
if (hasConflicting == true)
|
if (hasConflicting == true)
|
||||||
{
|
{
|
||||||
File.SetAttributes(hostsPath, FileAttributes.Normal);
|
try
|
||||||
await File.WriteAllTextAsync(hostsPath, hostsBuilder.ToString(), cancellationToken);
|
{
|
||||||
|
File.Move(hostsPath, Path.ChangeExtension(hostsPath, ".bak"), overwrite: true);
|
||||||
|
await File.WriteAllTextAsync(hostsPath, hostsBuilder.ToString(), cancellationToken);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning($"无法解决hosts文件冲突:{ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user