void MainMenu::fillLoadMenu( bool save /*= false*/ ) { const std::string buttonNames[]={"File0","File1","File2","File3","File4","File5"}; char** rc = PHYSFS_enumerateFiles("/"); char* curfile; CheckButton *button; for(int i=0;i<6;i++) { char* recentfile = NULL; PHYSFS_sint64 t = 0; std::stringstream filestart; filestart << i+1 << "_"; if( save ){ button = getCheckButton(*saveGameMenu.get(),buttonNames[i]); } else { button = getCheckButton(*loadGameMenu.get(),buttonNames[i]); } //make sure Button is connected only once button->clicked.clear(); if( save ) button->clicked.connect(makeCallback(*this,&MainMenu::selectSaveGameButtonClicked)); else { button->clicked.connect(makeCallback(*this,&MainMenu::selectLoadGameButtonClicked)); } for(char** i = rc; *i != 0; i++){ curfile = *i; if(std::string( curfile ).find( filestart.str() ) == 0 ) { // && !( curfile->d_type & DT_DIR ) ) is not portable. So // don't create a directoy named 2_ in a savegame-directory or // you can no longer load from slot 2. if (t == 0) { recentfile = curfile; t = PHYSFS_getLastModTime(recentfile); } else { if (PHYSFS_getLastModTime(curfile) > t) { /*#ifdef DEBUG fprintf(stderr," %s is more recent than previous %s\n", curfile, recentfile); #endif*/ recentfile = curfile; t = PHYSFS_getLastModTime(recentfile); } } } } #ifdef DEBUG fprintf(stderr,"Most recent file: %s\n\n",recentfile); #endif if(t != 0) { std::string f= recentfile; button->setCaptionText(f); } else { button->setCaptionText(_("empty")); } } }
int64 getLastModTime(const std::string& file) { int64 timestamp = PHYSFS_getLastModTime(file.c_str()); if (timestamp == -1) throw Exception("PhysFS::getLastModTime: Can't determine time of last modification"); return timestamp; }
long long CResourceManager::GetLastModificationTime(const std::string& filename) { if (PHYSFS_isInit()) { return PHYSFS_getLastModTime(CleanPath(filename).c_str()); } return -1; }
int64_t Resources::getLastModTime(const char* filename) { int64_t modtime = PHYSFS_getLastModTime(filename); if (modtime < 0) { PError << "couldn't determine modification time of '" << filename << "': " << PHYSFS_getLastError() << endl; return NULL; }; return modtime; }
int64_t getLastModTime(const char* filename) { int64_t modtime = PHYSFS_getLastModTime(filename); if(modtime < 0) throw Exception("couldn't determine modification time of '%s': %s", filename, PHYSFS_getLastError()); return modtime; }
uint64_t Virtual_file_system::file_last_modified(const std::string& name) const { PHYSFS_sint64 timestamp = PHYSFS_getLastModTime(name.c_str()); if (timestamp < 0) { return 0; } else { return uint64_t(timestamp); } }
bool physfsFile::UpdateDateTimeFromHost(void) { if(!open) return false; time_t mytime = (time_t)PHYSFS_getLastModTime(pname); /* Convert the stat to a FileStat */ struct tm *lctime; if((lctime=localtime(&mytime))!=0) { this->time=DOS_PackTime((Bit16u)lctime->tm_hour,(Bit16u)lctime->tm_min,(Bit16u)lctime->tm_sec); this->date=DOS_PackDate((Bit16u)(lctime->tm_year+1900),(Bit16u)(lctime->tm_mon+1),(Bit16u)lctime->tm_mday); } else { this->time=DOS_PackTime(0,0,0); this->date=DOS_PackDate(1980,1,1); } return true; }
static int cmd_getlastmodtime(char *args) { PHYSFS_sint64 rc = PHYSFS_getLastModTime(args); if (rc == -1) printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError()); else { char modstr[64]; modTimeToStr(rc, modstr, sizeof (modstr)); printf("Last modified: %s (%ld).\n", modstr, (long) rc); } /* else */ return(1); } /* cmd_getLastModTime */
bool physfsDrive::FindNext(DOS_DTA & dta) { char * dir_ent; char full_name[CROSS_LEN]; Bit8u srch_attr;char srch_pattern[DOS_NAMELENGTH_ASCII]; Bit8u find_attr; dta.GetSearchParams(srch_attr,srch_pattern); Bitu id = dta.GetDirID(); again: if (!dirCache.FindNext(id,dir_ent)) { DOS_SetError(DOSERR_NO_MORE_FILES); return false; } if(!WildFileCmp(dir_ent,srch_pattern)) goto again; char find_name[DOS_NAMELENGTH_ASCII];Bit16u find_date,find_time;Bit32u find_size; if(strlen(dir_ent)<DOS_NAMELENGTH_ASCII){ strcpy(find_name,dir_ent); upcase(find_name); } strcpy(full_name,srchInfo[id].srch_dir); strcat(full_name,dir_ent); dirCache.ExpandName(full_name); normalize(full_name,basedir); if (PHYSFS_isDirectory(full_name)) find_attr=DOS_ATTR_DIRECTORY|DOS_ATTR_ARCHIVE; else find_attr=DOS_ATTR_ARCHIVE; if (~srch_attr & find_attr & (DOS_ATTR_DIRECTORY | DOS_ATTR_HIDDEN | DOS_ATTR_SYSTEM)) goto again; /*file is okay, setup everything to be copied in DTA Block */ find_size=(Bit32u)PHYSFS_fileLength(full_name); time_t mytime = (time_t)PHYSFS_getLastModTime(full_name); struct tm *time; if((time=localtime(&mytime))!=0){ find_date=DOS_PackDate((Bit16u)(time->tm_year+1900),(Bit16u)(time->tm_mon+1),(Bit16u)time->tm_mday); find_time=DOS_PackTime((Bit16u)time->tm_hour,(Bit16u)time->tm_min,(Bit16u)time->tm_sec); } else { find_time=6; find_date=4; } dta.SetResult(find_name,find_size,find_date,find_time,find_attr); return true; }
bool physfsDrive::FileStat(const char* name, FileStat_Block * const stat_block) { char newname[CROSS_LEN]; strcpy(newname,basedir); strcat(newname,name); CROSS_FILENAME(newname); dirCache.ExpandName(newname); normalize(newname,basedir); time_t mytime = (time_t)PHYSFS_getLastModTime(newname); /* Convert the stat to a FileStat */ struct tm *time; if((time=localtime(&mytime))!=0) { stat_block->time=DOS_PackTime((Bit16u)time->tm_hour,(Bit16u)time->tm_min,(Bit16u)time->tm_sec); stat_block->date=DOS_PackDate((Bit16u)(time->tm_year+1900),(Bit16u)(time->tm_mon+1),(Bit16u)time->tm_mday); } else { stat_block->time=DOS_PackTime(0,0,0); stat_block->date=DOS_PackDate(1980,1,1); } stat_block->size=(Bit32u)PHYSFS_fileLength(newname); return true; }
physfsFile::physfsFile(const char* _name, PHYSFS_file * handle,Bit16u devinfo, const char* physname, bool write) { fhandle=handle; info=devinfo; strcpy(pname,physname); time_t mytime = (time_t)PHYSFS_getLastModTime(pname); /* Convert the stat to a FileStat */ struct tm *lctime; if((lctime=localtime(&mytime))!=0) { this->time=DOS_PackTime((Bit16u)lctime->tm_hour,(Bit16u)lctime->tm_min,(Bit16u)lctime->tm_sec); this->date=DOS_PackDate((Bit16u)(lctime->tm_year+1900),(Bit16u)(lctime->tm_mon+1),(Bit16u)lctime->tm_mday); } else { this->time=DOS_PackTime(0,0,0); this->date=DOS_PackDate(1980,1,1); } attr=DOS_ATTR_ARCHIVE; last_action=(write?WRITE:READ); open=true; name=0; SetName(_name); }
long GetFileModifyTime(std::string path) { return PHYSFS_getLastModTime(path.c_str()); }
// //////////////////////////////////////////////////////////////////////////// bool addLoadSave(LOADSAVE_MODE savemode, const char *title) { bool bLoad = true; char NewSaveGamePath[PATH_MAX] = {'\0'}; bLoadSaveMode = savemode; UDWORD slotCount; static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; switch(savemode) { case LOAD_FRONTEND_MISSION: case LOAD_INGAME_MISSION: case LOAD_MISSIONEND: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; case LOAD_FRONTEND_SKIRMISH: case LOAD_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); break; case SAVE_MISSIONEND: case SAVE_INGAME_MISSION: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); bLoad = false; break; case SAVE_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); bLoad = false; break; default: ASSERT("Invalid load/save mode!", "Invalid load/save mode!"); ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; } mode = bLoad; debug(LOG_SAVE, "called (%d, %s)", bLoad, title); if ((bLoadSaveMode == LOAD_INGAME_MISSION) || (bLoadSaveMode == SAVE_INGAME_MISSION) || (bLoadSaveMode == LOAD_INGAME_SKIRMISH) || (bLoadSaveMode == SAVE_INGAME_SKIRMISH)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { bool radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } psRequestScreen = new W_SCREEN; WIDGET *parent = psRequestScreen->psForm; /* add a form to place the tabbed form on */ // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) IntFormAnimated *loadSaveForm = new IntFormAnimated(parent); loadSaveForm->id = LOADSAVE_FORM; loadSaveForm->setGeometry(LOADSAVE_X, LOADSAVE_Y, LOADSAVE_W, slotsInColumn*(LOADENTRY_H + LOADSAVE_HGAP) + LOADSAVE_BANNER_DEPTH + 20); // Add Banner W_FORMINIT sFormInit; sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label W_LABINIT sLabInit; sLabInit.formID = LOADSAVE_BANNER; sLabInit.FontID = font_large; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 0; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. W_BUTINIT sButInit; sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 10; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots sButInit = W_BUTINIT(); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; debug(LOG_SAVE, "Searching \"%s\" for savegames", NewSaveGamePath); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(NewSaveGamePath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; struct tm *timeinfo; // See if this filename contains the extension we're looking for if (!strstr(*i, sExt)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", NewSaveGamePath, *i); savetime = PHYSFS_getLastModTime(savefile); timeinfo = localtime(&savetime); strftime(sSlotTips[slotCount], sizeof(sSlotTips[slotCount]), "%x %X", timeinfo); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }
sint64 getLastModTime(const string& filename) { return PHYSFS_getLastModTime(filename.c_str()); }
//**************************************************************************************** // Load menu/save menu? //***************************************************************************************** static BOOL _addLoadSave(BOOL bLoad, const char *sSearchPath, const char *sExtension, const char *title) { W_FORMINIT sFormInit; W_BUTINIT sButInit; W_LABINIT sLabInit; UDWORD slotCount; // removed hardcoded values! change with the defines above! -Q static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; const char* checkExtension; mode = bLoad; debug(LOG_SAVE, "called (%d, %s, %s, %s)", bLoad, sSearchPath, sExtension, title); if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { BOOL radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface pie_UploadDisplayBuffer(); // Upload the current display back buffer into system memory. radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } (void) PHYSFS_mkdir(sSearchPath); // just in case psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen,font_regular); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) LOADSAVE_X; sFormInit.y = (SWORD) LOADSAVE_Y; sFormInit.width = LOADSAVE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * LOADENTRY_H + LOADSAVE_HGAP* slotsInColumn)+ LOADSAVE_BANNER_DEPTH+20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label memset(&sLabInit, 0, sizeof(W_LABINIT)); sLabInit.formID = LOADSAVE_BANNER; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 3; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; sLabInit.FontID = font_regular; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 8; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.FontID = font_regular; sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; sButInit.FontID = font_regular; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sstrcpy(sPath, sSearchPath); // setup locals. sstrcpy(sExt, sExtension); debug(LOG_SAVE, "Searching \"%s\" for savegames", sSearchPath); // Check for an extension like ".ext", not "ext" sasprintf((char**)&checkExtension, ".%s", sExtension); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(sSearchPath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; // See if this filename contains the extension we're looking for if (!strstr(*i, checkExtension)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", sSearchPath, *i); savetime = PHYSFS_getLastModTime(savefile); sstrcpy(sSlotTips[slotCount], ctime(&savetime)); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }
bool operator()(char* a,char* b) { PHYSFS_sint64 atime = PHYSFS_getLastModTime((m_dirName + a).c_str()); PHYSFS_sint64 btime = PHYSFS_getLastModTime((m_dirName + b).c_str()); return ( atime > btime ); }