コード例 #1
0
ファイル: Config.cs プロジェクト: AlexCSDev/SMSSelfService
        public T GetValue <T>(string path, T defaultValue, bool writeDefaultIfEmpty = true)
        {
            string val = config.Settings[path].Value;

            if (val == "")
            {
                if (writeDefaultIfEmpty)
                {
                    config.Settings[path].Value = defaultValue.ToString();
                    config.Commit();
                }
                return(defaultValue);
            }
            return((T)Convert.ChangeType(val, typeof(T)));
        }
コード例 #2
0
        public static void Init()
        {
            var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            var userFilePath = Path.Combine(localAppData, "LukasHaefliger");

            if (!Directory.Exists(userFilePath))
            {
                Directory.CreateDirectory(userFilePath);
            }
            var configFilePath = Path.Combine(userFilePath, "mysqlGenConfig.xml");
            var alreadyExists  = File.Exists(configFilePath);
            var config         = new Xmlconfig(configFilePath, true);

            Xmlconfig             = config;
            Settings              = config.Settings;
            config.CommitOnUnload = true;
            if (alreadyExists)
            {
                return;
            }
            #region initDefault
            Settings["server"]["MySQL"]["ServerIP"].Value = "";
            Settings["server"]["MySQL"]["User"].Value     = "";
            Settings["server"]["MySQL"]["Database"].Value = "";
            Settings["server"]["MySQL"]["Port"].Value     = "3306";
            Settings["server"]["MySQL"]["Password"].Value = "";
            Settings["server"]["MySQL"]["Prefix"].Value   = "";
            config.Commit();

            #endregion
        }
