コード例 #1
0
    private config_class getConfig(string key)
    {    //获取玩家的设置,如果设置不存在,则返回空
        var list = getList();

        foreach (var p in list)
        {
            if (p.cfgName == key)
            {
                return(p);
            }
        }
        config_class x = new config_class(key, true);

        list.Add(x);
        return(x);
    }
コード例 #2
0
        //=============================================================
        // USED FOR CONFIG
        //=============================================================

        /// <summary>
        /// Loads the config. If loading the config fails, a new config file is created with default values.
        /// </summary>
        private void config_load()
        {
            //Attempt to load config
            try
            {
                //Declare variable used to open imagecache.json file
                StreamReader sr_config;

                //Open config.json file
                sr_config = new StreamReader(Application.StartupPath + @"\config.json");

                //Declare STRING to store contents of config.json
                string config_json = sr_config.ReadToEnd();

                //Load json object to config
                config = JsonConvert.DeserializeObject <config_class>(config_json);

                //If the directory is empty or null, use the default
                if (config.source == null || config.source == "")
                {
                    config.source = default_source;
                }

                //Close file
                sr_config.Close();
            }

            //If error loading config, use default values
            catch
            {
                //Create a new instance of config class, populate it with default values and write it to file
                config        = new config_class();
                config.source = default_source;
                config_write();
            }
        }
コード例 #3
0
        //=============================================================
        // USED FOR CONFIG
        //=============================================================
        /// <summary>
        /// Loads the config. If loading the config fails, a new config file is created with default values.
        /// </summary>
        private void config_load()
        {
            //Attempt to load config
            try
            {
                //Declare variable used to open imagecache.json file
                StreamReader sr_config;

                //Open config.json file
                sr_config = new StreamReader(Application.StartupPath + @"\config.json");

                //Declare STRING to store contents of config.json
                string config_json = sr_config.ReadToEnd();

                //Load json object to config
                config = JsonConvert.DeserializeObject<config_class>(config_json);

                //If the directory is empty or null, use the default
                if(config.source == null || config.source == "")
                {
                    config.source = default_source;
                }

                //Close file
                sr_config.Close();
            }

            //If error loading config, use default values
            catch
            {

                //Create a new instance of config class, populate it with default values and write it to file
                config = new config_class();
                config.source = default_source;
                config_write();
            }
        }