Пример #1
0
 public static void SaveList(string filePath)
 {
     try
     {
         var data = new IniData();
         data.Sections.AddSection("Head");
         var count = 0;
         for (var i = 1; i <= MaxMagic; i++)
         {
             var item = MagicList[i];
             if (item != null && item.TheMagic != null)
             {
                 count++;
                 data.Sections.AddSection(i.ToString());
                 var section = data[i.ToString()];
                 section.AddKey("IniFile", item.TheMagic.FileName);
                 section.AddKey("Level", item.Level.ToString());
                 section.AddKey("Exp", item.Exp.ToString());
             }
         }
         data["Head"].AddKey("Count", count.ToString());
         //Write to file
         File.WriteAllText(filePath, data.ToString(), Globals.LocalEncoding);
     }
     catch (Exception exception)
     {
         Log.LogFileSaveError("Magic list", filePath, exception);
     }
 }
Пример #2
0
        private static Mod AttemptLoadVirtualMod(ArchiveFileInfo sfarEntry, SevenZipExtractor archive, Mod.MEGame game, string md5)
        {
            var sfarPath   = sfarEntry.FileName;
            var cookedPath = FilesystemInterposer.DirectoryGetParent(sfarPath, true);

            //Todo: Check if value is CookedPC/CookedPCConsole as further validation
            if (!string.IsNullOrEmpty(FilesystemInterposer.DirectoryGetParent(cookedPath, true)))
            {
                var dlcDir        = FilesystemInterposer.DirectoryGetParent(cookedPath, true);
                var dlcFolderName = Path.GetFileName(dlcDir);
                if (!string.IsNullOrEmpty(dlcFolderName))
                {
                    var thirdPartyInfo = ThirdPartyServices.GetThirdPartyModInfo(dlcFolderName, game);
                    if (thirdPartyInfo != null)
                    {
                        Log.Information($@"Third party mod found: {thirdPartyInfo.modname}, preparing virtual moddesc.ini");
                        //We will have to load a virtual moddesc. Since Mod constructor requires reading an ini, we will build and feed it a virtual one.
                        IniData virtualModDesc = new IniData();
                        virtualModDesc[@"ModManager"][@"cmmver"]     = App.HighestSupportedModDesc.ToString();
                        virtualModDesc[@"ModManager"][@"importedby"] = App.BuildNumber.ToString();
                        virtualModDesc[@"ModInfo"][@"game"]          = @"ME3";
                        virtualModDesc[@"ModInfo"][@"modname"]       = thirdPartyInfo.modname;
                        virtualModDesc[@"ModInfo"][@"moddev"]        = thirdPartyInfo.moddev;
                        virtualModDesc[@"ModInfo"][@"modsite"]       = thirdPartyInfo.modsite;
                        virtualModDesc[@"ModInfo"][@"moddesc"]       = thirdPartyInfo.moddesc;
                        virtualModDesc[@"ModInfo"][@"unofficial"]    = @"true";
                        if (int.TryParse(thirdPartyInfo.updatecode, out var updatecode) && updatecode > 0)
                        {
                            virtualModDesc[@"ModInfo"][@"updatecode"] = updatecode.ToString();
                            virtualModDesc[@"ModInfo"][@"modver"]     = 0.001.ToString(CultureInfo.InvariantCulture); //This will force mod to check for update after reload
                        }
                        else
                        {
                            virtualModDesc[@"ModInfo"][@"modver"] = 0.0.ToString(CultureInfo.InvariantCulture); //Will attempt to look up later after mods have parsed.
                        }

                        virtualModDesc[@"CUSTOMDLC"][@"sourcedirs"]        = dlcFolderName;
                        virtualModDesc[@"CUSTOMDLC"][@"destdirs"]          = dlcFolderName;
                        virtualModDesc[@"UPDATES"][@"originalarchivehash"] = md5;

                        var archiveSize    = new FileInfo(archive.FileName).Length;
                        var importingInfos = ThirdPartyServices.GetImportingInfosBySize(archiveSize);
                        if (importingInfos.Count == 1 && importingInfos[0].GetParsedRequiredDLC().Count > 0)
                        {
                            OnlineContent.QueryModRelay(importingInfos[0].md5, archiveSize); //Tell telemetry relay we are accessing the TPIS for an existing item so it can update latest for tracking
                            virtualModDesc[@"ModInfo"][@"requireddlc"] = importingInfos[0].requireddlc;
                        }

                        return(new Mod(virtualModDesc.ToString(), FilesystemInterposer.DirectoryGetParent(dlcDir, true), archive));
                    }
                }
                else
                {
                    Log.Information($@"No third party mod information for importing {dlcFolderName}. Should this be supported for import? Contact Mgamerz on the ME3Tweaks Discord if it should.");
                }
            }

            return(null);
        }
