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); }
private void Write(ZeroLengthStreamPasser sp, KeyValuePair <string, string>[] text) { StreamEx s = sp.GetStream(); s.Position = 0; Int32 header = 0x8; Int32 count = text.Length; s.WriteInt32BigEndian(header); s.WriteInt32BigEndian(count); Encoding encoding = Encoding.GetEncoding("utf-8"); Int32[] keyaddresses = new Int32[count]; Int32[] blockaddress = new Int32[count]; s.Position = 0x8 + count * 8; for (int i = 0; i < count; i++) { if (text[i].Key.Length == 0) { keyaddresses[i] = 0; } else { keyaddresses[i] = (Int32)s.Position; s.WriteString(text[i].Key, text[i].Key.Length + 1, encoding); } if (text[i].Value.Length == 0) { blockaddress[i] = 0; } else { blockaddress[i] = (Int32)s.Position; string txt = text[i].Value; for (int k = 0; k < _convertChar.Count; k++) { txt = txt.Replace(_convertChar[k].Value, _convertChar[k].Key); } char[] chrs = txt.ToCharArray(); for (int j = 0; j < chrs.Length; j++) { if (_dicConvert.ContainsKey(chrs[j])) { chrs[j] = _dicConvert[chrs[j]]; } } s.Write(encoding.GetBytes(chrs)); s.WriteByte(0); //s.WriteString(txt.ToString(), encoding.GetByteCount(txt) + 1, encoding); } } s.Position = 0x8; for (int i = 0; i < count; i++) { s.WriteInt32BigEndian((keyaddresses[i] == 0) ? 0 : (keyaddresses[i] - (Int32)s.Position)); s.WriteInt32BigEndian((blockaddress[i] == 0) ? 0 : (blockaddress[i] - (Int32)s.Position)); } }