Exemple #1
0
        public TrojanConfigManager(string ConfigPath, InfoDispDelegate InfoDisp)
        {
            infoDisp = InfoDisp;
            infoDisp("Parsing config file", "LiConfMgmt");

            ConfPath        = ConfigPath;
            Config          = new TrojanConfig();
            Config.run_type = "client";
            Config.RunMode  = RunMode.Client;
        }
Exemple #2
0
        /// <summary>
        /// Load config from file. If Litrojan config file exists, it's preferred.
        /// </summary>
        public bool LoadConfig(bool LoadOriginal = false)
        {
            if (!File.Exists(ConfPath) && !File.Exists(Path.ChangeExtension(ConfPath, ".liconf")))
            {
                infoDisp("Config file not exist, creating new.", "LiConfMgmt");
                SaveConfig();
            }

            bool loadLiconf = false;

            if (!LoadOriginal && File.Exists(Path.ChangeExtension(ConfPath, ".liconf")))
            {
                ConfPath   = Path.ChangeExtension(ConfPath, ".liconf");
                loadLiconf = true;
            }

            JsonConvert.PopulateObject(File.ReadAllText(ConfPath), Config);

            if (loadLiconf)
            {
                infoDisp("Read Litrojan config successful.", "LiConfMgmt");
            }

            switch (Config.run_type)
            {
            case "client":
                if (!loadLiconf)
                {
                    infoDisp("Read client config successful.", "LiConfMgmt");
                }
                Config.RunMode = RunMode.Client;
                break;

            case "server":
                if (!loadLiconf)
                {
                    infoDisp("Read server config successful.", "LiConfMgmt");
                }
                Config.RunMode = RunMode.Server;
                break;

            case "forward":
                if (!loadLiconf)
                {
                    infoDisp("Read router config successful.", "LiConfMgmt");
                }
                Config.RunMode = RunMode.Router;
                break;

            default:
                infoDisp("Cannot parse config file. Using default values.", "LiConfMgmt");
                Config          = new TrojanConfig();
                Config.run_type = "client";
                Config.RunMode  = RunMode.Client;
                break;
            }

            if (!File.Exists(Path.ChangeExtension(ConfPath, ".liconf")))
            {
                SaveConfig();
            }

            return(true);
        }
        // Some 'system route' & 'speed test' things will goes here.

        public TrojanNetworkManager(TrojanConfig Config, NoticeDispDelegate NotiDisp)
        {
            conf     = Config;
            notiDisp = NotiDisp;
        }