Пример #3
0
        public void Save(string filePath)
        {
            var data = new IniData();

            data.Sections.AddSection("Init");
            Save(data["Init"]);
            File.WriteAllText(filePath, data.ToString(), Globals.LocalEncoding);
        }
Пример #4
0
        public static void SavePlayer()
        {
            var data = new IniData();

            data.Sections.AddSection("Init");
            Globals.ThePlayer.Save(data["Init"]);
            File.WriteAllText(StorageBase.PlayerFilePath, data.ToString(), Globals.LocalEncoding);
        }
Пример #5
0
    public static void saveSettings()
    {
        var text = ini.ToString();
        var f    = new File();

        f.Open("user://input.ini", File.ModeFlags.Write);
        f.StoreString(text);
        f.Close();
    }
Пример #6
0
        /// <summary>
        /// Converts token and public key data to an INI string.
        /// </summary>
        /// <returns>INI string for writing to conf files.</returns>
        public string TokenToString()
        {
            var iniData = new IniData();

            iniData["Token"]["Token"]    = Token;
            iniData["Keys"]["PublicKey"] = PublicKey;

            return(iniData.ToString());
        }
Пример #7
0
        /// <summary>
        ///     Writes the ini data to a stream.
        /// </summary>
        /// <param Name="writer">A write stream where the ini data will be stored</param>
        /// <param Name="iniData">An <see cref="IniData"/> instance.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref Name="writer"/> is <c>null</c>.
        /// </exception>
        public void WriteData(StreamWriter writer, IniData iniData)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("reader");
            }

            writer.Write(iniData.ToString());
        }
Пример #8
0
        public bool PendingChanges()
        {
            var pendingChanges = !(origPkgConf == null && (pkgConf == null || pkgConf.Sections.Count == 0));

            if (pendingChanges)
            {
                pendingChanges = (origPkgConf == null && pkgConf != null) || (origPkgConf != null && (pkgConf == null || origPkgConf.ToString() != pkgConf.ToString()));
            }

            return(pendingChanges);
        }
