aboutsummaryrefslogtreecommitdiff
path: root/tools/Crupest.SecretTool
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-10-04 01:40:42 +0800
committercrupest <crupest@outlook.com>2024-10-04 01:40:42 +0800
commit5042d32ea772faecb1f05a4ac6d675b51c5484d4 (patch)
tree7e0b29f476296bc0f4690cd1aa72826b5078fb90 /tools/Crupest.SecretTool
parent39c51129d32659dd93b4d1ab9bd945a0c57df2f9 (diff)
downloadcrupest-5042d32ea772faecb1f05a4ac6d675b51c5484d4.tar.gz
crupest-5042d32ea772faecb1f05a4ac6d675b51c5484d4.tar.bz2
crupest-5042d32ea772faecb1f05a4ac6d675b51c5484d4.zip
fix(secret-tool): fix download geodata and restart.
Diffstat (limited to 'tools/Crupest.SecretTool')
-rw-r--r--tools/Crupest.SecretTool/Crupest.SecretTool/FileWatcher.cs2
-rw-r--r--tools/Crupest.SecretTool/Crupest.SecretTool/GeoDataManager.cs19
-rw-r--r--tools/Crupest.SecretTool/Crupest.SecretTool/Program.cs6
3 files changed, 21 insertions, 6 deletions
diff --git a/tools/Crupest.SecretTool/Crupest.SecretTool/FileWatcher.cs b/tools/Crupest.SecretTool/Crupest.SecretTool/FileWatcher.cs
index 193874f..26e9231 100644
--- a/tools/Crupest.SecretTool/Crupest.SecretTool/FileWatcher.cs
+++ b/tools/Crupest.SecretTool/Crupest.SecretTool/FileWatcher.cs
@@ -19,7 +19,7 @@ public class FileWatcher(string directory, List<string> fileNames)
while (true)
{
- var result = sourceWatcher.WaitForChanged(WatcherChangeTypes.Changed);
+ var result = sourceWatcher.WaitForChanged(WatcherChangeTypes.Changed | WatcherChangeTypes.Created);
OnChanged?.Invoke();
}
}
diff --git a/tools/Crupest.SecretTool/Crupest.SecretTool/GeoDataManager.cs b/tools/Crupest.SecretTool/Crupest.SecretTool/GeoDataManager.cs
index 2d9e2eb..0b61cac 100644
--- a/tools/Crupest.SecretTool/Crupest.SecretTool/GeoDataManager.cs
+++ b/tools/Crupest.SecretTool/Crupest.SecretTool/GeoDataManager.cs
@@ -183,7 +183,7 @@ public class GeoDataManager
{
Assets =
[
- new("geosite", GeoSiteFileName, ToolGithub.Organization, ToolGithub.GeoSiteRepository, ToolGithub.GeoSiteRepository),
+ new("geosite", GeoSiteFileName, ToolGithub.Organization, ToolGithub.GeoSiteRepository, ToolGithub.GeoSiteReleaseFilename),
new("geoip", GeoIpFileName, ToolGithub.Organization, ToolGithub.GeoIpRepository, ToolGithub.GeoIpReleaseFilename),
new("geoip-cn", GeoIpCnFileName, ToolGithub.Organization, ToolGithub.GeoIpRepository, ToolGithub.GeoIpCnReleaseFilename),
];
@@ -205,9 +205,11 @@ public class GeoDataManager
return $"https://github.com/{user}/{repo}/releases/latest/download/{fileName}";
}
- private static void GithubDownloadRelease(HttpClient httpClient, string user, string repo, string fileName, string outputPath)
+ private static void GithubDownloadRelease(HttpClient httpClient, string user, string repo, string fileName, string outputPath, bool silent)
{
- using var responseStream = httpClient.GetStreamAsync(GetReleaseFileUrl(user, repo, fileName)).Result;
+ var url = GetReleaseFileUrl(user, repo, fileName);
+ if (!silent) Console.WriteLine($"Downloading {url} to {outputPath}");
+ using var responseStream = httpClient.GetStreamAsync(url).Result;
using var outputFileStream = File.OpenWrite(outputPath);
responseStream.CopyTo(outputFileStream);
}
@@ -236,12 +238,21 @@ public class GeoDataManager
{
Console.WriteLine($"Downloading {asset.Name}...");
}
- GithubDownloadRelease(httpClient, asset.GithubUser, asset.GithubRepo, asset.GithubReleaseFileName, Path.Combine(outputDir, asset.FileName));
+ GithubDownloadRelease(httpClient, asset.GithubUser, asset.GithubRepo, asset.GithubReleaseFileName, Path.Combine(outputDir, asset.FileName), silent);
if (!silent)
{
Console.WriteLine($"Downloaded {asset.Name}!");
}
}
+
+ if (!File.Exists(Program.RestartLabelFilePath))
+ {
+ File.Create(Program.RestartLabelFilePath);
+ }
+ else
+ {
+ File.SetLastWriteTime(Program.RestartLabelFilePath, DateTime.Now);
+ }
}
private static string GetGithubRepositoryArchiveUrl(string user, string repo)
diff --git a/tools/Crupest.SecretTool/Crupest.SecretTool/Program.cs b/tools/Crupest.SecretTool/Crupest.SecretTool/Program.cs
index afbcde9..9898af1 100644
--- a/tools/Crupest.SecretTool/Crupest.SecretTool/Program.cs
+++ b/tools/Crupest.SecretTool/Crupest.SecretTool/Program.cs
@@ -15,6 +15,9 @@ public static class Program
private const string SurgeRuleSetChinaOutputFileName = "ChinaRuleSet.txt";
private const string SurgeRuleSetGlobalOutputFileName = "GlobalRuleSet.txt";
+ public const string RestartLabelFileName = "restart.label";
+ public static string RestartLabelFilePath { get; } = Path.Combine(CrupestSecretToolDirectory, RestartLabelFileName);
+
public static void RunToolAndWatchConfigChange()
{
var executablePath = Controller.FindExecutable(CrupestSecretToolDirectory, out var isLocal) ??
@@ -42,7 +45,8 @@ public static class Program
}
var controller = new Controller(executablePath, Path.Combine(CrupestSecretToolDirectory, ConfigOutputFileName), assetsPath);
- var configFileWatcher = new FileWatcher(CrupestSecretToolDirectory, ToolConfig.ConfigFileNames);
+ var configFileWatcher = new FileWatcher(CrupestSecretToolDirectory,
+ [.. ToolConfig.ConfigFileNames, RestartLabelFileName]);
ToolConfig.FromDirectoryAndWriteToFile(CrupestSecretToolDirectory, Path.Join(CrupestSecretToolDirectory, ConfigOutputFileName));
controller.Start();