Exemplo n.º 1
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.");
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
        private void actionSave_Click(object sender, EventArgs e)
        {
            //if number of lines changed, ask user if he still wants to save
            if (langBox.Lines.Length != linesOnLoad && linesOnLoad != 0)
            {
                if (MessageBox.Show($"{msg1}\r\n{msg2}", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                lng = LNG.FromText(langBox.Lines);
                lng.Save(sfd.FileName);
                linesOnLoad = lng.Entries.Count;
            }
        }