Ejemplo n.º 1
0
        /// <summary>
        /// Imports file and exports it as text, then compares the result and test data.
        /// </summary>
        public void LangTextExportTest()
        {
            using (LNG lng = LNG.FromFile(filenameLng))
            {
                Assert.IsNotNull(lng, "LNG class FromFile failed.");

                lng.Export(filenameText);
            }

            Assert.IsTrue(File.Exists(filenameText));

            string[] parseddata = File.ReadAllLines(filenameText);

            int numEntries = parseddata.Length;

            Assert.IsTrue(numEntries > 0, "Unexpected number of entries.");
            Assert.AreEqual(numStrings, numEntries, 0, "Num strings mismatch.");

            for (int i = 0; i < numEntries; i++)
            {
                Assert.AreEqual(
                    testlist[i],
                    parseddata[i],
                    $"String {i} mismatch: {testlist[i]} vs {parseddata[i]}"
                    );
            }

            CleanUp();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            LNG lng;

            Console.WriteLine(
                "{0}\r\n{1}\r\n\r\n{2}\r\n",
                $"CTR-Tools: lng2txt - {Meta.GetSignature()}",
                "Converts LNG localization files to TXT and back.",
                Meta.GetVersion());

            if (args.Length == 0)
            {
                Console.WriteLine(
                    "{0}:\r\n\t{1}: {2}\r\n\t{3}: {4}",
                    "Usage",
                    "Convert to text", "lng2txt c:\\en.lng",
                    "Convert to .lng", "lng2txt c:\\en.txt"
                    );
                return;
            }

            Console.WriteLine("Current path: " + Environment.CurrentDirectory);

            foreach (string filename in args)
            {
                if (File.Exists(filename))
                {
                    string ext = Path.GetExtension(filename).ToLower();

                    try
                    {
                        switch (ext)
                        {
                        case ".lng":
                            lng = LNG.FromFile(filename);
                            lng.Export(Path.ChangeExtension(filename, "txt"), true);
                            continue;

                        case ".txt":
                            lng = LNG.FromText(File.ReadAllLines(filename, System.Text.Encoding.Default), true);
                            lng.Save(Path.ChangeExtension(filename, "lng"));
                            continue;

                        default:
                            Console.WriteLine("Unsupported file.");
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error: {ex.Message}");
                        continue;
                    }
                }
            }

            Console.WriteLine("Done.");
        }
Ejemplo n.º 3
0
 private void actionLoad_Click(object sender, EventArgs e)
 {
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         lng           = LNG.FromFile(ofd.FileName);
         linesOnLoad   = lng.Entries.Count;
         langBox.Lines = lng.Entries.ToArray();
     }
 }
Ejemplo n.º 4
0
        private void LangControl_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (files.Length > 0)
            {
                switch (Path.GetExtension(files[0]).ToLower())
                {
                case ".lng": lng = LNG.FromFile(files[0]); break;

                case ".txt": lng = LNG.FromText(File.ReadAllLines(files[0], System.Text.Encoding.Default)); break;

                default: MessageBox.Show("Unsupported file."); return;
                }

                langBox.Lines = lng.Entries.ToArray();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses the generated file and compares if obtained strings are equal to test data.
        /// </summary>
        public void LangParseTest()
        {
            using (LNG lng = LNG.FromFile(filenameLng))
            {
                Assert.IsNotNull(lng, "LNG class FromFile failed.");

                int numEntries = lng.Entries.Count;

                Assert.IsTrue(numEntries > 0, "Unexpected number of entries.");
                Assert.AreEqual(numStrings, numEntries, 0, "Num strings mismatch.");

                for (int i = 0; i < numEntries; i++)
                {
                    Assert.AreEqual(
                        testlist[i],
                        lng.Entries[i],
                        $"String {i} mismatch: {testlist[i]} vs {lng.Entries[i]}"
                        );
                }
            }

            LangTextExportTest();
        }
Ejemplo n.º 6
0
        private void button19_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd1 = new OpenFileDialog();
            OpenFileDialog ofd2 = new OpenFileDialog();

            if (ofd1.ShowDialog() == DialogResult.OK)
            {
                if (ofd2.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        LNG lng = LNG.FromFile(ofd1.FileName);

                        using (BinaryReaderEx br = new BinaryReaderEx(File.OpenRead(ofd2.FileName)))
                        {
                            br.Jump(0x74280);

                            List <LevelSlot> slots = new List <LevelSlot>();

                            for (int i = 0; i < 64; i++)
                            {
                                slots.Add(new LevelSlot(br));
                            }

                            foreach (LevelSlot s in slots)
                            {
                                textBox2.Text += s.ToString() + lng.Entries[s.title_index] + "\r\n";
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("error");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode.Tag != null)
            {
                BigEntry cf = treeView1.SelectedNode.Tag as BigEntry;

                if (Path.GetExtension(cf.Name) == ".lng")
                {
                    try
                    {
                        File.WriteAllBytes("temp.lng", cf.Data);
                        LNG lng = LNG.FromFile("temp.lng");
                        textBox4.Lines = lng.Entries.ToArray();
                        File.Delete("temp.lng");
                    }
                    catch
                    {
                    }
                }

                if (Path.GetExtension(cf.Name) == ".lev")
                {
                    try
                    {
                        File.WriteAllBytes("temp.lev", cf.Data);
                        Scene s = Scene.FromFile("temp.lev");
                        textBox4.Text = s.Info();
                        File.Delete("temp.lev");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }