diff options
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(); |