Ejemplo n.º 1
0
        /// <summary>
        /// Parses build information from an INI file.
        /// </summary>
        /// <param name="iniFile">The INI file.</param>
        private void INIParse(IniFile iniFile)
        {
            var versionSection = iniFile.GetSection(VERSION_SECTION);

            if (versionSection == null)
            {
                throw new ParseException("[" + VERSION_SECTION + "] section not found from " + iniFile.FileName);
            }

            ProductVersionInfo = new ProductVersionInfo();
            ProductVersionInfo.Parse(versionSection);

            var fileKeys = iniFile.GetSectionKeys(FILES_SECTION);

            if (fileKeys == null)
            {
                return;
            }

            foreach (string key in fileKeys)
            {
                string[] parts = iniFile.GetStringValue(FILES_SECTION, key, string.Empty).Split(',');

                try
                {
                    var fileInfo = new T();
                    fileInfo.Parse(parts);

                    FileInfos.Add(fileInfo);
                }
                catch (FormatException) { UpdaterLogger.Log("FormatException when parsing file information, INI key " + key); }
                catch (ParseException) { UpdaterLogger.Log("ParseException when parsing file information, INI key: " + key); }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes build information into the specified file path.
        /// Erases the file first if it already exists.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void Write(string filePath)
        {
            File.Delete(filePath);

            var iniFile = new IniFile(filePath);

            var versionSection = new IniSection(VERSION_SECTION);

            iniFile.AddSection(versionSection);
            ProductVersionInfo.Write(versionSection);

            var filesSection = new IniSection(FILES_SECTION);

            iniFile.AddSection(filesSection);

            for (int i = 0; i < FileInfos.Count; i++)
            {
                filesSection.SetStringValue(i.ToString(), FileInfos[i].GetString());
            }

            iniFile.WriteIniFile();
        }