Пример #9
0
        static void Main(string[] path)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Parallel.ForEach(Resource.Table.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries), item =>
            {
                RmDictionary.Add(item.Split(',')[0], item.Split(',')[1]);
            });

            if (!string.IsNullOrWhiteSpace(string.Join("", path)))
            {
                string ustFileStr = File.ReadAllText(string.Join("", path), EncodeJPN)
                                    .Replace(UstHeader, "");

                UstData = new FileIniDataParser().Parser.Parse(ustFileStr);

                UstData.Sections.RemoveSection("#PREV");
                UstData.Sections.RemoveSection("#NEXT");
                UstData.Sections.RemoveSection("#SETTING");

                //foreach (var itemSection in UstData.Sections)
                Parallel.ForEach(UstData.Sections, itemSection =>
                {
                    if (itemSection.Keys["Lyric"] == "R")
                    {
                        return;
                    }
                    try
                    {
                        if (itemSection.Keys["Lyric"].Contains(" "))
                        {
                            itemSection.Keys["Lyric"] = itemSection.Keys["Lyric"].Trim().Split(' ')[0] + " " +
                                                        RmDictionary[
                                itemSection.Keys["Lyric"].Trim().Split(' ')[1]];
                        }
                        else
                        {
                            itemSection.Keys["Lyric"] = RmDictionary[itemSection.Keys["Lyric"].Trim()];
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                });

                File.WriteAllText(string.Join("", path),
                                  UstHeader + UstData.ToString().Replace(" = ", "=").Replace("\r\n\r\n", "\r\n"), EncodeJPN);
            }
            else
            {
                Console.WriteLine(@"未包含应有的参数,请作为UTAU插件使用");
                Console.ReadKey();
            }
        }
Пример #10
0
        private static void SaveGameFile()
        {
            var data = new IniData();

            //State
            data.Sections.AddSection("State");
            var state = data["State"];

            state.AddKey("Map", Globals.TheMap.MapFileNameWithoutExtension + ".map");
            state.AddKey("Npc", NpcManager.FileName);
            state.AddKey("Obj", ObjManager.FileName);
            state.AddKey("Bgm", BackgroundMusic.FileName);
            state.AddKey("Chr", Globals.PlayerIndex.ToString());
            state.AddKey("Time", string.Format(
                             "{0:yyyy} 年{0:MM} 月{0:dd} 日 {0:HH} 时{0:mm} 分{0:ss} 秒",
                             DateTime.Now));

            //Save npc obj
            NpcManager.SaveNpc();
            ObjManager.Save();

            //Option
            data.Sections.AddSection("Option");
            var option = data["Option"];

            option.AddKey("MapTime", Map.MapTime.ToString());
            option.AddKey("SnowShow", (WeatherManager.IsSnowing ? 1 : 0).ToString());
            option.AddKey("RainFile", WeatherManager.IsRaining ? WeatherManager.RainFileName : "");
            option.AddKey("Water", Globals.IsWaterEffectEnabled ? "1" : "0");
            option.AddKey("MpcStyle", StorageBase.GetStringFromColor(Map.DrawColor));
            option.AddKey("AsfStyle", StorageBase.GetStringFromColor(Sprite.DrawColor));

            //Timer
            data.Sections.AddSection("Timer");
            var timer = data["Timer"];

            timer.AddKey("IsOn", GuiManager.IsTimerStarted() ? "1" : "0");
            if (GuiManager.IsTimerStarted())
            {
                timer.AddKey("TotalSecond", GuiManager.GetTimerCurrentSeconds().ToString());
                timer.AddKey("IsTimerWindowShow", GuiManager.IsTimerWindowHided() ? "0" : "1");
                timer.AddKey("IsScriptSet", ScriptExecuter.IsTimeScriptSet ? "1" : "0");
                timer.AddKey("TimerScript", ScriptExecuter.TimeScriptFileName);
                timer.AddKey("TriggerTime", ScriptExecuter.TimeScriptSeconds.ToString());
            }

            //Variables
            data.Sections.AddSection("Var");
            ScriptExecuter.SaveVariables(data["Var"]);

            //Wirte to file
            File.WriteAllText(StorageBase.GameIniFilePath, data.ToString(), Globals.LocalEncoding);
        }
Пример #11
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            IniData redConfigNew = new IniData();
            int     disableCount = 0;

            //datagrid to ini
            foreach (DataGridViewRow row in dataGridViewMain.Rows)
            {
                REDEngineFeature featureDef = ((BindingList <REDEngineFeature>)dataGridViewMain.DataSource)[row.Index];

                var kd = new KeyData(featureDef.FunctionName);
                kd.Value = featureDef.Enabled.ToString();

                if (featureDef.Enabled == false)
                {
                    disableCount++;
                }

                if (featureDef.Description != "")
                {
                    kd.Comments.Add(featureDef.Description);
                }

                if (featureDef.GroupName.Contains("Developer"))
                {
                    redConfigNew.Sections.AddSection(featureDef.GroupName);
                    redConfigNew[featureDef.GroupName].AddKey(kd);
                }

                if (featureDef.GroupName.Contains("Rendering"))
                {
                    redConfigNew.Sections.AddSection(featureDef.GroupName);
                    redConfigNew[featureDef.GroupName].AddKey(kd);
                }

                if (featureDef.GroupName.Contains("RayTracing"))
                {
                    redConfig.Sections.AddSection(featureDef.GroupName);
                    redConfig[featureDef.GroupName].AddKey(kd);
                }
            }

            //when everything is enabled, just clear the user.ini
            if (disableCount >= 1)
            {
                File.WriteAllText(path, redConfigNew.ToString());
            }
            else
            {
                File.Delete(path);
            }
        }
