Ejemplo n.º 1
0
        //SECRET STUFF!
        public static List <string> ReadTranslatedRawText(string FileName)
        {
            List <string> TRText = null;

            if (File.Exists(Path.Combine("Ext\\EngText", Path.GetFileNameWithoutExtension(FileName) + ".rawtext")) == true)
            {
                return(TRText = CommonTextStuff.TextExtractor(Path.Combine("Ext\\EngText", Path.GetFileNameWithoutExtension(FileName) + ".rawtext")));
            }

            return(TRText);
        }
Ejemplo n.º 2
0
        public static List <string> ReadJAPText(string FileName)
        {
            List <string> JAPText = null;

            string JapanseTextFolder = null;

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DR1 (PSP)") || DRAT.tabControl1.SelectedTab.Text.Contains("DR1 (PSVITA)"))
            {
                JapanseTextFolder = "DR1PSVITA";
            }

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DR1 (PC)"))
            {
                JapanseTextFolder = "DR1PC";
            }

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DR2 (PSVITA)"))
            {
                JapanseTextFolder = "DR2PSVITA";
            }

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DR2 (PC)"))
            {
                JapanseTextFolder = "DR2PC";
            }

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DRAE (PSVITA)"))
            {
                JapanseTextFolder = "DRAEPSVITA";
            }

            if (DRAT.tabControl1.SelectedTab.Text.Contains("DRAE (PC)"))
            {
                JapanseTextFolder = "DRAEPC";
            }

            if (File.Exists(Path.Combine("Ext\\JapText", JapanseTextFolder, Path.GetFileNameWithoutExtension(FileName) + ".rawtext")) == true)
            {
                return(JAPText = CommonTextStuff.TextExtractor(Path.Combine("Ext\\JapText", JapanseTextFolder, Path.GetFileNameWithoutExtension(FileName) + ".rawtext")));
            }

            return(JAPText);
        }
