SetValue() private method

private SetValue ( string section, string key, string define_value ) : void
section string
key string
define_value string
return void
Example #1
0
 public bool SolveGitCredentialStore()
 {
     if (!CheckGitCredentialStore())
     {
         string gcsFileName = Path.Combine(Settings.GetInstallDir(), @"GitCredentialWinStore\git-credential-winstore.exe");
         if (File.Exists(gcsFileName))
         {
             ConfigFile config = GitCommandHelpers.GetGlobalConfig();
             if (EnvUtils.RunningOnWindows())
             {
                 config.SetValue("credential.helper", "!\\\"" + GitCommandHelpers.FixPath(gcsFileName) + "\\\"");
             }
             else if (EnvUtils.RunningOnMacOSX())
             {
                 config.SetValue("credential.helper", "osxkeychain");
             }
             else
             {
                 config.SetValue("credential.helper", "cache --timeout=300"); // 5 min
             }
             config.Save();
             return(true);
         }
         return(false);
     }
     return(true);
 }
Example #2
0
        public static ConfigFile GetConfigFile()
        {
            if (!System.IO.File.Exists("songrequest.config"))
            {
                ConfigFile configFile = new ConfigFile("songrequest.config");
                configFile.SetValue("server.host", "*");
                configFile.SetValue("server.port", "8765");
                configFile.SetValue("server.clients", "all");

                if (Settings.IsRunningOnWindows())
                {
                    configFile.SetValue("library.path", "c:\\music");
                }
                else
                {
                    configFile.SetValue("library.path", "~/Music");
                }

                configFile.SetValue("library.minutesbetweenscans", "1");
                configFile.SetValue("library.extensions", "mp3");
                configFile.SetValue("player.minimalsonginqueue", "0");
                configFile.SetValue("player.maximalsonginqueue", "500");
                configFile.SetValue("player.startupvolume", "50");
                configFile.Save();
            }

            return(new ConfigFile("songrequest.config"));
        }
 public void Save()
 {
     cf.SetValue("Main", "ResolutionWidth", OS.WindowSize.x);
     cf.SetValue("Main", "ResolutionHeight", OS.WindowSize.y);
     if (cf.Save("user://" + cfName) == Error.Ok)
     {
         GD.Print("Saving data to: " + OS.GetUserDataDir() + "/" + cfName);
     }
 }
 public static void SetGlobalDiffToolToConfig(ConfigFile configFile, string diffTool)
 {
     if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
     {
         configFile.SetValue("diff.guitool", diffTool);
         return;
     }
     configFile.SetValue("diff.tool", diffTool);
 }
Example #5
0
 public static void SetGlobalDiffToolToConfig(ConfigFile configFile, string diffTool)
 {
     if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
     {
         configFile.SetValue("diff.guitool", diffTool);
         return;
     }
     configFile.SetValue("diff.tool", diffTool);
 }
        private string GetReleasesConfigFileText()
        {
            ConfigFile configFile = new ConfigFile("", true);

            configFile.SetValue("Version \"2.47\".ReleaseType", "Major");
            configFile.SetValue("Version \"2.48\".ReleaseType", "Major");
            configFile.SetValue("Version \"2.49\".ReleaseType", "ReleaseCandidate");
            configFile.SetValue("RCVersion \"2.50\".ReleaseType", "ReleaseCandidate");

            return(configFile.GetAsString());
        }
Example #7
0
    private void SaveConfig()
    {
        ConfigFile cfgFile = new ConfigFile();

        cfgFile.SetValue(_audioSectionName, _sfxOnKey, _sfxOn);
        cfgFile.SetValue(_audioSectionName, _musicOnKey, _musicOn);

        Error err = cfgFile.Save(_cfgPath);

        GD.Print(string.Format("SaveConfig() File:{0} Err:{1}", _cfgPath, err.ToString()));
    }
