Exemplo n.º 1
0
        public void WriteWZLabel(IniWriter File, int PlayerCount)
        {
            if (label != null)
            {
                var TypeNum = 0;
                switch (TypeBase.Type)
                {
                case UnitType.PlayerDroid:
                    TypeNum = 0;
                    break;

                case UnitType.PlayerStructure:
                    TypeNum = 1;
                    break;

                case UnitType.Feature:
                    TypeNum = 2;
                    break;

                default:
                    return;
                }
                File.AddSection("object_" + MapLink.ArrayPosition.ToStringInvariant());
                File.AddProperty("id", ID.ToStringInvariant());
                if (PlayerCount >= 0)   //not an FMap
                {
                    File.AddProperty("type", TypeNum.ToStringInvariant());
                    File.AddProperty("player", UnitGroup.GetPlayerNum(PlayerCount).ToStringInvariant());
                }
                File.AddProperty("label", label);
            }
        }
        public static void SetLocalizedFileNames(string filePath, string name)
        {
            IniWriter writer   = new IniWriter(GetDesktopIniPath(filePath));
            string    fileName = Path.GetFileName(filePath);

            writer.SetValue(LocalizedFileNames, fileName, name);
        }
Exemplo n.º 3
0
        private Result serialize_WZ_LabelsINI(IniWriter file)
        {
            var returnResult = new Result("Serializing labels INI", false);

            logger.Info("Serializing labels INI");

            try
            {
                foreach (var scriptPosition in map.ScriptPositions)
                {
                    scriptPosition.WriteWZ(file);
                }
                foreach (var scriptArea in map.ScriptAreas)
                {
                    scriptArea.WriteWZ(file);
                }
            }
            catch (Exception ex)
            {
                returnResult.WarningAdd(ex.Message);
                logger.ErrorException("Got an exception", ex);
            }

            return(returnResult);
        }
        public void NotOrderedWriteState()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.WriteKey("state", "Out of order");
        }
Exemplo n.º 5
0
        private Result serialize_FMap_Gateways(IniWriter File)
        {
            var returnResult = new Result("Serializing gateways", false);

            logger.Info("Serializing gateways");

            try
            {
                var a = 0;
                foreach (var gateway in map.Gateways)
                {
                    File.AddSection(a.ToStringInvariant());
                    File.AddProperty("AX", gateway.PosA.X.ToStringInvariant());
                    File.AddProperty("AY", gateway.PosA.Y.ToStringInvariant());
                    File.AddProperty("BX", gateway.PosB.X.ToStringInvariant());
                    File.AddProperty("BY", gateway.PosB.Y.ToStringInvariant());
                    a++;
                }
            }
            catch (Exception ex)
            {
                returnResult.ProblemAdd(ex.Message);
            }

            return(returnResult);
        }
Exemplo n.º 6
0
        public void LoadLanguages()
        {
            cmbLanguages.Items.Clear();
            cmbLanguages.Items.Add("(default) 简体中文");
            string str = AppString.Other.Translators + Environment.NewLine + new string('-', 74);

            if (Directory.Exists(AppConfig.LangsDir))
            {
                languages.Clear();
                foreach (string fileName in Directory.GetFiles(AppConfig.LangsDir, "*.ini"))
                {
                    string    langName = Path.GetFileNameWithoutExtension(fileName);
                    IniWriter reader   = new IniWriter(fileName);
                    string    language = reader.GetValue("General", "Language");
                    if (language.IsNullOrWhiteSpace())
                    {
                        language = langName;
                    }
                    string translator = reader.GetValue("General", "Translator");
                    str += Environment.NewLine + language + new string('\t', 5) + translator;
                    cmbLanguages.Items.Add(language);
                    languages.Add(langName);
                }
            }
            txtTranslators.Text        = str;
            cmbLanguages.SelectedIndex = GetSelectIndex();
        }
