Пример #1
0
        private void extractMatButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Settings.MtrlFolderDialogDirectory))
            {
                folderBrowserDialog.SelectedPath = Settings.MtrlFolderDialogDirectory;
            }
            else if (!string.IsNullOrEmpty(brg.FileName))
            {
                folderBrowserDialog.SelectedPath = Path.GetDirectoryName(brg.FileName);
            }

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                brg.SaveUI();
                for (int i = 0; i < brg.File.Materials.Count; i++)
                {
                    MtrlFile mtrl = new MtrlFile(brg.File.Materials[i]);
                    mtrl.Write(File.Open(Path.Combine(folderBrowserDialog.SelectedPath, Path.GetFileNameWithoutExtension(brg.FileName) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read));
                    //brg.File.Materials[i].WriteExternal(File.Open(Path.Combine(folderBrowserDialog.SelectedPath, Path.GetFileNameWithoutExtension(brg.FileName) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read));
                }
                brg.LoadUI();
            }
        }
Пример #2
0
        private static void Convert(string f)
        {
            string magic;
            using (FileStream fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BrgBinaryReader reader = new BrgBinaryReader(EndianBitConverter.Little, fs);
                magic = reader.ReadString(4);
            }

            if (f.EndsWith("anim.txt"))
            {
                AnimFile.ConvertToXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Anim converted.");
            }
            else if (f.EndsWith(".prt"))
            {
                PrtFile file = new PrtFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Prt converted.");
            }
            else if (magic == "MTRL")
            {
                MtrlFile file = new MtrlFile();
                file.Read(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Mtrl converted.");
            }
            else if (magic == "BANG")
            {
                string brgMtrlOutputPath = Path.Combine(Path.GetDirectoryName(f), "materials");
                if (!Directory.Exists(brgMtrlOutputPath))
                {
                    Directory.CreateDirectory(brgMtrlOutputPath);
                }

                BrgFile file = new BrgFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                for (int i = 0; i < file.Materials.Count; ++i)
                {
                    MtrlFile mtrl = new MtrlFile(file.Materials[i]);
                    mtrl.Write(File.Open(Path.Combine(brgMtrlOutputPath, Path.GetFileNameWithoutExtension(f) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read));
                }
                Console.WriteLine("Success! Mtrl files created.");
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(f);

                if (xmlDoc.DocumentElement.Name == "AnimFile")
                {
                    AnimFile.ConvertToAnim(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".txt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Anim converted.");
                }
                else if (xmlDoc.DocumentElement.Name == "ParticleFile")
                {
                    PrtFile file = PrtFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".prt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Prt converted.");
                }
                else
                {
                    MtrlFile file = MtrlFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".mtrl", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Mtrl converted.");
                }
            }
        }