Пример #1
0
        static public int exportFile(string path)
        {
            StreamEx s         = new StreamEx(path, FileMode.Open, FileAccess.Read);
            Int32    textCount = s.ReadInt32BigEndian();

            Int32[] textOffsets = new Int32[textCount + 1];
            for (int i = 0; i < textCount; i++)
            {
                textOffsets[i] = s.ReadInt32BigEndian();
            }
            textOffsets[textCount] = (Int32)s.Length;

            string[] texts = new string[textCount];
            for (int i = 0; i < textCount; i++)
            {
                s.Position = textOffsets[i];
                texts[i]   = s.ReadString(textOffsets[i + 1] - textOffsets[i], _sourceEncoding);

                // 处理字符集差异
                texts[i] = convertStringToGBK(texts[i]);
            }

            Agemo.WriteFile(path + ".txt", _destEncoding, from txt in texts select txt + "{END}");

            return(textCount);
        }
Пример #2
0
        static public int exportTogFile(string path)
        {
            SQLiteConnection conn = new SQLiteConnection(string.Format("data source={0}", path));

            SQLiteDataAdapter da = new SQLiteDataAdapter(
                "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Japanese' " +
                "UNION ALL " +
                "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Text'"
                , conn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            if ((long)dt.Rows[0][0] == 1)
            {
                da = new SQLiteDataAdapter("select string from Japanese", conn);
                dt = new DataTable();
                da.Fill(dt);
            }
            else if ((long)dt.Rows[1][0] == 1)
            {
                da = new SQLiteDataAdapter("select english from text", conn);
                dt = new DataTable();
                da.Fill(dt);
            }
            else
            {
                throw new Exception("没有找到Japanese或Text表");
            }

            List <string> texts = new List <string>();

            foreach (DataRow dr in dt.Rows)
            {
//                 if (dr[0].ToString() == string.Empty)
//                 {
//                     continue;
//                 }
                texts.Add(convertStringToGBK(dr[0].ToString()));
            }

            if (texts.Count != 0)
            {
                Agemo.WriteFile(path + ".txt", _destEncoding, from txt in texts select txt + "{END}");
            }

            return(texts.Count);
        }
Пример #3
0
        public static void Export(string input)
        {
            StreamEx s = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            // txt count
            s.Position = 0x0e;
            UInt16 txtCount = s.ReadUInt16BigEndian();

            // section offset
            s.Position = 0x10;
            Int32 sec1Offset = s.ReadInt32BigEndian();
            Int32 sec2Offset = s.ReadInt32BigEndian();
            Int32 sec3Offset = s.ReadInt32BigEndian();

            // get text offset
            s.Position = sec1Offset;
            UInt16[] txtOffset = new UInt16[txtCount + 1];
            for (int i = 0; i < txtCount; i++)
            {
                s.Position  += 6;
                txtOffset[i] = s.ReadUInt16BigEndian();
            }
            txtOffset[txtCount] = (UInt16)s.Length;

            // get text
            string[] txtVal = new string[txtCount];
            for (int i = 0; i < txtCount; i++)
            {
                s.Position = txtOffset[i];
                txtVal[i]  = s.ReadStringWithNull(txtOffset[i + 1] - txtOffset[i] - 2, Encoding.BigEndianUnicode);

                for (int k = 0; k < _convertChar.Count; k++)
                {
                    txtVal[i] = txtVal[i].Replace(_convertChar[k].Key, _convertChar[k].Value);
                }
            }

            Agemo.WriteFile(input + ".txt", _agemoEncoding, from txt in txtVal select txt + "{END}");
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Count() == 0)
            {
                return;
            }

            BSDJPN   bsdjpn   = new BSDJPN();
            Encoding encoding = Encoding.GetEncoding("gbk");
            string   f        = args[0];

            if (f.ToLower().EndsWith(".sdbjpn"))
            {
                KeyValuePair <string, string>[] pairs = bsdjpn.Read(f);
                string ff = f.Substring(0, f.Length - 6);
                Agemo.WriteFile(ff + "idx", encoding, from p in pairs select p.Key);
                Agemo.WriteFile(ff + "txt", encoding, from p in pairs select p.Value + "{END}");
            }

            else if (f.ToLower().EndsWith(".txt"))
            {
                string   ff     = f.Substring(0, f.Length - 3);
                string[] keys   = Agemo.ReadFile(ff + "idx", encoding);
                string[] blocks = Agemo.ReadFile(f, encoding);

                KeyValuePair <string, string>[] pairs = keys.Select(
                    (key, idx) => new KeyValuePair <string, string>
                        (key, blocks[idx].Length >= 5 ? blocks[idx].Substring(0, blocks[idx].Length - 5) : blocks[idx]))
                                                        .ToArray();

                if (args.Count() >= 2)
                {
                    bsdjpn.AddConvertChar(args[1]);
                }

                bsdjpn.Write(ff + "SDBJPN", pairs);
            }
        }