Exemplo n.º 7
0
 public void WriteWZ(IniWriter file)
 {
     file.AddSection("area_" + _ParentMapLink.ArrayPosition.ToStringInvariant());
     file.AddProperty("pos1", _PosA.X.ToStringInvariant() + ", " + _PosA.Y.ToStringInvariant());
     file.AddProperty("pos2", _PosB.X.ToStringInvariant() + ", " + _PosB.Y.ToStringInvariant());
     file.AddProperty("label", Label);
 }
        private void ChangeLanguage()
        {
            int index = GetSelectIndex();

            if (cmbLanguages.SelectedIndex == index)
            {
                return;
            }
            string language = languages[cmbLanguages.SelectedIndex];
            string msg      = "";

            if (cmbLanguages.SelectedIndex != 0)
            {
                string langPath = $@"{AppConfig.LangsDir}\{language}.ini";
                msg = new IniWriter(langPath).GetValue("Message", "RestartApp");
            }
            if (msg == "")
            {
                msg = AppString.Message.RestartApp;
            }
            if (AppMessageBox.Show(msg, MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                cmbLanguages.SelectedIndex = index;
            }
            else
            {
                if (language == CultureInfo.CurrentUICulture.Name)
                {
                    language = "";
                }
                AppConfig.Language = language;
                SingleInstance.Restart();
            }
        }
Exemplo n.º 9
0
        public void Write_EmptyKeysAndOrValues()
        {
            // Arrange
            IniFile       file     = new IniFile();
            StringBuilder fileText = new StringBuilder();

            file.Sections.Add(new IniSection("Fruit"));
            file["Fruit"].KeyValues.Add(string.Empty, "red");
            file["Fruit"].KeyValues.Add("orange", string.Empty);
            file.Sections.Add(new IniSection("Veggie"));
            file["Veggie"].KeyValues.Add(string.Empty, string.Empty);

            // Act
            using (StringWriter stringWriter = new StringWriter(fileText))
            {
                IniWriter.Write(file, stringWriter);
            }

            // Assert
            using (StringReader stringReader = new StringReader(fileText.ToString()))
            {
                Assert.AreEqual("[Fruit]", stringReader.ReadLine());
                Assert.AreEqual("=red", stringReader.ReadLine());
                Assert.AreEqual("orange=", stringReader.ReadLine());
                Assert.AreEqual(string.Empty, stringReader.ReadLine());
                Assert.AreEqual("[Veggie]", stringReader.ReadLine());
                Assert.AreEqual("=", stringReader.ReadLine());
            }
        }
Exemplo n.º 10
0
        public void Write_EmptySections()
        {
            // Arrange
            IniFile       file     = new IniFile();
            StringBuilder fileText = new StringBuilder();

            file.Sections.Add(new IniSection("Fruit"));
            file["Fruit"].KeyValues.Add("apple", "red");
            file["Fruit"].KeyValues.Add("orange", "orange");
            file.Sections.Add(new IniSection(string.Empty));
            file[string.Empty].KeyValues.Add("tomato", "red");
            file[string.Empty].KeyValues.Add("zucchini", "green");

            // Act
            using (StringWriter stringWriter = new StringWriter(fileText))
            {
                IniWriter.Write(file, stringWriter);
            }

            // Assert
            using (StringReader stringReader = new StringReader(fileText.ToString()))
            {
                Assert.AreEqual("[Fruit]", stringReader.ReadLine());
                Assert.AreEqual("apple=red", stringReader.ReadLine());
                Assert.AreEqual("orange=orange", stringReader.ReadLine());
                Assert.AreEqual(string.Empty, stringReader.ReadLine());
                Assert.AreEqual("[]", stringReader.ReadLine());
                Assert.AreEqual("tomato=red", stringReader.ReadLine());
                Assert.AreEqual("zucchini=green", stringReader.ReadLine());
            }
        }
Exemplo n.º 11
0
        public static void DeleteLocalizedFileNames(string filePath)
        {
            IniWriter writer   = new IniWriter(GetDesktopIniPath(filePath));
            string    fileName = Path.GetFileName(filePath);

            writer.DeleteKey(LocalizedFileNames, fileName);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Saves the current control bindings to an arbitrary stream.
 /// </summary>
 /// <param name="file">The writable stream to save to.</param>
 public void SaveConfiguration(Stream file)
 {
     using (IniWriter w = new IniWriter(file))
     {
         w.WriteSection("KeyBindings");
         rootcstate.WriteIni(w);
     }
 }
Exemplo n.º 13
0
        public void DisposeStringWriterNullReference()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.WriteSection("Test");
            iniWriter.Dispose();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Saves credentials to the default ini file.
        /// </summary>
        /// <param name="user">user name.</param>
        /// <param name="pass">password.</param>
        public void SaveCredentials(string user, string pass)
        {
            var location = new FileLocation(RootLocation.RoamingUserConfig, "CaveSystems GmbH", null, "auth", Ini.PlatformExtension);
            var writer   = IniWriter.FromLocation(location);

            writer.WriteSetting("auth", "user", user);
            writer.WriteSetting("auth", "pass", pass);
            writer.Save();
        }
Exemplo n.º 15
0
        public void ReplaceEndOfLine()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.WriteSection("Required");
            iniWriter.WriteKey("thanksgiving", "November\n 25th");

            Assert.AreEqual("thanksgiving = November 25th", ReadLine(writer, 2));
        }
Exemplo n.º 16
0
        public void NotOrderedWriteState()
        {
            Assert.Throws <InvalidOperationException>(() =>
            {
                var writer    = new StringWriter();
                var iniWriter = new IniWriter(writer);

                iniWriter.WriteKey("state", "Out of order");
            });
        }
Exemplo n.º 17
0
 /// <summary>
 /// Saves the current control bindings to a path on the filesystem.
 /// </summary>
 /// <param name="filename">The location of the file to write to. NOTE: This does NOT automatically use Game.PathTo()</param>
 public void SaveConfiguration(String filename)
 {
     using (FileStream fs = new FileStream(filename, FileMode.Create)){
         using (IniWriter w = new IniWriter(fs))
         {
             w.WriteSection("KeyBindings");
             Command.commands.WriteIni(w);
         }
     }
 }
Exemplo n.º 18
0
        public void SectionWithoutComment()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            Assert.AreEqual(IniWriteState.Start, iniWriter.WriteState);

            iniWriter.WriteSection("Test Section");
            Assert.AreEqual("[Test Section]", ReadLine(writer, 1));
            Assert.AreEqual(IniWriteState.Section, iniWriter.WriteState);
        }
