Example #1
0
        public static void Generate(string[] args)
        {
            string datatoolPath  = args.ElementAtOrDefault(1);
            string keyLinkFile   = args.ElementAtOrDefault(2);
            string outputFile    = args.ElementAtOrDefault(3);
            string overwatchPath = args.ElementAtOrDefault(4);

            // Return if one of the required arguments is missing.
            if (datatoolPath == null || outputFile == null)
            {
                Log.Write(LogLevel.Normal, syntax);
                return;
            }
            // Get the overwatch path.
            if (overwatchPath == null)
            {
                overwatchPath = "C:/Program Files (x86)/Overwatch";

                if (!Directory.Exists(overwatchPath))
                {
                    Log.Write(LogLevel.Normal, "Could not find a folder at the default Overwatch install location.");
                    Log.Write(LogLevel.Normal, syntax);
                    return;
                }
            }
            else if (!Directory.Exists(overwatchPath))
            {
                Log.Write(LogLevel.Normal, "Could not find a folder at " + overwatchPath + ".");
                Log.Write(LogLevel.Normal, syntax);
                return;
            }

            var datatool = new DataTool(datatoolPath, overwatchPath);

            XmlSerializer linkSerializer = new XmlSerializer(typeof(KeyLinkList));

            KeyLink[] keyLinks;
            using (var fileStream = File.OpenRead(keyLinkFile))
                keyLinks = ((KeyLinkList)linkSerializer.Deserialize(fileStream)).Methods;

            XmlSerializer serializer = new XmlSerializer(typeof(I18nLanguage));

            foreach (string lang in ProcLanguages)
            {
                // Dump the strings for the language.
                StringKeyGroup strings = new StringKeyGroup();
                datatool.DumpStrings(strings, lang, true, Log);

                I18nLanguage xml = new I18nLanguage();

                // Translate
                foreach (var keyword in Keywords())
                {
                    xml.Methods.Add(new I18nMethod(
                                        keyword,
                                        strings.ValueFromKeyAndLang(keyLinks.First(m => m.MethodName == keyword).Key, lang)
                                        ));
                }

                // Get the file
                string file = Path.Combine(outputFile, "i18n-" + lang + ".xml");

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                // Serialize
                using (var fileStream = File.Create(file))
                    using (StreamWriter writer = new StreamWriter(fileStream))
                        serializer.Serialize(writer, xml);

                Log.Write(LogLevel.Normal, "Finished " + lang + ".");
            }
        }
Example #2
0
        public static void GenerateKeyLink()
        {
            string datatoolPath  = "C:/Users/Deltin/Downloads/toolchain-release/DataTool.exe";
            string overwatchPath = "C:/Program Files (x86)/Overwatch";
            string previous      = "C:/Users/Deltin/Documents/GitHub/Overwatch-Script-To-Workshop/Deltinteger/Deltinteger/bin/Debug/netcoreapp3.0/Languages/key_links.xml";

            Console.OutputEncoding = System.Text.Encoding.Unicode;

            DataTool       datatool = new DataTool(datatoolPath, overwatchPath);
            StringKeyGroup strings  = new StringKeyGroup();

            datatool.DumpStrings(strings, "enUS", true, Log);
            datatool.DumpStrings(strings, "esES", false, Log);
            datatool.DumpStrings(strings, "itIT", false, Log);

            List <KeyLink> links      = new List <KeyLink>();
            var            serializer = new XmlSerializer(typeof(KeyLinkList));

            if (previous != null)
            {
                using (var lastStream = File.OpenRead(previous))
                {
                    var last = ((KeyLinkList)serializer.Deserialize(lastStream)).Methods;
                    links.AddRange(last);
                }
            }

            foreach (var keyword in Keywords())
            {
                if (!links.Any(link => link.MethodName.ToLower() == keyword.ToLower()))
                {
                    GetKeyLink(links, keyword, 5, strings);
                }
            }

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "")
                {
                    break;
                }

                KeyLink link = links.FirstOrDefault(l => l.MethodName == input);
                if (link == null)
                {
                    Console.WriteLine($"No keywords by that name exists.");
                }
                else
                {
                    links.Remove(link);
                    GetKeyLink(links, input, 5, strings);
                }
            }

            Console.Write("Save key links to file: ");
            string saveAt = Console.ReadLine();

            using (var fileStream = File.Create(saveAt))
                using (StreamWriter writer = new StreamWriter(fileStream))
                    serializer.Serialize(writer, new KeyLinkList(links.ToArray()));
        }