Exemplo n.º 1
0
        public static void Main()
        {
            //Create an instance of a ini file parser
            FileIniDataParser fileIniData = new FileIniDataParser();

            if (File.Exists("NewTestIniFile.ini"))
            {
                File.Delete("NewTestIniFile.ini");
            }

            //Parse the ini file
            IniData parsedData = fileIniData.LoadFile("TestIniFile.ini");

            //Write down the contents of the ini file to the console
            Console.WriteLine("---- Printing contents of the INI file ----\n");
            Console.WriteLine(parsedData.ToString());

            //Get concrete data from the ini file
            Console.WriteLine("---- Printing contents concrete data from the INI file ----");
            Console.WriteLine("setMaxErrors = " + parsedData["GeneralConfiguration"]["setMaxErrors"]);
            Console.WriteLine();

            //Modify the INI contents and save
            Console.WriteLine();
            //Write down the contents of the modified ini file to the console
            Console.WriteLine("---- Printing contents of the new INI file ----\n");
            IniData modifiedParsedData = ModifyINIData(parsedData);

            Console.WriteLine(modifiedParsedData.ToString());

            //Save to a file
            fileIniData.SaveFile("NewTestIniFile.ini", modifiedParsedData);
        }
Exemplo n.º 2
0
        public void CheckCorrectSave()
        {
            string fileString = strGoodINIFilePath + "_test.ini";

            IniData parsedData = iniParser.LoadFile(strGoodINIFilePath);

            iniParser.SaveFile(fileString, parsedData);

            Assert.That(File.Exists(fileString));
        }
        /// <summary>
        /// Saves any changes to ini file.
        /// </summary>
        public void SaveFile()
        {
            // No file loaded
            if (ini == null)
            {
                throw new Exception(fileNotLoadedError);
            }

            parser.SaveFile(filename, ini);
        }