Example #8
0
    public void update_lvl_info(int level, int score)
    {
        // load previous record for level. 0 - if no record.
        int previous_max_lvl_score = (int)settings_file.GetValue("level_score", level.ToString(), 0);

        // update record
        if (score > previous_max_lvl_score)
        {
            settings_file.SetValue("level_score", level.ToString(), score);
        }
        settings_file.Save(settings_file_path);
    }
        public void TestSetValueExisting()
        {
            var configFile = new ConfigFile(GetConfigFileName(), true);

            configFile.SetValue("section.key", "section.key");
            configFile.Save();

            configFile.SetValue("section.key", "section.keyoverwrite");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "section.key", "section.keyoverwrite");
        }
Example #10
0
        public void UncPathTest2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine(@"[path]");
                content.AppendLine(@"	unc = \\\\test\\"); //<- escaped value in config file

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\", configFile.GetValue("path.unc"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("path.unc", @"\\test\test2\");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\test2\", configFile.GetValue("path.unc"));
            }
        }
Example #11
0
        public void TestWithSectionWithDot2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[submodule.test.test]");
                content.AppendLine("path = test.test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("test.test", configFile.GetValue("submodule.test.test.path"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("submodule.test.test.path", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("submodule.test.test.path"));
            }
        }
Example #12
0
        public void TestRemoveSettingNonExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

            configFile.SetValue("section2.key1", "section2.key1");
            configFile.SetValue("section1.key2", "section1.key2");
            configFile.Save();

            configFile.RemoveSetting("section1.key1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.IsFalse(configFile.HasValue("section1.key1"));
            Assert.IsTrue(configFile.HasValue("section2.key1"));
            Assert.IsTrue(configFile.HasValue("section1.key2"));
        }
    private void _OnQuitPressed()
    {
        var setting = new ConfigFile();

        setting.Load("user://settings.cfg");

        if ((bool)setting.GetValue("Main", "Fullscreen", false) == false)
        {
            setting.SetValue("Main", "Width", OS.WindowSize.x);
            setting.SetValue("Main", "Height", OS.WindowSize.y);
            setting.Save("user://settings.cfg");
        }


        GetTree().Quit();
    }
        public void TestSetValueNonExisting()
        {
            var configFile = new ConfigFile(GetConfigFileName(), true);

            configFile.Save();

            configFile.SetValue("section1.key1", "section1key1");
            configFile.SetValue("section2.key1", "section2key1");
            configFile.SetValue("section1.key2", "section1key2");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "section1.key1", "section1key1");
            CheckValueIsEqual(configFile, "section2.key1", "section2key1");
            CheckValueIsEqual(configFile, "section1.key2", "section1key2");
        }
Example #15
0
        public void SpacesInSubSectionTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Settings.AppEncoding);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                Assert.AreEqual(@"test", configFile.GetValue("section.sub section.test"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                Assert.AreEqual(@"test2", configFile.GetValue("section.sub section.test"));
            }
        }
        public void TestSetValueSectionWithDotNonExisting()
        {
            var configFile = new ConfigFile(GetConfigFileName(), true);

            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.SetValue("submodule.test.test1.path1", "submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "submodule.test.test1.path1", "submodule.test.test1.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path1", "submodule.test.test2.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path2", "submodule.test.test2.path2");
        }
Example #17
0
    void SaveConfig()
    {
        var config = new ConfigFile();

        config.SetValue("audio", "music_volume", musicVolume);
        config.SetValue("audio", "sfx_volume", sfxVolume);
        config.SetValue("display", "fullscreen", fullScreen);
        config.SetValue("game_mode", "fast_mode", fastMode);

        var err = config.Save(configPath);

        if (err != Error.Ok)
        {
            GD.Print("Loi trong qua trinh save!");
        }
    }
        public void TestWithHiddenFile()
        {
            // TEST DATA
            {
                // Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), GitModule.SystemEncoding);

                // Make sure it is hidden
                var configFile = new FileInfo(GetConfigFileName());
                configFile.Attributes = FileAttributes.Hidden;
            }

            // PERFORM TEST
            {
                var configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section1.key1", "value1");
                CheckValueIsEqual(configFile, "section2.subsection.key2", "value2");
                CheckValueIsEqual(configFile, "section3.subsection.key3", "value3");

                configFile.SetValue("section1.key1", "new-value1");
                configFile.Save();
            }

            // CHECK WRITTEN VALUE
            {
                var configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section1.key1", "new-value1");
            }
        }
        public void SpacesInSubSectionTest()
        {
            // TEST DATA
            {
                var content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                // Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), GitModule.SystemEncoding);
            }

            // CHECK GET CONFIG VALUE
            {
                var configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section.sub section.test", "test");
            }

            // CHECK SET CONFIG VALUE
            {
                var configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            // CHECK WRITTEN VALUE
            {
                var configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section.sub section.test", "test2");
            }
        }
Example #20
0
        public void TestWithHiddenFile()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Settings.AppEncoding);

                //Make sure it is hidden
                FileInfo configFile = new FileInfo(GetConfigFileName());
                configFile.Attributes = FileAttributes.Hidden;
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                Assert.AreEqual("value1", configFile.GetValue("section1.key1"));
                Assert.AreEqual("value2", configFile.GetValue("section2.subsection.key2"));
                Assert.AreEqual("value3", configFile.GetValue("section3.subsection.key3"));

                configFile.SetValue("section1.key1", "newvalue1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                Assert.AreEqual("newvalue1", configFile.GetValue("section1.key1"));
            }
        }
