Exemple #1
0
        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();
            }
        }
Exemple #2
0
        public Stream Load(string fileName, string typeName)
        {
            try
            {
                MemoryStream memoryStream = new MemoryStream();
                FileStream   fileStream;
                switch (typeName)
                {
                case "System.String":
                    fileStream = File.OpenRead(fileName + ".txt");
                    TextHandler.WriteText(memoryStream, fileStream);
                    break;

                case "System.Xml.Linq.XElement":
                    fileStream = File.OpenRead(fileName + ".xml");
                    TextHandler.WriteText(memoryStream, fileStream);
                    break;

                case "Engine.Media.StreamingSource":
                    fileStream = File.OpenRead(fileName + ".ogg");
                    fileStream.CopyTo(memoryStream);
                    break;

                case "Engine.Graphics.Model":
                    fileStream = File.OpenRead(fileName + ".dae");
                    ModelHandler.WriteModel(memoryStream, fileStream);
                    //fileStream.CopyTo(memoryStream);
                    break;

                case "Engine.Graphics.Shader":
                    fileStream = File.OpenRead(fileName + ".shader");
                    fileStream.CopyTo(memoryStream);
                    break;

                case "Engine.Audio.SoundBuffer":
                    fileStream = File.OpenRead(fileName + ".wav");
                    SoundHandler.WriteSound(memoryStream, fileStream);
                    break;

                case "Engine.Graphics.Texture2D":
                    fileStream = File.OpenRead(fileName + ".png");
                    Texture2DHandler.WriteTexture2D(memoryStream, fileStream);
                    break;

                case "Engine.Media.BitmapFont":
                    try
                    {
                        fileStream = File.OpenRead(fileName + ".lst");
                    }
                    catch
                    {
                        fileStream = File.OpenRead(fileName + ".font");
                        fileStream.CopyTo(memoryStream);
                        break;
                    }
                    FileStream bitmapStream = File.OpenRead(fileName + ".png");
                    FontHandler.WriteFont(memoryStream, fileStream, bitmapStream);
                    bitmapStream.Dispose();
                    break;

                default:
                    throw new Exception("发现不能识别的文件 :" + fileName + "\n文件类型 :" + typeName);
                }
                fileStream.Dispose();
                memoryStream.Position = 0L;
                return(memoryStream);
            }
            catch (Exception e)
            {
                throw new Exception("文件写入错误 :" + fileName + "\t类型 :" + typeName + "\n具体错误信息 :" + e.Message);
            }
        }