diff options
author | crupest <crupest@outlook.com> | 2024-09-17 23:59:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-09-25 23:01:52 +0800 |
commit | b610b87deaae8ed029793049c6f75dcc87353424 (patch) | |
tree | a6a4c426983929ef8824c378aa283794737bfa8d /tools/Crupest.V2ray/Crupest.V2ray/Program.cs | |
parent | 57514635a10bad1feceda4c6f576baf07607af33 (diff) | |
download | crupest-b610b87deaae8ed029793049c6f75dcc87353424.tar.gz crupest-b610b87deaae8ed029793049c6f75dcc87353424.tar.bz2 crupest-b610b87deaae8ed029793049c6f75dcc87353424.zip |
refactor(secret): add cn geosite direct. refactor geodata manager.
Diffstat (limited to 'tools/Crupest.V2ray/Crupest.V2ray/Program.cs')
-rw-r--r-- | tools/Crupest.V2ray/Crupest.V2ray/Program.cs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/tools/Crupest.V2ray/Crupest.V2ray/Program.cs b/tools/Crupest.V2ray/Crupest.V2ray/Program.cs index e06a92d..a40aa21 100644 --- a/tools/Crupest.V2ray/Crupest.V2ray/Program.cs +++ b/tools/Crupest.V2ray/Crupest.V2ray/Program.cs @@ -4,6 +4,8 @@ namespace Crupest.V2ray; public static class Program { + public static string Name { get; } = typeof(Program).Namespace ?? throw new Exception("Can't get the name of Crupest.V2ray."); + public static string CrupestV2rayDirectory { get; } = Environment.GetEnvironmentVariable("CRUPEST_V2RAY_DIR") ?? Path.GetFullPath(Path.GetDirectoryName( @@ -13,10 +15,31 @@ public static class Program public static void RunV2rayAndWatchConfigChange() { - var v2rayPath = V2rayController.FindExecutable(CrupestV2rayDirectory) ?? + var v2rayPath = V2rayController.FindExecutable(CrupestV2rayDirectory, out var isLocal) ?? throw new Exception("Can't find v2ray executable either in Crupest.V2ray directory or in PATH."); - var v2rayController = new V2rayController(v2rayPath, Path.Combine(CrupestV2rayDirectory, ConfigOutputFileName), CrupestV2rayDirectory); + string? assetsPath; + if (isLocal) + { + assetsPath = CrupestV2rayDirectory; + var assetsComplete = GeoDataManager.Instance.HasAllAssets(CrupestV2rayDirectory, out var missing); + if (!assetsComplete) + { + throw new Exception($"Missing assets: {string.Join(", ", missing)} in {CrupestV2rayDirectory}. This v2ray is local. So only use assets in Crupest.V2ray directory."); + } + } + else + { + assetsPath = CrupestV2rayDirectory; + var assetsComplete = GeoDataManager.Instance.HasAllAssets(CrupestV2rayDirectory, out var missing); + if (!assetsComplete) + { + Console.WriteLine($"Missing assets: {string.Join(", ", missing)} in {CrupestV2rayDirectory}. This v2ray is global. So fallback to its own assets."); + assetsPath = null; + } + } + + var v2rayController = new V2rayController(v2rayPath, Path.Combine(CrupestV2rayDirectory, ConfigOutputFileName), assetsPath); var configFileWatcher = new FileWatcher(CrupestV2rayDirectory, V2rayConfig.ConfigFileNames); V2rayConfig.FromDirectoryAndWriteToFile(CrupestV2rayDirectory, Path.Join(CrupestV2rayDirectory, ConfigOutputFileName)); @@ -42,8 +65,7 @@ public static class Program var verb = args[0].ToLower(); if (verb == "download-geodata" || verb == "dg") { - var geoDataDownloader = new GeoDataDownloader(); - geoDataDownloader.Download(CrupestV2rayDirectory); + GeoDataManager.Instance.Download(CrupestV2rayDirectory, false); return; } else if (verb == "generate" || verb == "g") |