diff --git a/include/dos_system.h b/include/dos_system.h index 5edb0487..eab510e7 100644 --- a/include/dos_system.h +++ b/include/dos_system.h @@ -156,8 +156,9 @@ public: public: CFileInfo(void) { orgname[0] = shortname[0] = 0; - nextEntry = shortNr = 0; isDir = false; + id = MAX_OPENDIRS; + nextEntry = shortNr = 0; } ~CFileInfo(void) { for (Bit32u i=0; iid != MAX_OPENDIRS) + return dir->id; + for (Bit16u i=0; iid = i; + return i; + } + } LOG(LOG_FILES,LOG_NORMAL)("DIRCACHE: Too many open directories!"); + dir->id=0; return 0; } @@ -262,7 +269,7 @@ void DOS_Drive_Cache::CacheOut(const char* path, bool ignoreLastDir) { // delete file objects... for(Bit32u i=0; ifileList.size(); i++) { if (dirSearch[srchNr]==dir->fileList[i]) dirSearch[srchNr] = 0; - delete dir->fileList[i]; dir->fileList[i] = 0; + DeleteFileInfo(dir->fileList[i]); dir->fileList[i] = 0; } // clear lists dir->fileList.clear(); @@ -524,7 +531,10 @@ DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char* strcpy(buffer,dirPath); ReadDir(id,result); strcpy(dirPath,buffer); - free[id] = true; + if (dirSearch[id]) { + dirSearch[id]->id = MAX_OPENDIRS; + dirSearch[id] = 0; + } }; }; @@ -554,7 +564,10 @@ DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char* strcpy(buffer,dirPath); ReadDir(id,result); strcpy(dirPath,buffer); - free[id] = true; + if (dirSearch[id]) { + dirSearch[id]->id = MAX_OPENDIRS; + dirSearch[id] = 0; + } }; } }; @@ -598,9 +611,12 @@ bool DOS_Drive_Cache::OpenDir(CFileInfo* dir, const char* expand, Bit16u& id) { // Reset it.. close_directory(dirp); strcpy(dirPath,expandcopy); - free[id] = false; return true; } + if (dirSearch[id]) { + dirSearch[id]->id = MAX_OPENDIRS; + dirSearch[id] = 0; + } }; return false; } @@ -659,7 +675,10 @@ bool DOS_Drive_Cache::ReadDir(Bit16u id, char* &result) { // Try to open directory dir_information* dirp = open_directory(dirPath); if (!dirp) { - free[id] = true; + if (dirSearch[id]) { + dirSearch[id]->id = MAX_OPENDIRS; + dirSearch[id] = 0; + } return false; } // Read complete directory @@ -686,7 +705,10 @@ bool DOS_Drive_Cache::ReadDir(Bit16u id, char* &result) { };*/ }; if (SetResult(dirSearch[id], result, dirSearch[id]->nextEntry)) return true; - free[id] = true; + if (dirSearch[id]) { + dirSearch[id]->id = MAX_OPENDIRS; + dirSearch[id] = 0; + } return false; } @@ -730,7 +752,7 @@ bool DOS_Drive_Cache::FindFirst(char* path, Bit16u& id) { this->nextFreeFindFirst = 1; //the next free one after this search for(Bitu n=0; nnextEntry)) { // free slot - delete dirFindFirst[id]; dirFindFirst[id] = 0; + DeleteFileInfo(dirFindFirst[id]); dirFindFirst[id] = 0; return false; } return true; } + +void DOS_Drive_Cache::ClearFileInfo(CFileInfo *dir) { + for(Bit32u i=0; ifileList.size(); i++) { + if (CFileInfo *info = dir->fileList[i]) + ClearFileInfo(info); + } + if (dir->id != MAX_OPENDIRS) { + dirSearch[dir->id] = 0; + dir->id = MAX_OPENDIRS; + } +} + +void DOS_Drive_Cache::DeleteFileInfo(CFileInfo *dir) { + if (dir) + ClearFileInfo(dir); + delete dir; +}