示例#1
0
MPQFile::MPQFile(const char* filename):
	eof(false),
	buffer(0),
	pointer(0),
	size(0)
{
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = (*i)->mpq_a;
		
        mpq_hash hash = (*i)->GetHashEntry(filename);
		uint32 blockindex = hash.blockindex;

        if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) {
            continue; //file not found
        }
        
        int fileno = blockindex;

        //int fileno = libmpq_file_number(&mpq_a, filename);
		//if(fileno == LIBMPQ_EFILE_NOT_FOUND)
		//	continue;

        // Found!
		size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
		// HACK: in patch.mpq some files don't want to open and give 1 for filesize
		if (size<=1) {
			eof = true;
			buffer = 0;
			return;
		}
		buffer = new char[size];

		//libmpq_file_getdata
        libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);
		return;

	}
	eof = true;
	buffer = 0;
}
示例#2
0
int MPQFile::getSize(const char* filename)
{
	//if(m_bUseLocalFiles) {
		//wxString fn = gamePath;
		//fn.Append(filename);
		//if (wxFile::Exists(fn.fn_str())) {
		//	wxFile file(fn);
		//	return file.Length();
		//}
	//}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, filename);
		if (fileno != LIBMPQ_EFILE_NOT_FOUND)
			return libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
	}

	return 0;
}
示例#3
0
MPQFile::MPQFile(const char* filename, bool bUseLocalFiles):
	eof(false),
	buffer(0),
	pointer(0),
	size(0)
{
	m_bUseLocalFiles = bUseLocalFiles;
	if(m_bUseLocalFiles) {

		std::FILE* fp = fopen(filename, "rb");
		if(fp)
		{
			fseek(fp, 0, SEEK_END);
			size = ftell(fp);
			//
			if (size<=1) {
				eof = true;
				buffer = 0;
				return;
			}

			fseek(fp, 0, SEEK_SET);
			buffer = new unsigned char[size];
			fread(buffer,size,1,fp);
			fclose(fp);
			return;
		}

		//String fn;

		//fn = gamePath;
		//fn.Append(filename);

		//if (wxFile::Exists(fn.fn_str())) {
		//	// success
		//	wxFile file;
		//	// if successfully opened
		//	if (file.Open(fn.fn_str(), wxFile::read)) {
		//		size = file.Length();
		//		if (size > 0) {
		//			buffer = new unsigned char[size];
		//			// if successfully read data
		//			if (file.Read(buffer, size) > 0) {
		//				eof = false;
		//				return;
		//			} else {
		//				wxDELETEA(buffer);
		//				eof = true;
		//				size = 0;
		//			}
		//		}
		//	}
		//}
	}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end(); ++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, filename);
		if(fileno == LIBMPQ_EFILE_NOT_FOUND)
			continue;

		// Found!
		size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);

		// HACK: in patch.mpq some files don't want to open and give 1 for filesize
		if (size<=1) {
			eof = true;
			buffer = 0;
			return;
		}

		buffer = new unsigned char[size];
 		libmpq_file_getdata(&mpq_a, fileno, buffer);
		return;
	}

	eof = true;
	buffer = 0;
}
示例#4
0
void getFileLists(std::set<FileTreeItem> &dest, bool filterfunc(std::string))
{
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, "(listfile)");

		if(fileno != LIBMPQ_EFILE_NOT_FOUND) {
			// Found!
			size_t size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
			int retVal = libmpq_file_info(&mpq_a, LIBMPQ_FILE_COMPRESSION_TYPE, fileno);

			std::string temp = mpq_a.filename;
			//temp = temp.MakeLower();
			transform(temp.begin(),   temp.end(),   temp.begin(),   tolower);   
			int col = 0;
			if (temp.find("patch.mpq") != std::string::npos)
				col = 1;
			else if (temp.find("patch-2.mpq") != std::string::npos)
				col = 2;

			if (temp.find("wowtest") > -1)
				col = 3;

			// TODO: Add handling for uncompressed files.
			//if () {
			if (size > 0 && retVal != 0) {
				unsigned char *buffer = new unsigned char[size];
				libmpq_file_getdata(&mpq_a, fileno, buffer);
				unsigned char *p = buffer, *end = buffer + size;

				while (p <= end) {
					unsigned char *q=p;
					do {
						if (*q==13) 
							break;
					} while (q++<=end);

					std::string line((char*)p,q-p);
					if (line.length()==0) 
						break;

					//p += line.length();
					p = q + 2;
					//line.erase(line.length()-2, 2); // delete \r\n

					if (filterfunc(line.c_str())) {

						// This is just to help cleanup Duplicates
						// Ideally I should tokenise the string and clean it up automatically
						transform(line.begin(),   line.end(),   line.begin(),   tolower);   
						line[0] -= 32;
						int ret = line.find('\\');
						if (ret>-1)
							line[ret+1] -= 32;

						FileTreeItem tmp;
						tmp.fn = line;
						tmp.col = col;
						dest.insert(tmp);
					}
				}

				S_DEL(buffer);
				p = NULL;
				end = NULL;
			}
		}
	}
}