コード例 #3
0
ファイル: Config.cs プロジェクト: xbelt/WindowManager
        public static void Init()
        {
            var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            var userFilePath = Path.Combine(localAppData, "LukasHaefliger");

            if (!Directory.Exists(userFilePath))
            {
                Directory.CreateDirectory(userFilePath);
            }
            var configFilePath = Path.Combine(userFilePath, "windowSelector.xml");

#if DEBUG
            configFilePath += "d";
#endif
            var alreadyExists = File.Exists(configFilePath);
            var config        = new Xmlconfig(configFilePath, true);
            Xmlconfig             = config;
            Settings              = config.Settings;
            config.CommitOnUnload = true;
            if (alreadyExists)
            {
                return;
            }
            #region initDefault

            Settings["Settings"]["Color"].intValue = Color.Blue.ToArgb();
            Settings["Positions"]["N1"].Value      = "[" +
                                                     "{\"X\":0.0,\"Y\":50.0,\"Width\":50.0,\"Height\":50.0}," +
                                                     "{\"X\":0.0,\"Y\":50.0,\"Width\":25.0,\"Height\":50.0}," +
                                                     "{\"X\":0.0,\"Y\":50.0,\"Width\":33.33,\"Height\":50.0}," +
                                                     "{\"X\":0.0,\"Y\":50.0,\"Width\":66.67,\"Height\":50.0}" +
                                                     "]";
            Settings["Positions"]["N2"].Value = "[" +
                                                "{\"X\":0.0,\"Y\":50.0,\"Width\":100.0,\"Height\":50.0}," +
                                                "{\"X\":25.0,\"Y\":50.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":50.0,\"Y\":50.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":33.33,\"Y\":50.0,\"Width\":33.33,\"Height\":50.0}" +
                                                "]";
            Settings["Positions"]["N3"].Value = "[" +
                                                "{\"X\":50.0,\"Y\":50.0,\"Width\":50.0,\"Height\":50.0}," +
                                                "{\"X\":75.0,\"Y\":50.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":66.67,\"Y\":50.0,\"Width\":33.33,\"Height\":50.0}," +
                                                "{\"X\":33.33,\"Y\":50.0,\"Width\":66.67,\"Height\":50.0}" +
                                                "]";
            Settings["Positions"]["N4"].Value = "[" +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":50.0,\"Height\":100.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":33.33,\"Height\":100.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":66.67,\"Height\":100.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":25,\"Height\":100.0}" +
                                                "]";
            Settings["Positions"]["N5"].Value = "[" +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":100.0,\"Height\":100.0}," +
                                                "{\"X\":33.33,\"Y\":0.0,\"Width\":33.33,\"Height\":100.0}," +
                                                "{\"X\":16.67,\"Y\":0.0,\"Width\":66.67,\"Height\":100.0}" +
                                                "]";
            Settings["Positions"]["N6"].Value = "[" +
                                                "{\"X\":50.0,\"Y\":0.0,\"Width\":50.0,\"Height\":100.0}," +
                                                "{\"X\":66.67,\"Y\":0.0,\"Width\":33.33,\"Height\":100.0}," +
                                                "{\"X\":33.33,\"Y\":0.0,\"Width\":66.67,\"Height\":100.0}," +
                                                "{\"X\":75,\"Y\":0.0,\"Width\":25,\"Height\":100.0}" +
                                                "]";
            Settings["Positions"]["N7"].Value = "[" +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":50.0,\"Height\":50.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":33.33,\"Height\":50.0}," +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":66.67,\"Height\":50.0}" +
                                                "]";
            Settings["Positions"]["N8"].Value = "[" +
                                                "{\"X\":0.0,\"Y\":0.0,\"Width\":100.0,\"Height\":50.0}," +
                                                "{\"X\":25.0,\"Y\":0.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":50.0,\"Y\":0.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":33.33,\"Y\":0.0,\"Width\":33.33,\"Height\":50.0}" +
                                                "]";
            Settings["Positions"]["N9"].Value = "[" +
                                                "{\"X\":50.0,\"Y\":0.0,\"Width\":50.0,\"Height\":50.0}," +
                                                "{\"X\":75.0,\"Y\":0.0,\"Width\":25.0,\"Height\":50.0}," +
                                                "{\"X\":66.67,\"Y\":0.0,\"Width\":33.33,\"Height\":50.0}," +
                                                "{\"X\":33.33,\"Y\":0.0,\"Width\":66.67,\"Height\":50.0}" +
                                                "]";
            config.Commit();

            #endregion
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: xbelt/WindowManager
 public static void Commit()
 {
     Xmlconfig.Commit();
 }
コード例 #5
0
        public static void WriteOptions(VTankOptions options)
        {
            KeysConverter kc       = new KeysConverter();
            string        filename = GetConfigFilePath();
            Xmlconfig     config   = new Xmlconfig();

            config.Settings["ServerAddress"].Value                        = options.ServerAddress;
            config.Settings["ServerPort"].Value                           = options.ServerPort;
            config.Settings["DefaultAccount"].Value                       = options.DefaultAccount;
            config.Settings["MapsFolder"].Value                           = options.MapsFolder;
            config.Settings["options/video/Resolution"].Value             = options.videoOptions.Resolution;
            config.Settings["options/video/Windowed"].Value               = options.videoOptions.Windowed;
            config.Settings["options/video/TextureQuality"].Value         = options.videoOptions.TextureQuality;
            config.Settings["options/video/AntiAliasing"].Value           = options.videoOptions.AntiAliasing;
            config.Settings["options/video/ShadingEnabled"].Value         = options.videoOptions.ShadingEnabled;
            config.Settings["options/audio/ambientSound/Volume"].Value    = options.audioOptions.ambientSound.Volume;
            config.Settings["options/audio/ambientSound/Muted"].Value     = options.audioOptions.ambientSound.Muted;
            config.Settings["options/audio/backgroundSound/Volume"].Value = options.audioOptions.backgroundSound.Volume;
            config.Settings["options/audio/backgroundSound/Muted"].Value  = options.audioOptions.backgroundSound.Muted;
            config.Settings["options/gameplay/ShowNames"].Value           = options.gamePlayOptions.ShowNames;
            config.Settings["options/gameplay/ProfanityFilter"].Value     = options.gamePlayOptions.ProfanityFilter;
            config.Settings["options/gameplay/InterfacePlugin"].Value     = options.gamePlayOptions.InterfacePlugin;
            config.Settings["options/keybindings/Forward"].Value          = kc.ConvertToString(options.keyBindings.Forward);
            config.Settings["options/keybindings/Backward"].Value         = kc.ConvertToString(options.keyBindings.Backward);
            config.Settings["options/keybindings/RotateLeft"].Value       = kc.ConvertToString(options.keyBindings.RotateLeft);
            config.Settings["options/keybindings/RotateRight"].Value      = kc.ConvertToString(options.keyBindings.RotateRight);
            //config.Settings["options/keybindings/FirePrimary"].Value = kc.ConvertToString(options.keyBindings.FirePrimary);
            //config.Settings["options/keybindings/FireSecondary"].Value = kc.ConvertToString(options.keyBindings.FireSecondary);
            config.Settings["options/keybindings/Menu"].Value    = kc.ConvertToString(options.keyBindings.Menu);
            config.Settings["options/keybindings/Minimap"].Value = kc.ConvertToString(options.keyBindings.Minimap);
            config.Settings["options/keybindings/Score"].Value   = kc.ConvertToString(options.keyBindings.Score);
            config.Settings["options/keybindings/Camera"].Value  = kc.ConvertToString(options.keyBindings.Camera);
            config.Settings["options/keybindings/Pointer"].Value = options.keyBindings.Pointer;

            /*if (!System.IO.File.Exists(filename))
             * {
             *  System.IO.FileStream stream = System.IO.File.Create(filename);
             *  stream.Close();
             * }
             *
             * ExeConfigurationFileMap map = new ExeConfigurationFileMap();
             * map.ExeConfigFilename = filename;
             *
             * Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(
             *  map, ConfigurationUserLevel.None);
             *
             * foreach (String key in ConfigurationManager.AppSettings.AllKeys)
             * {
             *  configuration.AppSettings.Settings[key].Value =
             *      ConfigurationManager.AppSettings[key];
             * }
             *
             * configuration.Save(ConfigurationSaveMode.Modified);
             *
             * ConfigurationManager.RefreshSection("appSettings");*/

            if (!config.Commit())
            {
                config.Save(filename);
            }
        }