Exemplo n.º 4
0
        public static void EmuleAdunanzaConfigSetKey(string key, string value)
        {
            //Create an instance of a ini file parser
            IniParser.FileIniDataParser iniparser = new FileIniDataParser();

            IniData data = iniparser.ReadFile(EmuleAdunanzAConfigFileGetPath());

            data["eMule"][key] = value;

            iniparser.SaveFile(EmuleAdunanzAConfigFileGetPath(), data);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Function that saves a TCPSettings object to the location new setup file path and connect it to a HashDictionary file.
        /// </summary>
        /// <param name="newSetupFile">Path to a new setup file TCPSetting will be save to.</param>
        /// <param name="hashDictionaryName">Path to a HashDictionary file.</param>
        /// <param name="tcp">TCPSetting that has to be saved.</param>
        /// <returns></returns>
        public static void WriteTCPSettingToFile(string newSetupFile, string hashDictionaryName, TCPSettings tcp)
        {
            IniData id = GetSectionTemplate();

            // Field data of the class that has to be filled up.
            var fields = tcp.GetType().GetFields();

            foreach (var item in fields)
            {
                // Getting if the attribute does exist on the field.
                var attr = (Reading[])item.GetCustomAttributes(typeof(Reading), false);

                // Going while several Reading sections is going.
                foreach (var attrVal in attr)
                {
                    // Getting field type to make right cast.
                    var ft = item.FieldType;

                    // Casting to get the right value.
                    // The data in file has to be made right for this to work!
                    switch (ft.Name)
                    {
                    case "String":
                        if (item.Name != "hashDictionaryName")
                        {
                            id.Sections[attrVal.Section].AddKey(item.Name, (string)item.GetValue(tcp));
                        }
                        else
                        {
                            id.Sections[attrVal.Section].AddKey(item.Name, hashDictionaryName);

                            // Initialize HashDictionaryFile or reinitialize it if this existed.
                            FilerHashesIO.InitializeHashDictionaryFile(hashDictionaryName);
                        }
                        break;

                    case "Int32":
                        id.Sections[attrVal.Section].AddKey(item.Name, ((int)item.GetValue(tcp)).ToString());
                        break;

                    case "Boolean":
                        id.Sections[attrVal.Section].AddKey(item.Name, ((bool)item.GetValue(tcp) ? "Yes" : "No"));
                        break;

                    default:
                        break;
                    }
                }
            }

            FileIniDataParser fidp = new FileIniDataParser();

            fidp.SaveFile(newSetupFile, id);
        }
Exemplo n.º 6
0
        void Save()
        {
            if (_parser == null)
            {
                throw new ArgumentNullException("_parser");
            }
            if (_data == null)
            {
                throw new ArgumentNullException("_data");
            }

            _parser.SaveFile(Path.Combine(FileHelper.GetSettingsDirectory(), "Settings.ini"), _data);
        }
Exemplo n.º 7
0
 public void saveSettings()
 {
     foreach (gameEntry g in games)
     {
         String section = getCategoryNameFor(g);
         addValue(section, "exec", g.path);
         addValue(section, "execfolder", g.execfolder);
         addValue(section, "name", g.shortName);
         addValue(section, "installFXfolder", g.installFXfolder);
         addValue(section, "args", g.runArgs);
         addValue(section, "specialfolder", g.special_folder);
         addValue(section, "special", g.special_install ? "1" : "0");
     }
     parser.SaveFile(storageFile, parsedData);
 }
Exemplo n.º 8
0
        public static void EmuleAdunanzASetUdpPort(int port)
        {
            if ((port > 65554) && (port == 0))
            {
                throw new Exception("la Porta UDP da configurare non e' valida");
            }

            //Create an instance of a ini file parser
            IniParser.FileIniDataParser iniparser = new FileIniDataParser();

            IniData data = iniparser.ReadFile(EmuleAdunanzAConfigFileGetPath());

            data["eMule"]["UDPPort"] = port.ToString();

            iniparser.SaveFile(EmuleAdunanzAConfigFileGetPath(), data);
        }
Exemplo n.º 9
0
        public static void AmuleAdunanzaSetTcpPort(int port)
        {
            if ((port > 65554) && (port == 0))
            {
                throw new Exception("la Porta TCP da configurare non e' valida");
            }
            var conf = AmuleAdunanzaAduboxConfigFileGetPath();

            //Create an instance of a ini file parser
            IniParser.FileIniDataParser iniparser = new FileIniDataParser();
            IniData data = iniparser.ReadFile(conf);

            data["eMule"]["Port"] = port.ToString();

            iniparser.SaveFile(conf, data);
        }
Exemplo n.º 10
0
 public void Save()
 {
     _parser.SaveFile(GetSettingsFilePath, _iniData);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Save sectioned data to ini-file
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <param name="dict">key/value pair data</param>
        /// <param name="merge">if true - the data will be combined, old value will bee rewrite if some key </param>
        public static void SaveIni(string fileName, Dictionary <string, Dictionary <string, object> > dict, bool merge)
        {
            var parser = new FileIniDataParser();
            var data   = new IniData();

            if (!merge && File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            else
            {
                data = parser.LoadFile(fileName);
            }
            foreach (var section in dict)
            {
                var sectionName = section.Key;
                if (!data.Sections.ContainsSection(sectionName))
                {
                    data.Sections.AddSection(sectionName);
                }
                var sectionData = section.Value;
                var sec         = data.Sections[sectionName];

                foreach (var keyVal in sectionData)
                {
                    if (!sec.ContainsKey(keyVal.Key))
                    {
                        sec.AddKey(keyVal.Key);
                    }
                    sec[keyVal.Key] = ValueToString(keyVal.Value);
                }
            }
            parser.SaveFile(fileName, data);

            /*var file = new FileInfo(fileName);
             *  var dirInfo = file.Directory;
             *  if (dirInfo != null && !dirInfo.Exists)
             *          dirInfo.Create();
             *
             *  var parser = new FileIniDataParser();
             *  var data = new IniData();
             *  if(!merge)
             *  {
             *          if (File.Exists(fileName))
             *                  File.Delete(fileName);
             *  }else
             *          data = parser.LoadFile(fileName);
             *  foreach (var section in dict)
             *  {
             *          var sectionName = section.Key;
             *          if (!data.Sections.ContainsSection(sectionName))
             *                  data.Sections.AddSection(sectionName);
             *          var sectionData = section.Value;
             *          var sec = data.Sections[sectionName];
             *
             *          foreach (var keyVal in sectionData)
             *          {
             *                  if (!sec.ContainsKey(keyVal.Key))
             *                          sec.AddKey(keyVal.Key);
             *                  sec[keyVal.Key] = keyVal.Value.ToString();
             *          }
             *
             *  }
             *  parser.SaveFile(fileName, data);*/
        }
Exemplo n.º 12
0
 public void Save()
 {
     TryDelete();
     parser.SaveFile(iniLoc, iniData);
 }