Пример #12
0
        public void WritingTotring_Test()
        {
            IniData data = new IniData();

            data.Sections.AddSection("newSection1");
            data.Sections["newSection1"].AddKey("newKey1", "newValue1");
            data.Sections["newSection1"].AddKey("newKey2", "newValue5");

            string result = data.ToString();

            Assert.That(result, Is.Not.Empty);
            Assert.That(result.Length, Is.Not.EqualTo(0));
        }
Пример #13
0
        /// <summary>
        /// Converts settings data to an INI string.
        /// </summary>
        /// <returns>INI string for writing to conf files.</returns>
        public override string ToString()
        {
            var iniData = new IniData();

            InputSettingsConfig(iniData, "FxA", "BaseURL", FxA.BaseURL);
            InputSettingsConfig(iniData, "FxA", "Token", FxA.Token);
            InputSettingsConfig(iniData, "FxA", "PublicKey", FxA.PublicKey);
            InputSettingsConfig(iniData, "Language", "PreferredLanguage", Language.PreferredLanguage);
            InputSettingsConfig(iniData, "Network", "UnsecureNetworkAlert", Network.UnsecureNetworkAlert.ToString());
            InputSettingsConfig(iniData, "Network", "AllowLocalDeviceAccess", Network.AllowLocalDeviceAccess.ToString());

            return(iniData.ToString());
        }
        public void ReflectionConfigGenerator_GenerateConfigFile_GenerateTest()
        {
            var file = generator.GenerateConfigFile(new ReflectionConfigGenerator.GeneratorConfig()
            {
                Type = typeof(ConfigTest)
            });
            var data = new IniData();

            file.PushTo(data);
            Console.WriteLine(data.ToString());
            Assert.AreEqual(1, file["GLOBAL"]["Test2"].Value);
            Assert.AreEqual("yes2", file["Internal"]["Test3"].Value);
        }
Пример #15
0
        private static void Save(string fileName = null, bool isSaveParter = false)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                if (isSaveParter || string.IsNullOrEmpty(_fileName))
                {
                    //Can't save without file name.
                    return;
                }
                fileName = _fileName;
            }
            if (!isSaveParter)
            {
                _fileName = fileName;
            }
            var path = @"save\game\" + fileName;

            try
            {
                var count = 0;
                var data  = new IniData();
                data.Sections.AddSection("Head");
                if (!isSaveParter)
                {
                    data["Head"].AddKey("Map",
                                        MapBase.MapFileName);
                }

                var index = 0;
                foreach (var npc in _list)
                {
                    if ((isSaveParter && !npc.IsPartner) ||
                        (!isSaveParter && npc.IsPartner) ||
                        npc.SummonedByMagicSprite != null)
                    {
                        continue;
                    }
                    var sectionName = "NPC" + string.Format("{0:000}", index++);
                    data.Sections.AddSection(sectionName);
                    npc.Save(data[sectionName]);
                    count++;
                }
                data["Head"].AddKey("Count", count.ToString());
                File.WriteAllText(path, data.ToString(), Globals.LocalEncoding);
            }
            catch (Exception exception)
            {
                Log.LogFileSaveError("Npc", path, exception);
            }
        }
Пример #16
0
        public static void Initialize()
        {
            var data = new IniData();

            data["App"]["LastUpdateCheck"]     = DateTime.Now.ToString(CultureInfo.CurrentCulture);
            data["App"]["CloseMinimizeToTray"] = true.ToString();
            data["App"]["SelectedPhpVersion"]  = "php-7.3-ts";
            data["App"]["DocumentRoot"]        = DefaultDocumentRoot;
            data["App"]["DefaultPortHttp"]     = "80";
            data["App"]["DefaultPortHttps"]    = "443";
            data["App"]["VhostExtension"]      = ".test";

            File.WriteAllText(References.AppConfigFile, data.ToString());
        }
