using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; namespace FilterAPI { public class Config { private readonly Dictionary _configValues = new Dictionary(); private readonly string _configUrl = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Conf", "Config.txt"); public Config() { var configClient = new WebClient(); try { using (var configStream = new StreamReader(configClient.OpenRead(_configUrl) ?? throw new InvalidOperationException())) { var lines = new List(); string currentLine; while ((currentLine = configStream.ReadLine()) != null) { lines.Add(currentLine); } var decryptedLines = lines.ToArray(); foreach (var decryptedLine in decryptedLines) { var lineSplit = decryptedLine.Split(new[] { ": " }, StringSplitOptions.None); if (_configValues.ContainsKey(lineSplit[0])) { File.WriteAllLines( $"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "")}ConfDuplicateRow.txt", new[] { lineSplit[0] }); } _configValues.Add(lineSplit[0], lineSplit[1]); } } } catch (Exception error) { File.WriteAllLines( $"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "")}Crash.txt", new[] { error.ToString() }); Environment.Exit(0); } } public string GetConfigValue(string value) { if (value.Contains("Feature") || value.Contains("Stng")) // default features to false if not defined { try { return _configValues[value]; } catch { Debug.WriteLine($"Value not in config: {value}"); return "false"; } } try { return _configValues[value]; } catch { Debug.WriteLine($"Value not in config: {value}"); throw new KeyNotFoundException($"Value not in config: {value}"); } } } }