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; }
Bit8u DOS_FCBWrite(Bit16u seg,Bit16u offset,Bit16u recno) { DOS_FCB fcb(seg,offset); Bit8u fhandle,cur_rec;Bit16u cur_block,rec_size; fcb.GetSeqData(fhandle,rec_size); if (fhandle==0xff && rec_size!=0) { if (!DOS_FCBOpen(seg,offset)) return FCB_READ_NODATA; LOG(LOG_FCB,LOG_WARN)("Reopened closed FCB"); fcb.GetSeqData(fhandle,rec_size); } fcb.GetRecord(cur_block,cur_rec); Bit32u pos=((cur_block*128)+cur_rec)*rec_size; if (!DOS_SeekFile(fhandle,&pos,DOS_SEEK_SET)) return FCB_ERR_WRITE; MEM_BlockRead(Real2Phys(dos.dta())+recno*rec_size,dos_copybuf,rec_size); Bit16u towrite=rec_size; if (!DOS_WriteFile(fhandle,dos_copybuf,&towrite)) return FCB_ERR_WRITE; Bit32u size;Bit16u date,time; fcb.GetSizeDateTime(size,date,time); if (pos+towrite>size) size=pos+towrite; //time doesn't keep track of endofday date = DOS_PackDate(dos.date.year,dos.date.month,dos.date.day); Bit32u ticks = mem_readd(BIOS_TIMER); Bit32u seconds = (ticks*10)/182; Bit16u hour = (Bit16u)(seconds/3600); Bit16u min = (Bit16u)((seconds % 3600)/60); Bit16u sec = (Bit16u)(seconds % 60); time = DOS_PackTime(hour,min,sec); Bit8u temp=RealHandle(fhandle); Files[temp]->time=time; Files[temp]->date=date; fcb.SetSizeDateTime(size,date,time); if (++cur_rec>127) { cur_block++;cur_rec=0; } fcb.SetRecord(cur_block,cur_rec); return FCB_SUCCESS; }
Bit8u DOS_FCBIncreaseSize(Bit16u seg,Bit16u offset) { DOS_FCB fcb(seg,offset); Bit8u fhandle,cur_rec; Bit16u cur_block,rec_size; fcb.GetSeqData(fhandle,rec_size); fcb.GetRecord(cur_block,cur_rec); Bit32u pos=((cur_block*128)+cur_rec)*rec_size; if (!DOS_SeekFile(fhandle,&pos,DOS_SEEK_SET,true)) return FCB_ERR_WRITE; Bit16u towrite=0; if (!DOS_WriteFile(fhandle,dos_copybuf,&towrite,true)) return FCB_ERR_WRITE; Bit32u size; Bit16u date,time; fcb.GetSizeDateTime(size,date,time); if (pos+towrite>size) size=pos+towrite; //time doesn't keep track of endofday date = DOS_PackDate(dos.date.year,dos.date.month,dos.date.day); Bit32u ticks = mem_readd(BIOS_TIMER); Bit32u seconds = (ticks*10)/182; Bit16u hour = (Bit16u)(seconds/3600); Bit16u min = (Bit16u)((seconds % 3600)/60); Bit16u sec = (Bit16u)(seconds % 60); time = DOS_PackTime(hour,min,sec); Files[fhandle]->time = time; Files[fhandle]->date = date; fcb.SetSizeDateTime(size,date,time); fcb.SetRecord(cur_block,cur_rec); return FCB_SUCCESS; }
Virtual_File::Virtual_File(Bit8u * in_data,Bit32u in_size) { file_size=in_size; file_data=in_data; file_pos=0; date=DOS_PackDate(2002,10,1); time=DOS_PackTime(12,34,56); }
void VFILE_Register(const char * name,Bit8u * data,Bit32u size) { VFILE_Block * new_file=new VFILE_Block; new_file->name=name; new_file->data=data; new_file->size=size; new_file->date=DOS_PackDate(2002,10,1); new_file->time=DOS_PackTime(12,34,56); new_file->next=first_file; first_file=new_file; }
bool localDrive::FindNext(DOS_DTA & dta) { char * dir_ent; struct stat stat_block; char full_name[CROSS_LEN]; char dir_entcopy[CROSS_LEN]; Bit8u srch_attr;char srch_pattern[DOS_NAMELENGTH_ASCII]; Bit8u find_attr; dta.GetSearchParams(srch_attr,srch_pattern); Bit16u 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; strcpy(full_name,srchInfo[id].srch_dir); strcat(full_name,dir_ent); //GetExpandName might indirectly destroy dir_ent (by caching in a new directory //and due to its design dir_ent might be lost.) //Copying dir_ent first strcpy(dir_entcopy,dir_ent); if (stat(dirCache.GetExpandName(full_name),&stat_block)!=0) { goto again;//No symlinks and such } if(stat_block.st_mode & S_IFDIR) find_attr=DOS_ATTR_DIRECTORY; 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 */ char find_name[DOS_NAMELENGTH_ASCII];Bit16u find_date,find_time;Bit32u find_size; if(strlen(dir_entcopy)<DOS_NAMELENGTH_ASCII){ strcpy(find_name,dir_entcopy); upcase(find_name); } find_size=(Bit32u) stat_block.st_size; struct tm *time; if((time=localtime(&stat_block.st_mtime))!=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); }
bool localFile::UpdateDateTimeFromHost(void) { if(!open) return false; struct stat temp_stat; fstat(fileno(fhandle),&temp_stat); struct tm * ltime; if((ltime=localtime(&temp_stat.st_mtime))!=0) { time=DOS_PackTime((Bit16u)ltime->tm_hour,(Bit16u)ltime->tm_min,(Bit16u)ltime->tm_sec); date=DOS_PackDate((Bit16u)(ltime->tm_year+1900),(Bit16u)(ltime->tm_mon+1),(Bit16u)ltime->tm_mday); } else { time=1;date=1; } return true; }
bool Virtual_Drive::FileStat(const char* name, FileStat_Block * const stat_block){ VFILE_Block * cur_file=first_file; while (cur_file) { if (strcasecmp(name,cur_file->name)==0) { stat_block->attr=DOS_ATTR_ARCHIVE; stat_block->size=cur_file->size; stat_block->date=DOS_PackDate(2002,10,1); stat_block->time=DOS_PackTime(12,34,56); return true; } cur_file=cur_file->next; } return false; }
void VFILE_Register(const char * name, Bit8u * data, Bit16u size) { VFILE_Block * new_file = new VFILE_Block; new_file->name = name; new_file->data = data; new_file->size = size; _SYSTEMTIME systime; GetLocalTime(&systime); // Windows localdate/time new_file->date = DOS_PackDate(systime.wYear, systime.wMonth, systime.wDay); new_file->time = DOS_PackTime(systime.wHour, systime.wMinute, systime.wSecond); new_file->next = first_file; first_file = new_file; }
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 localDrive::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); struct stat temp_stat; if(stat(newname,&temp_stat)!=0) return false; /* Convert the stat to a FileStat */ struct tm *time; if((time=localtime(&temp_stat.st_mtime))!=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->size=(Bit32u)temp_stat.st_size; return true; }
Bit8u DOS_FCBWrite(Bit16u seg, Bit16u offset, Bit16u recno) { DOS_FCB fcb(seg, offset); Bit8u fhandle, cur_rec; Bit16u cur_block, rec_size; fcb.GetSeqData(fhandle, rec_size); fcb.GetRecord(cur_block, cur_rec); Bit32u pos=((cur_block*128)+cur_rec)*rec_size; if (!DOS_SeekFile(fhandle, &pos, DOS_SEEK_SET)) return FCB_ERR_WRITE; vPC_rBlockRead(dWord2Ptr(dos.dta())+recno*rec_size, dos_copybuf, rec_size); Bit16u towrite = rec_size; if (!DOS_WriteFile(fhandle, dos_copybuf, &towrite)) return FCB_ERR_WRITE; Bit32u size; Bit16u date, time; fcb.GetSizeDateTime(size, date, time); if (pos+towrite > size) size = pos+towrite; date = DOS_PackDate(dos.date.year, dos.date.month, dos.date.day); // Ttime doesn't keep track of endofday Bit32u ticks = vPC_rLodsd(BIOS_TIMER); Bit32u seconds = (ticks*10)/182; Bit16u hour = (Bit16u)(seconds/3600); Bit16u min = (Bit16u)((seconds % 3600)/60); Bit16u sec = (Bit16u)(seconds % 60); time = DOS_PackTime(hour, min, sec); Bit8u temp = RealHandle(fhandle); Files[temp]->time = time; Files[temp]->date = date; fcb.SetSizeDateTime(size, date, time); if (++cur_rec > 127) { cur_block++; cur_rec = 0; } fcb.SetRecord(cur_block, cur_rec); return FCB_SUCCESS; }