Ejemplo n.º 1
0
 private void buttonCreateAutoCustomFile_Click(object sender, EventArgs e)
 {
     Ex.Catch(() =>
     {
         var fileEnd  = Setting.FileEndOptions.Get(new SavingManager()).Value;
         var filePath = Path.Combine(PublicData.FolderConfigPath, $"autostart.{fileEnd}");
         //if ( File.Exists(filePath) ) throw new IOException($"Файл уже существует.\n{filePath}");
         var section = new IniFile(filePath, true).AddSection(PublicData.constAutoName);
         section.AddKey("code").SetValue(" ");
         section.AddKey("regex").SetValue(".+");
         section.IniFile.SaveShowMessage();
     });
     VisualRefresh();
 }
Ejemplo n.º 2
0
        public static IniFile ReadString(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(new IniFile());
            }

            var iniFile = new IniFile();

            var lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            for (int index = 0; index < lines.Length; index++)
            {
                var line = lines[index].Trim();

                if (string.IsNullOrWhiteSpace(line) || line.StartsWith(";") || line.StartsWith("#"))
                {
                    continue;
                }

                var sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim();

                var section = iniFile.AddSection(sectionName);
                if (section != null)
                {
                    continue;
                }

                iniFile.AddKey(line);
            }

            return(iniFile);
        }
Ejemplo n.º 3
0
        public void Ini_Save(string file, string section, string key, string value)
        {
            IniFile pIni = new IniFile(file);

            pIni.AddSection(section);
            pIni.DeleteKey(key, section);
            pIni.AddKey(key, value, section);
            pIni.Save();
        }
Ejemplo n.º 4
0
        public static IniFile ReadFromFile(string file)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                return(null);
            }

            if (!File.Exists(file))
            {
                return(new IniFile());
            }

            var iniFile = new IniFile();

            using (StreamReader reader = new StreamReader(file))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    if (string.IsNullOrWhiteSpace(line) || line.StartsWith(";") || line.StartsWith("#"))
                    {
                        continue;
                    }

                    var sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim();

                    var section = iniFile.AddSection(sectionName);
                    if (section != null)
                    {
                        continue;
                    }

                    iniFile.AddKey(line);
                }

                reader.Close();
            }

            return(iniFile);
        }