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); }
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); }
public static void Import(string input) { StreamEx s = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read); string[] txtVal = Agemo.ReadFile(input + ".txt", _agemoEncoding); StreamEx si = new StreamEx(input + ".imp", System.IO.FileMode.Create, System.IO.FileAccess.Write); // section offset s.Position = 0x10; Int32 sec1Offset = s.ReadInt32BigEndian(); Int32 sec2Offset = s.ReadInt32BigEndian(); Int32 sec3Offset = s.ReadInt32BigEndian(); // before text data s.Position = 0; byte[] beforeText = s.Read(sec3Offset); si.Write(beforeText); si.Flush(); // text UInt16[] txtOffset = new UInt16[txtVal.Length]; for (int i = 0; i < txtVal.Length; i++) { txtOffset[i] = (UInt16)si.Position; txtVal[i] = txtVal[i].Substring(0, txtVal[i].Length - 5); for (int k = 0; k < _convertChar.Count; k++) { txtVal[i] = txtVal[i].Replace(_convertChar[k].Value, _convertChar[k].Key); } for (int j = 0; j < txtVal[i].Length; j++) { si.WriteUInt16BigEndian((UInt16)txtVal[i][j]); } si.WriteUInt16(0); } // text offset si.Position = sec1Offset; for (int i = 0; i < txtOffset.Length; i++) { si.Position += 6; si.WriteUInt16BigEndian(txtOffset[i]); } si.Close(); }
static public int importFile(string path) { string[] texts = Agemo.ReadFile(path + ".txt", _destEncoding); 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; StreamEx sdest = new StreamEx(path + ".imp", System.IO.FileMode.Create, System.IO.FileAccess.Write); ssource.Position = 0; sdest.WriteFromStream(ssource, textOffset); for (int i = 0; i < texts.Length; i++) { texts[i] = texts[i].Remove(texts[i].Length - 5); // 处理字符集差异 foreach (KeyValuePair <string, string> kvp in _convertChar) { texts[i] = texts[i].Replace(kvp.Value, kvp.Key); } sdest.WriteString(texts[i], _sourceEncoding.GetByteCount(texts[i]) + 1, _sourceEncoding); } Int32 textLength = (int)(sdest.Position - textOffset); sdest.Position = 0x20; sdest.WriteInt32BigEndian(textLength); sdest.Close(); return(texts.Length); }
static public int importFile(string path) { string[] texts = Agemo.ReadFile(path, _destEncoding); StreamEx s = new StreamEx(path + ".scs", System.IO.FileMode.Create, System.IO.FileAccess.Write); s.WriteInt32BigEndian(texts.Length); s.Position += texts.Length * 4; Int32[] textOffset = new Int32[texts.Length]; for (int i = 0; i < texts.Length; i++) { texts[i] = texts[i].Remove(texts[i].Length - 5); textOffset[i] = (Int32)s.Position; // 处理字符集差异 foreach (KeyValuePair <string, string> kvp in _convertChar) { texts[i] = texts[i].Replace(kvp.Value, kvp.Key); } char[] chrs = texts[i].ToCharArray(); for (int j = 0; j < chrs.Length; j++) { if (_dicConvert.ContainsKey(chrs[j])) { chrs[j] = _dicConvert[chrs[j]]; } } s.Write(_sourceEncoding.GetBytes(chrs)); s.WriteByte(0); //s.WriteString(texts[i], _sourceEncoding.GetByteCount(texts[i]) + 1, _sourceEncoding); } s.Position = 4; for (int i = 0; i < textOffset.Length; i++) { s.WriteInt32BigEndian(textOffset[i]); } return(texts.Length); }
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}"); }
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); } }
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); }
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); }
static public int importFile(string path) { string[] texts = Agemo.ReadFile(path + ".txt", _destEncoding); for (int i = 0; i < texts.Length; i++) { texts[i] = texts[i].Remove(texts[i].Length - 5); // 处理字符集差异 foreach (KeyValuePair <string, string> kvp in _convertChar) { texts[i] = texts[i].Replace(kvp.Value, kvp.Key); } } StreamEx ssource = new StreamEx(path, FileMode.Open, FileAccess.Read); StreamEx sdest = new StreamEx(path + ".imp", System.IO.FileMode.Create, System.IO.FileAccess.Write); Int32 header = ssource.ReadInt32BigEndian(); if (header == _fixHeaderType1) { Console.Write("[SETU]"); sdest.WriteInt32BigEndian(_fixHeaderType1); sdest.WriteInt32(texts.Length); Int32[] textOffset = new Int32[texts.Length]; for (int i = 0; i < texts.Length; i++) { sdest.WriteInt32(0); // 长度占位写0 } for (int i = 0; i < texts.Length; i++) { if (texts[i].Length == 0) { textOffset[i] = 0; continue; } textOffset[i] = (Int32)sdest.Position; // 文本偏移量 sdest.Write(_sourceEncoding.GetBytes(texts[i])); sdest.WriteInt16(0); // 结束0 } ssource.Position = ssource.Length - 139; sdest.WriteFromStream(ssource, 139); sdest.Position = 8; for (int i = 0; i < textOffset.Length; i++) { sdest.WriteInt32(textOffset[i]); } } else if ((header >> 16) == _fixHeaderType2) { Console.Write("[0000]"); sdest.WriteInt16(0); for (int i = 0; i < texts.Length; i++) { sdest.Write(_sourceEncoding.GetBytes(texts[i])); sdest.WriteInt16(0); } } else if (header == _fixHeaderType3) { Console.Write("[TCRC]"); Int32 textBlockOffset = ssource.ReadInt32() + 8; // 指向"TEXT" ssource.Position = 0; sdest.WriteFromStream(ssource, textBlockOffset); // 写至索引结束 sdest.WriteFromStream(ssource, 4); // 写入"TEXT" Int32 sourceTextLength = ssource.ReadInt32(); // 原文本段长度 sdest.WriteInt32(0); List <Int32> textIndexes = new List <Int32>(); if (texts[0] != "{TEXT}") { throw new Exception("文本分段错误"); } int iText = 1; for (; iText < texts.Length && texts[iText] != "{NCPT}" && texts[iText] != "{NAME}"; iText++) { textIndexes.Add((Int32)sdest.Position - textBlockOffset - 8); // 获取偏移 sdest.Write(_sourceEncoding.GetBytes(texts[iText])); // 写入文本 sdest.WriteInt32(0); // 写入0结尾 } Int32 destTextLength = (Int32)sdest.Position - textBlockOffset - 8; // 文本段长度 sdest.Position = 8; for (int i = 0; i < textIndexes.Count; i++) { sdest.Position += 4; sdest.WriteInt32(textIndexes[i]); } if (sdest.Position != textBlockOffset) { throw new Exception("文本段写入失败"); } sdest.Position += 4; sdest.WriteInt32(destTextLength); if (iText < texts.Length) { ssource.Position = textBlockOffset + 8 + sourceTextLength; sdest.Position = textBlockOffset + 8 + destTextLength; if (texts[iText] == "{NCPT}") { ssource.Position += 4; Int32 ncptLength = ssource.ReadInt32(); // get ncpt block length ssource.Position -= 8; sdest.WriteFromStream(ssource, ncptLength + 8); iText++; } if (texts[iText] == "{NAME}") { sdest.WriteInt32BigEndian(0x4E414D45); Int32 nameBlockLengthPosition = (Int32)sdest.Position; sdest.WriteInt32(0); // 长度占位 sdest.WriteInt16(0); for (iText = iText + 1; iText < texts.Length; iText++) { sdest.Write(_sourceEncoding.GetBytes(texts[iText])); sdest.WriteInt16(0); } Int32 nameBlockLength = (Int32)sdest.Position - nameBlockLengthPosition - 4; sdest.Position = nameBlockLengthPosition; sdest.WriteInt32(nameBlockLength); } } } else { throw new Exception("不支持的文件头"); } sdest.Close(); return(texts.Length); }