Пример #17
0
    private WorldEntry generateBinWorld(string world_dir)
    {
        byte[]         icon_bin;
        KnyttWorldInfo world_info;

        string cache_dir        = "user://Cache/" + GDKnyttAssetManager.extractFilename(world_dir);
        string icon_cache_name  = cache_dir + "/Icon.png";
        string ini_cache_name   = cache_dir + "/World.ini";
        string played_flag_name = cache_dir + "/LastPlayed.flag";

        if (new Directory().DirExists(cache_dir))
        {
            icon_bin   = GDKnyttAssetManager.loadFile(icon_cache_name);
            world_info = getWorldInfo(GDKnyttAssetManager.loadFile(ini_cache_name));
        }
        else
        {
            KnyttBinWorldLoader binloader;
            byte[] ini_bin;
            try
            {
                binloader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world_dir));
            }
            catch (InvalidOperationException)
            {
                return(null);
            }
            icon_bin = binloader.GetFile("Icon.png");
            ini_bin  = binloader.GetFile("World.ini");

            GDKnyttAssetManager.ensureDirExists("user://Cache");
            new Directory().MakeDir(cache_dir);
            var f = new File();
            f.Open(icon_cache_name, File.ModeFlags.Write);
            f.StoreBuffer(icon_bin);
            f.Close();

            var ini_data = new IniData();
            world_info = getWorldInfo(ini_bin, merge_to: ini_data["World"]);
            f.Open(ini_cache_name, File.ModeFlags.Write);
            f.StoreString(ini_data.ToString());
            f.Close();
        }

        Texture icon        = GDKnyttAssetManager.loadTexture(icon_bin);
        var     last_played = new File().FileExists(played_flag_name) ? new File().GetModifiedTime(played_flag_name) : 0;

        return(new WorldEntry(icon, world_info, world_dir, last_played));
    }
Пример #18
0
        static void Main(string[] path)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            if (!string.IsNullOrWhiteSpace(string.Join("", path)))
            {
                string ustFileStr = File.ReadAllText(string.Join("", path))
                                    .Replace(UstHeader, "");

                UstData = new FileIniDataParser().Parser.Parse(ustFileStr);

                UstData.Sections.RemoveSection("#PREV");
                UstData.Sections.RemoveSection("#NEXT");
                UstData.Sections.RemoveSection("#SETTING");

                //foreach (var itemSection in UstData.Sections)
                Parallel.ForEach(UstData.Sections, itemSection =>
                {
                    if (itemSection.Keys["Lyric"] == "R")
                    {
                        return;
                    }
                    try
                    {
                        if (itemSection.Keys["Lyric"].Contains(" "))
                        {
                            itemSection.Keys["Lyric"] = itemSection.Keys["Lyric"].Trim().Split(' ')[0] + " " +
                                                        KanaConverter.RomajiToHiragana(itemSection.Keys["Lyric"].Trim()
                                                                                       .Split(' ')[1]);
                        }
                        else
                        {
                            itemSection.Keys["Lyric"] = KanaConverter.RomajiToHiragana(itemSection.Keys["Lyric"]);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                });

                File.WriteAllText(string.Join("", path),
                                  UstHeader + UstData.ToString().Replace(" = ", "=").Replace("\r\n\r\n", "\r\n"), EncodeJPN);
            }
            else
            {
                Console.WriteLine("未包含应有的参数,请作为UTAU插件使用");
                Console.ReadKey();
            }
        }
Пример #19
0
        public bool PendingChanges()
        {
            var pendingChanges = !(origPortConfig == null && (portConfig == null || (synoConfig == null || synoConfig.Sections.Count == 0)));

            if (pendingChanges)
            {
                pendingChanges = (origPortConfig == null && portConfig != null) || (origPortConfig != null && (portConfig == null || origPortConfig.ToString() != portConfig.ToString()));

                if (!pendingChanges)
                {
                    pendingChanges = (origSynoConfig == null && synoConfig != null) || (origSynoConfig != null && (synoConfig == null || origSynoConfig.ToString() != synoConfig.ToString()));
                }
            }

            return(pendingChanges);
        }
Пример #20
0
        /// <summary>
        ///     Writes the ini data to a stream.
        /// </summary>
        /// <param name="writer">A write stream where the ini data will be stored</param>
        /// <param name="iniData">An <see cref="IniData" /> instance.</param>
        /// <param name="formatter">Formaterr instance that controls how the ini data is transformed to a string</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="writer" /> is <c>null</c>.
        /// </exception>
        public void WriteData(StreamWriter writer, IniData iniData, IIniDataFormatter formatter)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }
            if (iniData == null)
            {
                throw new ArgumentNullException("iniData");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.Write(iniData.ToString(formatter));
        }
