Ejemplo n.º 1
0
        internal static async Task <IAdapterConfig> GetConfigFromFilePathImpl(string filePath)
        {
            string fileContent = await PathIO.ReadTextAsync(filePath);

            var            json        = JObject.Parse(fileContent);
            var            adapterType = json.GetValue(nameof(IAdapterConfig.AdapterType)).Value <string>();
            var            reader      = json.CreateReader();
            IAdapterConfig config;

            switch (adapterType)
            {
            case "shadowsocks":
                config = new ShadowsocksConfig();
                break;

            case "http":
                config = new HttpConfig();
                break;

            case "trojan":
                config = new TrojanConfig();
                break;

            default:
                throw adapterTypeNotFoundException;
            }
            serializer.Populate(reader, config);
            config.Path = filePath;
            return(config);
        }
Ejemplo n.º 2
0
        public static IAdapterConfig GetConfigFromFilePath(string filePath)
        {
            AdapterConfig baseConfig = null;

            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                baseConfig = serializer.ReadObject(stream) as AdapterConfig;
                if (baseConfig != null)
                {
                    baseConfig.Path = filePath;
                }
            }
            switch (baseConfig.AdapterType)
            {
            case "shadowsocks":
                return(ShadowsocksConfig.GetConfigFromFilePath(filePath));

            case "http":
                return(HttpConfig.GetConfigFromFilePath(filePath));

            case "trojan":
                return(TrojanConfig.GetConfigFromFilePath(filePath));

            default:
                throw adapterTypeNotFoundException;
            }
        }