Exemplo n.º 19
0
        public void FlushAndClose()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.WriteSection("Required");
            iniWriter.WriteKey("thanksgiving", "november 25th", "Football!");

            iniWriter.Close();
            Assert.AreEqual(IniWriteState.Closed, iniWriter.WriteState);
        }
Exemplo n.º 20
0
        public void KeyWithIndentation()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.Indentation = 2;
            iniWriter.WriteSection("Required");
            iniWriter.WriteKey("independence day", "july");
            Assert.AreEqual("  independence day = july", ReadLine(writer, 2));
            iniWriter.Indentation = 0;
        }
Exemplo n.º 21
0
        public void EmptyWithoutComment()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            Assert.AreEqual(IniWriteState.Start, iniWriter.WriteState);

            iniWriter.WriteEmpty();
            Assert.AreEqual("", ReadLine(writer, 1));
            Assert.AreEqual(IniWriteState.BeforeFirstSection, iniWriter.WriteState);
        }
Exemplo n.º 22
0
        public void NestedInifileTest()
        {
            var writer = new IniWriter();
            var test   = NestedRoot.Random(CultureInfo.InvariantCulture);

            writer.WriteProperties("test", test);

            var reader  = writer.ToReader();
            var current = reader.ReadObjectProperties <NestedRoot>("test");

            Assert.AreEqual(test, current);
        }
Exemplo n.º 23
0
        public static string GetLocalizedFileNames(string filePath, bool translate = false)
        {
            IniWriter writer   = new IniWriter(GetDesktopIniPath(filePath));
            string    fileName = Path.GetFileName(filePath);
            string    name     = writer.GetValue(LocalizedFileNames, fileName);

            if (translate)
            {
                name = ResourceString.GetDirectString(name);
            }
            return(name);
        }
Exemplo n.º 24
0
        public void KeyWithQuotesAndComment()
        {
            StringWriter writer    = new StringWriter();
            IniWriter    iniWriter = new IniWriter(writer);

            iniWriter.UseValueQuotes = true;
            iniWriter.WriteSection("Required");
            iniWriter.WriteKey("thanksgiving", "November 25th", "Football!");
            iniWriter.UseValueQuotes = false;
            Assert.AreEqual("thanksgiving = \"November 25th\" ; Football!",
                            ReadLine(writer, 2));
        }
