-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade: Support dynamic combine host from multi-source;
- Loading branch information
Showing
5 changed files
with
121 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace HostSyncer | ||
{ | ||
public class HostItem | ||
{ | ||
public string IP { get; set; } | ||
public string Domain { get; set; } | ||
|
||
public HostItem(string section) | ||
{ | ||
var meta = section.Trim().Split(' ', '\t'); | ||
if (meta.Length < 2) throw new NotSupportedException("\"" + section + "\" cannot be resolved!"); | ||
this.IP = meta.First().Trim(); | ||
this.Domain = meta.Last().Trim(); | ||
} | ||
} | ||
|
||
public class HostItemComparer : IEqualityComparer<HostItem> | ||
{ | ||
public bool Equals(HostItem x, HostItem y) | ||
{ | ||
return x.Domain == y.Domain; | ||
} | ||
|
||
public int GetHashCode(HostItem obj) | ||
{ | ||
string hCode = obj.IP + "^" + obj.Domain; | ||
return hCode.GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace HostSyncer | ||
{ | ||
public class HostModel | ||
{ | ||
public HostModel() | ||
{ | ||
this.IgnoreDomain = new string[] { }; | ||
this.OnlyDomain = null; | ||
} | ||
|
||
private static string EtcPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers", "etc"); | ||
public static string LocalHost => Path.Combine(EtcPath, "hosts"); | ||
public static string LocalHostBak => Path.Combine(EtcPath, "hosts.bak"); | ||
|
||
public string Repo { get; set; } | ||
public string TempFileSubfix { get; set; } | ||
|
||
public string SrcFile => $@"https://github.com/{this.Repo}/raw/master/hosts"; | ||
public string CommitInfoLink => $@"https://api.github.com/repos/{this.Repo}/commits?path=/hosts"; | ||
|
||
public string[] IgnoreDomain { get; internal set; } | ||
public string[] OnlyDomain { get; internal set; } | ||
|
||
public string DestPath => Path.Combine(HostModel.EtcPath, $@"hosts_{this.TempFileSubfix}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters