BLOCK* get_block(int block_size){ CVFS* vfs = getVFS(); BLOCK *ret = vfs->free,*suit; int max = 0; //return the data block of specified size //or greatest block smaller than specified block while(ret!=NULL){ if(ret->size>block_size){ BLOCK* found = new BLOCK(); found->offset =ret->offset; found->size = block_size; found->next = NULL; found->prev = NULL; ret->offset = ret->offset+block_size; ret->size-=block_size; return found; } if(ret->size==block_size){ ret->prev->next = ret->next; ret->next->prev = ret->prev; return ret; } if(ret->size>max){ max = ret->size; suit = ret; } } return suit; }
void Loc::ImportStrings() { Loc::AssociateWithFile(Loc::AIM_BIOGRAPHY, L"Localization/AimBiographies.xml"); Loc::AssociateWithFile(Loc::AIM_HISTORY, L"Localization/AimHistory.xml"); Loc::AssociateWithFile(Loc::AIM_POLICY, L"Localization/AimPolicy.xml"); Loc::AssociateWithFile(Loc::GAME_STRINGS, L"Localization/GameStrings.xml"); vfs::String bio, add, bio2; Loc::GetString(Loc::AIM_BIOGRAPHY,L"Bio",L"0",add); Loc::GetString(Loc::AIM_BIOGRAPHY,L"Add",L"10",bio); Loc::GetString(Loc::AIM_BIOGRAPHY,L"Bio",23,bio2); for(int i=0; i<200; ++i) { std::wstringstream wss; for(int exp=2; exp>=0; --exp) { int t = (int)std::pow((double)10,(double)exp); wss << (i % (t*10)) / t; } vfs::String s = wss.str() + L".EDT.xml"; vfs::Path filename(L"Localization/Dialogue"); filename += vfs::Path(s); if(getVFS()->fileExists(filename)) { Loc::AssociateWithFile(Loc::DIALOGUE,filename,vfs::toString<wchar_t>(i)); } } }
//list free blocks in the disk void list_free_blocks(){ CVFS* vfs = getVFS(); BLOCK *move = vfs->free; while(move != NULL){ printf("offset %d : size %d\n",move->offset,move->size); move = move->next; } }
//list all files in the file table void listFiles(){ CVFS *vfs = getVFS(); FT* trav = vfs->myft; while(trav!=NULL){ printf("%s\n",trav->name); trav = trav->next; } }
void initVFS(int vfs_size){ CVFS* fs = getVFS(); fs->disk = malloc(vfs_size); fs->disk_size = vfs_size; fs->myft = NULL; fs->free = new BLOCK(); fs->free->size = vfs_size; fs->free->offset = 0; fs->free->next = fs->free->prev = NULL; }
bool vfs::PropertyContainer::initFromXMLFile(vfs::Path const& sFileName, vfs::PropertyContainer::TagMap& tagmap) { vfs::tReadableFile *file = NULL; bool delete_file = false; if(getVFS()->fileExists(sFileName)) { vfs::COpenReadFile rfile(sFileName); file = &rfile.file(); rfile.release(); } else { vfs::CFile* rfile = new vfs::CFile(sFileName); delete_file = true; file = vfs::tReadableFile::cast(rfile); if(!file->openRead()) { delete file; return false; } } if(!file) { return false; } vfs::size_t size = file->getSize(); std::vector<vfs::Byte> buffer(size+1); SGP_TRYCATCH_RETHROW( file->read(&buffer[0],size), L"" ); buffer[size] = 0; file->close(); if(delete_file) delete file; XML_Parser parser = XML_ParserCreate(NULL); CPropertyXMLParser pp(*this,tagmap,parser,NULL); pp.grabParser(); if(!XML_Parse(parser, &buffer[0], size, TRUE)) { std::wstringstream wss; wss << L"XML Parser Error in Groups.xml: " << vfs::String::as_utf16(XML_ErrorString(XML_GetErrorCode(parser))) << L" at line " << XML_GetCurrentLineNumber(parser); SGP_THROW(wss.str().c_str()); //return false; } return true; }
bool CTransferRules::initFromTxtFile(vfs::Path const& sPath) { // try to open via VirtualFileSystem if(getVFS()->fileExists(sPath)) { return initFromTxtFile(getVFS()->getReadFile(sPath)); } else { // file doesn't exist or VFS not initialized yet vfs::IBaseFile* pFile = new vfs::CFile(sPath); if(pFile) { bool success = initFromTxtFile(vfs::tReadableFile::cast(pFile)); delete pFile; return success; } } return false; }
void vfs::CVirtualLocation::addFile(vfs::IBaseFile* file, vfs::String const& profileName) { vfs::CVirtualFile *pVFile = NULL; tVFiles::iterator it = m_VFiles.find(file->getName()); if(it == m_VFiles.end()) { vfs::Path fp = file->getPath(); vfs::CProfileStack& stack = *(getVFS()->getProfileStack()); pVFile = vfs::CVirtualFile::create(fp,stack); it = m_VFiles.insert(m_VFiles.end(), std::pair<vfs::Path,vfs::CVirtualFile*>(file->getName(),pVFile)); } it->second->add(file,profileName,true); }
bool vfs::CProfileStack::popProfile() { // there might be some files in this profile that are referenced in a Log object // we need to it to release the file vfs::Log::flushReleaseAll(); // an observer pattern would probably be the better solution, // but for now lets do it this way vfs::CVirtualProfile* prof = this->topProfile(); if(prof) { vfs::CVirtualProfile::Iterator loc_it = prof->begin(); for(; !loc_it.end(); loc_it.next()) { vfs::IBaseLocation* loc = loc_it.value(); vfs::IBaseLocation::Iterator f_it = loc->begin(); for(; !f_it.end(); f_it.next()) { vfs::IBaseFile* file = f_it.value(); vfs::Path sDir, sFile; if(file) { file->getPath().splitLast(sDir,sFile); vfs::CVirtualLocation* vloc = getVFS()->getVirtualLocation(sDir); if(vloc) { if( !vloc->removeFile(file) ) { VFS_THROW(_BS(L"Could not remove file [") << file->getPath() << L"] in Profile [" << prof->cName << L"]" << _BS::wget); } } else { VFS_THROW(_BS(L"Virtual location [") << sDir << L"] doesn't exist. Maybe the VFS was not properly setup." << _BS::wget); } } else { VFS_THROW(_BS(L"File is NULL during iteration over files in location [") << loc->getPath() << L"]" << _BS::wget); } } } // delete only when nothing went wrong this->m_profiles.pop_front(); delete prof; } return true; }
int createFile(const char* fileName){ CVFS *vfs = getVFS(); FT *trav = new FT(); //add new entry to the file table trav->next = vfs->myft; trav->name = (char*)fileName; trav->data = NULL; trav->size = 0; vfs->myft = trav; return SUCCESS; }
int deleteFile(const char* fileName){ CVFS *vfs=getVFS(); FT *trav = vfs->myft; FT *prev = NULL; //traverse till the required file while(trav!=NULL){ if(strcmp(trav->name,fileName)==0){ BLOCK *del = trav->data,*next; //add data block of the file to free data blocks while(del!=NULL){ next = del->next; add_to_free(del); del = next; } if(prev == NULL) vfs->myft = trav->next; else prev->next = trav->next; //printf("root %d %d\n",vfs->free->offset,vfs->free->size); del = vfs->free; //combine adjacent data blocks in the free to overcome fragmentation of data blocks in free while(del->next != NULL){ if(del->offset+del->size == del->next->offset){ del->size += del->next->size; next = del->next; del->next = del->next->next; free(next); } del = del->next; if(del==NULL) break; } //free the data entry free(trav); return SUCCESS; } prev = trav; trav = trav->next; } return NOTFOUND; }
FIFE::VFSSource* DirectoryProvider::createSource(const std::string& path) { if (isReadable(path)) { VFSSource* source = NULL; if ( hasSource(path)) { source = m_sources[path]; } else { source = new VFSDirectory(getVFS(), path); m_sources[path] = source; } return source; } else throw Exception("Path " + path + " is not readable."); }
int renameFile(const char* oldName,const char* newName){ CVFS *vfs=getVFS(); FT *trav = vfs->myft; //traverse till the required file while(trav!=NULL){ if(strcmp(trav->name,oldName)==0){ //rename and return success trav->name = (char*)newName; return SUCCESS; } trav = trav->next; } return NOTFOUND; }
bool ja2xp::convertSLFto7z(vfs::Path const& sSrc, vfs::Path const& sDst, bool bConvertSTIs, bool bPngOffsets) { vfs::CVirtualFileSystem::Iterator it = getVFS()->begin(sSrc); int file_counter = 0; for(; !it.end(); it.next()) { file_counter++; vfs::String::str_t fname = it.value()->getPath().c_wcs(); if( !vfs::StrCmp::Equal( fname.substr(fname.length()-4,4), L".slf") ) { std::wcout << L"\"" << fname << L"\" " << L"is not an .slf file" << std::endl; continue; } if(!it.value()->openRead()) { std::wcout << L"Could not open file \"" << sSrc() << L"\"" << std::endl; continue; } vfs::String::str_t new_fname = fname.substr(0,fname.length()-4) + L".jdc.7z"; vfs::Path out_name; if(vfs::StrCmp::Equal(sDst(), L".")) { out_name = vfs::Path(new_fname); } else { out_name = sDst; } std::wcout << L"Converting file \"" << it.value()->getPath().c_wcs() << L"\"" << std::endl; vfs::COpenWriteFile wfile(out_name,true,true); if(!convertSLFto7z(it.value(), &wfile.file(), bConvertSTIs, bPngOffsets)) { printf("\n"); continue; } printf("\n"); } if(file_counter == 0) { std::wcout << L"Nothing to convert!" << std::endl; } return true; }
void onReceipt(Message *m) { uint32_t vfs = getVFS(); int idx = getLinuxPID(m->Source); if(m->Code < _signalCount && _signals[m->Code] != 0) { _sig_func_ptr function = _signals[m->Code]; //I don't like this, but it's needed for POSIX compatibility _signals[m->Code] = 0; function(m->Code); } //This is a decent message handling system. Fairly simple if(idx != -1 && _pids[idx] != 0 && _pids[idx]->handler != 0) _pids[idx]->handler(m); }
//add blocks to free blocks in the disk void add_to_free(BLOCK* add){ CVFS *vfs = getVFS(); BLOCK *move = vfs->free,*prev=NULL; while(move != NULL){ if(move->offset == add->offset+add->size){ move->offset=add->offset; move->size += add->size; //printf("adding block offset %d:size %d to start of move\n",add->offset,add->size); return; } if(move->offset+move->size == add->offset){ move->size += add->size; //printf("adding block offset %d:size %d to end of move\n",add->offset,add->size); return; } if(move->offset>add->offset+add->size){ if(prev==NULL){ add->next = vfs->free; add->prev = NULL; vfs->free->prev = add; vfs->free = add; return; } add->next = move; add->prev = prev; move->prev = add; prev->next = add; return; //adding the block in the position such the next node starts after present block in lexicographical order } prev = move; move = move->next; } if(prev==NULL){ vfs->free = add; } prev->next = add; //printf("adding block offset %d:size %d at end\n",add->offset,add->size); }
int readFile(const char* fileName,void* buffer,int buffersize,int offset){ CVFS *vfs = getVFS(); FT *trav = vfs->myft; int bytes_read = 0; //traverse till the required file while(trav!=NULL){ if(strcmp(fileName,trav->name)==0){ BLOCK* move = trav->data; //traverse all data blocks of the file while(move != NULL && buffersize>0){ while(offset>=move->size){ offset -= move->size; move = move->next; } //copy the data in the data block to buffer memcpy(buffer,(void*)((char*)vfs->disk + move->offset + offset),min(buffersize,move->size-offset)); //increment the buffer point buffer = (char*)buffer + min(move->size-offset,buffersize); bytes_read += min(move->size-offset,buffersize); buffersize -= min(move->size-offset,buffersize); offset = 0; move = move->next; } return bytes_read; } trav = trav->next; } return -1; }
int writeFile(const char* fileName,const void* buffer,int buffersize,int offset){ CVFS *vfs = getVFS(); FT *trav = vfs->myft; if(buffersize > vfs->disk_size) return NOMEM; while(trav != NULL){ //search the file if(strcmp(trav->name,fileName)==0){ BLOCK *prev=NULL,*move=trav->data; if((offset && trav->size<=offset) || offset<-1) return NOTDEF; //traverse till end if(offset==-1){ if(move != NULL) { while(move->next != NULL){ move = move->next; } prev = move; move = move->next; } offset = 0; } if(offset>0){ //traverse till the data block which has specified offset while(offset>=move->size){ offset -= move->size; prev = move; move = move->next; } //write form offset to end of block or end of buffer memcpy((void*)((char*)vfs->disk + move->offset + offset),buffer,min(buffersize,move->size-offset)); //printf("written data:%s - to offset %d till %d characters\n",(char*)buffer,move->offset+offset,min(buffersize,move->size-offset)); buffer = (char*)buffer + min(buffersize,move->size-offset); buffersize -= move->size-offset; offset = 0; prev = move; move = move->next; } while(buffersize>0){ //allocate a new block when the next block is NULL for write if(move==NULL){ if(prev==NULL) move = trav->data = get_block(buffersize); else{ prev->next = get_block(buffersize); prev->next->prev = prev; move = prev->next; } trav->size += move->size; } //write the buffer to disk memcpy((void*)((char*)vfs->disk + move->offset),buffer,min(buffersize,move->size)); //printf("written data:%s - to offset %d till %d characters\n",(char*)buffer,move->offset,min(buffersize,move->size)); buffersize -= move->size; //move buffer pointer buffer = (char*)buffer + move->size; prev = move; move = move->next; } return SUCCESS; } trav = trav->next; } return NOTFOUND; }
BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename ) { BINKFLIC *pBink; // Get an available flic slot from the list if( !( pBink = BinkGetFreeFlic() ) ) { ErrorMsg("BINK ERROR: Out of flic slots, cannot open another"); return(NULL); } #ifndef USE_VFS // Attempt opening the filename if(!(pBink->hFileHandle = FileOpen( const_cast<CHAR8*>(cFilename), FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE ) ) ) { ErrorMsg("BINK ERROR: Can't open the BINK file"); return(NULL); } //Get the real file handle for the file man handle for the smacker file HANDLE hFile = GetRealFileHandleFromFileManFileHandle( pBink->hFileHandle ); #else vfs::Path introname(cFilename); vfs::Path dir,filename; introname.splitLast(dir,filename); vfs::Path tempfile = vfs::Path(L"Temp") + filename; if(!getVFS()->fileExists(tempfile)) { try { if(!getVFS()->fileExists(introname)) { return NULL; } vfs::COpenReadFile rfile(introname); vfs::size_t size = rfile->getSize(); std::vector<vfs::Byte> data(size); rfile->read(&data[0],size); vfs::COpenWriteFile wfile(tempfile,true); wfile->write(&data[0],size); } catch(std::exception& ex) { SGP_RETHROW(_BS(L"Intro file \"") << filename << L"\" could not be extracted" << _BS::wget, ex); } } #endif #ifndef USE_VFS if( !( pBink->BinkHandle = BinkOpen((CHAR8 *)hFile, BINKFILEHANDLE ) ) ) //| SMACKTRACKS #else vfs::Path tempfilename; try { vfs::COpenWriteFile wfile(tempfile); if(!wfile->_getRealPath(tempfilename)) { return NULL; } } catch(std::exception& ex) { SGP_RETHROW(L"Temporary intro file could not be read", ex); } if( !( pBink->BinkHandle = BinkOpen(tempfilename.to_string().c_str(), BINKNOTHREADEDIO /*BINKFILEHANDLE*/ ) ) ) //| SMACKTRACKS #endif { ErrorMsg("BINK ERROR: Bink won't open the BINK file"); return(NULL); } // Make sure we have a video surface BinkSetupVideo(); pBink->cFilename = cFilename; pBink->lpDDS = lpBinkVideoPlayback2; pBink->hWindow = hBinkDisplayWindow; // Bink flic is now open and ready to go pBink->uiFlags |= BINK_FLIC_OPEN; return( pBink ); }
BOOLEAN InitMainMenu( ) { //VOBJECT_DESC VObjectDesc; VSURFACE_DESC vs_desc = {}; //main Menu by JAzz UINT16 iCounter2; if(is_networked) { is_networked = FALSE; #ifdef USE_VFS // remove Multiplayer profile if it exists vfs::CProfileStack *PS = getVFS()->getProfileStack(); vfs::CVirtualProfile *pProf = PS->getProfile("_MULTIPLAYER"); if( pProf && (pProf == PS->topProfile()) ) { SGP_THROW_IFFALSE(PS->popProfile(), "Leaving Multiplayer mode : Could not remove \"_MULTIPLAYER\" profile"); } #endif // Snap: UN-Init MP save game directory if ( !InitSaveDir() ) { //if something didnt work, dont even know how to make error code...//hayden } } //Check to see whatr saved game files exist InitSaveGameArray(); //Create the background mouse mask CreateDestroyBackGroundMouseMask( TRUE ); CreateDestroyMainMenuButtons( TRUE ); // load background graphic and add it //Main Menu by Jazz for( iCounter2 = 1; iCounter2 < MAX_ELEMENT; iCounter2++ ) { //VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; vs_desc.fCreateFlags = VSURFACE_CREATE_FROMFILE | VSURFACE_SYSTEM_MEM_USAGE | VSURFACE_CREATE_FROMPNG_FALLBACK; if (gMainMenulayout[iCounter2].Visible == 1) { strcpy(vs_desc.ImageFile, gMainMenulayout[iCounter2].FileName); if( !AddVideoSurface( &vs_desc, &gMainMenulayout[iCounter2].uiIndex ) ) AssertMsg(0, String( "Missing %s", gMainMenulayout[iCounter2].FileName ) ); //if (iResolution >= _640x480 && iResolution < _800x600) //{ // strcpy(VObjectDesc.ImageFile, gMainMenulayout[iCounter2].FileName); // if( !AddVideoObject( &VObjectDesc, &gMainMenulayout[iCounter2].uiIndex ) ) // AssertMsg(0, String( "Missing %s", gMainMenulayout[iCounter2].FileName ) ); //} //else if (iResolution < _1024x768) //{ // strcpy(VObjectDesc.ImageFile, gMainMenulayout[iCounter2].FileName800x600); // if( !AddVideoObject( &VObjectDesc, &gMainMenulayout[iCounter2].uiIndex ) ) // AssertMsg(0, String( "Missing %s", gMainMenulayout[iCounter2].FileName800x600 ) ); //} //else //{ // strcpy(VObjectDesc.ImageFile, gMainMenulayout[iCounter2].FileName1024x768); // if( !AddVideoObject( &VObjectDesc, &gMainMenulayout[iCounter2].uiIndex ) ) // AssertMsg(0, String( "Missing %s", gMainMenulayout[iCounter2].FileName1024x768 ) ); //} } } //if there are no saved games, disable the button if( !IsThereAnySavedGameFiles() ) DisableButton( iMenuButtons[ LOAD_GAME ] ); #ifdef JA113DEMO DisableButton( iMenuButtons[ NEW_MP_GAME ] ); #endif gbHandledMainMenu = 0; fInitialRender = TRUE; SetPendingNewScreen( MAINMENU_SCREEN); guiMainMenuExitScreen = MAINMENU_SCREEN; DequeueAllKeyBoardEvents(); return( TRUE ); }
FIFE::VFSSource* DirectoryProvider::createSource(const std::string& path) const { if (isReadable(path)) return new VFSDirectory(getVFS(), path); else throw Exception("Path " + path + " is not readable."); }
bool vfs::canWrite() { vfs::CVirtualProfile *prof = getVFS()->getProfileStack()->topProfile(); return prof && prof->cWritable; }
UINT32 LoadSaveScreenHandle(void) { FDLG_LIST *FListNode; INT32 x; InputAtom DialogEvent; if( fEnteringLoadSaveScreen ) { LoadSaveScreenEntry(); } if( gbCurrentFileIOStatus ) //loading or saving map { UINT32 uiScreen; uiScreen = ProcessFileIO(); if( uiScreen == EDIT_SCREEN && gbCurrentFileIOStatus == LOADING_MAP ) RemoveProgressBar( 0 ); return uiScreen; } if( gubMessageBoxStatus ) { if( MessageBoxHandled() ) return ProcessLoadSaveScreenMessageBoxResult(); return LOADSAVE_SCREEN; } //handle all key input. while( DequeueEvent(&DialogEvent) ) { if( !HandleTextInput(&DialogEvent) && (DialogEvent.usEvent == KEY_DOWN || DialogEvent.usEvent == KEY_REPEAT) ) { HandleMainKeyEvents( &DialogEvent ); } } HandleMouseWheelEvents();//dnl ch36 150909 DrawFileDialog(); // Skip to first filename to show FListNode = FileList; for(x=0;x<iTopFileShown && x<iTotalFiles && FListNode != NULL;x++) { FListNode = FListNode->pNext; } // Show up to 8 filenames in the window SetFont( FONT12POINT1 ); if( gfNoFiles ) { SetFontForeground( FONT_LTRED ); SetFontBackground( 142 ); mprintf( iScreenWidthOffset + 226, iScreenHeightOffset + 126, L"NO FILES IN \\MAPS DIRECTORY" ); } else for(x=iTopFileShown;x<(iTopFileShown+8) && x<iTotalFiles && FListNode != NULL; x++) { if( !EditingText() && x == iCurrFileShown ) { SetFontForeground( FONT_GRAY2 ); SetFontBackground( FONT_METALGRAY ); } else { SetFontForeground( FONT_BLACK ); SetFontBackground( 142 ); } mprintf( iScreenWidthOffset + 186,(iScreenHeightOffset + 73+ (x-iTopFileShown)*15 ), L"%S", FListNode->FileInfo.zFileName); FListNode = FListNode->pNext; } RenderAllTextFields(); InvalidateScreen(); ExecuteBaseDirtyRectQueue(); EndFrameBufferRender(); switch( iFDlgState ) { case DIALOG_CANCEL: RemoveFileDialog(); fEnteringLoadSaveScreen = TRUE; return EDIT_SCREEN; case DIALOG_DELETE: sprintf( gszCurrFilename, "MAPS\\%S", gzFilename ); if( GetFileFirst(gszCurrFilename, &FileInfo) ) { CHAR16 str[40]; if( FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_HIDDEN|FILE_IS_SYSTEM) ) { swprintf( str, L" Delete READ-ONLY file %s? ", gzFilename ); gfReadOnly = TRUE; } else swprintf( str, L" Delete file %s? ", gzFilename ); gfDeleteFile = TRUE; CreateMessageBox( str ); } return LOADSAVE_SCREEN; case DIALOG_SAVE://dnl ch37 230909 { if(!ExtractFilenameFromFields()) { CreateMessageBox(L" Illegal filename. Try another filename? "); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return(LOADSAVE_SCREEN); } sprintf(gszCurrFilename, "MAPS\\%S", gzFilename); gfFileExists = FALSE; #ifndef USE_VFS gfReadOnly = FALSE; if(FileExists(gszCurrFilename)) { gfFileExists = TRUE; if(GetFileFirst(gszCurrFilename, &FileInfo)) { if(FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_DIRECTORY|FILE_IS_HIDDEN|FILE_IS_SYSTEM|FILE_IS_OFFLINE|FILE_IS_TEMPORARY)) gfReadOnly = TRUE; GetFileClose(&FileInfo); } } #else gfReadOnly = TRUE; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); while(!it.end()) { vfs::CVirtualProfile* prof = it.value(); if(prof->cWritable == true) { gfReadOnly = FALSE; vfs::Path const& path = gszCurrFilename; vfs::IBaseFile *file = prof->getFile(path); if(file) { gfFileExists = TRUE; if(file->implementsWritable() == false) gfReadOnly = TRUE; } break; } it.next(); } #endif if(gfReadOnly) { CreateMessageBox(L" File is read only! Choose a different name? "); return( LOADSAVE_SCREEN); } else if(gfFileExists) { CreateMessageBox(L" File exists, Overwrite? "); return(LOADSAVE_SCREEN); } RemoveFileDialog(); gbCurrentFileIOStatus = INITIATE_MAP_SAVE; return(LOADSAVE_SCREEN); } case DIALOG_LOAD: if( !ExtractFilenameFromFields() ) { CreateMessageBox( L" Illegal filename. Try another filename? " ); gfIllegalName = TRUE; iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN; } RemoveFileDialog(); CreateProgressBar( 0, iScreenWidthOffset + 118, iScreenHeightOffset + 183, iScreenWidthOffset + 522, iScreenHeightOffset + 202 ); DefineProgressBarPanel( 0, 65, 79, 94, iScreenWidthOffset + 100, iScreenHeightOffset + 155, iScreenWidthOffset + 540, iScreenHeightOffset + 235 ); swprintf( zOrigName, L"Loading map: %s", gzFilename ); SetProgressBarTitle( 0, zOrigName, BLOCKFONT2, FONT_RED, FONT_NEARBLACK ); gbCurrentFileIOStatus = INITIATE_MAP_LOAD; return LOADSAVE_SCREEN ; default: iFDlgState = DIALOG_NONE; } iFDlgState = DIALOG_NONE; return LOADSAVE_SCREEN ; }
void LoadSaveScreenEntry() { fEnteringLoadSaveScreen = FALSE; gbCurrentFileIOStatus = IOSTATUS_NONE; gfReadOnly = FALSE; gfFileExists = FALSE; gfLoadError = FALSE; gfIllegalName = FALSE; gfDeleteFile = FALSE; gfNoFiles = FALSE; gfSaveError = FALSE;//dnl ch37 200909 // setup filename dialog box // (*.dat and *.map) as file filter // If user clicks on a filename in the window, then turn off string focus and re-init the string with the new name. // If user hits ENTER or presses OK, then continue with the file loading/saving if(FileList) { TrashFDlgList(FileList); FileList = NULL; } iTopFileShown = iTotalFiles = 0; #ifdef USE_VFS//dnl ch37 300909 FDLG_LIST* TempFileList = NULL; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); while(!it.end()) { TempFileList = NULL; vfs::CVirtualProfile* prof = it.value(); memset(&FileInfo, 0, sizeof(GETFILESTRUCT)); strcpy(FileInfo.zFileName, "< "); strcat(FileInfo.zFileName, prof->cName.utf8().c_str()); strcat(FileInfo.zFileName, " >"); FileInfo.zFileName[FILENAME_BUFLEN] = 0; FileInfo.uiFileAttribs = FILE_IS_DIRECTORY; if(iCurrentAction == ACTION_SAVE_MAP && prof->cWritable == false) { it.next(); continue; } TempFileList = AddToFDlgList(TempFileList, &FileInfo); iTotalFiles++; vfs::CVirtualProfile::FileIterator fit = prof->files(L"MAPS/*"); while(!fit.end()) { vfs::String fname = fit.value()->getName().c_str(); memset(&FileInfo, 0, sizeof(GETFILESTRUCT)); strcpy(FileInfo.zFileName, fname.utf8().c_str()); FileInfo.uiFileSize = fname.length(); FileInfo.uiFileAttribs = (fit.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY); if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { TempFileList = AddToFDlgList(TempFileList, &FileInfo); iTotalFiles++; } fit.next(); } if(TempFileList) { while(TempFileList->pPrev) TempFileList = TempFileList->pPrev; if(FileList) { while(FileList->pNext) FileList = FileList->pNext; FileList->pNext = TempFileList; TempFileList->pPrev = FileList; } else FileList = TempFileList; } it.next(); } while(FileList->pPrev) FileList = FileList->pPrev; #else if(GetFileFirst("MAPS\\*.dat", &FileInfo)) { if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { FileList = AddToFDlgList(FileList, &FileInfo); iTotalFiles++; } while(GetFileNext(&FileInfo)) { if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) { FileList = AddToFDlgList(FileList, &FileInfo); iTotalFiles++; } } GetFileClose(&FileInfo); } #endif swprintf( zOrigName, L"%s Map (*.dat)", iCurrentAction == ACTION_SAVE_MAP ? L"Save" : L"Load" ); swprintf( gzFilename, L"%S", gubFilename ); CreateFileDialog( zOrigName ); if( !iTotalFiles ) { gfNoFiles = TRUE; if( iCurrentAction == ACTION_LOAD_MAP ) DisableButton( iFileDlgButtons[0] ); } iLastFileClicked = -1; iLastClickTime = 0; }
RawData* DAT1::open(const std::string& file) const { const RawDataDAT1::s_info& info = getInfo(file); return new RawData(new RawDataDAT1(getVFS(), m_datpath, info)); }
bool ja2xp::convertSTItoJPC(vfs::Path const& sSrc, vfs::Path const& sDst, bool bPacked, bool bOffsets, bool bOnePng, bool rgba) { vfs::CVirtualFileSystem::Iterator it = getVFS()->begin(sSrc); int file_counter = 0; for(; !it.end(); it.next()) { file_counter++; vfs::String::str_t fname = it.value()->getPath().c_wcs(); if( !vfs::StrCmp::Equal( fname.substr(fname.length()-4,4), L".sti") ) { std::wcout << L"\"" << fname << L"\" is not an .sti file" << std::endl; continue; } if(!it.value()->openRead()) { std::wcout << L"Could not open file \"" << sSrc() << L"\"" << std::endl; continue; } vfs::String::str_t fname_base = fname.substr(0,fname.length()-4); std::wcout << L"Converting file \"" << fname << L"\"" << std::endl; if(bOnePng) { vfs::Path out_name; if(vfs::StrCmp::Equal(sDst(), L".")) { out_name = vfs::Path(fname_base + L".png"); } else { out_name = sDst; } vfs::COpenWriteFile wfile(out_name,true,true); if( !convertSTItoPNG( it.value(), &(wfile.file()), rgba ) ) { std::wcout << L"error : could not convert sti image" << std::endl; continue; } } else if(bPacked) { vfs::Path out_name; if(vfs::StrCmp::Equal(sDst(), L".")) { out_name = vfs::Path(fname_base + L".jpc.7z"); } else { out_name = sDst; } vfs::COpenWriteFile wfile(out_name,true,true); if( !convertSTItoJPC( it.value(), &(wfile.file()), bOffsets, rgba ) ) { std::wcout << L"error : could not convert sti image" << std::endl; continue; } } else { if( !convertSTItoJPC( it.value(), vfs::Path(fname_base), bOffsets, rgba ) ) { std::wcout << L"error : could not convert sti image" << std::endl; continue; } } } if(file_counter == 0) { std::wcout << L"Nothing to convert!" << std::endl; } return true; }