public static void RecoverFont(Stream lstFileStream, Stream bitmapFileStream, Stream fontStream) { BinaryReader binaryReader = new BinaryReader(fontStream); int num = binaryReader.ReadInt32(); string data = ""; data += num + "\n"; for (int i = 0; i < num; i++) { data += binaryReader.ReadChar() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\t"; data += binaryReader.ReadSingle() + "\n"; } data += binaryReader.ReadSingle() + "\n"; data += binaryReader.ReadSingle() + "\t" + binaryReader.ReadSingle() + "\n"; data += binaryReader.ReadSingle() + "\n"; data += binaryReader.ReadChar(); lstFileStream.Write(Encoding.UTF8.GetBytes(data), 0, Encoding.UTF8.GetBytes(data).Length); Texture2DHandler.RecoverTexture2D(bitmapFileStream, fontStream); }
public void Load(List <PakInfo> listFileStream, string pakDirectory) { if (!Directory.Exists(pakDirectory)) { Directory.CreateDirectory(pakDirectory); } foreach (PakInfo pakContentFile in listFileStream) { Stream fileStream; switch (pakContentFile.typeName) { case "System.String": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.txt"); TextHandler.RecoverText(fileStream, pakContentFile.fileStream); break; case "System.Xml.Linq.XElement": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.xml"); TextHandler.RecoverText(fileStream, pakContentFile.fileStream); break; case "Engine.Media.StreamingSource": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.ogg"); pakContentFile.fileStream.CopyTo(fileStream); break; case "Engine.Graphics.Texture2D": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.png"); Texture2DHandler.RecoverTexture2D(fileStream, pakContentFile.fileStream); break; case "Engine.Audio.SoundBuffer": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.wav"); SoundHandler.RecoverSound(fileStream, pakContentFile.fileStream); break; case "Engine.Graphics.Model": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.dae"); ModelHandler.RecoverModel(fileStream, pakContentFile.fileStream); //pakContentFile.fileStream.CopyTo(fileStream); break; case "Engine.Graphics.Shader": fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.shader"); pakContentFile.fileStream.CopyTo(fileStream); break; case "Engine.Media.BitmapFont": try { fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.lst"); Stream bitmapStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.png"); FontHandler.RecoverFont(fileStream, bitmapStream, pakContentFile.fileStream); bitmapStream.Dispose(); } catch { pakContentFile.fileStream.Position = 0; fileStream = CreateFile($"{pakDirectory}/{pakContentFile.fileName}.font"); pakContentFile.fileStream.CopyTo(fileStream); } break; default: throw new Exception("发现无法识别的文件类型:" + pakContentFile.typeName + "\t文件名称:" + pakContentFile.fileName); } fileStream.Dispose(); pakContentFile.fileStream.Dispose(); } }