自己写的一个读取资源列表的源码,思想来自lua的单词分割解析模块,但是没有像lua一样通过buf来储存每个WORD,采用0x00字符串结束符来分割各个WORD,有点类似投机取巧的感觉,不是绝对安全的方法,所以并不推荐这样写,只是希望能汲取里面解析文件的思路,^_^
/*****************************
* ResManager.h *
*****************************/
#pragma once
struct img_member
{
wchar_t *name;
wchar_t *path;
bool mask;
};
struct aimg_member
{
wchar_t *name;
wchar_t *path;
int hnum;
int vnum;
};
struct music_member
{
char *name;
char *path;
};
class ResManagerClass
{
public:
std::list<img_member*> imglist;
std::list<aimg_member*> aimglist;
std::list<music_member*> musiclist;
bool LoadResArray(const char *resfile);
private:
FILE *f;
char *buf;
unsigned long filelen;
};
extern ResManagerClass ResManager;
/*****************************
* ResManager.cpp *
*****************************/
#include "StdAfx.h"
#include "resmanager.h"
using namespace std;
//每种格式的个数
#define MEMBER_NUM_IMG 3
#define MEMBER_NUM_AIMG 4
#define MEMBER_NUM_MUSIC 2
enum ResStyle {img,aimg,music,none};
ResManagerClass ResManager;
bool ResManagerClass::LoadResArray(const char *resfile)
{
if(fopen_s(&f,resfile,"rb"))
return false;
fseek(f,0,2); filelen = ftell(f); fseek(f,0,0);
buf = new char[filelen];
fread(buf,filelen,1,f);
//初始化各种mark
bool in_note = false, in_string = false;
int string_strat_pos = -1, mn_img = 0, mn_aimg = 0, mn_music = 0;
char *string = 0;
ResStyle style_entry = none;
char *imgmember_str[MEMBER_NUM_IMG], *aimgmember_str[MEMBER_NUM_AIMG], *musicmember_str[MEMBER_NUM_MUSIC];