//============================================================ // <T>资源导出按钮事件处理。</T> //============================================================ private void tsbResourceExport_Click(object sender, EventArgs e) { string directory = RMobileManager.MapTileConsole.DirectoryExport; // foreach (FMbMapTileCatalog tileCatalog in RMobileManager.MapTileConsole.MapTileCatalogs) { foreach (FMbMapTile tile in tileCatalog.MapTiles) { int id = tile.Id; string code = "0" + id; Bitmap bitmap = tile.Resource; int width = bitmap.Width; int height = bitmap.Height; FByteFile file = new FByteFile(); file.WriteUint16((ushort)width); file.WriteUint16((ushort)height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color color = bitmap.GetPixel(x, y); file.WriteUint8(color.R); file.WriteUint8(color.G); file.WriteUint8(color.B); file.WriteUint8(color.A); } } file.SaveFile(directory + "/" + code + ".ser"); } } MessageBox.Show("导出完成!"); }
protected bool ReadOptionalImport(FByteFile file) { FModuleInfoCollection modules = _import.Modules; modules.Clear(); SImageDataDirectory idd = _ntHeader.OptionalHeader.DataDirectory[(int)EImageDirectoryEntry.Import]; if (idd.VirtualAddress == 0) { return(false); } // Read modules int vaddress = ConvertRva(idd.VirtualAddress); int size = Marshal.SizeOf(typeof(SImageImportDescriptor)); while (true) { SImageImportDescriptor impDesc = (SImageImportDescriptor)file.GetStruct(vaddress, typeof(SImageImportDescriptor)); if (impDesc.Name == 0) { break; } FModuleInfo module = new FModuleInfo(); module.NameAddress = impDesc.Name; module.Name = file.GetString(ConvertRva(impDesc.Name)); module.FirstThunk = impDesc.FirstThunk; module.OriginalFirstThunk = impDesc.OriginalFirstThunk; ReadTrunks(file, module); modules.Push(module); vaddress += size; } return(true); }
//============================================================ // <T>从文件中加载数据。</T> //============================================================ public void LoadFile(string fileName) { Clear(); using (FByteFile file = new FByteFile(fileName)) { Unserialize(file); } }
//============================================================ // <T>序列化内容到输出流。</T> // // @param output 输出流 //============================================================ public void SerializeFile(string fileName) { FByteFile file = new FByteFile(); Serialize(file); file.SaveFile(fileName); }
//============================================================ // <T>序列化信息文件。</T> // // @param fileName 路径 //============================================================ public void SerializeFile(string fileName) { using (FByteFile file = new FByteFile()) { Serialize(file); file.SaveFile(fileName); } }
//============================================================ // <T>压缩数据文件。</T> // // @param fileName 文件名称 //============================================================ public void Compress(string fileName) { // 写入文件 using (FByteFile file = new FByteFile()) { byte[] data = CompressBytes(); file.Append(data); file.SaveFile(fileName); } }
//============================================================ // <T>压缩数据保存为指定文件。</T> // // @param fileName 文件名称 //============================================================ public void Compress(string fileName) { // 建立目录 RDirectory.MakeDirectoriesForFile(fileName); // 输出文件 byte[] data = InnerCompress(_memory, 0, _length); using (FByteFile file = new FByteFile()) { file.Assign(data, 0, data.Length); file.SaveFile(fileName); } }
//============================================================ // <T>分块压缩保存为字节数组指定文件。</T> // // @param fileName 文件名称 // @param blockSize 分块大小 //============================================================ public void BlockCompress(string fileName, int blockSize) { // 检查参数 if (null == fileName) { throw new FFatalException("File name is null."); } // 存储文件 using (FByteFile file = new FByteFile()) { BlockCompress(file, blockSize); file.SaveFile(fileName); } }
//============================================================ // <T>序列化。</T> //============================================================ public void Serialize() { string saveFile = RMoCommon.ParseEnvironment("${resource.root}") + "\\db\\map.db"; FByteFile file = new FByteFile(); file.WriteInt16((short)_maps.Count); foreach (FMbMap map in _maps) { map.Serialize(file); } file.SaveFile(saveFile); }
//============================================================ // <T>根据指定模式导出数据。</T> // // @param modeCd 导出模式 //============================================================ public override void Export(ERsExportMode modeCd) { // 打开资源 Open(); //............................................................ string exportDirectory = RContent2dManager.ResourceConsole.ExportDirectory + "\\sd"; //............................................................ FByteFile file = new FByteFile(); file.LoadFile(_fileName); file.SaveFile(exportDirectory + "\\" + Code + ".mp3"); //............................................................ _logger.Debug(this, "Export", "Export sound resource. (type_name={0}, code={1})", _typeName, _code); }
protected bool ReadSections(FByteFile file) { uint address = _dosHeader.e_lfanew + (uint)Marshal.SizeOf(typeof(SImageNtHeaders)); int count = _ntHeader.FileHeader.NumberOfSections; _sections = new SImageSectionHeader[count]; uint size = (uint)Marshal.SizeOf(typeof(SImageSectionHeader)); for (int n = 0; n < count; n++) { _sections[n] = (SImageSectionHeader)file.GetStruct((int)address, typeof(SImageSectionHeader)); address += size; } return(true); }
//============================================================ // <T>序列化为文件。</T> // // @param fileName 文件名 //============================================================ public void SerializeFile(string fileName) { FByteFile file = new FByteFile(); // 追加节点 foreach (FXmlElement element in _element.Elements) { if (element is FXmlNode) { element.Serialize(file); } } // 保存文件 file.SaveFile(fileName); }
//============================================================ // <T>根据指定模式导出数据。</T> // // @param modeCd 导出模式 //============================================================ public override void Export(ERsExportMode modeCd) { // 打开资源 Open(); //............................................................ string exportFileName = RContent3dManager.ThemeConsole.ExportDirectory + "\\" + Code + ".ser"; //............................................................ // 序列化数据 FByteFile file = new FByteFile(); Serialize(file); file.SaveFile(exportFileName); //............................................................ // 释放资源 Dispose(); _logger.Debug(this, "Export", "Export theme success. (file_name={0})", exportFileName); }
//============================================================ // <T>加载文件夹信息</T> // // @param config 文件路径。 //============================================================ public void ExportAll() { // 加载文件 FByteFile file = new FByteFile(); file.WriteInt32(_frames.Count); foreach (INamePair <FRcFrame> pair in _frames) { FRcFrame frame = pair.Value; // 打开顶层容器 frame.Open(); // 序列化顶层容器 frame.Serialize(file); } // 保存文件 file.SaveFile(_exportFileName); }
//============================================================ // <T>序列化数据。</T> //============================================================ public override void Export(ERsExportMode modeCd) { // 打开资源 Open(); //............................................................ string exportFileName = RContent3dManager.SenceConsole.ExportDirectory + "\\" + Code + ".ser"; //............................................................ // 序列化数据 FByteFile file = new FByteFile(); Serialize(file); file.SaveFile(exportFileName); //............................................................ // 释放资源 Dispose(); _logger.Debug(this, "Export", "Export model success. (file_name={0})", exportFileName); //// 打开资源 //Open(); ////............................................................ //string exportDeflateDirectory = RContent3dManager.ContentConsole.ExportDeflateDirectory + "\\p3.sc"; //string exportLzmaDirectory = RContent3dManager.ContentConsole.ExportLzmaDirectory + "\\p3.sc"; //string code = Code; //if (_techniqueName != "config") { // code = Code + "." + _techniqueName; //} ////............................................................ //// 序列化数据 //FByteStream stream = new FByteStream(); //Serialize(stream); ////............................................................ //// 保存Deflate数据 //using (FRsCompressFile file = new FRsCompressFile(ERsCompress.Deflate, stream, RResourceManager.CompressBlockSplit)) { // byte[] data = file.CompressBytes(); // RFile.WriteAllBytes(exportDeflateDirectory + "/sc_" + code + ".swf", data); //} ////............................................................ //// 保存LZMA数据 //using (FRsCompressFile file = new FRsCompressFile(ERsCompress.Lzma, stream, RResourceManager.CompressBlockSplit)) { // byte[] data = file.CompressBytes(); // RFile.WriteAllBytes(exportLzmaDirectory + "/sc_" + code + ".swf", data); //} ////............................................................ //// 释放资源 //Dispose(); }
//============================================================ // <T>根据指定模式导出数据。</T> // // @param modeCd 导出模式 //============================================================ public override void Export(ERsExportMode modeCd) { // 打开资源 Open(); //............................................................ FRsResourceConsole resourceConsole = RContent2dManager.ResourceConsole; string exportDirectory = resourceConsole.ExportDirectory; string fileName = exportDirectory + "\\" + _code + ".ser"; //............................................................ // 序列化数据 FByteFile file = new FByteFile(); Serialize(file); file.SaveFile(fileName); //............................................................ // 释放资源 Dispose(); _logger.Debug(this, "Export", "Export picture resource. (type_name={0}, code={1})", _typeName, _code); }
//============================================================ // <T>从文件中加载所有信息。</T> //============================================================ public void RestoreFiles() { // 保存属性 string configName = RFile.MakeFileName(_storagePath, "applications.ser"); FByteFile file = new FByteFile(configName); // 写入个数 int count = file.ReadInt32(); // 保存所有程序信息 for (int n = 0; n < count; n++) { FApplicationInfo info = new FApplicationInfo(); info.Name = file.ReadString(); // 保存程序信息 string fileName = RFile.MakeFileName(_storagePath, info.Name + ".ser"); info.LoadFile(fileName); _infos.Push(info); _activeInfo = info; } }
//============================================================ // <T>存储所有信息到文件中。</T> //============================================================ public void StoreFiles() { // 保存属性 FByteFile file = new FByteFile(); // 写入个数 int count = _infos.Count; file.WriteInt32(count); // 保存所有程序信息 for (int n = 0; n < count; n++) { FApplicationInfo info = _infos.Get(n); file.WriteString(info.Name); // 保存程序信息 string fileName = RFile.MakeFileName(_storagePath, info.Name + ".ser"); info.SaveFile(fileName); } // 保存文件 string configName = RFile.MakeFileName(_storagePath, "applications.ser"); file.SaveFile(configName); }
//============================================================ // <T>压缩方法</T> //============================================================ public void NotCompress(int size) { if (0 == size) { throw new FFatalException("Size is zero."); } // 构建缓冲数据 byte[] bytes = new byte[_length + RInt.SIZE_16K]; FByteFile file = new FByteFile(); // 计算分割块数 int splitCount = _length / size; if (0 != (_length % size)) { splitCount++; } // 写入压缩前数据总长度 file.WriteInt32(_length); // 写入分割块数 file.WriteInt32(splitCount); // 分段压缩数据 //int position = 0; int remain = _length; for (int n = 0; n < splitCount; n++) { //int compressLength = RCompressLzma.Compress(bytes,0,bytes.Length,_memory,position,Math.Min(size,remain)); //if(0 == compressLength) { // throw new FFatalException("Compress failure. (compress_length={0})",compressLength); //} //position += size; //remain -= size; //// 输出压缩后数据 //file.WriteInt32(compressLength); //file.WriteBytes(bytes,0,compressLength); } Clear(); WriteBytes(file.ToArray(), 0, file.Length); }
protected bool ReadTrunks(FByteFile file, FModuleInfo module) { // Trunk int ftSize = Marshal.SizeOf(typeof(SImageThunkData32)); int pOrgFt = ConvertRva(module.OriginalFirstThunk); int pFt = ConvertRva(module.FirstThunk); while (true) { SImageThunkData32 origThunk = (SImageThunkData32)file.GetStruct(pOrgFt, typeof(SImageThunkData32)); SImageThunkData32 realThunk = (SImageThunkData32)file.GetStruct(pFt, typeof(SImageThunkData32)); if (origThunk.Function == 0) { break; } if ((origThunk.Ordinal & 0x80000000) == 0x80000000) { break; } // Read name SImageImportByName impName = (SImageImportByName)file.GetStruct(ConvertRva(origThunk.AddressOfData), typeof(SImageImportByName)); if (impName.Name[0] == 0) { break; } // TrunkInfo FTrunkInfo trunk = new FTrunkInfo(); trunk.Name = RAscii.GetString(impName.Name); trunk.Address = origThunk.Function; trunk.Entry = (IntPtr)realThunk.Function; trunk.Hint = impName.Hint; module.Trunks.Push(trunk); // Loop pOrgFt += ftSize; pFt += ftSize; } return(true); }
protected void ReadOptionalExport(FByteFile file) { _export.Clear(); FFunctionInfos functions = _export.Functions; SImageDataDirectory idd = _ntHeader.OptionalHeader.DataDirectory[(int)EImageDirectoryEntry.Export]; if (idd.VirtualAddress != 0) { SImageExportDirectory imgExp = (SImageExportDirectory)file.GetStruct(ConvertRva(idd.VirtualAddress), typeof(SImageExportDirectory)); _export.Data = imgExp; _export.Name = file.GetString(ConvertRva(imgExp.Name)); // Read function int funcCount = imgExp.NumberOfFunctions; int funcAddr = ConvertRva(imgExp.AddressOfFunctions); for (int n = 0; n < funcCount; n++, funcAddr += RInt.BYTE_SIZE) { FFunctionInfo function = new FFunctionInfo(); function.FunctionIndex = (int)(n + imgExp.Base); function.FunctionAddress = file.GetUint32(funcAddr); function.FunctionAddressRva = ConvertRva(function.FunctionAddress); functions.Push(function); } // Read function names int nameCount = imgExp.NumberOfNames; int nameAddr = ConvertRva(imgExp.AddressOfNames); int nameOrdAddr = ConvertRva(imgExp.AddressOfNameOrdinals); for (int n = 0; n < nameCount; n++, nameAddr += RInt.BYTE_SIZE, nameOrdAddr += RShort.BYTE_SIZE) { int funcIndex = file.GetUint16(nameOrdAddr); FFunctionInfo function = functions[funcIndex]; function.NameAddress = file.GetUint32(nameAddr); function.NameAddressRva = ConvertRva(function.NameAddress); function.Name = file.GetString(function.NameAddressRva); } } }
public bool LoadFile(string filename) { FByteFile file = new FByteFile(filename); _memory = file; // DosHead _dosHeader = (SImageDosHeader)file.GetStruct(0, typeof(SImageDosHeader)); if (_dosHeader.e_magic != (uint)EImageSignature.Dos) { return(false); } // NtHead _ntHeader = (SImageNtHeaders)file.GetStruct((int)_dosHeader.e_lfanew, typeof(SImageNtHeaders)); if (_ntHeader.Signature != (uint)EImageSignature.Nt) { return(false); } // Module ReadSections(file); ReadOptionalExport(file); ReadOptionalImport(file); // Success return(true); }
//============================================================ // <T>数据反序列化文件。</T> // // @param fileName 文件名称 //============================================================ public void DataUnserializeFile(string fileName) { using (FByteFile file = new FByteFile(fileName)) { _mesh.DataUnserialize(file); } }
//============================================================ // <T>解压文件信息。</T> // // @param fileName 路径 //============================================================ public void UnserializeFile(string fileName) { using (FByteFile file = new FByteFile(fileName)) { Unserialize(file); } }