|
| 1 | +using AdobeBlockListConverter.Interfaces; |
| 2 | + |
| 3 | +namespace AdobeBlockListConverter.Services |
| 4 | +{ |
| 5 | + public class ConsoleUserInterface(IAppConfig config) : IUserInterface |
| 6 | + { |
| 7 | + private readonly IAppConfig _config = config ?? throw new ArgumentNullException(nameof(config)); |
| 8 | + |
| 9 | + public string GetUserInput(string prompt, string defaultValue = null) |
| 10 | + { |
| 11 | + Console.Write(prompt); |
| 12 | + string input = Console.ReadLine()?.Trim(); |
| 13 | + return string.IsNullOrEmpty(input) ? defaultValue : input; |
| 14 | + } |
| 15 | + |
| 16 | + public void WelcomeMessage() |
| 17 | + { |
| 18 | + Console.Title = "KCN-Server Adobe全家桶屏蔽域名表转换程序 -V1.0.0"; |
| 19 | + Console.WriteLine("KCN-Server Adobe全家桶屏蔽域名表转换程序 -V1.0.0\r\nFucking Adobe!通过配置Clash使你的Adobe全家桶不再弹窗。\r\n"); |
| 20 | + Console.WriteLine("Usage: AdobeBlockListConverter input<本地源文件路径,web为联网自动获取> output<输出文件路径,auto为创建在程序运行根目录下> [-q]<静默结束>\r\n"); |
| 21 | + Console.WriteLine($"请前往 {_config.GetBlockListUrl} 查看屏蔽域名列表。"); |
| 22 | + Console.WriteLine("配置步骤: \r\n1. 打开导出的预处理配置文本,复制文本。\r\n2. 打开Clash程序,点击左边栏配置项。\r\n3. 右键你正在使用的订阅(绿色),唤出二级菜单,点击配置文件预处理。\r\n5. 在编辑器里粘贴,把导出配置的url处改成你的订阅地址,然后保存。\r\n6. 回到主页,打开TUN模式,配置完成。"); |
| 23 | + Console.WriteLine("记得把导出配置的url处改成你的订阅地址再保存!要否则无法使用!\r\n"); |
| 24 | + } |
| 25 | + |
| 26 | + public void DisplayMessage(string message) |
| 27 | + { |
| 28 | + Console.WriteLine(message); |
| 29 | + } |
| 30 | + |
| 31 | + public void DisplayError(string message) |
| 32 | + { |
| 33 | + Console.ForegroundColor = ConsoleColor.Red; |
| 34 | + Console.WriteLine(message); |
| 35 | + Console.ResetColor(); |
| 36 | + } |
| 37 | + |
| 38 | + public void DisplaySuccess(string message) |
| 39 | + { |
| 40 | + Console.ForegroundColor = ConsoleColor.Green; |
| 41 | + Console.WriteLine(message); |
| 42 | + Console.ResetColor(); |
| 43 | + } |
| 44 | + |
| 45 | + public string GetInputFilePath(string[] args) |
| 46 | + { |
| 47 | + string inputFilePath; |
| 48 | + |
| 49 | + if (args.Length > 0 && args[0] != null) |
| 50 | + { |
| 51 | + inputFilePath = args[0]; |
| 52 | + DisplayMessage($"输入文件路径: {inputFilePath}"); |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + inputFilePath = GetUserInput("请输入源文件路径(输入web自动从网络获取):"); |
| 57 | + } |
| 58 | + |
| 59 | + return inputFilePath; |
| 60 | + } |
| 61 | + |
| 62 | + public string GetOutputFilePath(string[] args, string defaultPath) |
| 63 | + { |
| 64 | + string outputFilePath; |
| 65 | + |
| 66 | + if (args.Length > 1 && args[1] != null) |
| 67 | + { |
| 68 | + outputFilePath = args[1]; |
| 69 | + DisplayMessage($"输出文件路径: {outputFilePath}"); |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + outputFilePath = GetUserInput("请输入输出文件路径(输入auto自动创建在程序根目录):"); |
| 74 | + } |
| 75 | + |
| 76 | + if (string.IsNullOrEmpty(outputFilePath) || outputFilePath.Equals("auto", StringComparison.OrdinalIgnoreCase)) |
| 77 | + { |
| 78 | + outputFilePath = defaultPath; |
| 79 | + DisplayMessage($"文件自动创建于 {outputFilePath}"); |
| 80 | + } |
| 81 | + |
| 82 | + return outputFilePath; |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments