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; }
bool vfs::Path::expandEnv() { vfs::String::ptr_t raw_ptr = &_path[0]; std::stack<t_env> pos; vfs::Int32 pos_start = -1, pos_end = -1, pos_current = 0; while(*raw_ptr != 0) { if(*raw_ptr == L'$') { pos_start = pos_current; } else if(pos_start >= 0) { if(*raw_ptr == '(' && pos_current == (pos_start+1)) { // ensure the syntax $(VARNAME) is followed pos_end = pos_start; } //else //{ // pos_start = pos_end = -1; //} else if(pos_start == pos_end && *raw_ptr == ')') { pos_end = pos_current; } // if(pos_end >= 0 && pos_start != pos_end) { t_env e; e.start = pos_start; e.end = pos_end; pos.push(e); pos_start = pos_end = -1; } } pos_current++; raw_ptr++; } if(!pos.empty()) { while(!pos.empty()) { t_env v = pos.top(); vfs::String var_name = _path.substr(v.start+2, v.end-v.start-2); vfs::String var_value; if(!vfs::OS::getEnv(var_name, var_value)) { VFS_LOG_WARNING(_BS(L"Could not expand environment variable : ") << var_name << _BS::wget); return false; } _path.replace(v.start,v.end-v.start+1,var_value.c_wcs()); pos.pop(); } doCheck(); } return true; }
vfs::IBaseFile* vfs::CVirtualFileSystem::getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF) { VFS_LOG_DEBUG( (L"Get file : " + rLocalFilePath()).c_str() ); vfs::Path sDir,sFile; rLocalFilePath.splitLast(sDir,sFile); vfs::CVirtualLocation* pVLoc = this->getVirtualLocation(sDir); if(pVLoc) { vfs::CVirtualFile *pVFile = pVLoc->getVirtualFile(sFile); if(pVFile) { if(pVLoc->getIsExclusive()) { return pVFile->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE); } return pVFile->file(eSF); } } VFS_LOG_DEBUG( _BS(L"Could not find file : ") << rLocalFilePath << _BS::wget ); return NULL; }
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 ); }
//Because loading and saving the map takes a few seconds, we want to post a message //on the screen and then update it which requires passing the screen back to the main loop. //When we come back for the next frame, we then actually save or load the map. So this //process takes two full screen cycles. UINT32 ProcessFileIO() { INT16 usStartX, usStartY; CHAR8 ubNewFilename[50]; BOOLEAN fAltMap;//dnl ch31 150909 switch( gbCurrentFileIOStatus ) { case INITIATE_MAP_SAVE: //draw save message StartFrameBufferRender( ); SaveFontSettings(); SetFont( HUGEFONT ); SetFontForeground( FONT_LTKHAKI ); SetFontShadow( FONT_DKKHAKI ); SetFontBackground( 0 ); swprintf( zOrigName, L"Saving map: %s", gzFilename ); usStartX = iScreenWidthOffset + 320 - StringPixLength( zOrigName, LARGEFONT1 ) / 2; usStartY = iScreenHeightOffset + 180 - GetFontHeight( LARGEFONT1 ) / 2; mprintf( usStartX, usStartY, zOrigName ); InvalidateScreen( ); EndFrameBufferRender( ); gbCurrentFileIOStatus = SAVING_MAP; return LOADSAVE_SCREEN; case SAVING_MAP: //save map sprintf( ubNewFilename, "%S", gzFilename ); RaiseWorldLand(); if( gfShowPits ) RemoveAllPits(); OptimizeSchedules(); ShowHighGround(4);//dnl ch41 210909 //dnl ch33 091009 BOOLEAN fRet; if(gfVanillaMode && iNewMapWorldRows == OLD_WORLD_ROWS && iNewMapWorldCols == OLD_WORLD_COLS) fRet = SaveWorld(ubNewFilename, VANILLA_MAJOR_MAP_VERSION, VANILLA_MINOR_MAP_VERSION); else fRet = SaveWorld(ubNewFilename); if(!fRet) { //dnl ch37 150909 gfSaveError = TRUE; if(gfErrorCatch) { InitErrorCatchDialog(); return(EDIT_SCREEN); } gbCurrentFileIOStatus = IOSTATUS_NONE; CreateMessageBox((STR16)(_BS(L" Error saving ") << (const char*)ubNewFilename << L" file. Try another filename? " << _BS::wget).c_str() ); return(guiCurrentScreen); } if( gfShowPits ) AddAllPits(); GetSectorFromFileName(gzFilename, gWorldSectorX, gWorldSectorY, gbWorldSectorZ, fAltMap);//dnl ch31 140909 if( gfGlobalSummaryExists ) UpdateSectorSummary( gzFilename, gfUpdateSummaryInfo ); else//dnl ch30 150909 ReEvaluateWorld(ubNewFilename); iCurrentAction = ACTION_NULL; gbCurrentFileIOStatus = IOSTATUS_NONE; gfRenderWorld = TRUE; gfRenderTaskbar = TRUE; fEnteringLoadSaveScreen = TRUE; RestoreFontSettings(); if( gfErrorCatch ) { InitErrorCatchDialog(); return EDIT_SCREEN; } fNewMapSaved = TRUE; return EDIT_SCREEN; case INITIATE_MAP_LOAD: //draw load message SaveFontSettings(); gbCurrentFileIOStatus = LOADING_MAP; if( gfEditMode && iCurrentTaskbar == TASK_MERCS ) IndicateSelectedMerc( SELECT_NO_MERC ); SpecifyItemToEdit( NULL, -1 ); return LOADSAVE_SCREEN; case LOADING_MAP: //load map DisableUndo(); sprintf( ubNewFilename, "%S", gzFilename ); RemoveMercsInSector( ); // Want to override crash, so user can do something else. if(!ReEvaluateWorld(ubNewFilename) || !LoadWorld(ubNewFilename))//dnl ch36 140909 { EnableUndo(); gbCurrentFileIOStatus = IOSTATUS_NONE; gfGlobalError = FALSE; gfLoadError = TRUE; CreateMessageBox((STR16)(_BS(L" Error loading ") << (const char*)ubNewFilename << L" file. Try another filename? " << _BS::wget).c_str()); return(guiCurrentScreen); } //ADB these are NOT set yet! but they need to be, duh CompileWorldMovementCosts(); GetSectorFromFileName(gzFilename, gWorldSectorX, gWorldSectorY, gbWorldSectorZ, fAltMap);//dnl ch31 140909 RestoreFontSettings(); //Load successful, update necessary information. //ATE: Any current mercs are transfered here... //UpdateMercsInSector( gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); AddSoldierInitListTeamToWorld( ENEMY_TEAM, 255 ); AddSoldierInitListTeamToWorld( CREATURE_TEAM, 255 ); AddSoldierInitListTeamToWorld( MILITIA_TEAM, 255 ); AddSoldierInitListTeamToWorld( CIV_TEAM, 255 ); iCurrentAction = ACTION_NULL; gbCurrentFileIOStatus = IOSTATUS_NONE; if( !gfCaves && !gfBasement ) { gusLightLevel = 12; if( ubAmbientLightLevel != 4 ) { ubAmbientLightLevel = 4; LightSetBaseLevel( ubAmbientLightLevel ); } } else gusLightLevel = (UINT16)(EDITOR_LIGHT_MAX - ubAmbientLightLevel ); gEditorLightColor = gpLightColors[ 0 ]; gfRenderWorld = TRUE; gfRenderTaskbar = TRUE; fEnteringLoadSaveScreen = TRUE; InitJA2SelectionWindow(); ShowEntryPoints(); EnableUndo(); RemoveAllFromUndoList(); SetEditorSmoothingMode( gMapInformation.ubEditorSmoothingType ); if( gMapInformation.ubEditorSmoothingType == SMOOTHING_CAVES ) AnalyseCaveMapForStructureInfo(); AddLockedDoorCursors(); gubCurrRoomNumber = gubMaxRoomNumber; UpdateRoofsView(); UpdateWallsView(); ShowLightPositionHandles(); SetMercTeamVisibility( ENEMY_TEAM, gfShowEnemies ); SetMercTeamVisibility( CREATURE_TEAM, gfShowCreatures ); SetMercTeamVisibility( MILITIA_TEAM, gfShowRebels ); SetMercTeamVisibility( CIV_TEAM, gfShowCivilians ); BuildItemPoolList(); gpItemPool = NULL;//dnl ch26 210909 fShowHighGround = FALSE;//dnl ch2 210909 fRaiseWorld = FALSE;//dnl ch3 210909 ShowHighGround(4);//dnl ch41 210909 SetRenderCenter(WORLD_COLS/2, WORLD_ROWS/2);//dnl ch43 280909 if( gfShowPits ) AddAllPits(); if( iCurrentTaskbar == TASK_MAPINFO ) { //We have to temporarily remove the current textinput mode, //update the disabled text field values, then restore the current //text input fields. SaveAndRemoveCurrentTextInputMode(); UpdateMapInfoFields(); RestoreSavedTextInputMode(); } return EDIT_SCREEN; } gbCurrentFileIOStatus = IOSTATUS_NONE; return LOADSAVE_SCREEN; }