Example #21
0
        public void TestRemoveSettingSectionWithDotExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

            configFile.SetValue("submodule.test.test1.path1", "invalid");
            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.RemoveSetting("submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.IsFalse(configFile.HasValue("submodule.test.test1.path1"));
            CheckValueIsEqual(configFile, "submodule.test.test2.path1", "submodule.test.test2.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path2", "submodule.test.test2.path2");
        }
 protected void SetValue <T>(string section, string key, T value)
 {
     if (!_isLoaded)
     {
         return;
     }
     _configFile.SetValue(section, key, value);
 }
Example #23
0
 public void SetupProviderServiceConfig(string providerAssembly, ushort servicePort)
 {
     try {
         string     storageFolder   = Factory.Settings["AppDataFolder"];
         var        providersFolder = Path.Combine(storageFolder, "Providers");
         string     configFolder    = Path.Combine(providersFolder, "ProviderService");
         string     configFile      = Path.Combine(configFolder, "WarehouseTest.config");
         ConfigFile warehouseConfig = new ConfigFile(configFile);
         warehouseConfig.SetValue("ServerCacheFolder", "Test\\ServerCache");
         warehouseConfig.SetValue("ServiceAddress", "0.0.0.0");
         warehouseConfig.SetValue("ServicePort", servicePort.ToString());
         warehouseConfig.SetValue("ProviderAssembly", providerAssembly);
         // Clear the history files
     } catch (Exception ex) {
         log.Error("Setup error.", ex);
         throw ex;
     }
 }
Example #24
0
 public void SetupProviderServiceConfig()
 {
     try {
         var storageFolder   = Factory.Settings["AppDataFolder"];
         var providersPath   = Path.Combine(storageFolder, "Providers");
         var configPath      = Path.Combine(providersPath, "ProviderService");
         var configFile      = Path.Combine(configPath, "WarehouseTest.config");
         var warehouseConfig = new ConfigFile(configFile);
         warehouseConfig.SetValue("ServerCacheFolder", "Test\\ServerCache");
         var provider = ProviderPlugins[0];
         warehouseConfig.SetValue("ProviderAssembly", provider);
         warehouseConfig.SetValue("ProviderAddress", "inprocess");
         warehouseConfig.SetValue("ProviderPort", "6491");
     } catch (Exception ex) {
         log.Error("Setup error.", ex);
         throw ex;
     }
 }
Example #25
0
    private void _OnSoundToggled()
    {
        var node  = GetNode("GridContainer/Sound_Button") as TextureButton;
        var state = node.Pressed;
        var set   = new ConfigFile();

        set.Load("user://settings.cfg");
        set.SetValue("Main", "MuteAudio", state);
        Global.sound = state;
    }
