Exemple #1
0
        public static GameInfo Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            GameInfo result = IniSerializer.Deserialize <GameInfo>(ini);

            if (result.MappingsVersion == EngineVersion.Invalid)
            {
                result.MappingsVersion = result.EngineVersion;
            }
            if (result.DPLCVersion == EngineVersion.Invalid)
            {
                result.DPLCVersion = result.MappingsVersion;
            }
            if (result.GameName == null)
            {
                result.GameName = result.EngineVersion.ToString();
            }
            return(result);
        }
        private void CreateDefaultObjDefs()
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter           = "Object Definition Files (*.ini)|*.ini";
            dialog.InitialDirectory = modFolder;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Dictionary <string, ObjectData> tempObjDefs = new Dictionary <string, ObjectData>();
                tempObjDefs.Add("0", new ObjectData());
                foreach (ObjectListEntry obj in objList)
                {
                    if (!tempObjDefs.ContainsKey(obj.Name))
                    {
                        ObjectData objData = new ObjectData();
                        objData.Name    = obj.Name;
                        objData.RotType = "XYZ";
                        objData.SclType = "None";
                        if (!tempObjDefs.ContainsKey(obj.Name))
                        {
                            tempObjDefs.Add(obj.Name, objData);
                        }
                    }
                }

                IniSerializer.Serialize(tempObjDefs, dialog.FileName);
                objDefString   = dialog.FileName;
                objDefinitions = tempObjDefs;
            }
            else
            {
                this.Close();
            }
        }
        //public ObjListEditor()
        public ObjListEditor(string objlistpath, string objdefspath, string folder, IniDataSALVL lvlconfig)
        {
            InitializeComponent();
            salvl         = lvlconfig;
            modFolder     = folder;
            objListString = Path.Combine(folder, objlistpath);
            isSA2         = salvl.IsSA2;
            saved         = true;
            if (File.Exists(objListString))
            {
                ObjectListEntry[] objListArr = ObjectList.Load(objListString, isSA2);
                objList = new List <ObjectListEntry>(objListArr);
            }

            if (objdefspath == "" || !File.Exists(Path.Combine(folder, objdefspath)))
            {
                DialogResult error = MessageBox.Show(("Level Object Definitions not found. Please select a location to save the Definitions file."), "Definitions Not Located", MessageBoxButtons.OK);
                if (error == DialogResult.OK)
                {
                    CreateDefaultObjDefs();
                }
            }
            else
            {
                objDefString = Path.Combine(folder, objdefspath);
                if (File.Exists(objDefString))
                {
                    objDefinitions = IniSerializer.Deserialize <Dictionary <string, ObjectData> >(objDefString);
                }
            }
        }
        public void Should_serialize_complex_object()
        {
            var value = new ComplexClass
            {
                Class = new MyClass
                {
                    Int    = 1,
                    String = "x",
                },
                Dict = new Dictionary <string, MyClass>
                {
                    ["a"] = new MyClass
                    {
                        Int    = 2,
                        String = "y",
                    },
                    ["b"] = null,
                },
                Int = 123,
            };
            var res = IniSerializer.Serialize(value);

            Split(res).Should().BeEquivalentTo(
                $"Class.Int = {value.Class.Int}",
                $"Class.String = {value.Class.String}",
                $"Dict.a.Int = {value.Dict["a"].Int}",
                $"Dict.a.String = {value.Dict["a"].String}",
                $"Dict.b = {value.Dict["b"]}",
                $"Int = {value.Int}");
        }
