コード例 #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog.FilterIndex      = 1;
            openFileDialog.InitialDirectory = Path.GetDirectoryName(filePath);
            openFileDialog.FileName         = Path.GetFileName(filePath).Replace(".xml", ".lng");
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // Clean
                lngDataGridView.DataSource = null;
                lngDataGridView.Rows.Clear();
                lngDataGridView.Columns.Clear();
                filePath = openFileDialog.FileName;
                openFileDialog.Dispose();
                Stream s = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                try {
                    lngFile = new LngFile(s);
                }
                catch (Exception ex) {
                    MessageBox.Show("Conversion Failed!" + Environment.NewLine + ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                lngDataGridView.DataSource = lngFile.GetDataTable();

                this.Text = "Ego Language Editor - " + filePath;
            }
        }
コード例 #2
0
        private void compareFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lngFile == null)
            {
                return;
            }

            openFileDialog.FilterIndex      = 1;
            openFileDialog.InitialDirectory = Path.GetDirectoryName(filePath);
            openFileDialog.FileName         = Path.GetFileName(filePath).Replace(".xml", ".lng");
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    LngFile two = new LngFile(File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read));
                    openFileDialog.Dispose();
                    saveFileDialog.FilterIndex      = 2;
                    saveFileDialog.InitialDirectory = Path.GetDirectoryName(filePath);
                    saveFileDialog.FileName         = Path.GetFileName(filePath).Replace(".lng", "Differences.xml");
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        LngFile differences = lngFile.GetDifferences(two);
                        differences.WriteXml(File.Open(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read));
                        saveFileDialog.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The program failed to compare the files:" + Environment.NewLine + Environment.NewLine + ex.Message, "Ego Language Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #3
0
        public Form1(string[] args)
        {
            InitializeComponent();
            this.Icon = Properties.Resources.Ryder25;
            LNG       = new DataSet("language");
            fRF       = new FindAndReplaceForm(this.lngDataGridView);
            filePath  = openFileDialog.FileName;
            lngDataGridView.AutoSizeColumnsMode       = DataGridViewAutoSizeColumnsMode.Fill;
            lngDataGridView.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.DisplayedCells;
            lngDataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            lngDataGridView.AllowUserToAddRows        = false;
            lngDataGridView.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#E8EDFF");
            DgvFilterManager dgvfm = new DgvFilterManager(lngDataGridView);

            // Open With
            if (args.Length > 0)
            {
                if (File.Exists(args[0]) == true)
                {
                    filePath = args[0];
                    Stream s = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    lngFile = new LngFile(s);
                    lngDataGridView.DataSource = lngFile.GetDataTable();

                    this.Text = "Ego Language Editor - " + filePath;
                }
            }
        }
コード例 #4
0
 private void importAsXMLToolStripMenuItem_Click(object sender, EventArgs e)
 {
     openFileDialog.FilterIndex      = 2;
     openFileDialog.InitialDirectory = Path.GetDirectoryName(filePath);
     openFileDialog.FileName         = filePath.Replace(".lng", ".xml");
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         // Clean
         lngDataGridView.DataSource = null;
         lngDataGridView.Rows.Clear();
         lngDataGridView.Columns.Clear();
         LNG = new DataSet("language");
         //LNG.ReadXmlSchema(Path.GetFullPath(openFileDialog.FileName).Replace(Path.GetFileName(openFileDialog.FileName), string.Empty) +
         //Path.GetFileNameWithoutExtension(openFileDialog.FileName) + "_schema.xsd");
         try {
             LNG.ReadXml(File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read), XmlReadMode.ReadSchema);
         }
         catch (Exception ex) {
             MessageBox.Show("Loading XML failed!" + Environment.NewLine + ex.Message, "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         lngFile = new LngFile(LNG);
         lngDataGridView.DataSource = LNG.Tables[1];
         filePath  = openFileDialog.FileName;
         this.Text = "Ego Language Editor - " + openFileDialog.FileName;
         openFileDialog.Dispose();
     }
 }