Example #26
0
    private void _OnMusicToggled()
    {
        var node  = GetNode("GridContainer/Music_Button") as TextureButton;
        var state = node.Pressed;
        var set   = new ConfigFile();

        set.Load("user://settings.cfg");
        set.SetValue("Main", "MuteMusic", state);
        Global.music = state;
    }
Example #27
0
        public void ConfigFileTest()
        {
            string configFileName = @"./Test.config";
            var    configFile     = new ConfigFile(configFileName);
            var    expected       = "32";

            configFile.SetValue("Another/Simulate/MarkWalter", expected);
            var value = configFile.GetValue("Another/Simulate/MarkWalter");

            Assert.AreEqual(expected, value);
        }
Example #28
0
        public void RandomTestCase2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[core]");
                content.AppendLine("	repositoryformatversion = 0");
                content.AppendLine("	filemode = false");
                content.AppendLine("	bare = false");
                content.AppendLine("	logallrefupdates = true");
                content.AppendLine("	symlinks = false");
                content.AppendLine("	ignorecase = true");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[remote \"origin\"]");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/origin/*");
                content.AppendLine("	url = [email protected]:SDWH_Project_01.git");
                content.AppendLine(@"	puttykeyfile = C:\\Users\\sergiy.pustovit\\spustovit_sintez_key_1.ppk");
                content.AppendLine("[branch \"master\"]");
                content.AppendLine("	remote = origin");
                content.AppendLine("	merge = refs/heads/master");
                content.AppendLine("[gui]");
                content.AppendLine("	geometry = 917x503+25+25 201 191");
                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[remote \"test\"]");
                content.AppendLine("	url = [email protected]:project1.git");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/test/*");
                content.AppendLine("	puttykeyfile = C:/Users/sergiy.pustovit/spustovit_sintez_key_1.ppk");



                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), GitModule.SystemEncoding);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "core.repositoryformatversion", "0");
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("core.repositoryformatversion", "1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "core.repositoryformatversion", "1");
            }
        }
Example #29
0
    static public void Save()
    {
        var audio = Settings["audio"] as Dictionary;
        var keys  = Settings["keys"] as Dictionary;

        _conf.SetValue("audio", "master", audio["master"]);
        _conf.SetValue("audio", "music", audio["music"]);
        _conf.SetValue("audio", "monster", audio["music"]);

        _conf.SetValue("keys", "Move-Left", keys["Move-Left"]);
        _conf.SetValue("keys", "Move-Right", keys["Move-Right"]);
        _conf.SetValue("keys", "Jump", keys["Jump"]);
        _conf.SetValue("keys", "Action", keys["Action"]);
        _conf.SetValue("keys", "Pause", keys["Pause"]);
        _conf.SetValue("keys", "Okay", keys["Okay"]);
        _conf.Save(SavePath);
    }
Example #30
0
        public override void SaveSettings()
        {
            _gitModule.SetFilesEncoding(true, _commonLogic.ComboToEncoding(Local_FilesEncoding));

            if (_checkSettingsLogic.CanFindGitCmd())
            {
                ConfigFile localConfig = _gitModule.GetLocalConfig();

                if (string.IsNullOrEmpty(UserName.Text) || !UserName.Text.Equals(localConfig.GetValue("user.name")))
                {
                    localConfig.SetValue("user.name", UserName.Text);
                }
                if (string.IsNullOrEmpty(UserEmail.Text) || !UserEmail.Text.Equals(localConfig.GetValue("user.email")))
                {
                    localConfig.SetValue("user.email", UserEmail.Text);
                }
                localConfig.SetPathValue("core.editor", Editor.Text);
                localConfig.SetValue("merge.tool", LocalMergeTool.Text);


                if (KeepMergeBackup.CheckState == CheckState.Checked)
                {
                    localConfig.SetValue("mergetool.keepBackup", "true");
                }
                else if (KeepMergeBackup.CheckState == CheckState.Unchecked)
                {
                    localConfig.SetValue("mergetool.keepBackup", "false");
                }

                if (localAutoCrlfFalse.Checked)
                {
                    localConfig.SetValue("core.autocrlf", "false");
                }
                if (localAutoCrlfInput.Checked)
                {
                    localConfig.SetValue("core.autocrlf", "input");
                }
                if (localAutoCrlfTrue.Checked)
                {
                    localConfig.SetValue("core.autocrlf", "true");
                }

                CommonLogic.SetEncoding(_gitModule.GetFilesEncoding(true), localConfig, "i18n.filesEncoding");

                //Only save local settings when we are inside a valid working dir
                if (_gitModule.ValidWorkingDir())
                {
                    localConfig.Save();
                }
            }
        }
Example #31
0
    public override void _Ready()
    {
        settings_file = new ConfigFile();
        var error = settings_file.Load(settings_file_path);

        if (error == Error.Ok)                  // no errors

        {
        }
        settings_file.SetValue("player_skin_status", 1.ToString(), true);               // player skin_1 all time unlocked
        current_player_skin = get_current_player_skin_value();
    }
Example #32
0
        public void CaseSensitive()
        {
            // create test data
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("branch.BranchName1.remote", "origin1");
                configFile.Save();

                AddConfigValue(GetConfigFileName(), "branch.\"BranchName2\".remote", "origin2");
                AddConfigValue(GetConfigFileName(), "branch.\"branchName2\".remote", "origin3");
            }
            // verify
            {

                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

                string remote = "branch.BranchName1.remote";
                CheckValueIsEqual(configFile, remote, "origin1");

                remote = "branch.branchName1.remote";
                CheckIsNotEqual(configFile, remote, "origin1");

                remote = "branch \"BranchName1\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin1", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"BranchName2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin2", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchName2\".remote";
                Assert.AreNotEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), "origin2", "git config --get");
                Assert.AreNotEqual("origin2", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchName2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin3", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchname2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("", configFile.GetValue(remote), "ConfigFile");
            }
        }
Example #33
0
        public void CaseSensitive()
        {
            // create test data
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("branch.BranchName1.remote", "origin1");
                configFile.Save();

                AddConfigValue(GetConfigFileName(), "branch.\"BranchName2\".remote", "origin2");
                AddConfigValue(GetConfigFileName(), "branch.\"branchName2\".remote", "origin3");
            }
            // verify
            {

                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

                string remote = "branch.BranchName1.remote";
                Assert.AreEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch.branchName1.remote";
                Assert.AreNotEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch \"BranchName1\".remote";
                Assert.AreEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch \"BranchName2\".remote";
                Assert.AreEqual("origin2", configFile.GetValue(remote), remote);

                remote = "branch \"branchName2\".remote";
                Assert.AreNotEqual("origin2", configFile.GetValue(remote), remote);

                remote = "branch \"branchName2\".remote";
                Assert.AreEqual("origin3", configFile.GetValue(remote), remote);

                remote = "branch \"branchname2\".remote";
                Assert.AreEqual("", configFile.GetValue(remote), remote);

            }
        }
Example #34
0
        public void TestWithDirectories()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Encoding.UTF8);
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("directory.first", @"c:\program files\gitextensions\gitextensions.exe");
                configFile.Save();
            }

            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"c:/program files/gitextensions/gitextensions.exe", configFile.GetValue("directory.first"));
            }
        }
Example #35
0
        public void TestNonExistingFile()
        {
            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("directory.first", @"c:\program files\gitextensions\gitextensions.exe");
                configFile.Save();
            }

            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"c:/program files/gitextensions/gitextensions.exe", configFile.GetValue("directory.first"));
            }
        }
Example #36
0
        public void UncPathTest2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine(@"[path]");
                content.AppendLine(@"	unc = \\\\test\\"); //<- escaped value in config file

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\", configFile.GetValue("path.unc"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("path.unc", @"\\test\test2\");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\test2\", configFile.GetValue("path.unc"));
            }
        }
Example #37
0
        public void TestWithSectionWithDot2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[submodule.test.test]");
                content.AppendLine("path = test.test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("test.test", configFile.GetValue("submodule.test.test.path"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("submodule.test.test.path", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("submodule.test.test.path"));
            }
        }
Example #38
0
        public void TestSetValueNonExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.Save();

            configFile.SetValue("section1.key1", "section1key1");
            configFile.SetValue("section2.key1", "section2key1");
            configFile.SetValue("section1.key2", "section1key2");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.AreEqual("section1key1", configFile.GetValue("section1.key1"));
            Assert.AreEqual("section2key1", configFile.GetValue("section2.key1"));
            Assert.AreEqual("section1key2", configFile.GetValue("section1.key2"));
        }
Example #39
0
        public void TestSetValueExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("section.key", "section.key");
            configFile.Save();

            configFile.SetValue("section.key", "section.keyoverwrite");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.AreEqual("section.keyoverwrite", configFile.GetValue("section.key"));
        }
        public void RandomTestCase2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[core]");
                content.AppendLine("	repositoryformatversion = 0");
                content.AppendLine("	filemode = false");
                content.AppendLine("	bare = false");
                content.AppendLine("	logallrefupdates = true");
                content.AppendLine("	symlinks = false");
                content.AppendLine("	ignorecase = true");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[remote \"origin\"]");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/origin/*");
                content.AppendLine("	url = [email protected]:SDWH_Project_01.git");
                content.AppendLine("	puttykeyfile = C:\\Users\\sergiy.pustovit\\spustovit_sintez_key_1.ppk");
                content.AppendLine("[branch \"master\"]");
                content.AppendLine("	remote = origin");
                content.AppendLine("	merge = refs/heads/master");
                content.AppendLine("[gui]");
                content.AppendLine("	geometry = 917x503+25+25 201 191");
                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[remote \"test\"]");
                content.AppendLine("	url = [email protected]:project1.git");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/test/*");
                content.AppendLine("	puttykeyfile = C:/Users/sergiy.pustovit/spustovit_sintez_key_1.ppk");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("0", configFile.GetValue("core.repositoryformatversion"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("core.repositoryformatversion", "1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("1", configFile.GetValue("core.repositoryformatversion"));
            }
        }
Example #41
0
        public void TestSetValueExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("section.key", "section.key");
            configFile.Save();

            configFile.SetValue("section.key", "section.keyoverwrite");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "section.key", "section.keyoverwrite");
        }
        public void TestWithHiddenFile()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Encoding.UTF8);

                //Make sure it is hidden
                FileInfo configFile = new FileInfo(GetConfigFileName());
                configFile.Attributes = FileAttributes.Hidden;
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("value1", configFile.GetValue("section1.key1"));
                Assert.AreEqual("value2", configFile.GetValue("section2.subsection.key2"));
                Assert.AreEqual("value3", configFile.GetValue("section3.subsection.key3"));

                configFile.SetValue("section1.key1", "newvalue1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue1", configFile.GetValue("section1.key1"));
            }
        }
Example #43
0
 public static void SetEncoding(Encoding e, ConfigFile configFile, string name)
 {
     string value = e == null ? "" : e.HeaderName;
     configFile.SetValue(name, value);
 }
Example #44
0
        public void SpacesInSubSectionTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), GitModule.SystemEncoding);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section.sub section.test", "test");
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section.sub section.test", "test2");
            }
        }
Example #45
0
        public void TestWithHiddenFile()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), GitModule.SystemEncoding);

                //Make sure it is hidden
                FileInfo configFile = new FileInfo(GetConfigFileName());
                configFile.Attributes = FileAttributes.Hidden;
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section1.key1", "value1");
                CheckValueIsEqual(configFile, "section2.subsection.key2", "value2");
                CheckValueIsEqual(configFile, "section3.subsection.key3", "value3");

                configFile.SetValue("section1.key1", "newvalue1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                CheckValueIsEqual(configFile, "section1.key1", "newvalue1");
            }
        }
Example #46
0
        public void TestRemoveSettingSectionWithDotExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("submodule.test.test1.path1", "invalid");
            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.RemoveSetting("submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.IsFalse(configFile.HasValue("submodule.test.test1.path1"));
            CheckValueIsEqual(configFile, "submodule.test.test2.path1", "submodule.test.test2.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path2", "submodule.test.test2.path2");
        }
Example #47
0
        public void TestRemoveSettingNonExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("section2.key1", "section2.key1");
            configFile.SetValue("section1.key2", "section1.key2");
            configFile.Save();

            configFile.RemoveSetting("section1.key1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.IsFalse(configFile.HasValue("section1.key1"));
            Assert.IsTrue(configFile.HasValue("section2.key1"));
            Assert.IsTrue(configFile.HasValue("section1.key2"));
        }
Example #48
0
        public void TestSetValueSectionWithDotExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("submodule.test.test1.path1", "invalid");
            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.SetValue("submodule.test.test1.path1", "submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "submodule.test.test1.path1", "submodule.test.test1.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path1", "submodule.test.test2.path1");
            CheckValueIsEqual(configFile, "submodule.test.test2.path2", "submodule.test.test2.path2");
        }
        public void RandomTestCase1()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[mergetool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");
                content.AppendLine("[user]");
                content.AppendLine("	name = Sergey Pustovit");
                content.AppendLine("	email = [email protected]");
                content.AppendLine("[core]");
                content.AppendLine("	safecrlf = false");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[diff]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[difftool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("Sergey Pustovit", configFile.GetValue("user.name"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("user.name", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("user.name"));
            }
        }
Example #50
0
        public void TestSetValueSectionWithDotNonExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.SetValue("submodule.test.test1.path1", "submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.AreEqual("submodule.test.test1.path1", configFile.GetValue("submodule.test.test1.path1"));
            Assert.AreEqual("submodule.test.test2.path1", configFile.GetValue("submodule.test.test2.path1"));
            Assert.AreEqual("submodule.test.test2.path2", configFile.GetValue("submodule.test.test2.path2"));
        }
        public void SpacesInSubSectionTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test", configFile.GetValue("section.sub section.test"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test2", configFile.GetValue("section.sub section.test"));
            }
        }
Example #52
0
        public void TestSetValueNonExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.Save();

            configFile.SetValue("section1.key1", "section1key1");
            configFile.SetValue("section2.key1", "section2key1");
            configFile.SetValue("section1.key2", "section1key2");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            CheckValueIsEqual(configFile, "section1.key1", "section1key1");
            CheckValueIsEqual(configFile, "section2.key1", "section2key1");
            CheckValueIsEqual(configFile, "section1.key2", "section1key2");
        }
        public void NewLineTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[bugtraq]");
                content.AppendLine("	url = http://192.168.0.1:8080/browse/%BUGID%");
                content.AppendLine("	message = This commit fixes %BUGID%");
                content.AppendLine("	append = true");
                content.AppendLine("	label = Key:");
                content.AppendLine("	number = true");
                content.AppendLine("	logregex = \\n([A-Z][A-Z0-9]+-/d+)");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("\\n([A-Z][A-Z0-9]+-/d+)", configFile.GetValue("bugtraq.logregex"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("bugtraq.logregex", "data\\nnewline");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("data\\nnewline", configFile.GetValue("bugtraq.logregex"));
            }
        }
Example #54
0
        public void TestSave()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("branch.BranchName1.remote", "origin1");
            configFile.Save();

            byte[] expectedFileContent =
                GitModule.SystemEncoding.GetBytes(
                    String.Format("[branch \"BranchName1\"]{0}\tremote = origin1{0}", Environment.NewLine));

            Assert.IsTrue(File.Exists(GetConfigFileName()));
            byte[] fileContent = File.ReadAllBytes(GetConfigFileName());

            Assert.AreEqual(expectedFileContent.Length, fileContent.Length);
            for (int index = 0; index < fileContent.Length; index++)
            {
                Assert.AreEqual(expectedFileContent[index], fileContent[index]);
            }
        }