Exemple #5
0
        /// <summary>
        /// Create a PAK archive from a folder produced by ArchiveTool or PAKTool.
        /// </summary>
        static void BuildPAK(string filePath)
        {
            Console.WriteLine("Building PAK from folder: {0}", Path.GetFullPath(filePath));
            outputPath = Path.Combine(Environment.CurrentDirectory, filePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(outputPath);
            string inipath = Path.Combine(Path.GetFileNameWithoutExtension(outputPath), Path.GetFileNameWithoutExtension(outputPath) + ".ini");

            if (!File.Exists(inipath))
            {
                Console.WriteLine("PAK INI file not found: {0}", inipath);
                Console.WriteLine("The folder must contain either index.txt or an INI file to be recognized as a buildable archive folder.");
                Console.WriteLine("Press ENTER to exit.");
                Console.ReadLine();
                return;
            }
            PAKFile.PAKIniData list = IniSerializer.Deserialize <PAKFile.PAKIniData>(inipath);
            PAKFile            pak  = new PAKFile()
            {
                FolderName = list.FolderName
            };

            foreach (KeyValuePair <string, PAKFile.PAKIniItem> item in list.Items)
            {
                Console.WriteLine("Adding file: {0}", item.Key);
                pak.Entries.Add(new PAKFile.PAKEntry(item.Key, item.Value.LongPath, File.ReadAllBytes(Path.Combine(Path.GetFileNameWithoutExtension(outputPath), item.Key))));
            }
            Console.WriteLine("Output file: {0}", Path.ChangeExtension(outputPath, "pak"));
            pak.Save(Path.ChangeExtension(outputPath, "pak"));
            Console.WriteLine("Done!");
        }
 public When_the_object_is_serialized()
 {
     _serializedOutput
         = IniSerializer
           .Serialize(new ObjectToSerialize("Test Section Heading"))
           .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
Exemple #7
0
            public BankBank(byte[] file, int address, string dir)
            {
                header   = System.Text.Encoding.ASCII.GetString(file, address, 4);
                version  = BitConverter.ToInt32(file, address + 4);
                filesize = BitConverter.ToUInt32(file, address + 8);
                int programs_ptr = BitConverter.ToInt32(file, address + 0x10);

                program_count = BitConverter.ToInt32(file, address + 0x14);
                int curves_ptr = BitConverter.ToInt32(file, address + 0x18);

                curve_count = BitConverter.ToInt32(file, address + 0x1C);
                ptrs1       = BitConverter.ToInt32(file, address + 0x20);
                ptrs1_count = BitConverter.ToInt32(file, address + 0x24);
                ptrs2       = BitConverter.ToInt32(file, address + 0x28);
                ptrs2_count = BitConverter.ToInt32(file, address + 0x2C);
                Console.WriteLine("{0} v.{1}, size {2}, prg at {3}, prgs: {4}, cur at {5}, curs: {6}, p1 at {7}, p1s: {8}, p2 at {9}, p2s: {10}", header, version, filesize, programs_ptr.ToString("X"), program_count, curves_ptr.ToString("X"), curve_count, ptrs1.ToString("X"), ptrs1_count, ptrs2.ToString("X"), ptrs2_count);
                curves = new List <BankVelocityCurve>();
                for (int c = 0; c < curve_count; c++)
                {
                    BankVelocityCurve curve = new BankVelocityCurve(file, curves_ptr + 128 * c, c);
                    curves.Add(curve);
                    IniSerializer.Serialize(curve, Path.Combine(dir, "CURVE" + c.ToString("D2") + ".ini"));
                }
                programs = new List <BankProgram>();
                for (int i = 0; i < program_count; i++)
                {
                    programs.Add(new BankProgram(file, programs_ptr + 4 * i, i, dir));
                }
            }
Exemple #8
0
        static void Main(string[] args)
        {
            Queue <string> argq = new Queue <string>(args);
            string         inifilename;

            if (argq.Count > 0)
            {
                inifilename = argq.Dequeue();
                Console.WriteLine("INI File: {0}", inifilename);
            }
            else
            {
                Console.Write("INI File: ");
                inifilename = Console.ReadLine();
            }
            Dictionary <int, string> modelnames = IniSerializer.Deserialize <Dictionary <int, string> >(inifilename, inisettings);
            string mdlfilename;

            if (argq.Count > 0)
            {
                mdlfilename = argq.Dequeue();
                Console.WriteLine("Model File: {0}", mdlfilename);
            }
            else
            {
                Console.Write("Model File: ");
                mdlfilename = Console.ReadLine();
            }
            ModelFile model = new ModelFile(mdlfilename);

            NJS_OBJECT[] objects = model.Model.GetObjects();
            string       repmdlfilename;

            if (argq.Count > 0)
            {
                repmdlfilename = argq.Dequeue();
                Console.WriteLine("Replacement Model File: {0}", repmdlfilename);
            }
            else
            {
                Console.Write("Replacement Model File: ");
                repmdlfilename = Console.ReadLine();
            }
            ModelFile repmodel = new ModelFile(repmdlfilename);

            NJS_OBJECT[] repobjects = repmodel.Model.GetObjects();
            if (objects.Length != repobjects.Length)
            {
                Console.WriteLine("Models have different structures, the game may crash.");
            }
            foreach (KeyValuePair <int, string> item in modelnames.ToList())
            {
                if (objects.Any((obj) => obj.Name == item.Value))
                {
                    modelnames[item.Key] = repobjects[Array.IndexOf(objects, objects.Single((o) => o.Name == item.Value))].Name;
                }
            }
            ModelFile.CreateFile(mdlfilename, repmodel.Model, null, null, repmodel.Author, repmodel.Description, "replaceMDL", repmodel.Metadata, repmodel.Format);
            IniSerializer.Serialize(modelnames, inisettings, inifilename);
        }
Exemple #9
0
        private void ExportFolder(string dir)
        {
            Directory.CreateDirectory(dir);
            string fname = Path.GetFileName(dir);

            IniSerializer.Serialize(meta, Path.Combine(dir, fname + ".ini"));
            meta.Icon.Save(Path.Combine(dir, fname + ".bmp"));
            if (meta.TextureData != null && meta.TextureData.Length > 0)
            {
                File.WriteAllBytes(Path.Combine(dir, fname + ".pvm"), meta.TextureData);
            }
            if (meta.SoundData != null && meta.SoundData.Length > 0)
            {
                File.WriteAllBytes(Path.Combine(dir, fname + ".mlt"), meta.SoundData);
            }
            if (meta.ModelData != null && meta.ModelData.Length > 0)
            {
                byte[]     prsdata      = FraGag.Compression.Prs.Decompress(meta.ModelData);
                uint       modelpointer = BitConverter.ToUInt32(prsdata, 0) - 0xCCA4000;
                NJS_OBJECT mdl          = new NJS_OBJECT(prsdata, (int)modelpointer, 0xCCA4000, ModelFormat.Basic, null);
                ModelFile.CreateFile(Path.Combine(dir, fname + ".sa1mdl"), mdl, null, null, null, null, ModelFormat.Basic);
                if (exportBinaryDataToolStripMenuItem.Checked)
                {
                    File.WriteAllBytes(Path.Combine(dir, fname + ".prs"), meta.ModelData);
                    File.WriteAllBytes(Path.Combine(dir, fname + ".bin"), prsdata);
                }
            }
        }
        public void GivenASerializerWithDefaultConstructorThenDefaultsAreUsed()
        {
            var serializer = new IniSerializer();

            Assert.Same(IniSerializationOptions.Default, serializer.Options);
            Assert.Same(IniNormalizer.Default, serializer.Normalizer);
        }
Exemple #11
0
        public static Settings Load()
        {
            filename = Path.Combine(Application.StartupPath, "SonLVL.ini");
            if (File.Exists(filename))
            {
                Settings result = IniSerializer.Deserialize <Settings>(filename);
                switch (result.CurrentTab)
                {
                case Tab.Chunks:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Chunks;
                    break;

                case Tab.Blocks:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Blocks;
                    break;

                case Tab.Tiles:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Tiles;
                    break;

                case Tab.Solids:
                    result.CurrentTab    = Tab.Art;
                    result.CurrentArtTab = ArtTab.Solids;
                    break;
                }
                return(result);
            }
            else
            {
                Settings result = new Settings();
                // Import old style settings
                // Any new settings should not be added to the old settings class, and should have defaults applied here.
                Properties.Settings oldset = Properties.Settings.Default;
                result.ShowHUD  = oldset.ShowHUD;
                result.Emulator = oldset.Emulator;
                result.MRUList  = new List <string>();
                if (oldset.MRUList != null)
                {
                    foreach (string item in oldset.MRUList)
                    {
                        if (!string.IsNullOrEmpty(item))
                        {
                            result.MRUList.Add(item);
                        }
                    }
                }
                result.ShowGrid  = oldset.ShowGrid;
                result.GridColor = oldset.GridColor;
                result.Username  = oldset.Username;
                result.IncludeObjectsInForegroundSelection = oldset.IncludeObjectsInForegroundSelection;
                result.TransparentBackFGBGExport           = true;
                result.ViewLowPlane = result.ViewHighPlane = true;
                result.ZoomLevel    = "1x";
                result.ShowMenu     = true;
                return(result);
            }
        }
        /// <summary>
        /// Sets the path for a specified game in GamePaths.ini.
        /// </summary>
        public static void SetGamePath(string gameName, string gamePath)
        {
            Dictionary <string, string> gamePathsList;
            string appdata           = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SA Tools");
            string gamePathsFilePath = Path.Combine(appdata, "GamePaths.ini");

            if (File.Exists(gamePathsFilePath))
            {
                gamePathsList = IniSerializer.Deserialize <Dictionary <string, string> >(gamePathsFilePath);
            }
            else
            {
                if (!Directory.Exists(appdata))
                {
                    Directory.CreateDirectory(appdata);
                }
                gamePathsList = new Dictionary <string, string>();
            }
            if (gamePathsList.ContainsKey(gameName))
            {
                gamePathsList[gameName] = gamePath;
            }
            else
            {
                gamePathsList.Add(gameName, gamePath);
            }
            IniSerializer.Serialize(gamePathsList, gamePathsFilePath);
        }
Exemple #13
0
        private void PopulateListBox()
        {
            listBox1.BeginUpdate();
            listBox1.Items.Clear();
            string objListPath = Path.Combine(folder, levels[keyList[lstLevelSelect.SelectedIndex]].ObjectList);
            string objDefPath  = Path.Combine(folder, levels[keyList[lstLevelSelect.SelectedIndex]].ObjectDefinition);

            objList = new List <ObjectListEntry>(ObjectList.Load(objListPath, salvl.IsSA2));
            objDefs = IniSerializer.Deserialize <Dictionary <string, ObjectData> >(objDefPath);

            foreach (ObjectListEntry obj in objList)
            {
                string key = obj.Name;
                string val;

                if (objDefs[obj.Name].Name != null)
                {
                    val = objDefs[obj.Name].Name;
                }
                else
                {
                    val = obj.Name;
                }

                KeyValuePair <string, string> entry = new KeyValuePair <string, string>(key, val);
                listBox1.Items.Add(entry);
                listBox1.DisplayMember = "Value";
            }
            listBox1.EndUpdate();
        }
Exemple #14
0
        /// <summary>
        /// Attempts to load settings from ConfigFile.
        /// </summary>
        /// <returns>DialogResult.OK on success, DialogResult.Ignore if the file doesn't exist,
        /// and whatever is returned by the input from MessageBox if an error occurs.</returns>
        public static DialogResult LoadSettings()
        {
            DialogResult result;

            do
            {
                try
                {
                    if (File.Exists(Config))
                    {
                        Settings = IniSerializer.Deserialize <ProgramSettings>(Config);
                        result   = DialogResult.OK;
                    }
                    else
                    {
                        Settings.Filters.AddRange(DefaultFilters);
                        result = DialogResult.Ignore;
                    }
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show("Too Lazy to Read was unable to load your settings?!\n\n"
                                             + ex.Message,
                                             "Error loading configuration", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                }
            } while (result == DialogResult.Retry);

            return(result);
        }
Exemple #15
0
        public void GivenASerializerWithDefaultConstructorWhenSerializingAsStringThenMinimizedResultAreCreated()
        {
            var serializer = new IniSerializer();
            var result     = serializer.SerializeAsString(ContainerToSerialize);

            Assert.Equal(ContainerSerializedAndMinimized, result);
        }
Exemple #16
0
        private void Save()
        {
            loaderini.Mods.Clear();

            foreach (ListViewItem item in modListView.CheckedItems)
            {
                loaderini.Mods.Add((string)item.Tag);
            }

            loaderini.UpdateCheck     = checkUpdateStartup.Checked;
            loaderini.ModUpdateCheck  = checkUpdateModsStartup.Checked;
            loaderini.UpdateUnit      = (UpdateUnit)comboUpdateFrequency.SelectedIndex;
            loaderini.UpdateFrequency = (int)numericUpdateFrequency.Value;

            IniSerializer.Serialize(loaderini, loaderinipath);

            List <Code> selectedCodes   = new List <Code>();
            List <Code> selectedPatches = new List <Code>();

            foreach (Code item in codesCheckedListBox.CheckedIndices.OfType <int>().Select(a => codes[a]))
            {
                if (item.Patch)
                {
                    selectedPatches.Add(item);
                }
                else
                {
                    selectedCodes.Add(item);
                }
            }

            CodeList.WriteDatFile(patchdatpath, selectedPatches);
            CodeList.WriteDatFile(codedatpath, selectedCodes);
        }
        private void Save()
        {
            loaderini.Mods.Clear();

            foreach (ListViewItem item in modListView.CheckedItems)
            {
                loaderini.Mods.Add((string)item.Tag);
            }

            loaderini.EnableConsole = enableDebugConsole.Checked;
            loaderini.StartingScene = startingScene.SelectedIndex;

            IniSerializer.Serialize(loaderini, loaderinipath);

            List <Code> selectedCodes   = new List <Code>();
            List <Code> selectedPatches = new List <Code>();

            foreach (Code item in codesCheckedListBox.CheckedIndices.OfType <int>().Select(a => codes[a]))
            {
                if (item.Patch)
                {
                    selectedPatches.Add(item);
                }
                else
                {
                    selectedCodes.Add(item);
                }
            }

            using (FileStream fs = File.Create(patchdatpath))
                using (BinaryWriter bw = new BinaryWriter(fs, System.Text.Encoding.ASCII))
                {
                    bw.Write(new[] { 'c', 'o', 'd', 'e', 'v', '5' });
                    bw.Write(selectedPatches.Count);
                    foreach (Code item in selectedPatches)
                    {
                        if (item.IsReg)
                        {
                            bw.Write((byte)CodeType.newregs);
                        }
                        WriteCodes(item.Lines, bw);
                    }
                    bw.Write(byte.MaxValue);
                }
            using (FileStream fs = File.Create(codedatpath))
                using (BinaryWriter bw = new BinaryWriter(fs, System.Text.Encoding.ASCII))
                {
                    bw.Write(new[] { 'c', 'o', 'd', 'e', 'v', '5' });
                    bw.Write(selectedCodes.Count);
                    foreach (Code item in selectedCodes)
                    {
                        if (item.IsReg)
                        {
                            bw.Write((byte)CodeType.newregs);
                        }
                        WriteCodes(item.Lines, bw);
                    }
                    bw.Write(byte.MaxValue);
                }
        }
        private void toolImportFilter_Click(object sender, EventArgs e)
        {
            using (var open = new OpenFileDialog {
                Filter = "INI File|*.ini"
            })
            {
                if (open.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var import = IniSerializer.Deserialize <List <Filter> >(open.FileName);

                if (import.Count == 0)
                {
                    MessageBox.Show("This file doesn't contain any filters.", "Import error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                using (var window = new FilterSelect(import))
                {
                    if (window.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    foreach (int i in window.SelectedFilters)
                    {
                        Program.Settings.Filters.Add(window.FilterList[i]);
                    }
                }
            }
        }
            public void Then_the_output_is_created_correctly()
            {
                const string expected =
                    "[Section_1]\r\n" +
                    "Item1=Value_1_1\r\n" +
                    "Item2=Value_1_2\r\n" +
                    "Item3=Value_1_3\r\n" +
                    "[Section_2]\r\n" +
                    "Item1=Value_2_1\r\n" +
                    "Item2=Value_2_2\r\n" +
                    "Item3=Value_2_3";

                var serializedOutput =
                    IniSerializer.Serialize(
                        new[]
                {
                    new ObjectToSerialize("Section_1")
                    {
                        Item1 = "Value_1_1",
                        Item2 = "Value_1_2",
                        Item3 = "Value_1_3",
                    },
                    new ObjectToSerialize("Section_2")
                    {
                        Item1 = "Value_2_1",
                        Item2 = "Value_2_2",
                        Item3 = "Value_2_3",
                    }
                });

                Assert.AreEqual(expected, serializedOutput);
            }
Exemple #20
0
            /// <summary>
            /// Load from a file (VMS or INI)
            /// </summary>
            public static VMS_DLC LoadFile(string filename)
            {
                switch (Path.GetExtension(filename.ToLowerInvariant()))
                {
                case ".vms":
                    return(new VMS_DLC(File.ReadAllBytes(filename)));

                case ".ini":
                    break;

                default:
                    System.Windows.Forms.MessageBox.Show("Unknown file format. Use VMS or INI.");
                    return(new VMS_DLC());
                }
                VMS_DLC header = IniSerializer.Deserialize <VMS_DLC>(filename);

                header.Icon        = new Bitmap(Path.ChangeExtension(filename, ".bmp"));
                header.SoundData   = new byte[0];
                header.TextureData = File.ReadAllBytes(Path.ChangeExtension(filename, ".pvm"));
                if (File.Exists(Path.ChangeExtension(filename, ".bin")))
                {
                    header.ModelData = FraGag.Compression.Prs.Compress(File.ReadAllBytes(Path.ChangeExtension(filename, ".bin")));
                }
                else
                {
                    header.ModelData = ConvertModel(Path.ChangeExtension(filename, ".sa1mdl"));
                }
                if (header.ContainsSound)
                {
                    header.SoundData = File.ReadAllBytes(Path.ChangeExtension(filename, ".mlt"));
                }
                return(header);
            }
        private void toolExportFilter_Click(object sender, EventArgs e)
        {
            using (var window = new FilterSelect(Program.Settings.Filters))
            {
                DialogResult result = window.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                using (var save = new SaveFileDialog {
                    Filter = "INI File|*.ini"
                })
                {
                    if (save.ShowDialog() != DialogResult.OK || window.SelectedFilters.Count <= 0)
                    {
                        return;
                    }

                    if (window.FiltersModified)
                    {
                        Program.Settings.Filters = window.FilterList;
                    }

                    List <Filter> export = window.SelectedFilters.Select(i => Program.Settings.Filters[i]).ToList();

                    IniSerializer.Serialize(export, save.FileName);
                }
            }
        }
Exemple #22
0
        public static DllIniData LoadMultiINI(List <string> fileName,
                                              ref Dictionary <string, bool> defaultExportState)
        {
            defaultExportState.Clear();
            DllIniData             newIniData = new DllIniData();
            List <DllDataItemInfo> curItems   = new List <DllDataItemInfo>();

            foreach (string arrFile in fileName)
            {
                DllIniData IniData = IniSerializer.Deserialize <DllIniData>(arrFile);

                Environment.CurrentDirectory = Path.GetDirectoryName(arrFile);

                foreach (KeyValuePair <string, FileTypeHash> item in IniData.Files)
                {
                    bool modified = HelperFunctions.FileHash(item.Key) != item.Value.Hash;
                    defaultExportState.Add(item.Key, modified);
                }

                foreach (DllDataItemInfo item in IniData.DataItems)
                {
                    CheckItems(item, IniData, ref defaultExportState);

                    curItems.Add(item);
                }
            }
            newIniData.DataItems = curItems;

            return(newIniData);
        }
Exemple #23
0
        // Loads a split INI file and lists all filenames by address in ascending order, as well as saves a sorted INI file
        static void SplitLF(string[] args)
        {
            string  inifilename = args[0];
            IniData inifile     = IniSerializer.Deserialize <IniData>(inifilename);

            inifile.Files = SortIniData(inifile.Files);
            IniSerializer.Serialize(inifile, Path.GetFileNameWithoutExtension(inifilename) + "_sorted.ini");
        }
        public override ISerializer ApplyInternal()
        {
            var ser = new IniSerializer(_builder, _mapper);

            VerifyErrors(ser);

            return(ser);
        }
        public void GivenASerializerReceivingCustomOptionsThenDefaultNormalizerIsUsed()
        {
            var options    = new IniSerializationOptions();
            var serializer = new IniSerializer(options);

            Assert.Same(options, serializer.Options);
            Assert.Same(IniNormalizer.Default, serializer.Normalizer);
        }
        public void GivenASerializerReceivingCustomNormalizerThenDefaultOptionsAreUsed()
        {
            var normalizer = new IniNormalizer();
            var serializer = new IniSerializer(normalizer);

            Assert.Same(IniSerializationOptions.Default, serializer.Options);
            Assert.Same(normalizer, serializer.Normalizer);
        }
 public void Save(string path)
 {
     if (!Directory.Exists(Path.GetDirectoryName(path)))
     {
         Directory.CreateDirectory(Path.GetDirectoryName(path));
     }
     IniSerializer.Serialize(this, path);
 }
        public void GivenASerializerReceivingCustomParametersThenReferencesAreTheSame()
        {
            var options    = new IniSerializationOptions();
            var normalizer = new IniNormalizer();
            var serializer = new IniSerializer(options, normalizer);

            Assert.Same(options, serializer.Options);
            Assert.Same(normalizer, serializer.Normalizer);
        }
            public void Then_the_name_of_the_class_is_used_as_the_section_heading()
            {
                var serializedOutput =
                    IniSerializer
                    .Serialize(
                        new ObjectToSerialize());

                Assert.AreEqual("[ObjectToSerialize]", serializedOutput);
            }
Exemple #30
0
        /*[IniName("map")]
         * public string MappingsFile { get; set; }
         * [IniName("mapgame")]
         * public EngineVersion MappingsGame { get; set; }
         * [IniName("mapfmt")]
         * public MappingsFormat MappingsFormat { get; set; }
         * [IniName("dplc")]
         * public string DPLCFile { get; set; }
         * [IniName("dplcgame")]
         * public EngineVersion DPLCGame { get; set; }
         * [IniName("dplcfmt")]
         * public MappingsFormat DPLCFormat { get; set; }
         * [IniName("anim")]
         * public string AnimationFile { get; set; }
         * [IniName("animfmt")]
         * public MappingsFormat AnimationFormat { get; set; }
         * [IniName("startpal")]
         * public int StartPalette { get; set; }*/

        public static Dictionary <string, AnimationInfo> Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            Dictionary <string, AnimationInfo> result = IniSerializer.Deserialize <Dictionary <string, AnimationInfo> >(ini);

            foreach (KeyValuePair <string, AnimationInfo> anim in result)
            {
                /*if (anim.Value.MappingsGame == EngineVersion.Invalid)
                 *      anim.Value.MappingsGame = anim.Value.Game;
                 * if (anim.Value.DPLCGame == EngineVersion.Invalid)
                 *      anim.Value.DPLCGame = anim.Value.Game;
                 * if (anim.Value.MappingsFormat == MappingsFormat.Invalid)
                 *      anim.Value.MappingsFormat = MappingsFormat.Binary;
                 * if (anim.Value.DPLCFormat == MappingsFormat.Invalid)
                 *      anim.Value.DPLCFormat = MappingsFormat.Binary;
                 * if (anim.Value.AnimationFormat == MappingsFormat.Invalid)
                 *      anim.Value.AnimationFormat = MappingsFormat.Binary;*/
                Dictionary <string, string> inisection = ini[anim.Key];
                List <byte> frmspd = new List <byte>();
                Dictionary <string, int> frmspr = new Dictionary <string, int>();
                anim.Value.SprList = new List <SpriteInfo[]>();
                for (int i = 0; i < anim.Value.Frames.Length; i++)
                {
                    string sprName = anim.Value.Frames[i].Sprite;
                    if (anim.Value.Frames[i].Speed >= 0xF0)
                    {
                        frmspd.Add(0);
                        frmspd.Add(anim.Value.Frames[i].Speed);
                        break;
                    }

                    if (!frmspr.ContainsKey(sprName))
                    {
                        frmspr[sprName] = anim.Value.SprList.Count;

                        string[]     vals    = inisection[sprName].Split('|');
                        SpriteInfo[] sprinfs = new SpriteInfo[vals.Length];
                        for (int j = 0; j < vals.Length; j++)
                        {
                            sprinfs[j] = new SpriteInfo(vals[j]);
                        }
                        anim.Value.SprList.Add(sprinfs);
                    }
                    frmspd.Add((byte)frmspr[sprName]);
                    frmspd.Add((byte)(anim.Value.Frames[i].Speed * 2));
                }
                anim.Value.Animation = new Animation(frmspd.ToArray(), 0, anim.Key + "_Load");
            }
            return(result);
        }
Exemple #31
0
 private void loadSettingsButton_Click(object sender, EventArgs e)
 {
     var path = GetIniPath();
     if (!File.Exists(path))
     {
         SetStatus("No INI file at " + path);
         return;
     }
     var iser = new IniSerializer();
     using (var tw = new StreamReader(path, Encoding.UTF8))
     {
         iser.Parse(tw.ReadToEnd());
         iser.UpdateObject("Tracker", _tracker);
         iser.UpdateObject("StrokeRecognizer", _strokeRecognizer);
         iser.UpdateObject("Drawing", _drawing);
         iser.UpdateObject("DrawParams", _drawWindow.DrawParams);
         UpdatePropertyGrids();
         SetStatus("Loaded from " + path);
     }
 }
Exemple #32
0
 private void saveSettingsButton_Click(object sender, EventArgs e)
 {
     var iser = new IniSerializer();
     iser.WriteObject("Tracker", _tracker);
     iser.WriteObject("StrokeRecognizer", _strokeRecognizer);
     iser.WriteObject("Drawing", _drawing);
     iser.WriteObject("DrawParams", _drawWindow.DrawParams);
     var path = GetIniPath();
     using (var tw = new StreamWriter(path, false, Encoding.UTF8))
     {
         tw.Write(iser.GetValue());
     }
     SetStatus("Saved to " + path);
 }