//! 使用PHYSFS的例子
/*
dev c++
核动力机器人
2009.08.16
*/
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include "physfs.h"
using namespace std;
int main(int argc, char *argv[])
{
//! 初始化PHYSFS
bool flag = PHYSFS_init(0);
std::cout<<"初始化physfs: "<<flag<<std::endl;
std::cout<<PHYSFS_addToSearchPath("C://Documents and Settings//Administrator//My Documents//dev", false)<<std::endl;
char** buf = PHYSFS_getSearchPath();
if(buf == 0)
{
std::cout<<"get search path failed."<<std::endl;
}
else
{
std::vector<std::string> dirs;
for(char** i = buf; *i != 0; ++i)
{
dirs.push_back(*i);
}
std::cout<<"dirs is: "<<dirs.size()<<std::endl;
PHYSFS_freeList(buf);
std::copy(dirs.begin(),dirs.end(),std::ostream_iterator<std::string>(cout,"/n"));
}
//! 获取目录分隔符
std:cout<<PHYSFS_getDirSeparator()<<std::endl;
//! 获取基本目录路径
std::cout<<PHYSFS_getBaseDir()<<endl;
//std::cout<<PHYSFS_getLastError()<<std::endl;
//! 获取基本程序路径
cout<<"get basic user dir is: "<<PHYSFS_getUserDir()<<endl;
//! 获取写路径
//cout<<"write dir is: "<<PHYSFS_getWriteDir()<<endl;
//! 设置写路径
//cout<<"set write path is: "<<PHYSFS_setWriteDir("C://Documents and Settings//Administrator//My Documents//dev")<<endl;
//std::cout<<PHYSFS_getLastError()<<std::endl;
PHYSFS_file* file;
file = PHYSFS_openRead("1.txt");
if(file==NULL)
cout<<"load file failed"<<endl;
else
cout<<"open file is: ok"<<endl;
//! 获取文件长度
int size = PHYSFS_fileLength(file);
std::cout<<size<<endl;
//! 获取当前file ptr
std::cout<<PHYSFS_fileLength(file)<<endl;
char *ptr = new char[size];
std::cout<<PHYSFS_read(file, ptr, 10, 1)<<endl;
cout<<ptr<<endl;
delete []ptr;
PHYSFS_close(file);
std::cout<<PHYSFS_getLastError()<<std::endl;
//! 终止PHYSFS
PHYSFS_deinit();
system("PAUSE");
return EXIT_SUCCESS;
}