Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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);
        }
        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}");
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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);
                }
        }
 public When_the_object_is_serialized()
 {
     _serializedOutput
         = IniSerializer
           .Serialize(new ObjectToSerialize("Test Section Heading"))
           .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
            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);
            }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
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));
                }
            }
Exemplo n.º 12
0
 public void Save(string path)
 {
     if (!Directory.Exists(Path.GetDirectoryName(path)))
     {
         Directory.CreateDirectory(Path.GetDirectoryName(path));
     }
     IniSerializer.Serialize(this, path);
 }
Exemplo n.º 13
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 void Then_the_name_of_the_class_is_used_as_the_section_heading()
            {
                var serializedOutput =
                    IniSerializer
                    .Serialize(
                        new ObjectToSerialize());

                Assert.AreEqual("[ObjectToSerialize]", serializedOutput);
            }
Exemplo n.º 15
0
        public override void CreateIndexFile(string path)
        {
            Dictionary <string, PAKIniItem> list = new Dictionary <string, PAKIniItem>(Entries.Count);

            foreach (PAKEntry item in Entries)
            {
                list.Add(FolderName + "\\" + item.Name, new PAKIniItem(item.LongPath));
            }
            IniSerializer.Serialize(list, Path.Combine(Path.GetFileNameWithoutExtension(path), Path.GetFileNameWithoutExtension(path) + ".ini"));
        }
Exemplo n.º 16
0
        public void Save()
        {
            string path = GetSettingsPath();

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            IniSerializer.Serialize(this, path);
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            string dir = Environment.CurrentDirectory;

            try
            {
                Queue <string> argq = new Queue <string>(args);
                if (argq.Count > 0 && argq.Peek().Equals("/be", StringComparison.OrdinalIgnoreCase))
                {
                    ByteConverter.BigEndian = true;
                    argq.Dequeue();
                }
                string filename;
                if (argq.Count > 0)
                {
                    filename = argq.Dequeue();
                    Console.WriteLine("File: {0}", filename);
                }
                else
                {
                    Console.Write("File: ");
                    filename = Console.ReadLine();
                }
                filename = Path.Combine(Environment.CurrentDirectory, filename);
                Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, Path.GetDirectoryName(filename));
                byte[] file = File.ReadAllBytes(filename);
                if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
                {
                    file = FraGag.Compression.Prs.Decompress(file);
                }
                Directory.CreateDirectory(Path.GetFileNameWithoutExtension(filename));
                Dictionary <int, int>    processedanims = new Dictionary <int, int>();
                Dictionary <int, string> ini            = new Dictionary <int, string>();
                int address = 0;
                int i       = ByteConverter.ToInt16(file, address);
                while (i != -1)
                {
                    int aniaddr = ByteConverter.ToInt32(file, address + 4);
                    if (!processedanims.ContainsKey(aniaddr))
                    {
                        new NJS_MOTION(file, aniaddr, 0, ByteConverter.ToInt16(file, address + 2))
                        .Save(Path.GetFileNameWithoutExtension(filename) + "/" + i.ToString(NumberFormatInfo.InvariantInfo) + ".saanim");
                        processedanims[aniaddr] = i;
                    }
                    ini[i]   = "animation_" + aniaddr.ToString("X8");
                    address += 8;
                    i        = ByteConverter.ToInt16(file, address);
                }
                IniSerializer.Serialize(ini, new IniCollectionSettings(IniCollectionMode.IndexOnly), Path.Combine(Path.GetFileNameWithoutExtension(filename), Path.GetFileNameWithoutExtension(filename) + ".ini"));
            }
            finally
            {
                Environment.CurrentDirectory = dir;
            }
        }
