Description: Rewrite mount without arguments to display volume label as well. Some refactoring of the code. Add mount -z X, where X is the new virtual drive for the Wine Team. Origin: upstream, http://sourceforge.net/p/dosbox/code-0/3736/ Author: Peter Veenstra Last-Update: 2011-07-23 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -49,27 +49,55 @@ #endif void MSCDEX_SetCDInterface(int intNr, int forceCD); - +static Bitu ZDRIVE_NUM = 25; class MOUNT : public Program { public: - void Run(void) - { + void ListMounts(void) { + char name[DOS_NAMELENGTH_ASCII];Bit32u size;Bit16u date;Bit16u time;Bit8u attr; + /* Command uses dta so set it to our internal dta */ + RealPt save_dta = dos.dta(); + dos.dta(dos.tables.tempdta); + DOS_DTA dta(dos.dta()); + + WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_1")); + WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_FORMAT"),"Drive","Type","Label"); + for(int p = 0;p < 8;p++) WriteOut("----------"); + + for (int d = 0;d < DOS_DRIVES;d++) { + if (!Drives[d]) continue; + + char root[4] = {'A'+d,':','\\',0}; + bool ret = DOS_FindFirst(root,DOS_ATTR_VOLUME); + if (ret) { + dta.GetResult(name,size,date,time,attr); + DOS_FindNext(); //Mark entry as invalid + } else name[0] = 0; + + /* Change 8.3 to 11.0 */ + char* dot = strchr(name,'.'); + if(dot && (dot - name == 8) ) { + name[8] = name[9];name[9] = name[10];name[10] = name[11];name[11] = 0; + } + + root[1] = 0; //This way, the format string can be reused. + WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_FORMAT"),root, Drives[d]->GetInfo(),name); + } + dos.dta(save_dta); + } + + void Run(void) { DOS_Drive * newdrive;char drive; std::string label; std::string umount; + std::string newz; //Hack To allow long commandlines ChangeToLongCmd(); /* Parse the command line */ /* if the command line is empty show current mounts */ if (!cmd->GetCount()) { - WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_1")); - for (int d=0;dGetInfo()); - } - } + ListMounts(); return; } @@ -84,12 +112,12 @@ if (cmd->FindString("-u",umount,false)) { umount[0] = toupper(umount[0]); int i_drive = umount[0]-'A'; - if(i_drive < DOS_DRIVES && i_drive >= 0 && Drives[i_drive]) { + if (i_drive < DOS_DRIVES && i_drive >= 0 && Drives[i_drive]) { switch (DriveManager::UnmountDrive(i_drive)) { case 0: Drives[i_drive] = 0; if(i_drive == DOS_GetDefaultDrive()) - DOS_SetDrive(toupper('Z') - 'A'); + DOS_SetDrive(ZDRIVE_NUM); WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_SUCCESS"),umount[0]); break; case 1: @@ -104,8 +132,46 @@ } return; } - - // Show list of cdroms + + /* Check for moving Z: */ + /* Only allowing moving it once. It is merely a convenience added for the wine team */ + if (ZDRIVE_NUM == 25 && cmd->FindString("-z", newz,false)) { + newz[0] = toupper(newz[0]); + int i_newz = newz[0] - 'A'; + if (i_newz >= 0 && i_newz < DOS_DRIVES-1 && !Drives[i_newz]) { + ZDRIVE_NUM = i_newz; + /* remap drives */ + Drives[i_newz] = Drives[25]; + Drives[25] = 0; + DOS_Shell *fs = static_cast(first_shell); //dynamic ? + /* Update environment */ + std::string line = ""; + char ppp[2] = {newz[0],0}; + std::string tempenv = ppp; tempenv += ":\\"; + if (fs->GetEnvStr("PATH",line)){ + std::string::size_type idx = line.find('='); + std::string value = line.substr(idx +1 , std::string::npos); + while ( (idx = value.find("Z:\\")) != std::string::npos || + (idx = value.find("z:\\")) != std::string::npos ) + value.replace(idx,3,tempenv); + line = value; + } + if (!line.size()) line = tempenv; + fs->SetEnv("PATH",line.c_str()); + tempenv += "COMMAND.COM"; + fs->SetEnv("COMSPEC",tempenv.c_str()); + + /* Update batch file if running from Z: (very likely: autoexec) */ + if(fs->bf) { + std::string &name = fs->bf->filename; + if(name.length() >2 && name[0] == 'Z' && name[1] == ':') name[0] = newz[0]; + } + /* Change the active drive */ + if (DOS_GetDefaultDrive() == 25) DOS_SetDrive(i_newz); + } + return; + } + /* Show list of cdroms */ if (cmd->FindExist("-cd",false)) { int num = SDL_CDNumDrives(); WriteOut(MSG_Get("PROGRAM_MOUNT_CDROMS_FOUND"),num); @@ -1347,8 +1413,9 @@ /*Add Messages */ MSG_Add("PROGRAM_MOUNT_CDROMS_FOUND","CDROMs found: %d\n"); + MSG_Add("PROGRAM_MOUNT_STATUS_FORMAT","%-5s %-58s %-12s\n"); MSG_Add("PROGRAM_MOUNT_STATUS_2","Drive %c is mounted as %s\n"); - MSG_Add("PROGRAM_MOUNT_STATUS_1","Current mounted drives are:\n"); + MSG_Add("PROGRAM_MOUNT_STATUS_1","The currently mounted drives are:\n"); MSG_Add("PROGRAM_MOUNT_ERROR_1","Directory %s doesn't exist.\n"); MSG_Add("PROGRAM_MOUNT_ERROR_2","%s isn't a directory\n"); MSG_Add("PROGRAM_MOUNT_ILL_TYPE","Illegal type %s\n");