1
0
Fork 0

Added Class to deactivate cache, for debugging purposes.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@644
This commit is contained in:
Ulf Wohlers 2003-01-19 17:55:05 +00:00
parent 75072258ec
commit b9434bbf8b
3 changed files with 80 additions and 21 deletions

View file

@ -78,8 +78,8 @@ void DOS_Drive_Cache::SetBaseDir(const char* baseDir)
{
strcpy(dirBase->fullname,baseDir);
if (OpenDir(baseDir)) {
struct dirent result;
ReadDir(&result);
struct dirent* result;
ReadDir(result);
};
};
@ -112,10 +112,6 @@ char* DOS_Drive_Cache::GetExpandName(const char* path)
void DOS_Drive_Cache::AddEntry(const char* path)
{
CacheOut(path);
return;
// FIXME: Code doesnt seem to work with arena ??? Why is that ?
// Get Last part...
char file [CROSS_LEN];
@ -124,6 +120,11 @@ void DOS_Drive_Cache::AddEntry(const char* path)
CFileInfo* dir = FindDirInfo(path,expand);
char* pos = strrchr(path,CROSS_FILESPLIT);
char* name = pos+1;
if (GetLongName(dir,name)<0) {
int brk = 0;
};
if (pos) {
strcpy(file,pos+1);
@ -131,12 +132,13 @@ void DOS_Drive_Cache::AddEntry(const char* path)
// Sort Lists - filelist has to be alphabetically sorted
std::sort(dir->fileList.begin(), dir->fileList.end(), SortByName);
// Output list - user defined
switch (sortDirType) {
/* switch (sortDirType) {
case ALPHABETICAL : std::sort(dir->outputList.begin(), dir->outputList.end(), SortByName); break;
case DIRALPHABETICAL : std::sort(dir->outputList.begin(), dir->outputList.end(), SortByDirName); break;
case ALPHABETICALREV : std::sort(dir->outputList.begin(), dir->outputList.end(), SortByNameRev); break;
case DIRALPHABETICALREV : std::sort(dir->outputList.begin(), dir->outputList.end(), SortByDirNameRev); break;
};
};*/
// nextEntry++;
// LOG_DEBUG("DIR: Added Entry %s",path);
} else {
// LOG_DEBUG("DIR: Error: Failed to add %s",path);
@ -170,7 +172,7 @@ void DOS_Drive_Cache::CacheOut(const char* path, bool ignoreLastDir)
dir->outputList.clear();
dir->shortNr = 0;
save_dir = 0;
nextEntry = 0;
// nextEntry = 0;
};
bool DOS_Drive_Cache::IsCachedIn(CFileInfo* curDir)
@ -357,8 +359,8 @@ DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char*
if (pos) work[(Bit32u)pos-(Bit32u)path] = 0;
if (!IsCachedIn(curDir)) {
if (OpenDir(curDir,work)) {
struct dirent result;
ReadDir(&result);
struct dirent* result;
ReadDir(result);
};
}
};
@ -425,7 +427,7 @@ void DOS_Drive_Cache::CreateEntry(CFileInfo* dir, const char* name)
dir->outputList.push_back(info);
};
bool DOS_Drive_Cache::ReadDir(struct dirent* result)
bool DOS_Drive_Cache::ReadDir(struct dirent* &result)
{
if (dirFirstTime) {
if (!IsCachedIn(dirSearch)) {
@ -466,8 +468,11 @@ bool DOS_Drive_Cache::ReadDir(struct dirent* result)
return SetResult(dirSearch, result, nextEntry);
};
bool DOS_Drive_Cache::SetResult(CFileInfo* dir, struct dirent* result, Bit16u entryNr)
bool DOS_Drive_Cache::SetResult(CFileInfo* dir, struct dirent* &result, Bit16u entryNr)
{
static struct dirent res;
result = &res;
if (entryNr>=dir->outputList.size()) return false;
CFileInfo* info = dir->outputList[entryNr];
// copy filename, short version
@ -477,3 +482,33 @@ bool DOS_Drive_Cache::SetResult(CFileInfo* dir, struct dirent* result, Bit16u en
return true;
};
// ****************************************************************************
// No Dir Cache,
// ****************************************************************************
DOS_No_Drive_Cache::DOS_No_Drive_Cache(const char* path)
{
SetBaseDir(path);
};
void DOS_No_Drive_Cache::SetBaseDir(const char* path)
{
strcpy(basePath,path);
}
bool DOS_No_Drive_Cache::OpenDir(const char* path)
{
strcpy(dirPath,path);
if((srch_opendir=opendir(dirPath))==NULL) return false;
return true;
};
bool DOS_No_Drive_Cache::ReadDir(struct dirent* &result)
{
if((result=readdir(srch_opendir))==NULL) {
closedir(srch_opendir);
srch_opendir=NULL;
return false;
}
return true;
};

View file

@ -112,7 +112,7 @@ bool localDrive::FindFirst(char * _dir,DOS_DTA & dta) {
bool localDrive::FindNext(DOS_DTA & dta) {
struct dirent dir_ent;
struct dirent* dir_ent;
struct stat stat_block;
char full_name[CROSS_LEN];
@ -122,12 +122,12 @@ bool localDrive::FindNext(DOS_DTA & dta) {
dta.GetSearchParams(srch_attr,srch_pattern);
again:
if (!dirCache.ReadDir(&dir_ent)) return false;
if (!dirCache.ReadDir(dir_ent)) return false;
if(!WildFileCmp(dir_ent.d_name,srch_pattern)) goto again;
if(!WildFileCmp(dir_ent->d_name,srch_pattern)) goto again;
strcpy(full_name,srch_dir);
strcat(full_name,dir_ent.d_name);
strcat(full_name,dir_ent->d_name);
if (stat(dirCache.GetExpandName(full_name),&stat_block)!=0) {
goto again;
}
@ -143,8 +143,8 @@ 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_ent.d_name)<DOS_NAMELENGTH_ASCII){
strcpy(find_name,dir_ent.d_name);
if(strlen(dir_ent->d_name)<DOS_NAMELENGTH_ASCII){
strcpy(find_name,dir_ent->d_name);
upcase(find_name);
}

View file

@ -39,7 +39,7 @@ public:
void SetBaseDir (const char* path);
void SetDirSort (TDirSort sort) { sortDirType = sort; };
bool OpenDir (const char* path);
bool ReadDir (struct dirent* result);
bool ReadDir (struct dirent* &result);
void ExpandName (char* path);
char* GetExpandName (const char* path);
@ -72,7 +72,7 @@ private:
Bit16s GetLongName (CFileInfo* info, char* shortname);
void CreateShortName (CFileInfo* dir, CFileInfo* info);
Bit16u CreateShortNameID (CFileInfo* dir, const char* name);
bool SetResult (CFileInfo* dir, struct dirent* result, Bit16u entryNr);
bool SetResult (CFileInfo* dir, struct dirent* &result, Bit16u entryNr);
bool IsCachedIn (CFileInfo* dir);
CFileInfo* FindDirInfo (const char* path, char* expandedPath);
bool RemoveSpaces (char* str);
@ -91,6 +91,30 @@ private:
};
class DOS_No_Drive_Cache {
public:
DOS_No_Drive_Cache (void) {};
DOS_No_Drive_Cache (const char* path);
~DOS_No_Drive_Cache (void) {};
typedef enum TDirSort { NOSORT, ALPHABETICAL, DIRALPHABETICAL, ALPHABETICALREV, DIRALPHABETICALREV };
void SetBaseDir (const char* path);
void SetDirSort (TDirSort sort) {};
bool OpenDir (const char* path);
bool ReadDir (struct dirent* &result);
void ExpandName (char* path) {};
char* GetExpandName (const char* path) { return (char*)path; };
void CacheOut (const char* path, bool ignoreLastDir = false) {};
void AddEntry (const char* path) {};
public:
char basePath [CROSS_LEN];
char dirPath [CROSS_LEN];
DIR* srch_opendir;
};
class localDrive : public DOS_Drive {
public:
localDrive(const char * startdir,Bit16u _bytes_sector,Bit8u _sectors_cluster,Bit16u _total_clusters,Bit16u _free_clusters,Bit8u _mediaid);