Пример #21
0
        public static void Main()
        {
            //Create an instance of a ini file parser
            FileIniDataParser fileIniData = new FileIniDataParser();

            if (File.Exists("NewTestIniFile.ini"))
            {
                File.Delete("NewTestIniFile.ini");
            }

            // This is a special ini file where we use the '#' character for comment lines
            // so we need to change the configuration of the parser
            fileIniData.Parser.Configuration.CommentChar = '#';


            //Parse the ini file
            IniData parsedData = fileIniData.ReadFile("TestIniFile.ini");

            //Write down the contents of the ini file to the console
            Console.WriteLine("---- Printing contents of the INI file ----\n");
            Console.WriteLine(parsedData.ToString());
            Console.WriteLine();

            //Get concrete data from the ini file
            Console.WriteLine("---- Printing setMaxErrors value from GeneralConfiguration section ----");
            Console.WriteLine("setMaxErrors = " + parsedData["GeneralConfiguration"]["setMaxErrors"]);
            Console.WriteLine();

            //Modify the INI contents and save
            Console.WriteLine();

            // Modify the loaded ini file
            IniData modifiedParsedData = ModifyINIData(parsedData);

            //Write down the contents of the modified ini file to the console
            Console.WriteLine("---- Printing contents of the new INI file ----");
            Console.WriteLine(modifiedParsedData.ToString());
            Console.WriteLine();

            //Save to a file
            Console.WriteLine("---- Saving the new ini file to the file NewTestIniFile.ini ----");
            Console.WriteLine();

            fileIniData.WriteFile("NewTestIniFile.ini", modifiedParsedData);
        }
Пример #22
0
        /// <summary>
        /// Converts settings data to an INI string.
        /// </summary>
        /// <returns>INI string for writing to conf files.</returns>
        public override string ToString()
        {
            var iniData = new IniData();

            InputSettingsConfig(iniData, "FxA", "BaseURL", FxA.BaseURL);
            InputSettingsConfig(iniData, "FxA", "Token", FxA.Token);
            InputSettingsConfig(iniData, "FxA", "PublicKey", FxA.PublicKey);
            InputSettingsConfig(iniData, "Language", "PreferredLanguage", Language.PreferredLanguage);
            InputSettingsConfig(iniData, "Network", "UnsecureNetworkAlert", Network.UnsecureNetworkAlert.ToString());
            InputSettingsConfig(iniData, "Network", "CaptivePortalAlert", Network.CaptivePortalAlert.ToString());
            InputSettingsConfig(iniData, "Network", "CaptivePortalDetectionIp", Network.CaptivePortalDetectionIp.ToString());
            InputSettingsConfig(iniData, "Network", "AllowLocalDeviceAccess", Network.AllowLocalDeviceAccess.ToString());
            InputSettingsConfig(iniData, "Network", "EnableIPv6", Network.EnableIPv6.ToString());
            InputSettingsConfig(iniData, "Network", "IPv4Address", Network.IPv4Address);
            InputSettingsConfig(iniData, "Network", "IPv6Address", Network.IPv6Address);

            return(iniData.ToString());
        }
Пример #23
0
    // Save the configuration in memory to disk
    public void Save()
    {
        string optionsFile = Game.AppData() + "/config.ini";
        string content     = data.ToString();

        try
        {
            if (!Directory.Exists(Game.AppData()))
            {
                Directory.CreateDirectory(Game.AppData());
            }
            File.WriteAllText(optionsFile, content);
        }
        catch (System.Exception)
        {
            ValkyrieDebug.Log("Warning: Unable to write to config file: " + optionsFile + System.Environment.NewLine);
        }
    }
