Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrototypeBackend.ConfigurationManager"/> class.
        /// </summary>
        /// <param name="UserFolderPath">User folder path.</param>
        public ConfigurationManager(string UserFolderPath = null)
        {
            if (UserFolderPath == null)
            {
                //Linux|Mac
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    UserFolder  = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                    UserFolder += @"/.config/micrologger/Config.ini";
                }
                //Windows
                else
                {
                    UserFolder  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    UserFolder += @"\micrologger\Config.ini";
                    Console.WriteLine(UserFolder);
                }
            }
            else
            {
                UserFolder = UserFolderPath;
            }

            if (File.Exists(UserFolder))
            {
                GeneralData = ParseSettings(UserFolder);
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Exemplo n.º 2
0
        public ConfigLoader(string configFilePath = null)
        {
            if (string.IsNullOrEmpty(configFilePath))
            {
                configFilePath = AppDomain.CurrentDomain.BaseDirectory + "config.ini";
                if (!File.Exists(configFilePath))
                {
                    throw new Exception("Could not find configuration file");
                }
            }

            Logger.Info("Loading configuration from: " + configFilePath);

            try
            {
                var parser = new IniParser.FileIniDataParser();
                ConfigData = parser.ReadFile(configFilePath);
            }
            catch (FileNotFoundException)
            {
                throw new Exception("Could not find configuration file at: " + configFilePath);
            }
            catch (ParsingException e)
            {
                throw new Exception("Unable to parse configuration file [" + configFilePath + "]: " + e.Message);
            }

            foreach (var section in ConfigData.Sections)
                foreach (var item in section.Keys)
                {
                    item.Value = item.Value.Replace("{AppDir}", AppDomain.CurrentDomain.BaseDirectory);
                    item.Value = item.Value.Replace("{AppDataDir}", AppDomain.CurrentDomain.BaseDirectory);
                }
        }
Exemplo n.º 3
0
        public void remove_all_keys_in_section_without_deleting_the_section()
		{
			IniData data = new IniData();
			data.Sections.AddSection("test");
			data.Sections.AddSection("test2");

			data["test"].AddKey("key1", "value1");
			data["test"].AddKey("key2", "value2");

			data["test2"].AddKey("key3", "value3");
			data["test2"].AddKey("key4", "value4");

			Assert.That (data["test"].ContainsKey("key1"));
			Assert.That (data["test"].ContainsKey("key2"));
			Assert.That (data["test2"].ContainsKey("key3"));
			Assert.That (data["test2"].ContainsKey("key4"));

			data.Sections.GetSectionData("test").ClearKeyData();
			Assert.That (data.Sections.ContainsSection("test"));
			Assert.That (data["test"].ContainsKey("key1"), Is.False);
			Assert.That (data["test"].ContainsKey("key2"), Is.False);

			data["test2"].RemoveAllKeys();
			Assert.That (data.Sections.ContainsSection("test2"));
			Assert.That (data["test2"].ContainsKey("key3"), Is.False);
			Assert.That (data["test2"].ContainsKey("key4"), Is.False);

		}
Exemplo n.º 4
0
        public frmMain()
        {
            InitializeComponent();

            // Loads config file
            data = parser.LoadFile("config.ini");
            // New emulator class
            emulator = new Emulator(data["emulator"]["gametitle"]);

            // New IRC events
            client.GotIrcError += client_GotIrcError;
            client.Closed += client_Closed;
            client.Connected += client_Connected;
            client.GotMessage += client_GotMessage;

            // Loads in saved progress
            if (data["progress"]["date"] == string.Empty)
            {
                StartTime = DateTime.UtcNow;
            }
            else
                StartTime = DateTime.Parse(data["progress"]["date"]);

            CmdSent = long.Parse(data["progress"]["sent"]);
        }
Exemplo n.º 5
0
        public void check_add_keydata_method_using_key_and_value_strings()
        {
            var newData = new IniData();

            newData.Sections.AddSection("newSection");
            newData["newSection"].AddKey("newKey1", "value1");

            Assert.That(newData["newSection"]["newKey1"], Is.EqualTo("value1"));
        }
Exemplo n.º 6
0
        public void correct_comment_assigment_to_keydata()
        {
            IniData inidata = new IniData();
            inidata.Sections.AddSection("TestSection");

            KeyData key = new KeyData("TestKey");
            key.Value = "TestValue";
            key.Comments.Add("This is a comment");
            inidata["TestSection"].SetKeyData(key);

            Assert.That(inidata["TestSection"].GetKeyData("TestKey").Comments[0], Is.EqualTo("This is a comment"));
        }
Exemplo n.º 7
0
        public static bool LoadConfig(string configFilePath = null)
        {
            if (string.IsNullOrEmpty(configFilePath))
            {
                configFilePath = GetConfigPath();
            }
            
            if (!string.IsNullOrEmpty(configFilePath))
            {
                try
                {
                    var loader = new ConfigLoader(configFilePath);
                    _configData = loader.ConfigData;
                }
                catch (Exception)
                {
                    Logger.Error("Could not find a configuration file. " +
                                 "Include one in the application directory or specify one with --config.");
                    return false;
                }
            }
            else
            {
                _configData = new IniData();
            }

            // Defaults. AddSection/AddKey take no action if they already exist.
            _configData.Sections.AddSection("Application");
            _configData["Application"].AddKey("LogLevel", "Info");
            _configData["Application"].AddKey("AutoUpdate", "true");
            _configData["Application"].AddKey(
                "UpdatesReleaseUrl", "https://downloads.allauthapp.com/allauth-desktop/win-update-pkgs");
            _configData["Application"].AddKey(
                "AccountManagementUrl", "https://account.allauthapp.com");

            _configData.Sections.AddSection("Management");
            _configData["Management"].AddKey("Https", "true");
            _configData["Management"].AddKey("Host", "management.api.allauthapp.com");
            _configData["Management"].AddKey("Port", "443");
            _configData["Management"].AddKey("ApiVersion", "1");

            //if (!Program.AppEnvDebug)
            //{
            //    // Immutable for release
            //    _configData["Management"]["Https"] = "true";
            //    _configData["Management"]["Host"] = "management.api.allauthapp.com";
            //    _configData["Management"]["Port"] = "443";
            //    _configData["Management"]["ApiVersion"] = "1";
            //}

            return true;
        }
Exemplo n.º 8
0
        public EngineConfigs(string customConfigs)
        {
            var parser = new IniDataParser();
            _iniData = parser.Parse(DefaultEngineConfigs);

            if (!string.IsNullOrEmpty(customConfigs))
            {
                if (customConfigs.Trim() != "")
                {
                    var userIniData = parser.Parse(customConfigs);
                    _iniData.Merge(userIniData);
                }
            }
        }
Exemplo n.º 9
0
        public void CreateIniFileProgramatically()
        {
			var iniData = new IniData();
			iniData.Global.AddKey("UseSeparateRepositoryForAssets", true.ToString());
			
			iniData.Sections.AddSection("MainRepository");
			iniData["MainRepository"]["Type"] = "git";
			iniData["MainRepository"]["RelativePath"] = ".";
			
			Assert.That(iniData["MainRepository"].ContainsKey("Type"));
			Assert.That(iniData["MainRepository"].ContainsKey("RelativePath"));
			
			iniData.Sections.AddSection("AssetsRepository");
			iniData["AssetsRepository"]["Type"] = "svn";
			iniData["AssetsRepository"]["RelativePath"] = "./Assets";
			
			Assert.That(iniData["AssetsRepository"].ContainsKey("Type"));
			Assert.That(iniData["AssetsRepository"].ContainsKey("RelativePath"));
			
			Console.WriteLine(iniData.ToString());
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Parses a string containing valid ini data
        /// </summary>
        /// <param name="iniDataString">
        ///     String with data
        /// </param>
        /// <returns>
        ///     An <see cref="IniData"/> instance with the data contained in
        ///     the <paramref name="iniDataString"/> correctly parsed an structured.
        /// </returns>
        /// <exception cref="ParsingException">
        ///     Thrown if the data could not be parsed
        /// </exception>
        public IniData Parse(string iniDataString)
        {
            IniData iniData = new IniData();
            iniData.Configuration = this.Configuration.Clone();

            if (string.IsNullOrEmpty(iniDataString))
            {
                return iniData;
            }

            _currentCommentListTemp.Clear();
            _currentSectionNameTemp = null;

            try
            {
                var lines = iniDataString.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (var line in lines)
                {
                    ProcessLine(line, iniData);
                }

                // Orphan comments, assing to last section
                if (_currentCommentListTemp.Count > 0)
                {
                    iniData.Sections.GetSectionData(_currentSectionNameTemp).TrailingComments
                        .AddRange(_currentCommentListTemp);
                    _currentCommentListTemp.Clear();
                }

            }
            catch
            {
                if (Configuration.ThrowExceptionsOnError)
                    throw;

                return null;
            }

            return (IniData)iniData.Clone();
        }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            var options = Options.ParseCommandLineArgs(args);
            if (options == null)
                return;

            var folder = Path.Combine(Path.GetTempPath(), "LfMerge.TestApp");
            LfMergeSettingsIni.ConfigDir = folder;

            MainClass.Container = MainClass.RegisterTypes().Build();
            var settings = MainClass.Container.Resolve<LfMergeSettingsIni>();
            var config = new IniData();
            var main = config.Global;
            main["BaseDir"] = folder;
            settings.Initialize(config);

            var queueDir = settings.GetQueueDirectory(QueueNames.Synchronize);
            Directory.CreateDirectory(queueDir);
            File.WriteAllText(Path.Combine(queueDir, options.PriorityProject), string.Empty);

            MainClass.Main(new string[0]);
        }
Exemplo n.º 12
0
        private void ParseCsv(string filePath, string fileName, IniParser.Model.IniData iniData, int keyIndex, List <int> listValueIndex)
        {
            iniData.Sections.AddSection(fileName);

            var csv = new CsvHelper.CsvReader(File.OpenText(filePath));

            while (csv.Read())
            {
                var key = csv.GetField(keyIndex);
                foreach (var valueIndex in listValueIndex)
                {
                    var value = csv.GetField(valueIndex);
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        if (!string.IsNullOrWhiteSpace(key))
                        {
                            iniData.Sections.GetSectionData(fileName).Keys.AddKey(valueIndex + "@" + fileName + "@" + key, value.SurroundWithQuotes());
                        }
                    }
                }
            }
        }
 protected virtual IEnumerable<Models.Configuration> GetConfigurationsCore(IniData mergedIniData)
 {
     foreach (var globalData in mergedIniData.Global)
     {
         yield return new Models.Configuration
         {
             Group = GlobalSectionName,
             Key = globalData.KeyName,
             Value = globalData.Value
         };
     }
     foreach (var section in mergedIniData.Sections)
     {
         foreach (var keyValue in section.Keys)
         {
             yield return new Models.Configuration
             {
                 Group = section.SectionName,
                 Key = keyValue.KeyName,
                 Value = keyValue.Value
             };
         }
     }
 }
