Delphi/C# - My favorite programming language

My Links

Blog Stats



  PhysicsFS is a library to provide abstract access to various archives. It is intended for use in video games, and the design was somewhat inspired by Quake 3's file subsystem. The programmer defines a "write directory" on the physical filesystem. No file writing done through the PhysicsFS API can leave that write directory, for security. For example, an embedded scripting language cannot write outside of this path if it uses PhysFS for all of its I/O, which means that untrusted scripts can run more safely. Symbolic links can be disabled as well, for added safety. For file reading, the programmer lists directories and archives that form a "search path". Once the search path is defined, it becomes a single, transparent hierarchical filesystem. This makes for easy access to ZIP files in the same way as you access a file directly on the disk, and it makes it easy to ship a new archive that will override a previous archive on a per-file basis. Finally, PhysicsFS gives you platform-abstracted means to determine if CD-ROMs are available, the user's home directory, where in the real filesystem your program is running, etc.


  让我找到一个封装好的库 - BooGame,另外还有一个TAO (文件太大,有30多M)。



  然后using Tao.PhysFs,BooGame里有一个FileSystem.cs,可以做参考,不过其封装得不够完善。

  首先 Fs.PHYSFS_init("init"); //这里的"init"没啥特别意义,总之传入一个字符串就可以

  然后是添加搜索路径,Fs.PHYSFS_addToSearchPath("D:\\Temp", 1); //如果有写入要求的话,写入的临时目录要先添加,否则修改过的数据无法被找到,后面的参数1是一个定值

  下面来mount一个压缩包,Fs.PHYSFS_addToSearchPath("D:\\", 1);

  接着设置写入的临时目录:Fs.PHYSFS_setWriteDir("D:\\"); //对压缩包的文件所作的任何修改都会被存入此处指定的临时目录。


  接下来就是文件目录的通常操作了,除了是使用 Fs.PHYSFS_XXX 这样的语句外,与通常的文件操作没有太大区别。更详细的使用帮助,请参考http://


  提示,里面的openWrite, openAppend实在不好用(需要Marshal.AllocHGlobal来分配内存),不如直接在临时目录下直接读写之。


  PS: 这个版本有点老了,好像是1.0.1,现在最新的是2.0.2,从1.1开始就支持了7z格式。



posted on 2011-04-11 13:45 Icebird 阅读(...) 评论(...) 编辑 收藏