INIBlocks ReadINI()
        {
            IsBini = false;
            INIManager iniManager = new INIManager(File);

            return(iniManager.Read());
        }
Beispiel #2
0
        List <INIBlock> ReadINI()
        {
            IsBINI = false;
            INIManager iniManager = new INIManager(File)
            {
                ReadWriteComments = ReadWriteComments,
            };

            return(iniManager.Read());
        }
        public void Write(EditorINIData data)
        {
            //sort blocks first
            for (int i = 0; i < Helper.Template.Data.Files[data.TemplateIndex].Blocks.Count; i++)
            {
                Template.Block templateBlock = Helper.Template.Data.Files[data.TemplateIndex].Blocks[i];

                for (int j = i; j < data.Blocks.Count; j++)
                {
                    if (data.Blocks[j].Name.ToLower() == templateBlock.Name.ToLower())
                    {
                        //swap blocks
                        EditorINIBlock temporaryBlock = data.Blocks[i];
                        data.Blocks[i] = data.Blocks[j];
                        data.Blocks[j] = temporaryBlock;
                        break;
                    }
                }
            }

            //save data
            INIBlocks newData = new INIBlocks();

            foreach (EditorINIBlock block in data.Blocks)
            {
                INIOptions newBlock = new INIOptions();
                for (int i = 0; i < block.Options.Count; i++)
                {
                    if (block.Options[i].Values.Count > 0)
                    {
                        List <INIOption> newOption = new List <INIOption>();

                        for (int j = 0; j < block.Options[i].Values.Count; j++)
                        {
                            newOption.Add(new INIOption(block.Options[i].Values[j].Value.ToString()));

                            //add suboptions as options with defined parent
                            if (block.Options[i].Values[j].SubOptions != null)
                            {
                                for (int k = 0; k < block.Options[i].Values[j].SubOptions.Count; k++)
                                {
                                    newOption.Add(new INIOption(block.Options[i].Values[j].SubOptions[k].ToString(), block.Options[i].ChildName));
                                }
                            }
                        }

                        newBlock.Add(block.Options[i].Name, newOption);
                    }
                }
                newData.Add(block.Name, newBlock);
            }

            try
            {
                //if (IsBini)
                //{
                //    BINIManager biniManager = new BINIManager(File);
                //    biniManager.Data = newData;
                //    biniManager.Write();
                //}
                //else
                //{
                INIManager iniManager = new INIManager(File);
                iniManager.Write(newData);
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public void Write(EditorINIData data)
        {
            //save data
            List <INIBlock> newData = new List <INIBlock>();

            foreach (EditorINIBlock block in data.Blocks)
            {
                INIOptions newBlock = new INIOptions();
                foreach (EditorINIOption option in block.Options)
                {
                    if (option.Values.Count > 0)
                    {
                        List <INIOption> newOption = new List <INIOption>();

                        foreach (EditorINIEntry entry in option.Values)
                        {
                            string optionValue = entry.Value.ToString();
                            if (optionValue == "=")
                            {
                                //use an empty value for options which dont have values and are simply defined when using the option key followed by a colon equal
                                newOption.Add(new INIOption
                                {
                                    Value = string.Empty
                                });
                            }
                            else
                            {
                                newOption.Add(new INIOption
                                {
                                    Value = optionValue
                                });
                            }

                            //add suboptions as options with defined parent
                            if (entry.SubOptions != null)
                            {
                                for (int k = 0; k < entry.SubOptions.Count; ++k)
                                {
                                    newOption.Add(new INIOption
                                    {
                                        Value  = entry.SubOptions[k].ToString(),
                                        Parent = option.ChildName
                                    });
                                }
                            }
                        }

                        newBlock.Add(option.Name, newOption);
                    }
                }
                newData.Add(new INIBlock
                {
                    Name     = block.Name,
                    Options  = newBlock,
                    Comments = block.Comments,
                });
            }

            //if (IsBINI)
            //{
            //    BINIManager biniManager = new BINIManager(File);
            //    biniManager.Data = newData;
            //    biniManager.Write();
            //}
            //else
            //{
            INIManager iniManager = new INIManager(File)
            {
                WriteEmptyLine    = WriteEmptyLine,
                WriteSpaces       = WriteSpaces,
                ReadWriteComments = ReadWriteComments,
            };

            iniManager.Write(newData);
            //}
        }