From af1673c6f2ffd32729ab531e5bda30cf5f770cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Tue, 14 Nov 2006 20:01:42 +0000 Subject: [PATCH] re-fix deleting of hostwise open files (makes Alien Carnage work again without breaking Abuse) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2722 --- include/dos_system.h | 8 ++++++-- src/dos/dos_files.cpp | 18 ++++++++++-------- src/dos/drive_fat.cpp | 3 ++- src/dos/drive_local.cpp | 8 ++------ src/dos/drive_virtual.cpp | 1 + 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/dos_system.h b/include/dos_system.h index 0e1311e1..5e48e278 100644 --- a/include/dos_system.h +++ b/include/dos_system.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_system.h,v 1.36 2006-06-22 13:15:07 qbix79 Exp $ */ +/* $Id: dos_system.h,v 1.37 2006-11-14 20:01:42 c2woody Exp $ */ #ifndef DOSBOX_DOS_SYSTEM_H #define DOSBOX_DOS_SYSTEM_H @@ -96,10 +96,14 @@ private: class DOS_Device : public DOS_File { public: - DOS_Device(const DOS_Device& orig):DOS_File(orig) {devnum=orig.devnum; } + DOS_Device(const DOS_Device& orig):DOS_File(orig) { + devnum=orig.devnum; + open=true; + } DOS_Device & operator= (const DOS_Device & orig) { DOS_File::operator=(orig); devnum=orig.devnum; + open=true; return *this; } DOS_Device():DOS_File(),devnum(0){}; diff --git a/src/dos/dos_files.cpp b/src/dos/dos_files.cpp index a2208227..b4d29e1e 100644 --- a/src/dos/dos_files.cpp +++ b/src/dos/dos_files.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_files.cpp,v 1.78 2006-08-05 10:39:44 qbix79 Exp $ */ +/* $Id: dos_files.cpp,v 1.79 2006-11-14 20:01:42 c2woody Exp $ */ #include #include @@ -307,7 +307,7 @@ bool DOS_ReadFile(Bit16u entry,Bit8u * data,Bit16u * amount) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[handle]) { + if (!Files[handle] || !Files[handle]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; @@ -330,7 +330,7 @@ bool DOS_WriteFile(Bit16u entry,Bit8u * data,Bit16u * amount) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[handle]) { + if (!Files[handle] || !Files[handle]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; @@ -353,7 +353,7 @@ bool DOS_SeekFile(Bit16u entry,Bit32u * pos,Bit32u type) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[handle]) { + if (!Files[handle] || !Files[handle]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; @@ -370,7 +370,9 @@ bool DOS_CloseFile(Bit16u entry) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - Files[handle]->Close(); + if (Files[handle]->IsOpen()) { + Files[handle]->Close(); + } DOS_PSP psp(dos.psp()); psp.SetFileHandle(entry,0xff); if (Files[handle]->RemoveRef()<=0) { @@ -576,7 +578,7 @@ bool DOS_DuplicateEntry(Bit16u entry,Bit16u * newentry) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[handle]) { + if (!Files[handle] || !Files[handle]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; @@ -601,7 +603,7 @@ bool DOS_ForceDuplicateEntry(Bit16u entry,Bit16u newentry) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[orig]) { + if (!Files[orig] || !Files[orig]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; @@ -1037,7 +1039,7 @@ bool DOS_GetFileDate(Bit16u entry, Bit16u* otime, Bit16u* odate) DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - if (!Files[handle]) { + if (!Files[handle] || !Files[handle]->IsOpen()) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; diff --git a/src/dos/drive_fat.cpp b/src/dos/drive_fat.cpp index 9ec8d786..b1323cda 100644 --- a/src/dos/drive_fat.cpp +++ b/src/dos/drive_fat.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: drive_fat.cpp,v 1.18 2006-07-05 21:18:14 c2woody Exp $ */ +/* $Id: drive_fat.cpp,v 1.19 2006-11-14 20:01:42 c2woody Exp $ */ #include #include @@ -91,6 +91,7 @@ fatFile::fatFile(const char* /*name*/, Bit32u startCluster, Bit32u fileLen, fatD firstCluster = startCluster; myDrive = useDrive; filelength = fileLen; + open = true; loadedSector = false; curSectOff = 0; seekpos = 0; diff --git a/src/dos/drive_local.cpp b/src/dos/drive_local.cpp index a9ebcfe8..3afab93e 100644 --- a/src/dos/drive_local.cpp +++ b/src/dos/drive_local.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: drive_local.cpp,v 1.71 2006-08-17 12:07:22 c2woody Exp $ */ +/* $Id: drive_local.cpp,v 1.72 2006-11-14 20:01:42 c2woody Exp $ */ #include #include @@ -160,11 +160,7 @@ bool localDrive::FileUnlink(char * name) { Bitu max = DOS_FILES; while(Files[i]->IsOpen() && max--) { Files[i]->Close(); - if (Files[i]->RemoveRef()<=0) { - delete Files[i]; - Files[i]=0; - break; - } + if (Files[i]->RemoveRef()<=0) break; } found_file=true; } diff --git a/src/dos/drive_virtual.cpp b/src/dos/drive_virtual.cpp index 7ac1d0e2..2f900b6c 100644 --- a/src/dos/drive_virtual.cpp +++ b/src/dos/drive_virtual.cpp @@ -85,6 +85,7 @@ Virtual_File::Virtual_File(Bit8u * in_data,Bit32u in_size) { file_pos=0; date=DOS_PackDate(2002,10,1); time=DOS_PackTime(12,34,56); + open=true; } bool Virtual_File::Read(Bit8u * data,Bit16u * size) {