Ejemplo n.º 3
0
        /* I'M LEAVING THE XML STUFF FOR COMPATIBILITY WITH OLDER VERSIONS OF DRAT */

        public static void ConvertXmlToPo(string SingleXML)
        {
            List <string> XMLOriginalSentences = null, XMLTranslatedSentences = null, XMLSpeakers = null, XMLComments = null, JAPText = null;

            using (FileStream TRANSLATEDXML = new FileStream(SingleXML, FileMode.Open, FileAccess.Read))
                using (StreamReader XMLStreamReader = new StreamReader(TRANSLATEDXML, Encoding.Unicode))
                {
                    string XmlText = XMLStreamReader.ReadToEnd();

                    XMLOriginalSentences   = CommonTextStuff.ExtractTextFromXML(XmlText, "<ORIGINAL N°", "</ORIGINAL N°", SingleXML);
                    XMLTranslatedSentences = CommonTextStuff.ExtractTextFromXML(XmlText, "<TRANSLATED N°", "</TRANSLATED N°", SingleXML);
                    XMLSpeakers            = CommonTextStuff.ExtractTextFromXML(XmlText, "<SPEAKER N°", "</SPEAKER N°", SingleXML);
                    XMLComments            = CommonTextStuff.ExtractTextFromXML(XmlText, "<COMMENT N°", "</COMMENT N°", SingleXML);
                }

            // If the user has checked "Add japanase texts", then extract the japanese text.
            if (DRAT.aDDJAPANESETEXTToolStripMenuItem.Checked == true)
            {
                JAPText = ReadJAPText(SingleXML);
            }

            //Read the language used by the user' OS, this way the editor can spellcheck the translation.
            System.Globalization.CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            Po po = new Po
            {
                Header = new PoHeader(DRAT.tabControl1.SelectedTab.Text, "your_email", currentCulture.Name)
            };

            try
            {
                for (int i = 0; i < XMLOriginalSentences.Count; i++)
                {
                    PoEntry entry = new PoEntry();

                    // "Speaker"
                    if (DRAT.hIDESPEAKERSToolStripMenuItem.Checked == false && XMLSpeakers.Count > 0 && XMLSpeakers[i] != null && XMLSpeakers[i] != "")
                    {
                        entry.Context = $"{i + 1:D4} | {XMLSpeakers[i]}";
                    }
                    else
                    {
                        entry.Context = $"{i + 1:D4}";
                    }

                    // "Original"
                    if (XMLOriginalSentences.Count > 0 && XMLOriginalSentences[i] != null && XMLOriginalSentences[i] != "")
                    {
                        entry.Original = XMLOriginalSentences[i];
                    }
                    else
                    {
                        entry.Original   = "[EMPTY_LINE]";
                        entry.Translated = "[EMPTY_LINE]";
                    }

                    // "Translated"
                    if (XMLTranslatedSentences.Count > 0 && XMLTranslatedSentences[i] != null && XMLTranslatedSentences[i] != "")
                    {
                        if (XMLOriginalSentences[i].Length == 1 || XMLOriginalSentences[i] == " \n" || XMLOriginalSentences[i] == "\n" || XMLOriginalSentences[i] == "..." || XMLOriginalSentences[i] == "…" || XMLOriginalSentences[i] == "...\n" || XMLOriginalSentences[i] == "…\n" || XMLOriginalSentences[i] == "\"...\"" || XMLOriginalSentences[i] == "\"…\"" || XMLOriginalSentences[i] == "\"...\n\"" || XMLOriginalSentences[i] == "\"…\n\"")
                        {
                            entry.Translated = XMLOriginalSentences[i];
                        }
                        else if (XMLTranslatedSentences[i] != XMLOriginalSentences[i])
                        {
                            entry.Translated = XMLTranslatedSentences[i];
                        }
                    }

                    // "Comments"
                    if (XMLComments.Count > 0 && XMLComments[i] != null && XMLComments[i] != "")
                    {
                        entry.TranslatorComment = XMLComments[i].Replace("\n", "\n# "); //The repalce is needed, otherwise PoEditor is not going to load correctly the jp text and the Repack is gonna crash.;
                    }

                    // "Japanese"
                    if (DRAT.aDDJAPANESETEXTToolStripMenuItem.Checked == true && JAPText != null && JAPText.Count > 0 && i < JAPText.Count)
                    {
                        if (JAPText[i] != "" && JAPText[i] != null)
                        {
                            entry.ExtractedComments = JAPText[i].Replace("\n", "\n#. "); //The repalce is needed, otherwise PoEditor is not going to load correctly the jp text and the Repack is gonna crash.
                        }
                        else
                        {
                            entry.ExtractedComments = "[EMPTY_LINE]";
                        }
                    }
                    else
                    {
                        entry.ExtractedComments = "JAPANESE LINE NOT FOUND";
                    }

                    po.Add(entry);
                }

                string NewPoAddress = Path.Combine(Path.GetDirectoryName(SingleXML), Path.GetFileNameWithoutExtension(SingleXML) + ".po");

                ConvertFormat.To <BinaryFormat>(po).Stream.WriteTo(NewPoAddress);
            }
            catch
            {
                MessageBox.Show("\"" + SingleXML + "\"'s structure appears to be corrupted. Please check the code tags' integrity.\n\nYou can use an older version of DRAT to extract again the XML from the original English or Japanese file and compare it with yours.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        public static void ExtractLIN(string LINAddress, string DestinationDir)
        {
            // Open file.LIN in FileStream.
            using (FileStream LIN = new FileStream(LINAddress, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader BinReaderLIN = new BinaryReader(LIN))
                {
                    uint Nparti = BinReaderLIN.ReadUInt32(); // Number of parts that make up the LIN.

                    // If the LIN has of 1 or 2 parts, continue.
                    // If the LIN has just 1 file that means that there is not text, just bytecode.
                    if (Nparti == 0x02 || Nparti == 0x01)
                    {
                        uint HeaderSize       = BinReaderLIN.ReadUInt32(),
                             SecondFileOffset = BinReaderLIN.ReadUInt32(), // The second file contains the text, the first file contains the bytecode.
                             LINSize          = (uint)LIN.Length,          // Calculate directly the size of the LIN instead of reading it from the file, this way the tool can work with LINs from PSP (PZ) as they are "incorrect".
                             NSentences       = 0;                         // Senteces within the file.

                        // If the beginning of the second file corresponds to the size of the file or equal to 0, than there are no sentences.
                        if (SecondFileOffset != LINSize && SecondFileOffset > 0)
                        {
                            LIN.Seek(SecondFileOffset, SeekOrigin.Begin);
                            NSentences = BinReaderLIN.ReadUInt32();
                        }

                        // If the file contains text or the user has nevertheless chosen to process files with no text, then continue.
                        if (NSentences > 0 || (NSentences <= 0 && DRAT.ignoreLINWoTextToolStripMenuItem.Checked == false))
                        {
                            if (Directory.Exists(DestinationDir) == false)
                            {
                                Directory.CreateDirectory(DestinationDir);
                            }

                            LIN.Seek(HeaderSize, SeekOrigin.Begin);                         // Moves at the beginning of the first file, the bytecode, which is located immediately after the header.
                            byte[] FirstFileBody = new byte[SecondFileOffset - HeaderSize]; // Will contains the bytecode.

                            LIN.Read(FirstFileBody, 0, FirstFileBody.Length);               // Insert the bytecode inside "FirstFileBody".

                            // File.bytecode's address.
                            string BytecodeAddress = Path.Combine(DestinationDir, Path.GetFileNameWithoutExtension(LINAddress) + ".bytecode");

                            // Makes a file called "FileName.bytecode" e saves the "FirstFileBody" in it.
                            using (FileStream bytecode = new FileStream(BytecodeAddress, FileMode.Create, FileAccess.Write))
                                bytecode.Write(FirstFileBody, 0, FirstFileBody.Length);

                            if (NSentences > 0)                                               // If there is text to extract, extract it.
                            {
                                byte[] SecondFileBody = new byte[LINSize - SecondFileOffset]; // Will contains all the text.

                                LIN.Read(SecondFileBody, 0, SecondFileBody.Length);           // Insert the text inside "SecondFileBody".

                                string RawTexAddress = Path.Combine(DestinationDir, Path.GetFileNameWithoutExtension(LINAddress) + ".rawtext");

                                // Create a file called "TextRaw.bin" and inserts all the contents of "SecondFileBody" in it.
                                using (FileStream TextRaw = new FileStream(RawTexAddress, FileMode.Create, FileAccess.Write))
                                    TextRaw.Write(SecondFileBody, 0, SecondFileBody.Length);

                                /* If the user has checked the "HIDE SPEAKERS box", then pass "null".
                                 * Null = don't store and don't print the speakers. */
                                if (DRAT.hIDESPEAKERSToolStripMenuItem.Checked == true)
                                {
                                    CommonTextStuff.MakePO(CommonTextStuff.TextExtractor(RawTexAddress), null, DestinationDir);
                                }
                                else
                                {
                                    CommonTextStuff.MakePO(CommonTextStuff.TextExtractor(RawTexAddress), BytecodeAddress, DestinationDir);
                                }

                                // Deletes FileName.rawtext.
                                File.Delete(RawTexAddress);
                                while (File.Exists(RawTexAddress))
                                {
                                }
                            }
                        }
                    }
                }
            }
        }