コード例 #5
0
        private static void Convert(string f)
        {
            string magic;
            string xmlMagic;

            using (var fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                PkgBinaryReader reader = new PkgBinaryReader(fs);
                magic = reader.ReadString(4);

                // Skip first byte since BXMLBig starts with \0 causing empty string
                reader.Seek(1, SeekOrigin.Begin);
                xmlMagic = reader.ReadString(3);
            }

            if (xmlMagic == "\"Rr" || xmlMagic == "BXM")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                XmlFile file = new XmlFile(fsi);
                file.Write(fso, XMLType.Text);
                Console.WriteLine("Success! XML converted.");
            }
            else if (magic == "LNGT")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                LngFile file = new LngFile(fsi);
                file.WriteXml(fso);
                Console.WriteLine("Success! Lng converted.");
            }
            else if (magic == "!pkg")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                using var fso = File.Open(f + ".json", FileMode.Create, FileAccess.Write, FileShare.Read);
                PkgFile file = PkgFile.ReadPkg(fsi);
                file.WriteJson(fso);
                Console.WriteLine("Success! Pkg converted.");
            }
            else
            {
                bool          isJSON = false;
                JsonException jsonEx = null;
                try
                {
                    using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                    using var fso = File.Open(f + ".pkg", FileMode.Create, FileAccess.Write, FileShare.Read);
                    PkgFile pkgFile = PkgFile.ReadJson(fsi);
                    pkgFile.WritePkg(fso);
                    Console.WriteLine("Success! JSON converted.");
                    isJSON = true;
                }
                catch (JsonException e)
                {
                    jsonEx = e;
                }

                if (!isJSON)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    try
                    {
                        xmlDoc.Load(f);
                    }
                    catch (XmlException e)
                    {
                        throw new AggregateException("Could not determine the file type! Showing json, and xml errors: ", jsonEx, e);
                    }

                    if (xmlDoc.DocumentElement.Name == "language")
                    {
                        using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                        using var fso = File.Open(f + ".lng", FileMode.Create, FileAccess.Write, FileShare.Read);
                        DataSet dataSet = new DataSet("language");
                        dataSet.ReadXml(fsi, XmlReadMode.ReadSchema);
                        LngFile file = new LngFile(dataSet);
                        file.Write(fso);
                        Console.WriteLine("Success! XML converted.");
                    }
                    else
                    {
                        using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                        using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                        XmlFile file = new XmlFile(fsi);
                        file.Write(fso);
                        Console.WriteLine("Success! XML converted.");
                    }
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ptasev/Ego-Engine-Modding
        private static void Convert(string f)
        {
            var    fileName = Path.GetFileName(f);
            var    ext      = Path.GetExtension(f);
            string magic;
            string xmlMagic;

            using (var fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                PkgBinaryReader reader = new PkgBinaryReader(fs);
                magic = reader.ReadString(4);

                // Skip first byte since BXMLBig starts with \0 causing empty string
                reader.Seek(1, SeekOrigin.Begin);
                xmlMagic = reader.ReadString(3);
            }

            if (xmlMagic == "\"Rr" || xmlMagic == "BXM")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                XmlFile file = new XmlFile(fsi);
                using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                file.Write(fso, XMLType.Text);
                Console.WriteLine("Success! XML converted.");
            }
            else if (magic == "LNGT")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                LngFile file = new LngFile(fsi);
                using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                file.WriteXml(fso);
                Console.WriteLine("Success! Lng converted.");
            }
            else if (magic == "!pkg")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                PkgFile file = PkgFile.ReadPkg(fsi);
                using var fso = File.Open(f + ".json", FileMode.Create, FileAccess.Write, FileShare.Read);
                file.WriteJson(fso);
                Console.WriteLine("Success! Pkg converted.");
            }
            else if (ext == ".tpk")
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                var tpk = new TpkFile();
                tpk.Read(fsi);
                Console.WriteLine($"Tpk name '{tpk.Name}', image format '{tpk.Format}'.");
                var dds = tpk.ToDds();
                using var fso = File.Open(f + ".dds", FileMode.Create, FileAccess.Write, FileShare.Read);
                dds.Write(fso, -1);
                Console.WriteLine("Success! Tpk converted.");
            }
            else if (fileName.EndsWith(".tpk.dds"))
            {
                using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                var dds = new DdsFile(fsi);
                var tpk = new TpkFile()
                {
                    Name = fileName.Remove(fileName.IndexOf('.'))
                };
                tpk.FromDds(dds);
                using var fso = File.Open(f + ".tpk", FileMode.Create, FileAccess.Write, FileShare.Read);
                tpk.Write(fso);
                Console.WriteLine("Success! DDS converted.");
            }
            else
            {
                bool          isJSON = false;
                JsonException jsonEx = null;
                try
                {
                    using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                    PkgFile pkgFile = PkgFile.ReadJson(fsi);
                    using var fso = File.Open(f + ".pkg", FileMode.Create, FileAccess.Write, FileShare.Read);
                    pkgFile.WritePkg(fso);
                    Console.WriteLine("Success! JSON converted.");
                    isJSON = true;
                }
                catch (JsonException e)
                {
                    jsonEx = e;
                }

                if (!isJSON)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    try
                    {
                        xmlDoc.Load(f);
                    }
                    catch (XmlException e)
                    {
                        throw new AggregateException("Could not determine the file type! Showing json, and xml errors: ", jsonEx, e);
                    }

                    if (xmlDoc.DocumentElement.Name == "language")
                    {
                        using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                        DataSet dataSet = new DataSet("language");
                        dataSet.ReadXml(fsi, XmlReadMode.ReadSchema);
                        LngFile file = new LngFile(dataSet);
                        using var fso = File.Open(f + ".lng", FileMode.Create, FileAccess.Write, FileShare.Read);
                        file.Write(fso);
                        Console.WriteLine("Success! XML converted.");
                    }
                    else
                    {
                        using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read);
                        XmlFile file = new XmlFile(fsi);
                        using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read);
                        file.Write(fso);
                        Console.WriteLine("Success! XML converted.");
                    }
                }
            }
        }
コード例 #7
0
 public AddRow(LngFile _file)
 {
     InitializeComponent();
     file = _file;
     textBox1.SelectAll();
 }