/****************************************************************************************** * vfs���Ͽ��� ������ �����Ѵ� * �ٸ� ���丮���� �ε����� ���� ������ ���� ���� �� �ִ�. ==> ���� */ VFileHandle * CVFS_Manager::OpenFile (const char *FileName) { VFileHandle *pVF = NULL; std::vector<VEntry *>::iterator iv = m_vecVFS.begin (); if(FileName == NULL) { return NULL; } if( FileExistsInVfs( FileName ) ) // vfs �ȿ� ������ �װ� ���� open �Ѵ�. ���� �ܺ� ���Ϸ� ���� ���� �˻� { char rightName[1024]; ::__ConvertPath (FileName, rightName); for(; iv != m_vecVFS.end (); iv++) { if((pVF = (*iv)->pVFS->OpenFile (rightName))) { pVF->hVFS = (VHANDLE)this; return pVF; } } } else if(_access (FileName, 0) == 0 && _access (FileName, 4) == 0) { if((pVF = new VFileHandle)) { _fmode = _O_BINARY; if((pVF->fp = fopen (FileName, "r"))) { pVF->lCurrentOffset = 0; pVF->lStartOff = 0; pVF->lEndOff = __vfseek (pVF->fp, 0, SEEK_END); pVF->sFileName = FileName; pVF->btFileType = 1; /// �ۿ� �ִ� ������ ��� 1 pVF->hVFS = NULL; pVF->pData = NULL; fseek (pVF->fp, 0, SEEK_SET); return pVF; } } } return NULL; /// �߰����� ���ϸ� pVF��NULL�� ���� }
short CIndex::AddFile(const char* VfsName, const char* FileName, const char* TargetName, int version, int crc, bool deleted) { string name = VfsName; transform(name.begin(), name.end(), name.begin(), ::toupper); if(!name.compare("ROOT.VFS")) { return 2; // invalid vfs } if(FileExistsInVfs(name.c_str())) { return 4; } bool VfsFound = false; for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { if(!name.compare((*i)->GetVFSName())) { VfsFound = true; if(!FlatFile::Exist((char*)FileName)) { return 5; // doesn't exist } FlatFile* srcFile = new FlatFile(FileName, "rb"); if(!srcFile->IsOpen()) { delete srcFile; srcFile = NULL; return 3; // can't open } CVFSFile::File* TargetFile = new CVFSFile::File(); short len = strlen(TargetName) + 1; char* NormalizedTargetName = new char[len]; CIndex::NormalizePath(TargetName, NormalizedTargetName); for(short j = 0; j < (len - 1); j++) { NormalizedTargetName[j] = toupper(NormalizedTargetName[j]); } TargetFile->path = NormalizedTargetName; TargetFile->version = version; TargetFile->crc = crc; TargetFile->vfsIndex = distance(ListVFS->begin(), i); TargetFile->currentPosition = 0; TargetFile->deleted = false; TargetFile->hash = toHash(TargetFile->path); TargetFile->offset = (*i)->VFile->Size(); TargetFile->length = srcFile->Size(); if(TargetFile->length == 0) { delete TargetFile; TargetFile = NULL; return 10; } TargetFile->data = new unsigned char[TargetFile->length]; if(TargetFile->data == NULL || TargetFile->data == (unsigned char*)-1) { delete TargetFile; TargetFile = NULL; return 6; // memalloc fail } if(!srcFile->ReadData(TargetFile->data, TargetFile->length)) { delete TargetFile; TargetFile = NULL; return 6; // memalloc fail (not really but it suits the error the best) } long pos = (*i)->VFile->Position(); (*i)->VFile->Seek((*i)->VFile->Size()); (*i)->VFile->WriteData(TargetFile->data, TargetFile->length); (*i)->VFile->Seek(pos); (*i)->Files->push_back(TargetFile); (*i)->FileTable.addHash(TargetFile->hash, TargetFile); (*i)->SetFileCount((*i)->GetFileCount() + 1); this->changed = true; srcFile->Close(); delete srcFile; srcFile = NULL; delete[] NormalizedTargetName; NormalizedTargetName = NULL; } } if(VfsFound == false) { return 2; // invalid vfs } return 0; }
// FileName �� �ε��������Ϳ� ���� �����Ͱ� ��ġ�ϴ��� üũ�Ѵ� short CVFS_Manager::TestFile (const char * FileName) { if(FileExistsInVfs ( FileName ) ) { VEntry * pVEntry = GetVEntryWF ( FileName ); VFileHandle * pVF = OpenFile (FileName ); if(pVF && pVEntry) { VfsInfo VfsRange ; if(GetVfsInfo ( pVEntry->sVFSName.c_str (), &VfsRange) ) // GetVEntryWF �����ߴٸ� GetVfsInfo �� �����ؾ� �Ѵ� { if (pVF->lStartOff < VfsRange.lStartOff || pVF->lEndOff > VfsRange.lEndOff ) { ::VCloseFile ( pVF ); pVF = NULL; return VTEST_INVALIDRANGE; } } else { ::VCloseFile ( pVF ); pVF = NULL; return VTEST_CANTKNOWVFSINFO; } long lSize = GetFileLength ( FileName ); if( lSize == 0 ) { ::VCloseFile ( pVF ); pVF = NULL; return VTEST_ZEROLENGTH; } BYTE * pbtData = new BYTE[ lSize ]; if( pbtData ) { size_t stReadCnt = ::vfread (pbtData, sizeof (BYTE), lSize, pVF); if( stReadCnt != (size_t)lSize ) { ::VCloseFile ( pVF ); pVF = NULL; delete [] pbtData; pbtData = NULL; return VTEST_LENGTHNOTMATCH; } ::VCloseFile ( pVF ); pVF = NULL; DWORD dwCRC = CLibCrc::GetIcarusCrc ( pbtData , lSize ); VFileInfo FileInfo; this->GetFileInfo ( FileName, &FileInfo , false); if( FileInfo.dwCRC != dwCRC ) { delete [] pbtData; pbtData = NULL; return VTEST_CRCNOTMATCH; } delete [] pbtData; pbtData = NULL; return VTEST_SUCCESS; } return VTEST_NOTENOUGHMEM; } return VTEST_CANTOPEN; } if( FileExists ( FileName ) ) return VTEST_OUTFILE; return VTEST_FILENOTEXISTS; }