Пример #5
0
        static public int exportFile(string path)
        {
            StreamEx ssource = new StreamEx(path, FileMode.Open, FileAccess.Read);

            Int32 header = ssource.ReadInt32BigEndian();

            if (header != 0x00444D47)
            {
                throw new Exception("不支持的文件头");
            }

            ssource.Position = 0x14;
            Int32 tagCount   = ssource.ReadInt32BigEndian();
            Int32 textCount  = ssource.ReadInt32BigEndian();
            Int32 textOffset = ssource.ReadInt32BigEndian() + tagCount * 8 + 0x30;

            ssource.Position = textOffset;

            List <string> texts = new List <string>();

            while (ssource.Position < ssource.Length)
            {
                Int64  curPos   = ssource.Position;
                string curToken = ssource.ReadString((int)(ssource.Length - ssource.Position), _sourceEncoding);
                ssource.Position = curPos + _sourceEncoding.GetByteCount(curToken) + 1;

                // 处理字符集差异
                foreach (KeyValuePair <string, string> kvp in _convertChar)
                {
                    curToken = curToken.Replace(kvp.Key, kvp.Value);
                }

                texts.Add(curToken);
            }
            Agemo.WriteFile(path + ".txt", _destEncoding, from txt in texts select txt + "{END}");

            return(texts.Count);
        }
Пример #6
0
        static public int exportFile(string path)
        {
            StreamEx s = new StreamEx(path, FileMode.Open, FileAccess.Read);

            List <string> texts = new List <string>();

            Int32 header = s.ReadInt32BigEndian();

            if (header == _fixHeaderType1)
            {
                Console.Write("[SETU]");
                Int32 textCount = s.ReadInt32();

                Int32[] textOffset = new Int32[textCount];
                for (int i = 0; i < textCount; i++)
                {
                    textOffset[i] = s.ReadInt32();
                }

                for (int i = 0; i < textCount; i++)
                {
                    string txt = "";
                    if (textOffset[i] != 0)
                    {
                        s.Position = textOffset[i];
                        txt        = readUnicodeString(s, 2);
                    }
                    texts.Add(txt);
                }
            }
            else if ((header >> 16) == _fixHeaderType2)
            {
                Console.Write("[0000]");
                s.Position = 2;
                while (s.Position < s.Length)
                {
                    texts.Add(readUnicodeString(s, 2));
                }
            }
            else if (header == _fixHeaderType3)
            {
                Console.Write("[TCRC]");
                Int32        textOffset = s.ReadInt32() + 8;
                List <Int32> indexes    = new List <Int32>();
                while (s.Position < textOffset)
                {
                    s.Position += 4;
                    indexes.Add(s.ReadInt32());
                }
                if (s.ReadInt32BigEndian() != 0x54455854) //TEXT
                {
                    throw new Exception("TEXT段错误");
                }

                Int32 nextBlockOffset = s.ReadInt32() + (Int32)s.Position;

                textOffset += 8;
                texts.Add("{TEXT}");
                for (int i = 0; i < indexes.Count; i++)
                {
                    s.Position = textOffset + indexes[i];
                    texts.Add(readUnicodeString(s, 4));
                }

                if (nextBlockOffset < s.Length)
                {
                    s.Position = nextBlockOffset;
                    if (s.ReadInt32BigEndian() == 0x4E504354) //NCPT
                    {
                        texts.Add("{NCPT}");
                        s.Position = s.ReadInt32() + s.Position;
                    }
                    if (s.ReadInt32BigEndian() == 0x4E414D45) //NAME
                    {
                        texts.Add("{NAME}");
                        Int32 nameBlockLength = s.ReadInt32();
                        s.Position += 2;
                        while (s.Position < s.Length)
                        {
                            texts.Add(readUnicodeString(s, 2));
                        }
                    }
                }
            }
            else
            {
                throw new Exception("不支持的文件头");
            }

            for (int i = 0; i < texts.Count; i++)
            {
                // 处理字符集差异
                foreach (KeyValuePair <string, string> kvp in _convertChar)
                {
                    texts[i] = texts[i].Replace(kvp.Key, kvp.Value);
                }
            }
            Agemo.WriteFile(path + ".txt", _destEncoding, from txt in texts select txt + "{END}");

            return(texts.Count);
        }