4 #define __STORMLIB_SELF__
6 MPQArchiveSet gOpenArchives
;
8 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
9 MPQArchive::MPQArchive(const char* filename
)
11 BOOL succ
= SFileOpenArchive(filename
, 0, 0,&hMPQ
);
13 printf("Opening %s\n", filename
);
15 printf("Error!!!Not open archive %s\n", filename
);
18 void MPQArchive::close()
20 SFileCloseArchive(hMPQ
);
23 bool MPQArchiveSet::Open( std::vector
<std::string
> const& archiveNames
)
25 for (size_t i
=0; i
< archiveNames
.size(); ++i
)
27 MPQArchive
mpqarch(archiveNames
[i
].c_str());
29 archives
.push_back(mpqarch
);
32 return !archives
.empty();
35 MPQArchiveSet::~MPQArchiveSet()
38 for (ArchiveSet::iterator ar_itr
= archives
.begin(); ar_itr
!= archives
.end(); ++ar_itr
)
42 MPQFile::MPQFile(const char* filename
):
48 for(ArchiveSet::const_iterator i
=gOpenArchives
.archives
.begin(); i
!=gOpenArchives
.archives
.end();++i
)
52 BOOL succ
= SFileOpenFileEx(hMPQ
,filename
,0, &hFile
);
55 DWORD s
= SFileGetFileSize(hFile
, 0);
64 SFileReadFile(hFile
, buffer
, s
, 0, 0);
65 SFileCloseFile(hFile
);
81 size_t MPQFile::read(void* dest
, size_t bytes
)
86 size_t rpos
= pointer
+ bytes
;
89 bytes
= size
- pointer
;
93 memcpy(dest
, &(buffer
[pointer
]), bytes
);
100 bool MPQFile::isEof()
105 void MPQFile::seek(int offset
)
108 eof
= (pointer
>= size
);
111 void MPQFile::seekRelative(int offset
)
114 eof
= (pointer
>= size
);
117 void MPQFile::close()
125 size_t MPQFile::getSize()
130 size_t MPQFile::getPos()
135 char* MPQFile::getBuffer()
140 char* MPQFile::getPointer()
142 return buffer
+ pointer
;