Пример #24
0
    // Save the configuration in memory to disk
    public void Save()
    {
        string optionsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/Valkyrie/config.ini";
        string content     = data.ToString();

        try
        {
            if (!Directory.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/Valkyrie"))
            {
                Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/Valkyrie");
            }
            File.WriteAllText(optionsFile, content);
        }
        catch (System.Exception)
        {
            ValkyrieDebug.Log("Warning: Unable to write to config file: " + optionsFile + System.Environment.NewLine);
        }
    }
Пример #25
0
        static void FixInis()
        {
            WriteLine($"Fixing Inis");

            IniDataParser parser = new IniDataParser();

            data.IniFixes.GroupBy(dr => dr.File).ToList().ForEach(dr =>
            {
                if (File.Exists(dr.Key))
                {
                    IniData config = parser.Parse(File.ReadAllText(dr.Key));
                    foreach (IniFix fix in dr)
                    {
                        config[fix.Section][fix.Key] = fix.Value;
                    }
                    File.WriteAllText(dr.Key, config.ToString());
                }
            });
        }
Пример #26
0
        public void SaveTrapIndexIgnoreList(string filePath)
        {
            try
            {
                var data = new IniData();
                data.Sections.AddSection("Init");
                var section = data["Init"];
                var count   = _ingnoredTrapsIndex.Count;
                for (var i = 0; i < count; i++)
                {
                    section.AddKey(i.ToString(), _ingnoredTrapsIndex[i].ToString());
                }

                File.WriteAllText(filePath, data.ToString(), Globals.LocalEncoding);
            }
            catch (Exception exception)
            {
                Log.LogFileSaveError("Trap index ignore list", filePath, exception);
            }
        }
Пример #27
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());
        }
Пример #28
0
        public static void Save(string fileName = null)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                if (string.IsNullOrEmpty(_fileName))
                {
                    //Can't save without file name.
                    return;
                }
                fileName = _fileName;
            }
            _fileName = fileName;
            var path = @"save\game\" + fileName;

            try
            {
                var count = _list.Count;
                var data  = new IniData();
                data.Sections.AddSection("Head");
                data["Head"].AddKey("Map",
                                    Globals.TheMap.MapFileNameWithoutExtension + ".map");
                data["Head"].AddKey("Count", count.ToString());

                var node = _list.First;
                for (var i = 0; i < count; i++, node = node.Next)
                {
                    var sectionName = "OBJ" + string.Format("{0:000}", i);
                    data.Sections.AddSection(sectionName);
                    var obj = node.Value;
                    obj.Save(data[sectionName]);
                }
                File.WriteAllText(path, data.ToString(), Globals.LocalEncoding);
            }
            catch (Exception exception)
            {
                Log.LogFileSaveError("Obj", path, exception);
            }
        }
Пример #29
0
 public static void SaveList(string filePath)
 {
     try
     {
         var data = new IniData();
         data.Sections.AddSection("Memo");
         var memoSection = data["Memo"];
         var count       = MemoList.Count;
         memoSection.AddKey("Count", count.ToString());
         var i = 0;
         foreach (var memo in MemoList)
         {
             memoSection.AddKey(i.ToString(), memo);
             i++;
         }
         //Write to file
         File.WriteAllText(filePath, data.ToString(), Globals.LocalEncoding);
     }
     catch (Exception exception)
     {
         Log.LogFileSaveError("Memo file", filePath, exception);
     }
 }
Пример #30
0
    public void SetQuestAvailability(string key, bool isAvailable)
    {
        // update list of local quest
        IniData localManifest = IniRead.ReadFromString("");
        string  saveLocation  = ContentData.DownloadPath();

        if (File.Exists(saveLocation + "/manifest.ini"))
        {
            localManifest = IniRead.ReadFromIni(saveLocation + "/manifest.ini");
        }

        if (isAvailable)
        {
            IniData downloaded_quest = IniRead.ReadFromString(remote_quests_data[key].ToString());
            localManifest.Remove(key);
            localManifest.Add(key, downloaded_quest.data["Quest"]);
        }
        else
        {
            if (localManifest.Get(key) != null)
            {
                localManifest.Remove(key);
            }
            // we need to delete /temp and reload list
            UnloadLocalQuests();
        }

        if (File.Exists(saveLocation + "/manifest.ini"))
        {
            File.Delete(saveLocation + "/manifest.ini");
        }
        File.WriteAllText(saveLocation + "/manifest.ini", localManifest.ToString());

        // update status quest
        remote_quests_data[key].downloaded       = isAvailable;
        remote_quests_data[key].update_available = false;
    }