Exemplo n.º 14
0
 public IniData(IniData ori) : this((SectionDataCollection)ori.Sections)
 {
     Global        = (KeyDataCollection)ori.Global.Clone();
     Configuration = ori.Configuration.Clone();
 }
Exemplo n.º 15
0
 public IniData(IniData ori)
     : this((SectionDataCollection) ori.Sections)
 {
     Global = (KeyDataCollection) ori.Global.Clone();
     Configuration = ori.Configuration.Clone();
 }
Exemplo n.º 16
0
        /// <summary>
        ///     Merges the other iniData into this one by overwriting existing values.
        ///     Comments get appended.
        /// </summary>
        /// <param name="toMergeIniData">
        ///     IniData instance to merge into this. 
        ///     If it is null this operation does nothing.
        /// </param>
        public void Merge(IniData toMergeIniData)
        {
            if (toMergeIniData == null) return;

            Global.Merge(toMergeIniData.Global);

            Sections.Merge(toMergeIniData.Sections);
        }
Exemplo n.º 17
0
        /// <summary>
        ///     Parses a string containing valid ini data
        /// </summary>
        /// <param name="iniDataString">
        ///     String with data
        /// </param>
        /// <returns>
        ///     An <see cref="IniData"/> instance with the data contained in
        ///     the <paramref name="iniDataString"/> correctly parsed an structured.
        /// </returns>
        /// <exception cref="ParsingException">
        ///     Thrown if the data could not be parsed
        /// </exception>
        public IniData Parse(string iniDataString)
        {
            IniData iniData = new IniData();
            iniData.Configuration = this.Configuration.Clone();

            if (string.IsNullOrEmpty(iniDataString))
            {
                return iniData;
            }

            _currentCommentListTemp.Clear();
            _currentSectionNameTemp = null;

            try
            {
                foreach (var line in iniDataString.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                    ProcessLine(line, iniData);
            }
            catch
            {
                if (Configuration.ThrowExceptionsOnError)
                    throw;

                return null;
            }

            return (IniData)iniData.Clone();
        }
Exemplo n.º 18
0
 /// <summary>
 ///     Copies an instance of the <see cref="IniParser.Model.IniDataCaseInsensitive" /> class
 /// </summary>
 /// <param name="ori">Original </param>
 public IniDataCaseInsensitive(IniData ori)
     : this(new SectionDataCollection(ori.Sections, StringComparer.OrdinalIgnoreCase))
 {
     Global        = (KeyDataCollection)ori.Global.Clone();
     Configuration = ori.Configuration.Clone();
 }
Exemplo n.º 19
0
        /// <summary>
        ///     Proccess a string which contains an ini section.
        /// </summary>
        /// <param name="line">
        ///     The string to be processed
        /// </param>
        protected virtual void ProcessSection(string line, IniData currentIniData)
        {
            // Get section name with delimiters from line...
            string sectionName = Configuration.SectionRegex.Match(line).Value.Trim();

            // ... and remove section's delimiters to get just the name
            sectionName = sectionName.Substring(1, sectionName.Length - 2).Trim();

            // Check that the section's name is not empty
            if (sectionName == string.Empty)
            {
                throw new ParsingException("Section name is empty");
            }

            // Temporally save section name.
            _currentSectionNameTemp = sectionName;

            //Checks if the section already exists
            if (currentIniData.Sections.ContainsSection(sectionName))
            {
                if (Configuration.AllowDuplicateSections)
                {
                    return;
                }

                throw new ParsingException(string.Format("Duplicate section with name '{0}' on line '{1}'", sectionName, line));
            }

            // If the section does not exists, add it to the ini data
            currentIniData.Sections.AddSection(sectionName);

            // Save comments read until now and assign them to this section
            currentIniData.Sections.GetSectionData(sectionName).LeadingComments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Exemplo n.º 20
0
        /// <summary>
        ///     Processes one line and parses the data found in that line
        ///     (section or key/value pair who may or may not have comments)
        /// </summary>
        /// <param name="currentLine">The string with the line to process</param>
        protected virtual void ProcessLine(string currentLine, IniData currentIniData)
        {
            currentLine = currentLine.Trim();

            // Extract comments from current line and store them in a tmp field
            if (LineContainsAComment(currentLine))
            {
                currentLine = ExtractComment(currentLine);
            }

            // By default comments must spann a complete line (i.e. the comment character
            // must be located at the beginning of a line, so it seems that the following
            // check is not needed.
            // But, if the comment parsing behaviour is changed in a derived class e.g. to
            // to allow parsing comment characters in the middle of a line, the implementor
            // will be forced to rewrite this complete method.
            // That was actually the behaviour for parsing comments
            // in earlier versions of the library, so checking if the current line is empty
            // (meaning the complete line was a comment) is future-proof.

            // If the entire line waas a comment now should be empty,
            // so no further processing is needed.
            if (currentLine == String.Empty)
                return;

            //Process sections
            if (LineMatchesASection(currentLine))
            {
                ProcessSection(currentLine, currentIniData);
                return;
            }

            //Process keys
            if (LineMatchesAKeyValuePair(currentLine))
            {
                ProcessKeyValuePair(currentLine, currentIniData);
                return;
            }

            if (Configuration.SkipInvalidLines)
                return;

            throw new ParsingException(
                "Unknown file format. Couldn't parse the line: '" + currentLine + "'.");
        }
Exemplo n.º 21
0
        /// <summary>
        ///     Processes a string containing an ini key/value pair.
        /// </summary>
        /// <param name="line">
        ///     The string to be processed
        /// </param>
        protected virtual void ProcessKeyValuePair(string line, IniData currentIniData)
        {
            //string sectionToUse = _currentSectionNameTemp;

            // get key and value data
            string key = ExtractKey(line);
            string value = ExtractValue(line);

            // Check if we haven't read any section yet
            if (string.IsNullOrEmpty(_currentSectionNameTemp))
            {
                if (!Configuration.AllowKeysWithoutSection)
                {
                    throw new ParsingException("key value pairs must be enclosed in a section");
                }

                AddKeyToKeyValueCollection(key, value, currentIniData.Global, "global");
            }
            else
            {
                var currentSection = currentIniData.Sections.GetSectionData(_currentSectionNameTemp);

                AddKeyToKeyValueCollection(key, value, currentSection.Keys, _currentSectionNameTemp);
            }
        }
Exemplo n.º 22
0
        public void ExtractMod(string modPath)
        {
            if (!Directory.Exists(this.OutputExtractFolderPath))
            {
                throw new InvalidOperationException("You must choose an extraction path");
            }

            string outputFilePath = this.OutputExtractFolderPath + "\\Democracy3ModExtractedText.ini";

            if (File.Exists(outputFilePath))
            {
                File.Delete(outputFilePath);
            }

            var iniData = new IniParser.Model.IniData();

            // MOD RACINE
            string modBasePath = this.GameFolderPath.Replace("data", "") + "\\" + modPath + "\\data";

            if (!Directory.Exists(modBasePath))
            {
                throw new InvalidOperationException("Mod is not installed");
            }

            iniData.Sections.AddSection("Mod__" + modPath);

            // SIMULATION
            var path  = modBasePath + "\\simulation\\";
            var files = Directory.GetFiles(path);

            foreach (var filePath in files)
            {
                var fileName = filePath.Replace(path, "");
                if (fileName == "achievements.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 2
                    });
                }
                else if (fileName == "policies.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 2
                    });
                }
                else if (fileName == "pressuregroups.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        8, 3, 9, 10
                    });
                }
                else if (fileName == "simulation.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        3, 2
                    });
                }
                else if (fileName == "situations.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        3, 2, 6, 7
                    });
                }
                else if (fileName == "votertypes.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        8, 2, 3
                    });
                }
                else if (fileName == "sliders.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 5, 6, 7, 8, 9, 10
                    });
                }
            }

            // Attacks
            path = modBasePath + "\\simulation\\attacks\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "SuccessText", "GUIName"
                    });
                }
            }

            // Dilemmas
            path = modBasePath + "\\simulation\\dilemmas\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "description", "guiname", "name"
                    });
                }
            }

            // Events
            path = modBasePath + "\\simulation\\events\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "description", "guiname"
                    });
                }
            }

            // Missions
            path = modBasePath + "\\missions\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetDirectories(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "") + ".txt";
                    ParseIni(filePath + "\\" + fileName, fileName, iniData, new List <string> {
                        "description", "guiname"
                    });
                }
            }

            var parser = new IniParser.FileIniDataParser();

            parser.WriteFile(outputFilePath, iniData, Encoding.UTF8);
        }