Exemplo n.º 25
0
        public void Write_FileWithComments()
        {
            // Arrange
            IniFile       file     = new IniFile();
            StringBuilder fileText = new StringBuilder();

            file.Sections.Add(new IniSection("Fruit"));
            file["Fruit"].KeyValues.Add("apple", "red");
            file["Fruit"].KeyValues.Add("orange", "orange");
            file["Fruit"].KeyValues.Add("banana", "yellow");
            file.Sections.Add(new IniSection("Veggie"));
            file["Veggie"].KeyValues.Add("tomato", "red");
            file["Veggie"].KeyValues.Add("zucchini", "green");
            file["Veggie"].KeyValues.Add("cucumber", "green");

            file["Fruit"].Comments.Add("Something about fruit.");
            file["Fruit"].KeyValues["apple"].Comments.Add("Something about apples.");
            file["Fruit"].KeyValues["apple"].Comments.Add("Something else about apples.");
            file["Veggie"].Comments.Add("Something about veggies.");
            file["Veggie"].Comments.Add("Something else about veggies.");
            file["Veggie"].Comments.Add("Even more about veggies!");
            file["Veggie"].KeyValues["zucchini"].Comments.Add("Something about zucchini.");

            // Act
            using (StringWriter stringWriter = new StringWriter(fileText))
            {
                IniWriter.Write(file, stringWriter);
            }

            // Assert
            using (StringReader stringReader = new StringReader(fileText.ToString()))
            {
                Assert.AreEqual(";Something about fruit.", stringReader.ReadLine());
                Assert.AreEqual("[Fruit]", stringReader.ReadLine());
                Assert.AreEqual(";Something about apples.", stringReader.ReadLine());
                Assert.AreEqual(";Something else about apples.", stringReader.ReadLine());
                Assert.AreEqual("apple=red", stringReader.ReadLine());
                Assert.AreEqual("orange=orange", stringReader.ReadLine());
                Assert.AreEqual("banana=yellow", stringReader.ReadLine());
                Assert.AreEqual(string.Empty, stringReader.ReadLine());
                Assert.AreEqual(";Something about veggies.", stringReader.ReadLine());
                Assert.AreEqual(";Something else about veggies.", stringReader.ReadLine());
                Assert.AreEqual(";Even more about veggies!", stringReader.ReadLine());
                Assert.AreEqual("[Veggie]", stringReader.ReadLine());
                Assert.AreEqual("tomato=red", stringReader.ReadLine());
                Assert.AreEqual(";Something about zucchini.", stringReader.ReadLine());
                Assert.AreEqual("zucchini=green", stringReader.ReadLine());
                Assert.AreEqual("cucumber=green", stringReader.ReadLine());
            }
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            string filePath    = "D:/org.ini";
            string fileContent = File.ReadAllText(filePath);
            var    iniData     = IniReader.ReadFromString(fileContent);

            if (iniData != null)
            {
                string content = IniWriter.WriteToString(iniData);
                File.WriteAllText("D:/test.ini", content);
            }

            Console.ReadKey();
        }
