Added support for reading volume labels
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@957
This commit is contained in:
parent
4916b5fb6c
commit
336e693b61
6 changed files with 100 additions and 15 deletions
|
@ -104,6 +104,8 @@ public:
|
|||
void DeleteEntry (const char* path, bool ignoreLastDir = false);
|
||||
|
||||
void EmptyCache (void);
|
||||
void SetLabel (const char* name);
|
||||
char* GetLabel (void) { return label; };
|
||||
|
||||
class CFileInfo {
|
||||
public:
|
||||
|
@ -140,7 +142,6 @@ private:
|
|||
Bit16u GetFreeID (CFileInfo* dir);
|
||||
void Clear (void);
|
||||
|
||||
|
||||
CFileInfo* dirBase;
|
||||
char dirPath [CROSS_LEN];
|
||||
char basePath [CROSS_LEN];
|
||||
|
@ -155,6 +156,7 @@ private:
|
|||
char dirSearchName [MAX_OPENDIRS];
|
||||
bool free [MAX_OPENDIRS];
|
||||
|
||||
char label [CROSS_LEN];
|
||||
};
|
||||
|
||||
class DOS_No_Drive_Cache {
|
||||
|
@ -182,6 +184,9 @@ public:
|
|||
Bit16u GetCurrentEntry (void) { return 0; };
|
||||
|
||||
void EmptyCache (void) {};
|
||||
|
||||
void SetLabel (const char* name) {};
|
||||
char* GetLabel (void) {};
|
||||
|
||||
public:
|
||||
char basePath [CROSS_LEN];
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
bool PlayAudioSector (unsigned long start,unsigned long len);
|
||||
bool PauseAudio (bool resume);
|
||||
bool StopAudio (void);
|
||||
bool ReadSectors (void* buffer, bool raw, unsigned long sector, unsigned long num) { return true; };
|
||||
bool ReadSectors (void* buffer, bool raw, unsigned long sector, unsigned long num) { return false; };
|
||||
bool LoadUnloadMedia (bool unload);
|
||||
|
||||
private:
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "dos_system.h"
|
||||
#include "dos_inc.h"
|
||||
#include "setup.h"
|
||||
#include "support.h"
|
||||
|
||||
#include "cdrom.h"
|
||||
|
||||
|
@ -101,6 +102,7 @@ public:
|
|||
int AddDrive (Bit16u _drive, char* physicalPath, Bit8u& subUnit);
|
||||
void GetDrives (PhysPt data);
|
||||
void GetDriverInfo (PhysPt data);
|
||||
bool GetVolumeName (Bit8u subUnit, char* name);
|
||||
bool GetCopyrightName (Bit16u drive, PhysPt data);
|
||||
bool GetAbstractName (Bit16u drive, PhysPt data);
|
||||
bool GetDocumentationName(Bit16u drive, PhysPt data);
|
||||
|
@ -233,18 +235,15 @@ int CMscdex::AddDrive(Bit16u _drive, char* physicalPath, Bit8u& subUnit)
|
|||
osi.dwOSVersionInfoSize = sizeof(osi);
|
||||
GetVersionEx(&osi);
|
||||
if ((osi.dwPlatformId==VER_PLATFORM_WIN32_NT) && (osi.dwMajorVersion>4)) {
|
||||
// WIN NT/200/XP
|
||||
if (useCdromInterface==CDROM_USE_ASPI) {
|
||||
cdrom[numDrives] = new CDROM_Interface_Aspi();
|
||||
LOG(LOG_MISC,"MSCDEX: ASPI Interface.");
|
||||
break;
|
||||
} else if (useCdromInterface==CDROM_USE_IOCTL) {
|
||||
// only WIN NT/200/XP
|
||||
if (useCdromInterface==CDROM_USE_IOCTL) {
|
||||
cdrom[numDrives] = new CDROM_Interface_Ioctl();
|
||||
LOG(LOG_MISC,"MSCDEX: IOCTL Interface.");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Win 95/98/ME - always use ASPI
|
||||
}
|
||||
if (useCdromInterface==CDROM_USE_ASPI) {
|
||||
// all Wins - ASPI
|
||||
cdrom[numDrives] = new CDROM_Interface_Aspi();
|
||||
LOG(LOG_MISC,"MSCDEX: ASPI Interface.");
|
||||
break;
|
||||
|
@ -432,6 +431,26 @@ bool CMscdex::ReadVTOC(Bit16u drive, Bit16u volume, PhysPt data, Bit16u& error)
|
|||
return (error==0);
|
||||
};
|
||||
|
||||
bool CMscdex::GetVolumeName(Bit8u subUnit, char* data)
|
||||
{
|
||||
if (subUnit>=numDrives) return false;
|
||||
Bit16u drive = dinfo[subUnit].drive;
|
||||
|
||||
Bit16u error,seg,size = 128;
|
||||
bool success = false;
|
||||
if (DOS_AllocateMemory(&seg,&size)) {
|
||||
PhysPt ptoc = PhysMake(seg,0);
|
||||
success = ReadVTOC(drive,0x00,ptoc,error);
|
||||
if (success) {
|
||||
MEM_StrCopy(ptoc+40,data,31);
|
||||
data[31] = 0;
|
||||
rtrim(data);
|
||||
};
|
||||
DOS_FreeMemory(seg);
|
||||
}
|
||||
return success;
|
||||
};
|
||||
|
||||
bool CMscdex::GetCopyrightName(Bit16u drive, PhysPt data)
|
||||
{
|
||||
Bit16u error,seg,size = 128;
|
||||
|
@ -879,6 +898,11 @@ int MSCDEX_AddDrive(char driveLetter, const char* physicalPath, Bit8u& subUnit)
|
|||
return result;
|
||||
};
|
||||
|
||||
bool MSCDEX_GetVolumeName(Bit8u subUnit, char* name)
|
||||
{
|
||||
return mscdex->GetVolumeName(subUnit,name);
|
||||
};
|
||||
|
||||
bool MSCDEX_HasMediaChanged(Bit8u subUnit)
|
||||
{
|
||||
static TMSF leadOut[MSCDEX_MAX_DRIVES];
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
void Run(void)
|
||||
{
|
||||
DOS_Drive * newdrive;char drive;
|
||||
std::string label;
|
||||
|
||||
// Show list of cdroms
|
||||
if (cmd->FindExist("-cd",false)) {
|
||||
|
@ -141,6 +142,8 @@ public:
|
|||
/* Set the correct media byte in the table */
|
||||
mem_writeb(Real2Phys(dos.tables.mediaid)+drive-'A',newdrive->GetMediaByte());
|
||||
WriteOut("Drive %c mounted as %s\n",drive,newdrive->GetInfo());
|
||||
/* check if volume label is given */
|
||||
if (cmd->FindString("-label",label,true)) newdrive->dirCache.SetLabel(label.c_str());
|
||||
return;
|
||||
showusage:
|
||||
WriteOut(MSG_Get("PROGRAM_MOUNT_USAGE"));
|
||||
|
|
|
@ -57,9 +57,9 @@ DOS_Drive_Cache::DOS_Drive_Cache(void)
|
|||
dirBase = new CFileInfo;
|
||||
save_dir = 0;
|
||||
srchNr = 0;
|
||||
label[0] = 0;
|
||||
for (Bit32u i=0; i<MAX_OPENDIRS; i++) { dirSearch[i] = 0; free[i] = true; };
|
||||
SetDirSort(DIRALPHABETICAL);
|
||||
|
||||
};
|
||||
|
||||
DOS_Drive_Cache::DOS_Drive_Cache(const char* path)
|
||||
|
@ -67,6 +67,7 @@ DOS_Drive_Cache::DOS_Drive_Cache(const char* path)
|
|||
dirBase = new CFileInfo;
|
||||
save_dir = 0;
|
||||
srchNr = 0;
|
||||
label[0] = 0;
|
||||
for (Bit32u i=0; i<MAX_OPENDIRS; i++) { dirSearch[i] = 0; free[i] = true; };
|
||||
SetDirSort(DIRALPHABETICAL);
|
||||
SetBaseDir(path);
|
||||
|
@ -94,6 +95,27 @@ void DOS_Drive_Cache::EmptyCache(void)
|
|||
SetBaseDir(basePath);
|
||||
};
|
||||
|
||||
void DOS_Drive_Cache::SetLabel(const char* vname)
|
||||
{
|
||||
Bitu togo = 8;
|
||||
Bitu vnamePos = 0;
|
||||
Bitu labelPos = 0;
|
||||
bool point = false;
|
||||
while (togo>0) {
|
||||
if (vname[vnamePos]==0) break;
|
||||
if (!point && (vname[vnamePos]=='.')) { togo=4; point=true; }
|
||||
label[labelPos] = vname[vnamePos];
|
||||
labelPos++; vnamePos++;
|
||||
togo--;
|
||||
if ((togo==0) && !point) {
|
||||
if (vname[vnamePos]=='.') vnamePos++;
|
||||
label[labelPos]='.'; labelPos++; point=true; togo=3;
|
||||
}
|
||||
};
|
||||
label[labelPos]=0;
|
||||
// LOG(LOG_ERROR,"CACHE: Set volume label to %s",label);
|
||||
};
|
||||
|
||||
Bit16u DOS_Drive_Cache::GetFreeID(CFileInfo* dir)
|
||||
{
|
||||
for (Bit32u i=0; i<MAX_OPENDIRS; i++) if (free[i] || (dir==dirSearch[i])) return i;
|
||||
|
@ -109,6 +131,13 @@ void DOS_Drive_Cache::SetBaseDir(const char* baseDir)
|
|||
char * result;
|
||||
ReadDir(id,result);
|
||||
};
|
||||
// Get Volume Label
|
||||
#if defined (WIN32)
|
||||
char label[256];
|
||||
char drive[4] = "C:\\";
|
||||
drive[0] = basePath[0];
|
||||
if (GetVolumeInformation(drive,label,256,NULL,NULL,NULL,NULL,0)) SetLabel(label);
|
||||
#endif
|
||||
};
|
||||
|
||||
void DOS_Drive_Cache::ExpandName(char* path)
|
||||
|
@ -619,7 +648,6 @@ bool DOS_No_Drive_Cache::OpenDir(const char* path, Bit16u& id)
|
|||
|
||||
bool DOS_No_Drive_Cache::ReadDir(Bit16u id, char* &result)
|
||||
{
|
||||
|
||||
static char res[CROSS_LEN];
|
||||
dirent * ent;
|
||||
|
||||
|
|
|
@ -111,6 +111,14 @@ bool localDrive::FindFirst(char * _dir,DOS_DTA & dta) {
|
|||
if (!dirCache.OpenDir(tempDir,id)) return false;
|
||||
strcpy(srchInfo[id].srch_dir,tempDir);
|
||||
dta.SetDirID(id);
|
||||
|
||||
Bit8u sAttr;
|
||||
dta.GetSearchParams(sAttr,tempDir);
|
||||
if (sAttr & DOS_ATTR_VOLUME) {
|
||||
// Get Volume Label
|
||||
dta.SetResult(dirCache.GetLabel(),0,0,0,DOS_ATTR_VOLUME);
|
||||
return true;
|
||||
}
|
||||
return FindNext(dta);
|
||||
}
|
||||
|
||||
|
@ -391,6 +399,8 @@ localFile::localFile(const char* _name, FILE * handle,Bit16u devinfo) {
|
|||
|
||||
int MSCDEX_AddDrive(char driveLetter, const char* physicalPath, Bit8u& subUnit);
|
||||
bool MSCDEX_HasMediaChanged(Bit8u subUnit);
|
||||
bool MSCDEX_GetVolumeName(Bit8u subUnit, char* name);
|
||||
|
||||
|
||||
cdromDrive::cdromDrive(const char driveLetter, const char * startdir,Bit16u _bytes_sector,Bit8u _sectors_cluster,Bit16u _total_clusters,Bit16u _free_clusters,Bit8u _mediaid, int& error)
|
||||
:localDrive(startdir,_bytes_sector,_sectors_cluster,_total_clusters,_free_clusters,_mediaid)
|
||||
|
@ -398,11 +408,16 @@ cdromDrive::cdromDrive(const char driveLetter, const char * startdir,Bit16u _byt
|
|||
// Init mscdex
|
||||
error = MSCDEX_AddDrive(driveLetter,startdir,subUnit);
|
||||
strcpy(info,"CDRom.");
|
||||
// Get Volume Label
|
||||
char name[32];
|
||||
if (MSCDEX_GetVolumeName(subUnit,name)) dirCache.SetLabel(name);
|
||||
};
|
||||
|
||||
bool cdromDrive::FileOpen(DOS_File * * file,char * name,Bit32u flags)
|
||||
{
|
||||
if ((flags==OPEN_READWRITE) || (flags==OPEN_WRITE)) {
|
||||
if (flags==OPEN_READWRITE) {
|
||||
flags = OPEN_READ;
|
||||
} else if (flags==OPEN_WRITE) {
|
||||
DOS_SetError(DOSERR_ACCESS_DENIED);
|
||||
return false;
|
||||
}
|
||||
|
@ -449,13 +464,23 @@ bool cdromDrive::GetFileAttr(char * name,Bit16u * attr)
|
|||
bool cdromDrive::FindFirst(char * _dir,DOS_DTA & dta)
|
||||
{
|
||||
// If media has changed, reInit drivecache.
|
||||
if (MSCDEX_HasMediaChanged(subUnit)) dirCache.EmptyCache();
|
||||
if (MSCDEX_HasMediaChanged(subUnit)) {
|
||||
dirCache.EmptyCache();
|
||||
// Get Volume Label
|
||||
char name[32];
|
||||
if (MSCDEX_GetVolumeName(subUnit,name)) dirCache.SetLabel(name);
|
||||
}
|
||||
return localDrive::FindFirst(_dir,dta);
|
||||
};
|
||||
|
||||
void cdromDrive::SetDir(const char* path)
|
||||
{
|
||||
// If media has changed, reInit drivecache.
|
||||
if (MSCDEX_HasMediaChanged(subUnit)) dirCache.EmptyCache();
|
||||
if (MSCDEX_HasMediaChanged(subUnit)) {
|
||||
dirCache.EmptyCache();
|
||||
// Get Volume Label
|
||||
char name[32];
|
||||
if (MSCDEX_GetVolumeName(subUnit,name)) dirCache.SetLabel(name);
|
||||
}
|
||||
localDrive::SetDir(path);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue