Beispiel #1
0
        public static bool Tdb2Xml(string srcfile, string dstfile)
        {
            TextDataBase tdb = TextDataBase.LoadFromFile(srcfile);

            if (tdb == null)
            {
                return(false);
            }
            XmlDocument xmldoc  = new XmlDocument();
            XmlNode     tdbnode = xmldoc.CreateElement("TextDataBase");
            XmlNode     plat    = xmldoc.CreateElement("Platform");

            plat.InnerText = tdb.IsBigEndian ? "PS3" : "PC";
            tdbnode.AppendChild(plat);
            XmlNode linecount = xmldoc.CreateElement("StringCount");

            linecount.InnerText = tdb.LineCount.ToString();
            tdbnode.AppendChild(linecount);
            XmlNode languagecount = xmldoc.CreateElement("LanguageCount");

            languagecount.InnerText = tdb.LangCount.ToString();
            tdbnode.AppendChild(languagecount);
            XmlNode unknownval = xmldoc.CreateElement("Unknown");

            unknownval.InnerText = tdb.Unknown.ToString();
            tdbnode.AppendChild(unknownval);
            // fun starts here...
            for (int LangIndex = 0; LangIndex < tdb.LangCount; LangIndex++)
            {
                XmlNode langnode = xmldoc.CreateElement("Language" + LangIndex);
                for (int LineIndex = 0; LineIndex < tdb.LineCount; LineIndex++)
                {
                    XmlNode linenode = xmldoc.CreateElement("String" + LineIndex);
                    linenode.InnerText = tdb.Languages[LangIndex][LineIndex];
                    langnode.AppendChild(linenode);
                }
                tdbnode.AppendChild(langnode);
            }
            xmldoc.AppendChild(tdbnode);
            XmlWriterSettings settings = new XmlWriterSettings {
                Indent = true, NewLineChars = "\n"
            };
            XmlWriter writer = XmlWriter.Create(dstfile, settings);

            xmldoc.Save(writer);
            writer.Close();
            return(true);
        }
Beispiel #2
0
        public static bool Xml2Tdb(string srcfile, string dstfile, string overrideplatform = null)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(srcfile);
            TextDataBase tdb      = new TextDataBase();
            string       platform = "";

            if (overrideplatform != null)
            {
                platform = overrideplatform;
            }
            else
            {
                XmlNode plat = xmldoc.SelectSingleNode("//TextDataBase/Platform");
                if (plat != null)
                {
                    platform = plat.InnerText;
                }
            }

            if (platform.ToUpper() == "PS3")
            {
                tdb.IsBigEndian = true;
            }
            else if (platform.ToUpper() == "PC")
            {
                tdb.IsBigEndian = false;
            }
            else
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid platform.");
                return(false);
            }

            XmlNode lcnode = xmldoc.SelectSingleNode("//TextDataBase/StringCount");

            if (lcnode == null || !int.TryParse(lcnode.InnerText, out tdb.LineCount))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid string count.");
                return(false);
            }

            XmlNode lgnode = xmldoc.SelectSingleNode("//TextDataBase/LanguageCount");

            if (lgnode == null || !int.TryParse(lgnode.InnerText, out tdb.LangCount))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid language count.");
                return(false);
            }

            XmlNode unode = xmldoc.SelectSingleNode("//TextDataBase/Unknown");

            if (unode == null || !int.TryParse(unode.InnerText, out tdb.Unknown))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid 'unknown' value.");
                return(false);
            }

            tdb.InitializeArrayOfLanguages();

            for (int LangIndex = 0; LangIndex < tdb.LangCount; LangIndex++)
            {
                for (int LineIndex = 0; LineIndex < tdb.LineCount; LineIndex++)
                {
                    XmlNode CurrentLineNode = xmldoc.SelectSingleNode("//TextDataBase/Language" + LangIndex + "/String" + LineIndex);
                    if (CurrentLineNode != null)
                    {
                        tdb.Languages[LangIndex].Add(CurrentLineNode.InnerText);
                    }
                    else
                    {
                        tdb.Languages[LangIndex].Add("");
                    }
                }
            }
            return(tdb.SaveToFile(dstfile));
        }
Beispiel #3
0
        public static TextDataBase LoadFromFile(string tdbfile)
        {
            TextDataBase tdb = new TextDataBase();
            FileStream   fs  = null;

            try
            {
                fs = new FileStream(tdbfile, FileMode.Open);
                byte[] buff = new byte[4];
                fs.Seek(0, SeekOrigin.Begin);
                fs.Read(buff, 0, 4);
                if (System.Text.Encoding.ASCII.GetString(buff) != "#TDB")
                {
                    System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | Missing #TDB signature.");
                    fs.Close();
                    return(null);
                }
                int lcl = ReadInteger(fs, 4, false);
                int lcb = ReadInteger(fs, 4, true);
                lcl &= 0x0000FFFF;
                lcb &= 0x0000FFFF;
                if (lcl == lcb && lcb == 0)
                {
                    System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | TDB file is empty. LineCount = 0");
                    fs.Close();
                    return(null);
                }
                if (lcl == 0)
                {
                    tdb.IsBigEndian = true;
                    tdb.LineCount   = lcb;
                }
                else
                {
                    tdb.LineCount = lcl;
                }

                tdb.LangCount = ReadInteger(fs, 8, tdb.IsBigEndian);
                tdb.InitializeArrayOfLanguages();

                tdb.Unknown = ReadInteger(fs, 0xC, tdb.IsBigEndian);

                int rIndex = 0x10;

                for (int i = 0; i < tdb.LineCount; i++)
                {
                    int lineID = ReadInteger(fs, rIndex, tdb.IsBigEndian); // This is not used, but is counted.
                    System.Diagnostics.Debug.Print("TDB Line #" + lineID);
                    rIndex += 4;
                    //
                    for (int j = 0; j < tdb.LangCount; j++)
                    {
                        rIndex = GetStringFromStreamToList(fs, rIndex, tdb.Languages[j], tdb.IsBigEndian);
                    }
                }
                fs.Close();
                return(tdb);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | " + ex.GetType().Name + ": " + ex.Message);
                if (fs != null)
                {
                    fs.Close();
                }
                return(null);
            }
        }