Exemplo n.º 27
0
 public static void WriteINI()
 {
     using (FileStream FS = new FileStream("Settings.INI", FileMode.OpenOrCreate, FileAccess.Write))
     {
         using (IniWriter IW = new IniWriter(FS))
         {
             IW.WriteSection("ProgramSettings");
             IW.WriteKey("SavePassword", "" + SavePassword);
             IW.WriteKey("UserName", "\"" + UserName + "\"");
             IW.WriteKey("DataSource", "\"" + DataSource + "\"");
             IW.WriteKey("ConnectionString", "\"" + DatabaseControlService.ConnectString + "\"");
             IW.WriteKey("LastPage", "" + LastPage);
         }
     }
 }
 private void AddGuidDic()
 {
     using (AddGuidDicDialog dlg = new AddGuidDicDialog())
     {
         dlg.ItemText = GuidInfo.GetText(Item.Guid);
         dlg.ItemIcon = GuidInfo.GetImage(Item.Guid);
         var location = GuidInfo.GetIconLocation(Item.Guid);
         dlg.ItemIconPath  = location.IconPath;
         dlg.ItemIconIndex = location.IconIndex;
         IniWriter writer = new IniWriter
         {
             FilePath            = AppConfig.UserGuidInfosDic,
             DeleteFileWhenEmpty = true
         };
         string     section  = Item.Guid.ToString();
         MyListItem listItem = (MyListItem)Item;
         if (dlg.ShowDialog() != DialogResult.OK)
         {
             if (dlg.IsDelete)
             {
                 writer.DeleteSection(section);
                 GuidInfo.RemoveDic(Item.Guid);
                 listItem.Text  = Item.ItemText;
                 listItem.Image = GuidInfo.GetImage(Item.Guid);
             }
             return;
         }
         if (dlg.ItemText.IsNullOrWhiteSpace())
         {
             AppMessageBox.Show(AppString.Message.TextCannotBeEmpty);
             return;
         }
         dlg.ItemText = ResourceString.GetDirectString(dlg.ItemText);
         if (dlg.ItemText.IsNullOrWhiteSpace())
         {
             AppMessageBox.Show(AppString.Message.StringParsingFailed);
             return;
         }
         else
         {
             GuidInfo.RemoveDic(Item.Guid);
             writer.SetValue(section, "Text", dlg.ItemText);
             writer.SetValue(section, "Icon", dlg.ItemIconLocation);
             listItem.Text  = dlg.ItemText;
             listItem.Image = dlg.ItemIcon;
         }
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Write out DatItem using the supplied StreamWriter
        /// </summary>
        /// <param name="iw">IniWriter to output to</param>
        /// <param name="datItem">DatItem object to be output</param>
        private void WriteDatItem(IniWriter iw, DatItem datItem)
        {
            /*
             * The rominfo order is as follows:
             * 1 - parent name
             * 2 - parent description
             * 3 - game name
             * 4 - game description
             * 5 - rom name
             * 6 - rom crc
             * 7 - rom size
             * 8 - romof name
             * 9 - merge name
             */

            // Pre-process the item name
            ProcessItemName(datItem, true);

            // Build the state
            switch (datItem.ItemType)
            {
            case ItemType.Rom:
                var rom = datItem as Rom;

                iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
                iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
                iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
                if (string.IsNullOrWhiteSpace(rom.Machine.Description ?? string.Empty))
                {
                    iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
                }
                else
                {
                    iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}");
                }
                iw.WriteString($"¬{rom.Name ?? string.Empty}");
                iw.WriteString($"¬{rom.CRC ?? string.Empty}");
                iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}");
                iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}");
                iw.WriteString($"¬{rom.MergeTag ?? string.Empty}");
                iw.WriteString("¬");
                iw.WriteLine();

                break;
            }

            iw.Flush();
        }
Exemplo n.º 30
0
        private Result serialize_FMap_Info(IniWriter file)
        {
            var ReturnResult = new Result("Serializing general map info", false);

            logger.Info("Serializing general map info");

            try
            {
                if (map.Tileset == null)
                {
                }
                else if (map.Tileset == App.Tileset_Arizona)
                {
                    file.AddProperty("Tileset", "Arizona");
                }
                else if (map.Tileset == App.Tileset_Urban)
                {
                    file.AddProperty("Tileset", "Urban");
                }
                else if (map.Tileset == App.Tileset_Rockies)
                {
                    file.AddProperty("Tileset", "Rockies");
                }

                file.AddProperty("Size", map.Terrain.TileSize.X.ToStringInvariant() + ", " + map.Terrain.TileSize.Y.ToStringInvariant());

                file.AddProperty("AutoScrollLimits", map.InterfaceOptions.AutoScrollLimits.ToStringInvariant());
                file.AddProperty("ScrollMinX", map.InterfaceOptions.ScrollMin.X.ToStringInvariant());
                file.AddProperty("ScrollMinY", map.InterfaceOptions.ScrollMin.Y.ToStringInvariant());
                file.AddProperty("ScrollMaxX", map.InterfaceOptions.ScrollMax.X.ToStringInvariant());
                file.AddProperty("ScrollMaxY", map.InterfaceOptions.ScrollMax.Y.ToStringInvariant());

                file.AddProperty("Name", map.InterfaceOptions.CompileName);
                file.AddProperty("Players", map.InterfaceOptions.CompileMultiPlayers);
                file.AddProperty("Author", map.InterfaceOptions.CompileMultiAuthor);
                file.AddProperty("License", map.InterfaceOptions.CompileMultiLicense);
                if (map.InterfaceOptions.CampaignGameType >= 0)
                {
                    file.AddProperty("CampType", map.InterfaceOptions.CampaignGameType.ToStringInvariant());
                }
            }
            catch (Exception ex)
            {
                ReturnResult.ProblemAdd(ex.Message);
            }

            return(ReturnResult);
        }