Exemplo n.º 1
0
bool CIndex::AddVFS(const char* VfsName)
{
	char* NormalizedName = new char[strlen(VfsName) + 1];
	CIndex::NormalizePath(VfsName, NormalizedName);
	short len = strlen(NormalizedName);
	for(short i = 0; i < len; i++)
	{
		name[i] = toupper(NormalizedName[i]);
	}
	if(!strcmp(NormalizedName, "ROOT.VFS"))
	{
		return false;
	} 
	CVFSFile* Vfs = new CVFSFile();
	Vfs->SetVFSName(NormalizedName);
	this->vfsCount++;
	this->changed = true;
	Vfs->VFile = new FlatFile(NormalizedName, "wb");
	ListVFS->push_back(Vfs);
	delete[] NormalizedName;
	NormalizedName = NULL;
	return true;
}
Exemplo n.º 2
0
bool CIndex::Open(const char* FileName, const char* Mode)
{
	UNREFERENCED_PARAMETER(Mode);
	IFile = new FlatFile();
	if(!IFile->Open(FileName, "rb"))
	{
		return false;
	}
	this->name = (char*)FileName;
	this->baseVersion = IFile->Read<int>();
	this->currentVersion = IFile->Read<int>();
	this->vfsCount = IFile->Read<int>();
	bool HasRoot = false;
	for(int i = 0; i < vfsCount; i++)
	{
		CVFSFile* VfsFile = new CVFSFile();
		short len = IFile->Read<short>();
		VfsFile->SetVFSName((char*)IFile->ReadBytes(len));
		if(!strcmp(VfsFile->GetVFSName(), "ROOT.VFS"))
		{
			HasRoot = true;
		}
		VfsFile->SetDataOffset(IFile->Read<unsigned int>());
		ListVFS->push_back(VfsFile);
	}
	if(HasRoot == true)
	{
		for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i)
		{
			if(i == ListVFS->end())
			{
				break;
			}
			if(!strcmp((*i)->GetVFSName(), "ROOT.VFS"))
			{
				delete (*i);
				(*i) = NULL;
				i = ListVFS->erase(i);
				vfsCount--;
				break;
			}
		}
	}
	for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i)
	{
		IFile->Seek((*i)->GetDataOffset());
		(*i)->SetFileCount(IFile->Read<unsigned int>());
		(*i)->SetDeleteCount(IFile->Read<unsigned int>());
		(*i)->SetStartOffset(IFile->Read<unsigned int>());
		unsigned int j = 0;
		while(j < (*i)->GetFileCount())
		{
			CVFSFile::File* RoseFile = new CVFSFile::File();
			RoseFile->vfsIndex = distance(ListVFS->begin(), i);
			RoseFile->data = NULL;
			short len = IFile->Read<short>();
			RoseFile->path = (char*)IFile->ReadBytes(len);
			RoseFile->offset = IFile->Read<int>();
			RoseFile->length = IFile->Read<int>();
			int bs = IFile->Read<int>();
			RoseFile->deleted = IFile->Read<bool>();
			bool ct = IFile->Read<bool>();
			RoseFile->btEncrypted = IFile->Read<unsigned char>();
			RoseFile->version = IFile->Read<int>();
			RoseFile->crc = IFile->Read<int>();
			RoseFile->lEndOff = RoseFile->offset + RoseFile->length;
			RoseFile->hash = toHash(RoseFile->path);
			(*i)->Files->push_back(RoseFile); // do allow deleted files
			if(!RoseFile->deleted) // but do not make a hash for them
			{
				(*i)->FileTable.addHash(RoseFile->hash, RoseFile);
			}
			j++;
		}
	}
	IFile->Close();
	for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i)
	{
		(*i)->VFile = new FlatFile();
		(*i)->VFile->Open((*i)->GetVFSName(), "rb+");
	}
	this->Opened = true;
	return true;
}