Beispiel #4
0
        public static bool Xml2Tdb(string srcfile, string dstfile, string overrideplatform = null)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(srcfile);
            TextDataBase tdb = new TextDataBase();
            string platform = "";

            if (overrideplatform != null)
            {
                platform = overrideplatform;
            }
            else
            {
                XmlNode plat = xmldoc.SelectSingleNode("//TextDataBase/Platform");
                if (plat != null)
                    platform = plat.InnerText;
            }

            if (platform.ToUpper() == "PS3")
            {
                tdb.IsBigEndian = true;
            }
            else if (platform.ToUpper() == "PC")
            {
                tdb.IsBigEndian = false;
            }
            else
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid platform.");
                return false;
            }

            XmlNode lcnode = xmldoc.SelectSingleNode("//TextDataBase/StringCount");
            if (lcnode == null || !int.TryParse(lcnode.InnerText, out tdb.LineCount))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid string count.");
                return false;
            }

            XmlNode lgnode = xmldoc.SelectSingleNode("//TextDataBase/LanguageCount");
            if (lgnode == null || !int.TryParse(lgnode.InnerText, out tdb.LangCount))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid language count.");
                return false;
            }

            XmlNode unode = xmldoc.SelectSingleNode("//TextDataBase/Unknown");
            if (unode == null || !int.TryParse(unode.InnerText, out tdb.Unknown))
            {
                System.Diagnostics.Debug.Print("Xml2Tdb: missing or invalid 'unknown' value.");
                return false;
            }

            tdb.InitializeArrayOfLanguages();

            for (int LangIndex = 0; LangIndex < tdb.LangCount; LangIndex++)
            {
                for (int LineIndex = 0; LineIndex < tdb.LineCount; LineIndex++)
                {
                    XmlNode CurrentLineNode = xmldoc.SelectSingleNode("//TextDataBase/Language" + LangIndex + "/String" + LineIndex);
                    if (CurrentLineNode != null)
                    {
                        tdb.Languages[LangIndex].Add(CurrentLineNode.InnerText);
                    }
                    else
                        tdb.Languages[LangIndex].Add("");
                }
            }
            return tdb.SaveToFile(dstfile);
        }
Beispiel #5
0
        public static TextDataBase LoadFromFile(string tdbfile)
        {
            TextDataBase tdb = new TextDataBase();
            FileStream fs = null;
            try
            {
                fs = new FileStream(tdbfile, FileMode.Open);
                byte[] buff = new byte[4];
                fs.Seek(0, SeekOrigin.Begin);
                fs.Read(buff, 0, 4);
                if (System.Text.Encoding.ASCII.GetString(buff) != "#TDB")
                {
                    System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | Missing #TDB signature.");
                    fs.Close();
                    return null;
                }
                int lcl = ReadInteger(fs, 4, false);
                int lcb = ReadInteger(fs, 4, true);
                lcl &= 0x0000FFFF;
                lcb &= 0x0000FFFF;
                if (lcl == lcb && lcb == 0)
                {
                    System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | TDB file is empty. LineCount = 0");
                    fs.Close();
                    return null;
                }
                if (lcl == 0)
                {
                    tdb.IsBigEndian = true;
                    tdb.LineCount = lcb;
                }
                else
                    tdb.LineCount = lcl;

                tdb.LangCount = ReadInteger(fs, 8, tdb.IsBigEndian);
                tdb.InitializeArrayOfLanguages();

                tdb.Unknown = ReadInteger(fs, 0xC, tdb.IsBigEndian);

                int rIndex = 0x10;

                for (int i = 0; i < tdb.LineCount; i++)
                {
                    int lineID = ReadInteger(fs, rIndex, tdb.IsBigEndian); // This is not used, but is counted.
                    System.Diagnostics.Debug.Print("TDB Line #" + lineID);
                    rIndex += 4;
                    //
                    for (int j = 0; j < tdb.LangCount; j++)
                    {
                        rIndex = GetStringFromStreamToList(fs, rIndex, tdb.Languages[j], tdb.IsBigEndian);
                    }
                }
                fs.Close();
                return tdb;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print("TextDataBase.CreateFromFile | " + ex.GetType().Name + ": " + ex.Message);
                if(fs != null)
                    fs.Close();
                return null;
            }
        }