Exemplo n.º 18
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string moddir = Path.Combine(Path.Combine(Environment.CurrentDirectory, "mods"), ValidateFilename(textModName.Text));

            if (textModName.Text.Length <= 0)
            {
                MessageBox.Show("You can't have a mod without a name.", "Invalid mod name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (Directory.Exists(moddir))
                {
                    MessageBox.Show("A mod with that name already exists."
                                    + "\nPlease choose a different name or rename the existing one.", "Mod already exists",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                Directory.CreateDirectory(moddir);

                if (checkRedirectMainSave.Checked || checkRedirectChaoSave.Checked)
                {
                    Directory.CreateDirectory(Path.Combine(moddir, "SAVEDATA"));
                }

                SADXModInfo newMod = new SADXModInfo
                {
                    Name             = textModName.Text,
                    Author           = textModAuthor.Text,
                    Description      = textModDescription.Text,
                    Version          = textVersion.Text,
                    RedirectMainSave = checkRedirectMainSave.Checked,
                    RedirectChaoSave = checkRedirectChaoSave.Checked,
                    GitHubRepo       = textGitHubRepo.Text,
                    GitHubAsset      = textGitHubAttachment.Text,
                    UpdateUrl        = textDirUrl.Text
                };

                IniSerializer.Serialize(newMod, Path.Combine(moddir, "mod.ini"));

                if (checkOpenFolder.Checked)
                {
                    System.Diagnostics.Process.Start(moddir);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(this, error.Message, "Mod Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public When_the_object_is_serialized()
 {
     _serializedOutput =
         IniSerializer
         .Serialize(
             new ObjectToSerialize
     {
         MyPropertyName = "MyPropertyValue"
     })
         .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
 public When_the_object_is_serialized()
 {
     _serializedOutput =
         IniSerializer
         .Serialize(
             new ObjectToSerialize("Section Heading for section with one property")
     {
         Item1 = "Value Of Item 1"
     })
         .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
        public void Should_serialize_nullable()
        {
            long?value = 321;
            var  res   = IniSerializer.Serialize(value);

            Split(res).Should().BeEquivalentTo($"value = {value}");

            value = null;
            res   = IniSerializer.Serialize(value);
            Split(res).Should().BeEquivalentTo("value = ");
        }
        public void Should_serialize_dictionary_of_simples()
        {
            var value = new Dictionary <int, string>
            {
                [100] = "str",
                [200] = "ing",
            };
            var res = IniSerializer.Serialize(value);

            Split(res).Should().BeEquivalentTo($"100 = {value[100]}", $"200 = {value[200]}");
        }
        public void Should_serialize_struct_of_simples()
        {
            var value = new MyStruct
            {
                Int    = 123,
                String = "string",
            };
            var res = IniSerializer.Serialize(value);

            Split(res).Should().BeEquivalentTo($"Int = {value.Int}", $"String = {value.String}");
        }
 public When_the_properties_on_the_object_to_be_serialized_have_the_order_set()
 {
     _serializedOutput =
         IniSerializer.Serialize(
             new ObjectToSerialize("Section Heading for section with ordered properties")
     {
         Item1 = "Position 3",
         Item2 = "Position 1",
         Item3 = "Position 2",
     }).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
Exemplo n.º 25
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (CheckForUpdates())
            {
                return;
            }

            if (!File.Exists(datadllpath))
            {
                MessageBox.Show(this, "MIDIOUT.dll could not be found.\n\nCannot determine state of installation.",
                                Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                installButton.Hide();
            }
            else if (File.Exists(datadllorigpath))
            {
                installed          = true;
                installButton.Text = "Uninstall loader";
                using (MD5 md5 = MD5.Create())
                {
                    byte[] hash1 = md5.ComputeHash(File.ReadAllBytes(loaderdllpath));
                    byte[] hash2 = md5.ComputeHash(File.ReadAllBytes(datadllpath));

                    if (!hash1.SequenceEqual(hash2))
                    {
                        DialogResult result = MessageBox.Show(this, "Installed loader DLL differs from copy in mods folder."
                                                              + "\n\nDo you want to overwrite the installed copy?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                        if (result == DialogResult.Yes)
                        {
                            File.Copy(loaderdllpath, datadllpath, true);
                        }
                    }
                }
            }

            List <string> uris = Program.UriQueue.GetUris();

            foreach (string str in uris)
            {
                HandleUri(str);
            }

            Program.UriQueue.UriEnqueued += UriQueueOnUriEnqueued;

            CheckForModUpdates();

            // If we've checked for updates, save the modified
            // last update times without requiring the user to
            // click the save button.
            if (checkedForUpdates)
            {
                IniSerializer.Serialize(loaderini, loaderinipath);
            }
        }
Exemplo n.º 26
0
        private void Save()
        {
            loaderini.Mods.Clear();

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

            loaderini.DebugConsole = consoleCheckBox.Checked;
            loaderini.DebugFile    = fileCheckBox.Checked;
            loaderini.Game         = gameS3.Checked ? Game.S3 : (gameSK.Checked ? Game.SK : Game.S3K);
            if (paletteAccurateButton.Checked)
            {
                loaderini.Palette = PaletteSetting.Accurate;
            }
            else if (paletteLinearButton.Checked)
            {
                loaderini.Palette = PaletteSetting.Linear;
            }
            else if (paletteSKCButton.Checked)
            {
                loaderini.Palette = PaletteSetting.SKC;
            }
            else
            {
                loaderini.Palette = PaletteSetting.Old;
            }
            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);
        }
 public When_the_object_is_serialized()
 {
     _serializedOutput =
         IniSerializer
         .Serialize(
             new ObjectToSerialize("Section Heading for section with multiple properties")
     {
         StringValue      = "Value Of Item 1",
         IntegerValue     = 3,
         PropertyToIgnore = "StringValueWithNoAttribute"
     })
         .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 }
Exemplo n.º 28
0
        public static void ExportINI(DllIniData IniData,
                                     Dictionary <string, bool> itemsToExport, string fileName)
        {
            string     dstfol = Path.GetDirectoryName(fileName);
            DllIniData output = new DllIniData()
            {
                Name     = IniData.Name,
                Game     = IniData.Game,
                Exports  = IniData.Exports,
                TexLists = IniData.TexLists
            };
            List <string> labels = new List <string>();

            foreach (KeyValuePair <string, FileTypeHash> item in
                     IniData.Files.Where(i => itemsToExport[i.Key]))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(dstfol, item.Key)));
                File.Copy(item.Key, Path.Combine(dstfol, item.Key), true);
                switch (item.Value.Type)
                {
                case "landtable":
                    LandTable tbl = LandTable.LoadFromFile(item.Key);
                    labels.AddRange(tbl.GetLabels());
                    break;

                case "model":
                case "basicmodel":
                case "chunkmodel":
                case "gcmodel":
                case "basicdxmodel":
                    NJS_OBJECT mdl = new ModelFile(item.Key).Model;
                    labels.AddRange(mdl.GetLabels());
                    break;

                case "animation":
                    NJS_MOTION ani = NJS_MOTION.Load(item.Key);
                    labels.Add(ani.Name);
                    break;
                }
                output.Files.Add(item.Key, new FileTypeHash(item.Value.Type, null));
            }
            output.Items = new List <DllItemInfo>(IniData.Items.Where(a => labels.Contains(a.Label)));
            foreach (var item in IniData.DataItems.Where(i => itemsToExport[i.Filename]))
            {
                Directory.CreateDirectory(Path.Combine(dstfol, item.Filename));
                CopyDirectory(new DirectoryInfo(item.Filename), Path.Combine(dstfol, item.Filename));
                output.DataItems.Add(item);
            }
            IniSerializer.Serialize(output, fileName);
        }
Exemplo n.º 29
0
        // Loads a split INI file and a list of filenames and replaces INI filenames for models and animations with the names specified in the list
        static void SplitRF(string[] args)
        {
            string  inifilename  = args[0];
            string  listfilename = args[1];
            IniData inifile      = IniSerializer.Deserialize <IniData>(inifilename);

            string[] list = File.ReadAllLines(listfilename);
            int      n    = 0;
            Dictionary <int, string> filenames = new Dictionary <int, string>();
            Dictionary <string, SA_Tools.FileInfo> fileinfo_new = new Dictionary <string, SA_Tools.FileInfo>();

            foreach (KeyValuePair <string, SA_Tools.FileInfo> fileinfo in inifile.Files)
            {
                if (list.Length <= n)
                {
                    Console.WriteLine("Item outside of bounds!");
                    continue;
                }
                if (!((list[n].Length >= 6 && list[n].Substring(0, 6) == "DELETE")))
                {
                    Console.WriteLine("{0}", list[n]);
                    fileinfo.Value.Filename = list[n];
                    filenames.Add(fileinfo.Value.Address, list[n]);
                    fileinfo_new.Add(fileinfo.Value.Address.ToString("X8"), fileinfo.Value);
                }
                else
                {
                    Console.WriteLine("Deleted: {0}", fileinfo.Value.Filename);
                }
                n++;
            }
            // Relink animations
            foreach (KeyValuePair <string, SA_Tools.FileInfo> fileinfo in inifile.Files)
            {
                if (fileinfo.Value.CustomProperties.ContainsKey("animations"))
                {
                    string[] anims = fileinfo.Value.CustomProperties["animations"].Split(',');
                    for (int a = 0; a < anims.Length; a++)
                    {
                        string newfilename           = filenames[int.Parse(Path.GetFileNameWithoutExtension(anims[a]), System.Globalization.NumberStyles.AllowHexSpecifier)];
                        System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
                        PathRelativePathTo(sb, Path.GetFullPath(fileinfo.Value.Filename), 0, Path.GetFullPath(newfilename), 0);
                        anims[a] = sb.ToString();
                    }
                    fileinfo.Value.CustomProperties["animations"] = string.Join(",", anims);
                }
            }
            inifile.Files = fileinfo_new;
            IniSerializer.Serialize(inifile, Path.GetFileNameWithoutExtension(inifilename) + "_replaced.ini");
        }
Exemplo n.º 30
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string moddir = Path.Combine(ModsPath, ValidateFilename(textModName.Text));

            Directory.CreateDirectory(moddir);

            Rayman2ModInfo newMod = new Rayman2ModInfo
            {
                Name        = textModName.Text,
                Author      = textModAuthor.Text,
                Description = textModDescription.Text,
                Version     = textModVersion.Text
            };

            if (dllCheckBox.Checked == true)
            {
                newMod.DLLFile = textModDLL.Text;
            }

            if (exeCheckBox.Checked == true)
            {
                newMod.EXEFile = textModExe.Text;
            }

            if (noneRadioButton.Checked == false)
            {
                if (gitRadioButton.Checked == true)
                {
                    newMod.GitHubRepo  = updateInfo1.Text;
                    newMod.GitHubAsset = updateInfo2.Text;
                }
                else if (gbRadioButton.Checked == true)
                {
                    newMod.GameBananaItemType = updateInfo1.Text;
                    newMod.GameBananaItemId   = long.Parse(updateInfo2.Text);
                }
                else if (urlRadioButton.Checked == true)
                {
                    newMod.UpdateUrl    = updateInfo1.Text;
                    newMod.ChangelogUrl = updateInfo2.Text;
                }
            }

            IniSerializer.Serialize(newMod, Path.Combine(moddir, "mod.ini"));

            DialogResult = DialogResult.OK;
            Close();
        }