Exemplo n.º 1
0
        /// <summary>
        /// Static Main() method.
        /// </summary>
        private static void Main()
        {
#if DEBUG
            INIFile ini = new INIFile(@"..\Release\demo.ini");
#else
            INIFile ini = new INIFile("demo.ini");
#endif

            Console.WriteLine("FILE MAP");
            Console.WriteLine("========");
            Console.WriteLine("- INI file sections: " + string.Join(",", ini.GetSections()));
            Console.WriteLine("- INI file sections (including abstract sections): " + string.Join(",", ini.GetSections(true)));
            Console.WriteLine();
            foreach (string s in ini.GetSections())
            {
                Console.WriteLine($"[{s.ToUpperInvariant()}]");
                foreach (string k in ini.GetKeysInSection(s))
                {
                    Console.WriteLine("- " + k);
                }
                Console.WriteLine();
            }

            Console.WriteLine("VALUES READING TEST");
            Console.WriteLine("===================");
            Console.WriteLine("Value exists (cat->legs): " + ini.ValueExists("cat", "legs"));
            Console.WriteLine("Value exists (cat->tentacles): " + ini.ValueExists("cat", "tentacles"));
            Console.WriteLine();
            Console.WriteLine("Value (cat->legs): " + ini.GetValue <int>("cat", "legs"));
            Console.WriteLine("Value (cat->weight_in_kilograms): " + ini.GetValue <float>("cat", "weight_in_kilograms"));
            Console.WriteLine("Value (kitten->legs): " + ini.GetValue <int>("kitten", "legs"));
            Console.WriteLine("Value (kitten->weight_in_kilograms): " + ini.GetValue <float>("kitten", "weight_in_kilograms"));
            Console.WriteLine();

            Console.WriteLine("VALUES WRITING TEST");
            Console.WriteLine("===================");
            Console.WriteLine("Set (cat->weight_in_kilograms) to 8.4");
            ini.SetValue("cat", "weight_in_kilograms", 8.4f);
            Console.WriteLine("Value (cat->weight_in_kilograms): " + ini.GetValue <float>("cat", "weight_in_kilograms"));

            Console.WriteLine();
            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        protected override bool OnLoad(string iniFilePath)
        {
            var ini = new INIFile(iniFilePath);

            Theater = ini.GetValue <string>("Situation", "Theater").ToLowerInvariant();

            RedCoordinates = new List <Coordinates>();
            foreach (string key in ini.GetKeysInSection("RedCoordinates"))
            {
                RedCoordinates.Add(ini.GetValue <Coordinates>("RedCoordinates", key));
            }

            BlueCoordinates = new List <Coordinates>();
            foreach (string key in ini.GetKeysInSection("BlueCoordinates"))
            {
                BlueCoordinates.Add(ini.GetValue <Coordinates>("BlueCoordinates", key));
            }

            if (ini.GetSections().Contains("nospawncoordinates"))
            {
                NoSpawnCoordinates = new List <Coordinates>();
                foreach (string key in ini.GetKeysInSection("NoSpawnCoordinates"))
                {
                    NoSpawnCoordinates.Add(ini.GetValue <Coordinates>("NoSpawnCoordinates", key));
                }
            }

            if (ini.GetSections().Contains("briefingdescription"))
            {
                BriefingDescriptions = new List <string>();
                foreach (string key in ini.GetKeysInSection("BriefingDescription"))
                {
                    BriefingDescriptions.Add(ini.GetValue <string>("BriefingDescription", key));
                }
            }

            if (!Database.Instance.EntryExists <DBEntryTheater>(Theater))
            {
                throw new Exception($"Situation \"{ID}\" located on non-existing theater \"{Theater}\".");
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads strings from a .ini file.
        /// </summary>
        /// <param name="ini">The ini file to load from.</param>
        /// <returns>True is successful, false if an error happened.</returns>
        protected override bool OnLoad(INIFile ini)
        {
            Strings.Clear();

            foreach (string section in ini.GetSections())
            {
                foreach (string key in ini.GetKeysInSection(section))
                {
                    string stringKey = MakeStringKey(section, key);

                    if (Strings.ContainsKey(stringKey))
                    {
                        Strings[stringKey] = ini.GetValue(section, key, "");
                    }
                    else
                    {
                        Strings.Add(stringKey, ini.GetValue(section, key, ""));
                    }
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        protected override bool OnLoad(string iniFilePath)
        {
            int i;

            var ini = new INIFile(iniFilePath);

            // [Briefing] section
            BriefingNames = ini.GetValueArray <string>("Briefing", "Names");

            // [Theater] section
            DCSID               = ini.GetValue <string>("Theater", "DCSID");
            DefaultMapCenter    = ini.GetValue <Coordinates>("Theater", "DefaultMapCenter");
            MagneticDeclination = ini.GetValue <double>("Theater", "MagneticDeclination");

            // [Daytime] section
            DayTime = new MinMaxI[12];
            for (i = 0; i < 12; i++)
            {
                MinMaxI?dayTimeValue = ParseMinMaxTime(ini.GetValueArray <string>("Daytime", ((Month)i).ToString()));

                if (!dayTimeValue.HasValue) // Cast failed
                {
                    BriefingRoom.PrintToLog(
                        $"Wrong format for daytime value for month {(Month)i} in theater {ID}, using default value",
                        LogMessageErrorLevel.Warning);
                }

                DayTime[i] = dayTimeValue ?? DEFAULT_DAYTIME;
            }


            // Water Coordinates
            WaterCoordinates = new List <Coordinates>();
            foreach (string key in ini.GetKeysInSection("WaterCoordinates"))
            {
                WaterCoordinates.Add(ini.GetValue <Coordinates>("WaterCoordinates", key));
            }


            List <DBEntryTheaterSpawnPoint> spawnPointsList = new List <DBEntryTheaterSpawnPoint>();

            foreach (string key in ini.GetKeysInSection("SpawnPoints"))
            {
                DBEntryTheaterSpawnPoint sp = new DBEntryTheaterSpawnPoint();
                if (sp.Load(ini, key))
                {
                    spawnPointsList.Add(sp);
                }
            }
            SpawnPoints = spawnPointsList.ToArray();

            WaterExclusionCoordinates = new List <List <Coordinates> >();
            if (ini.GetSections().Contains("waterexclusioncoordinates"))
            {
                // Water Exclusion Coordinates
                var tempList = new List <Coordinates>();
                var groupID  = ini.GetKeysInSection("WaterExclusionCoordinates").First().Split(".")[0];
                foreach (string key in ini.GetKeysInSection("WaterExclusionCoordinates"))
                {
                    var newGroupId = key.Split(".")[0];
                    if (groupID != newGroupId)
                    {
                        groupID = newGroupId;
                        WaterExclusionCoordinates.Add(tempList);
                        tempList = new List <Coordinates>();
                    }
                    tempList.Add(ini.GetValue <Coordinates>("WaterExclusionCoordinates", key));
                }
                WaterExclusionCoordinates.Add(tempList);
            }

            // [Temperature] section
            Temperature = new MinMaxI[12];
            for (i = 0; i < 12; i++)
            {
                Temperature[i] = ini.GetValue <MinMaxI>("Temperature", ((Month)i).ToString());
            }

            return(true);
        }