Exemplo n.º 23
0
        public void ExtractAllSentences()
        {
            //this.textBoxOutputFolder.Text == OutputExtractFolderPath
            // this.textBoxSource.Text == GameFolderPath
            if (!Directory.Exists(this.OutputExtractFolderPath))
            {
                throw new InvalidOperationException("You must choose an extraction path");
            }

            string outputFilePath = this.OutputExtractFolderPath + "\\Democracy3MainExtractedText.ini";

            if (File.Exists(outputFilePath))
            {
                File.Delete(outputFilePath);
            }

            var iniData = new IniParser.Model.IniData();

            // RACINE
            string path  = this.GameFolderPath + "\\";
            var    files = Directory.GetFiles(path);

            foreach (var filePath in files)
            {
                var fileName = filePath.Replace(path, "");
                if (fileName == "strings.ini")
                {
                    ParseIni(filePath, fileName, iniData);
                }
                else if (fileName == "tutorial.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 2, new List <int> {
                        11, 3
                    });
                }
            }

            // SIMULATION
            path  = this.GameFolderPath + "\\simulation\\";
            files = Directory.GetFiles(path);
            foreach (var filePath in files)
            {
                var fileName = filePath.Replace(path, "");
                if (fileName == "achievements.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 2
                    });
                }
                else if (fileName == "policies.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 2
                    });
                }
                else if (fileName == "pressuregroups.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        8, 3, 9, 10
                    });
                }
                else if (fileName == "simulation.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        3, 2
                    });
                }
                else if (fileName == "situations.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        3, 2, 6, 7
                    });
                }
                else if (fileName == "votertypes.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        8, 2, 3
                    });
                }
                else if (fileName == "sliders.csv")
                {
                    ParseCsv(filePath, fileName, iniData, 1, new List <int> {
                        4, 5, 6, 7, 8, 9, 10
                    });
                }
            }

            // Attacks
            path = this.GameFolderPath + "\\simulation\\attacks\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "SuccessText", "GUIName"
                    });
                }
            }

            // Dilemmas
            path = this.GameFolderPath + "\\simulation\\dilemmas\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "description", "guiname", "name"
                    });
                }
            }

            // Events
            path = this.GameFolderPath + "\\simulation\\events\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetFiles(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "");
                    ParseIni(filePath, fileName, iniData, new List <string> {
                        "description", "guiname"
                    });
                }
            }

            // Missions
            path = this.GameFolderPath + "\\missions\\";
            if (Directory.Exists(path))
            {
                files = Directory.GetDirectories(path);
                foreach (var filePath in files)
                {
                    var fileName = filePath.Replace(path, "") + ".txt";
                    ParseIni(filePath + "\\" + fileName, fileName, iniData, new List <string> {
                        "description", "guiname"
                    });
                }
            }

            var parser = new IniParser.FileIniDataParser();

            parser.WriteFile(outputFilePath, iniData, Encoding.UTF8);

            //MessageBox.Show("You can now send the file to transifex website\nFile path : " + outputFilePath, "Extraction finished...", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrototypeBackend.ConfigurationManager"/> class.
        /// </summary>
        /// <param name="UserFolderPath">User folder path.</param>
        public ConfigurationManager(string UserFolderPath = null)
        {
            if (UserFolderPath == null) {

                //Linux|Mac
                if (Environment.OSVersion.Platform == PlatformID.Unix) {
                    UserFolder = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
                    UserFolder += @"/.config/micrologger/Config.ini";
                }
                //Windows
                else {
                    UserFolder = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
                    UserFolder += @"\micrologger\Config.ini";
                    Console.WriteLine (UserFolder);
                }
            } else {
                UserFolder = UserFolderPath;
            }

            if (File.Exists (UserFolder)) {
                GeneralData = ParseSettings (UserFolder);
            } else {
                throw new FileNotFoundException ();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        ///     Processes one line and parses the data found in that line
        ///     (section or key/value pair who may or may not have comments)
        /// </summary>
        /// <param name="currentLine">The string with the line to process</param>
        protected void ProcessLine(string currentLine, IniData currentIniData)
        {
            currentLine = currentLine.Trim();

            // Extract comments from current line and store them in a tmp field
            if (LineContainsAComment(currentLine))
                currentLine = ExtractComment(currentLine);

            // If the entire line is a comment now should be empty,
            // so no further processing is needed.
            if (currentLine == String.Empty)
                return;

            //Process sections
            if (LineMatchesASection(currentLine))
            {
                ProcessSection(currentLine, currentIniData);
                return;
            }

            //Process keys
            if (LineMatchesAKeyValuePair(currentLine))
            {
                ProcessKeyValuePair(currentLine, currentIniData);
                return;
            }

            if (Configuration.SkipInvalidLines)
                return;

            throw new ParsingException(
                "Unknown file format. Couldn't parse the line: '" + currentLine + "'.");
        }
Exemplo n.º 26
0
        /// <summary>
        ///     Parses a string containing valid ini data and put the data into an existing ini file
        ///     by overwriting the existing content
        /// </summary>
        /// <param name="iniDataString">
        ///     String with data
        /// </param>
        /// <returns>
        ///     An <see cref="IniData"/> instance with the data contained in
        ///     the <paramref name="iniDataString"/> correctly parsed an structured.
        /// </returns>
        /// <exception cref="ParsingException">
        ///     Thrown if the data could not be parsed
        /// </exception>
        public IniData ParseAndOverwrite(string iniDataString, IniData iniData)
        {
            // store old config
            bool oldAllowDuplicateKeys = Configuration.AllowDuplicateKeys;
            bool oldAllowDuplicateSections = Configuration.AllowDuplicateSections;
            bool oldOverrideDuplicateKeys = Configuration.OverrideDuplicateKeys;

            // allow to overwrite everything
            Configuration.AllowDuplicateKeys = true;
            Configuration.AllowDuplicateSections = true;
            Configuration.OverrideDuplicateKeys = true;

            ParseInto(iniDataString, iniData);

            // restore old config
            Configuration.AllowDuplicateKeys = oldAllowDuplicateKeys;
            Configuration.AllowDuplicateSections = oldAllowDuplicateSections;
            Configuration.OverrideDuplicateKeys = oldOverrideDuplicateKeys;

            return iniData;
        }
Exemplo n.º 27
0
        /// <summary>
        ///     Parses a string containing valid ini data
        /// </summary>
        /// <param name="iniDataString">
        ///     String with data
        /// </param>
        /// <returns>
        ///     An <see cref="IniData"/> instance with the data contained in
        ///     the <paramref name="iniDataString"/> correctly parsed an structured.
        /// </returns>
        /// <exception cref="ParsingException">
        ///     Thrown if the data could not be parsed
        /// </exception>
        public IniData Parse(string iniDataString)
        {
            IniData iniData = new IniData();
            iniData.Configuration = this.Configuration.Clone();

            iniData = ParseInto(iniDataString, iniData);
            if (iniData == null) return null;
            return (IniData)(iniData).Clone();
        }