From 1b31218f2bd07e876a070b6a07478a2d55da8bf2 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 6 Aug 2002 09:19:56 +0000 Subject: [PATCH] added FileStat and FileExits to the drives Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@110 --- src/dos/drive_local.cpp | 29 +++++++++++++++++++++++++++-- src/dos/drive_virtual.cpp | 28 ++++++++++++++++++++++++++++ src/dos/drives.h | 7 ++++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/dos/drive_local.cpp b/src/dos/drive_local.cpp index 9b7cf0a1..59171647 100644 --- a/src/dos/drive_local.cpp +++ b/src/dos/drive_local.cpp @@ -187,6 +187,7 @@ bool localDrive::RemoveDir(char * dir) { char newdir[512]; strcpy(newdir,basedir); strcat(newdir,dir); + CROSS_FILENAME(newdir); int temp=rmdir(newdir); return (temp==0); } @@ -195,6 +196,7 @@ bool localDrive::TestDir(char * dir) { char newdir[512]; strcpy(newdir,basedir); strcat(newdir,dir); + CROSS_FILENAME(newdir); int temp=access(newdir,F_OK); return (temp==0); } @@ -206,8 +208,8 @@ bool localDrive::Rename(char * oldname,char * newname) { CROSS_FILENAME(newold); char newnew[512]; strcpy(newnew,basedir); - strcat(newnew,newnew); - CROSS_FILENAME(newname); + strcat(newnew,newname); + CROSS_FILENAME(newnew); int temp=rename(newold,newnew); return (temp==0); @@ -223,6 +225,28 @@ bool localDrive::FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit return true; }; +bool localDrive::FileExists(const char* name) const { + char newname[512]; + strcpy(newname,basedir); + strcat(newname,name); + CROSS_FILENAME(newname); + FILE* Temp=fopen(newname,"br"); + if(Temp==NULL) return false; + fclose(Temp); + return true; +} + +bool localDrive::FileStat(const char* name, struct stat* const stat_block) const { + char newname[512]; + strcpy(newname,basedir); + strcat(newname,name); + CROSS_FILENAME(newname); + if(stat(newname,stat_block)!=0) return false; + return true; + +} + + localDrive::localDrive(char * startdir) { strcpy(basedir,startdir); @@ -275,3 +299,4 @@ localFile::localFile(FILE * handle,Bit16u devinfo) { info=devinfo; } + diff --git a/src/dos/drive_virtual.cpp b/src/dos/drive_virtual.cpp index b8140e1d..0be5dc6e 100644 --- a/src/dos/drive_virtual.cpp +++ b/src/dos/drive_virtual.cpp @@ -19,10 +19,12 @@ #include #include #include +#include #include "dosbox.h" #include "dos_system.h" #include "drives.h" #include "support.h" +#include "cross.h" struct VFILE_Block { char * name; @@ -151,6 +153,32 @@ bool Virtual_Drive::TestDir(char * dir) { return false; } +bool Virtual_Drive::FileStat(const char* name, struct stat* const stat_block) const { + VFILE_Block * cur_file=first_file; + while (cur_file) { + if (strcasecmp(name,cur_file->name)==0) { + stat_block->st_size=cur_file->size; + struct tm tijd; + tijd.tm_hour=0;tijd.tm_min=0;tijd.tm_sec=0; + tijd.tm_year=80;tijd.tm_mday=6;tijd.tm_mon=0; + stat_block->st_mtime=mktime(&tijd); + /* more not needed at the moment (fcbopen.....)*/ + return true; + } + cur_file=cur_file->next; + } + return false; +} + +bool Virtual_Drive::FileExists(const char* name) const { + VFILE_Block * cur_file=first_file; + while (cur_file) { + if (strcasecmp(name,cur_file->name)==0) return true; + cur_file=cur_file->next; + } + return false; +} + static void FillDTABlock(DTA_FindBlock * dta,VFILE_Block * fill_file) { strcpy(dta->name,fill_file->name); dta->size=fill_file->size; diff --git a/src/dos/drives.h b/src/dos/drives.h index a2dcf75e..b46e376a 100644 --- a/src/dos/drives.h +++ b/src/dos/drives.h @@ -21,7 +21,7 @@ #include #include - +#include "dos_system.h" class localDrive : public DOS_Drive { public: @@ -37,6 +37,8 @@ public: bool GetFileAttr(char * name,Bit16u * attr); bool Rename(char * oldname,char * newname); bool FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit16u * free); + bool FileExists(const char* name) const ; + bool FileStat(const char* name, struct stat* const stat_block) const; private: bool FillDTABlock(DTA_FindBlock * dta); char basedir[512]; @@ -63,6 +65,9 @@ public: bool GetFileAttr(char * name,Bit16u * attr); bool Rename(char * oldname,char * newname); bool FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit16u * free); + bool FileExists(const char* name) const ; + bool FileStat(const char* name, struct stat* const stat_block) const; + private: VFILE_Block * search_file; char search_string[255];