BOOL SetDisk(HWND hwnd, BYTE newDisk, PBOOL phpfs) { APIRET rc; BYTE buf[128]; ULONG ulAct; CHAR ch = newDisk; newDisk = newDisk > 'Z'? newDisk - 'a' + 1: newDisk - 'A' + 1; DosError(0); // disabilita dialogo errore drive not ready rc = DosQueryFSInfo(newDisk, FSIL_VOLSER, buf, sizeof(buf)); DosError(1); if (rc && rc != 125) { // se drive not ready-> retry, cancel if (WinMessageBox(HWND_DESKTOP, hwnd, DRIVE_NOT_READY, NULL, 0, MB_RETRYCANCEL | MB_ERROR | MB_MOVEABLE) == MBID_RETRY) { return SetDisk(hwnd, newDisk, phpfs); } else { return 1; } /* endif */ } /* endif */ DosSetDefaultDisk(newDisk); *phpfs = isHPFS(ch); if (hwnd != HWND_DESKTOP) { // mostra/nasconde data-ora creazione e ultimo accesso secondo FS DlgShowCtl(hwnd, STB_CREATED, *phpfs); DlgShowCtl(hwnd, STB_ACCESSED, *phpfs); } /* endif */ return 0; }
int gs_chdir(char *dirname) { int rc = 0; DosError(FERR_DISABLEHARDERR); #ifdef __BORLANDC__ if (isalpha(dirname[0]) && (dirname[1]==':')) (void) setdisk(toupper(dirname[0])-'A'); if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':'))) chdir(dirname); rc = 1; #else #ifdef __IBMC__ if (isalpha(dirname[0]) && (dirname[1]==':')) if (_chdrive(toupper(dirname[0])-'A'+1)) rc = -1; if (!rc && !((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':'))) rc = _chdir(dirname); #else if (isalpha((int)(dirname[0])) && (dirname[1]==':')) if (_chdrive(dirname[0])) rc = -1; rc = _chdir2(dirname); #endif #endif DosError(FERR_ENABLEHARDERR); return rc; }
void FilesCnr::getFiles() { PFILEFINDBUF3 pffb = NULL; OString FileSpec(scanDirectory); ULONG bufSize = sizeof(FILEFINDBUF3) * 200; HDIR hdir = HDIR_CREATE; ULONG ulMaxFiles = 200; APIRET rc; freeItems(); FileList.reset(); DosAllocMem((PPVOID)&pffb, bufSize, PAG_READ | PAG_WRITE | PAG_COMMIT); if (!pffb) return; FileSpec + "\\*"; DosError(FERR_DISABLEHARDERR); rc = DosFindFirst(FileSpec.text, &hdir, FILE_NORMAL | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, pffb, bufSize, &ulMaxFiles, FIL_STANDARD); while(!rc) { insertFiles(pffb, ulMaxFiles); rc = DosFindNext(hdir, pffb, bufSize, &ulMaxFiles); } DosFindClose(hdir); DosError(FERR_ENABLEHARDERR); DosFreeMem(pffb); }
static int disc_is_inserted(ULONG drive) { int rc; char buf[20]; DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION); rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf)); DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION); return(rc == NO_ERROR); } /* is_cdrom_inserted */
/* * goToDir - go to a specified directory */ static bool goToDir( gui_window *gui, char *dir ) { char drive[_MAX_DRIVE]; unsigned total; bool removed_end; size_t len; int rc; gui = gui; if( dir == NULL ) { return( false ); } if( dir[0] == 0 ) { return( true ); } if( !(dir[1] == ':' && dir[2] == 0) ) { len = strlen( dir ); removed_end = false; if( dir[len - 1] == FILE_SEP_CHAR ) { if( len > 1 && dir[len - 2] != ':' ) { dir[len - 1] = 0; removed_end = true; } } #ifdef __OS2__ /* prevent hard error popup */ DosError( 1 ); #endif rc = chdir( dir ); #ifdef __OS2__ /* allow hard error popup: Grrr can't restore to original state */ DosError( 0 ); #endif if( removed_end ) { dir[len - 1] = FILE_SEP_CHAR; } if( rc ) { return( false ); } } splitPath( dir, drive, NULL, NULL, NULL ); if( drive[0] != 0 ) { #if defined( __UNIX__ ) || defined( __NETWARE__ ) total = 1; #else _dos_setdrive( toupper( drive[0] ) - 'A' + 1, &total ); #endif } return( true ); } /* goToDir */
unsigned long SysDriveInfo(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { char *arg; /* Temp var for holding args */ unsigned char buf[256]; /* Give DosQFSInfo 256 bytes */ unsigned long drivenum; /* Drive number (A=1, B=2, */ /* etc) */ FSALLOCATE FSInfoBuf; /* Structure required by */ /* DosQfsInfo */ long rc; /* OS/2 return code */ #ifdef DLOGGING logmessage(__func__); #endif /* validate arguments */ if (numargs != 1 || args[0].strlength > 2 || args[0].strlength == 0) return INVALID_ROUTINE; /* validate the arg */ arg = args[0].strptr; /* get argument pointer */ /* drive letter? */ if ((strlen(arg) == 2 && arg[1] != ':') || !isalpha(arg[0])) return INVALID_ROUTINE; else drivenum = toupper(arg[0])-'A'+1; /* Get the drive number */ /* query the disk */ DosError(0); /* Disable hard-error pop-up */ /* Get the drive info */ rc = DosQueryFSInfo(drivenum, 2, buf, sizeof(buf)); DosQueryFSInfo(drivenum, 1, (char *)&FSInfoBuf, sizeof(FSInfoBuf)); if (rc == 0 || rc == 125) { sprintf(retstr->strptr, "%c: %-12lu %-12lu %-13s", (drivenum+'A'-1), FSInfoBuf.cSectorUnit * FSInfoBuf.cbSector *FSInfoBuf.cUnitAvail, FSInfoBuf.cSectorUnit * FSInfoBuf.cbSector *FSInfoBuf.cUnit, &buf[5]); /* create return string */ retstr->strlength = strlen(retstr->strptr); } else retstr->strlength = 0; /* return null string */ DosError(1); /* Enable hard-error pop-up */ return VALID_ROUTINE; /* no error on call */ }
BOOL fillDrvList(PINSTALLDATA pid, HWND hprgs) { char dev[4]; FSALLOCATE fsa; BYTE buf[32]; CHAR achdd[32]; ULONG ulDriveNum = 0; ULONG ulDriveMap = 0; ULONG ul, idx, tot; int i, j, k; PFSQBUFFER2 pfsqb = (PFSQBUFFER2)buf; strcpy(dev, " :"); DosError(0); DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap); // conta drive presenti for (i = 2, tot = 0; i < 26; ++i) tot += (ulDriveMap & 1L << i)? 1: 0; // per ogni drive presente raccogli informazioni for (i = 2, j = 0, k = 0, idx = 0; i < 26; i++) {// ripete x tutti i drive // DosSleep(1000); if (ulDriveMap & 1L << i) { // se trova partizione if (Wincrease(&idx, hprgs, tot)) return FALSE; ul = 32; dev[0] = (CHAR)(i + 'A'); if (DosQueryFSInfo(i + 1, FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) continue; // se drive non disponibile passa a successivo DosQueryFSAttach((PSZ)dev, 1, FSAIL_QUERYNAME, (PFSQBUFFER2)&buf, &ul); if (pfsqb->iType != 3 || // se non drive locale (strcmp(pfsqb->szName + 3, "FAT") && // o nŠ FAT strcmp(pfsqb->szName + 3, "HPFS") && strcmp(pfsqb->szName + 3, "JFS"))) // e nŠ HPFS continue; // passa al successivo pid->cMbDrv[i] = (ULONG)((float)fsa.cbSector * (float)fsa.cSectorUnit * (float)fsa.cUnitAvail) / 1048576; sprintf(achdd, "%s % 15d MB", dev, pid->cMbDrv[i]); DlgLboxInsertItem(pid->hwnd, LBX_INSTDRV, LIT_END, achdd); // seleziona l'item corrispondente al drive menzionato in pad->path if (dev[0] == *pid->tpath) k = j; j++; } // end if } // end for Wincrease(&idx, hprgs, tot); DosError(1); DlgLboxSelectItem(pid->hwnd, LBX_INSTDRV, k); WinPostMsg(hprgs, PRGSM_END, MPVOID, MPVOID); return TRUE; }
VOID QueryVolumeLabel (ULONG ulDriveNumber, PSZ pszVolumeLabel) { FSINFO fsInfo; DosError (FERR_DISABLEHARDERR); if (!DosQueryFSInfo (ulDriveNumber, FSIL_VOLSER, &fsInfo, sizeof(FSINFO))) strcpy (pszVolumeLabel, fsInfo.vol.szVolLabel); else pszVolumeLabel[0] = '\0'; DosError (FERR_ENABLEHARDERR); return; }
int QueryDriveReady( int drive ) { char curdir[255]; unsigned int maxpath = 254; int rval = 254; // turn off VIOPOPUP error window (void)DosError( 2 ); rval = ( DosQueryCurrentDir( (ULONG)drive, curdir, (PULONG)&maxpath ) == 0 ); // turn VIOPOPUP error window back on (void)DosError( 1 ); return rval; }
static void GetArguments(void) { if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0))) { DosError(); } }
void InitInt( void ) { PFNSIGHANDLER handler; USHORT action; interruptOccurred = 0; DosSetSigHandler( doInterrupt, &handler, &action,SIGA_ACCEPT,SIG_CTRLC); DosSetSigHandler( doInterrupt, &handler, &action,SIGA_ACCEPT,SIG_CTRLBREAK); DosError( 0x0002 ); /* disable hard-error processing */ }
Bool volume_open (char letter, volh *handle) { char openpath[8]; ULONG resAction, rc; HFILE dh; sprintf(openpath,"%c:",letter); DosError(FERR_DISABLEHARDERR); rc = DosOpen(openpath,&dh,&resAction,0,0,OPEN_ACTION_OPEN_IF_EXISTS, OPEN_FLAGS_DASD|OPEN_FLAGS_NO_CACHE|OPEN_FLAGS_NOINHERIT| OPEN_SHARE_DENYNONE|OPEN_FLAGS_FAIL_ON_ERROR|OPEN_ACCESS_READWRITE,0); // OPEN_SHARE_DENYREADWRITE if (rc==0) { voldata *vh = (voldata*)malloc(sizeof(voldata)); struct { b Infotype, DriveUnit; } DriveRequest; d psize = sizeof(DriveRequest), dsize = sizeof(vh->bpb); memset(vh, 0, sizeof(voldata)); vh->dh = dh; /* good news is that real BPB returned with REAL sectors per track value, not written into FAT spt field. This is actual for 127/255 spt disks, formatted to FAT in Windows (where FAT spt is 63) */ DriveRequest.Infotype =1; //0; DriveRequest.DriveUnit=0; if (DosDevIOCtl(dh,IOCTL_DISK,DSK_GETDEVICEPARAMS,(PVOID)&DriveRequest, sizeof(DriveRequest),&psize,(PVOID)&vh->bpb,sizeof(vh->bpb),&dsize)==0) { u64 sectors = vh->bpb.cSectors; if (!sectors) sectors = vh->bpb.cLargeSectors; vh->volsize = sectors; vh->ssize = vh->bpb.usBytesPerSector; } else { FSALLOCATE fa; if (DosQueryFSInfo(letter-'A'+1,FSIL_ALLOC,&fa,sizeof(fa))) memset(&fa,0,sizeof(fa)); vh->volsize = ((u64)fa.cSectorUnit*fa.cbSector*fa.cUnit)/fa.cbSector; vh->ssize = fa.cbSector; } vh->drive = letter; *handle = vh; return True; } else { printf("Error %d (%X)\n",rc,rc); } *handle = 0; return False; }
PSZ GetFSName(PSZ pszDevice) { static BYTE Buffer[200]; ULONG ulBufferSize; PFSQBUFFER2 fsqBuf = (PFSQBUFFER2)Buffer; APIRET rc; ulBufferSize = sizeof Buffer; DosError(0); rc = DosQueryFSAttach(pszDevice, 1L, FSAIL_QUERYNAME, fsqBuf, &ulBufferSize); DosError(1); if (rc) return ""; return fsqBuf->szName + fsqBuf->cbName + 1; }
VOID QueryDiskSpace (ULONG drvNum, PULONG totalSpace, PULONG allocated, PULONG available) { FSALLOCATE fsAllocate; DosError (FERR_DISABLEHARDERR); if (!DosQueryFSInfo (drvNum, FSIL_ALLOC, &fsAllocate, sizeof(FSALLOCATE))) { *totalSpace = fsAllocate.cSectorUnit * fsAllocate.cUnit * fsAllocate.cbSector; *available = fsAllocate.cSectorUnit * fsAllocate.cUnitAvail * fsAllocate.cbSector; *allocated = *totalSpace - *available; } else *totalSpace = *allocated = *available = 0L; DosError (FERR_ENABLEHARDERR); return; }
int main(int argc,char*argv[]) { EXCEPTIONREGISTRATIONRECORD xcpt = { 0, &sighndlr }; /* make me immortile */ DosError(FERR_DISABLEEXCEPTION|FERR_DISABLEHARDERR); DosSetExceptionHandler(&xcpt); printf("My PID is %d, kill me!\n",getpid()); while(1) { sleep(0); } }
//---------------------------------- // 'User Function' private: ScanDrives //---------------------------------- void PrjPath::ScanDrives(void) { char s[MAXPATHSIZE]; // GET DRIVES m_Drives->Clear(); m_Drives->ClearList(); char max; DosError(2); // NO ANOYING POPUP ERROR DRIVE NOT READY !! for(int drv = 'C'; drv<=HiDrive; drv++) { struct { unsigned long serno; unsigned char vollen; char volume[MAXPATHSIZE]; }infobuf; infobuf.vollen = 0; infobuf.volume[0] = NULL; int rc = DosQueryFSInfo(drv-'@',2,&infobuf,sizeof(infobuf)); if(rc == 0 || infobuf.vollen > 0 ) { max = drv; sprintf(s,"%c: [%s]",drv,infobuf.volume); m_Drives->AddString(s); } } DosError(1); // Allow Popup excecptions again !!! HiDrive = max; // Next Time Scan C-HiDrive skipping CD-ROMS sprintf(s,"C: - %c:",HiDrive); // // select current Disk Drive char s2[2+1]; strncpy(s2,m_origdir,2); s2[2]=NULL; // s2="x:" strupr(s2); int i = m_Drives->FindString(s2,-1); m_Drives->SetSelIndex(i); SetDlgItemText(ID_HIDRIVE,s); // DoDirectories(); }
VOID QueryDiskSpace (ULONG ulDriveNumber, PULONG pulTotalSpace, PULONG pulAllocated, PULONG pulAvailable) { FSALLOCATE fsAllocate; DosError (FERR_DISABLEHARDERR); if (!DosQueryFSInfo (ulDriveNumber, FSIL_ALLOC, &fsAllocate, sizeof(FSALLOCATE))) { *pulTotalSpace = fsAllocate.cSectorUnit * fsAllocate.cUnit * fsAllocate.cbSector; *pulAvailable = fsAllocate.cSectorUnit * fsAllocate.cUnitAvail * fsAllocate.cbSector; *pulAllocated = *pulTotalSpace - *pulAvailable; } else *pulTotalSpace = *pulAllocated = *pulAvailable = 0L; DosError (FERR_ENABLEHARDERR); return; }
void InitInt( void ) { #ifdef _M_I86 PFNSIGHANDLER handler; USHORT action; #endif interruptOccurred = false; #ifdef _M_I86 DosSetSigHandler( doInterrupt, &handler, &action,SIGA_ACCEPT,SIG_CTRLC); DosSetSigHandler( doInterrupt, &handler, &action,SIGA_ACCEPT,SIG_CTRLBREAK); #endif DosError( 0x0002 ); /* disable hard-error processing */ }
int main(int argc, char **argv) { HFILE dHandle; char *drive = "a:"; int choice; copyr(); if ((argc > 2) || ((argc == 2) && (argv[1][1] != ':'))) { fputs("usage: dskcpy2 drive_letter:", stderr); exit(1); } if (argc == 2) drive = argv[1]; DosError(HARDERROR_DISABLE); do { choice = dskcpy_menu(gotSource, drive); switch (choice) { case READ_SOURCE: query("Place SOURCE disk in drive %s and strike any key when ready..", drive); if ((dHandle = opendrive(drive)) == 0) errorexit(dHandle); if (lockdrive(dHandle)) errorexit(dHandle); if (readsource(dHandle)) errorexit(dHandle); if (unlockdrive(dHandle)) errorexit(dHandle); DosClose(dHandle); break; case COPY_TARGET: query("Place TARGET disk in drive %s and strike any key when ready..", drive); if ((dHandle = opendrive(drive)) == 0) errorexit(dHandle); if (lockdrive(dHandle)) errorexit(dHandle); if (writetarget(dHandle)) errorexit(dHandle); if (unlockdrive(dHandle)) errorexit(dHandle); DosClose(dHandle); break; default: break; } } while (choice != EXIT_DSKCPY); return _DosError; }
int main(void) { int maxdrives,curdrive, x; unsigned long disksize,diskfree,clustersize,sizesum=0,freesum=0; unsigned long capacity; char label[41],file_system[256]; #ifdef __OS2__ DosError(FERR_DISABLEHARDERR|FERR_ENABLEEXCEPTION); #endif printf("\nDF/" VERSION_BITS "bit v" VERSION_NO " Copyright (c) Timo Kokkonen, OH6LXV " " " RELEASE_DATE "\n\n"); curdrive=getdisk(); maxdrives=setdisk(curdrive); if (maxdrives-2<=0) return 1; printf("disk free used total capacity cluster file system\n"); for(x=3;x<=maxdrives;x++) { label[0]=0; file_system[0]=0; #ifdef __MSDOS__ if (!DriveExists(x)) continue; #endif if (getDiskSize(x,&disksize,&diskfree,&clustersize)) { getDiskLabel(x,label); strcpy(file_system,getIFSname(x)); } sizesum+=disksize; freesum+=diskfree; if (disksize==0) capacity=0; else capacity=((disksize-diskfree)/(disksize/100)); printf("%c:%-12s %8luk %8luk %8luk %3lu%% %5lu bytes %-8s \n", x+64,label,diskfree/1024,(disksize-diskfree)/1024,disksize/1024, capacity,clustersize,file_system); } printf("\nTotal: %9luk %9luk %9luk %3lu%% \n", freesum/1024,(sizesum-freesum)/1024,sizesum/1024, (sizesum-freesum)/(sizesum/100)); return 0; }
VOID QueryDrives (HWND hWnd) { PFSQBUFFER2 pfsq2; ULONG ulLen, ulInx, ulAction, ulParmLen, ulDataLen; APIRET RetCode; HFILE hFile; BIOSPARAMETERBLOCK bpb; CHAR szDrive[3] = " :"; BYTE cBlock = 0; WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP,SPTR_WAIT,FALSE)); /* Allocate buffer */ DosAllocMem ((PPVOID)&pfsq2, 1024L, fALLOC); DosError (FERR_DISABLEHARDERR); ulNumDrives = 0L; for (ulInx = 0; ulInx < 26; ulInx++) { szDrive[0] = (CHAR)('A' + ulInx); ulLen = 1024L; RetCode = DosQueryFSAttach (szDrive, 0L, FSAIL_QUERYNAME, pfsq2, &ulLen); DriveInfo[ulNumDrives].szDrive[0] = szDrive[0]; DriveInfo[ulNumDrives].szDrive[1] = '\0'; if (RetCode == ERROR_NOT_READY) { /* Assume local, removable, and FAT file system */ strcpy (DriveInfo[ulNumDrives].szLocation, "Local"); strcpy (DriveInfo[ulNumDrives].szRemovable, "Yes"); strcpy (DriveInfo[ulNumDrives].szFileSystem, "FAT"); DriveInfo[ulNumDrives].ulDescriptionIndex = 10L; ulNumDrives++; } else if (RetCode != ERROR_INVALID_DRIVE) { bpb.fsDeviceAttr = 0; /* Attempt to open the device */ if (!DosOpen (szDrive, &hFile, &ulAction, 0L, FILE_NORMAL, FILE_OPEN, OPEN_FLAGS_DASD | OPEN_SHARE_DENYNONE, 0L)) { ulParmLen = sizeof(BYTE); ulDataLen = sizeof(BIOSPARAMETERBLOCK); DosDevIOCtl (hFile, IOCTL_DISK, DSK_GETDEVICEPARAMS, (PVOID)&cBlock, ulParmLen, &ulParmLen, (PVOID)&bpb, ulDataLen, &ulDataLen); DosClose (hFile); } else { /* Remote drives may not allow themselves to be opened with the OPEN_FLAGS_DASD access flag. Default to not removable and description of unknown. */ bpb.fsDeviceAttr = 0x0001; bpb.bDeviceType = 7; } /* Is the drive remote? */ if (pfsq2->iType == FSAT_REMOTEDRV) strcpy (DriveInfo[ulNumDrives].szLocation, "Remote"); else strcpy (DriveInfo[ulNumDrives].szLocation, "Local"); /* Is the drive removable? */ if (bpb.fsDeviceAttr & 0x0001) strcpy (DriveInfo[ulNumDrives].szRemovable, "No"); else strcpy (DriveInfo[ulNumDrives].szRemovable, "Yes"); /* Set the description index */ if (bpb.bDeviceType < 10) DriveInfo[ulNumDrives].ulDescriptionIndex = (LONG)bpb.bDeviceType; else DriveInfo[ulNumDrives].ulDescriptionIndex = 7L; /* Set the file system name */ strncpy (DriveInfo[ulNumDrives].szFileSystem, (PSZ)(pfsq2->szName + 1 + pfsq2->cbName), 15); ulNumDrives++; } } DosError (FERR_ENABLEHARDERR); DosFreeMem (pfsq2); /* Add items to the drive listbox */ for (ulInx = 0; ulInx < ulNumDrives; ulInx++) WinSendDlgItemMsg (hWnd, IDC_DRIVELIST, LM_INSERTITEM, (MPARAM)LIT_END, DriveInfo[ulInx].szDrive); WinSendDlgItemMsg (hWnd, IDC_DRIVELIST, LM_SELECTITEM, 0L, (MPARAM)TRUE); WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP,SPTR_ARROW,FALSE)); return; }
//------------------------------------------------------------------------- // // Show - Display the file dialog // //------------------------------------------------------------------------- NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) { NS_ENSURE_ARG_POINTER(retval); PRBool result = PR_FALSE; nsCAutoString fileBuffer; char *converted = ConvertToFileSystemCharset(mDefault); if (nsnull == converted) { LossyCopyUTF16toASCII(mDefault, fileBuffer); } else { fileBuffer.Assign(converted); nsMemory::Free( converted ); } char *title = ConvertToFileSystemCharset(mTitle); if (nsnull == title) title = ToNewCString(mTitle); nsCAutoString initialDir; if (mDisplayDirectory) mDisplayDirectory->GetNativePath(initialDir); // If no display directory, re-use the last one. if(initialDir.IsEmpty()) initialDir = mLastUsedDirectory; mFile.Truncate(); FILEDLG filedlg; memset(&filedlg, 0, sizeof(FILEDLG)); filedlg.cbSize = sizeof(FILEDLG); filedlg.pszTitle = title; if (mMode == modeGetFolder) { PL_strncat(filedlg.szFullFile, initialDir.get(), MAX_PATH); PL_strncat(filedlg.szFullFile, "\\", 1); PL_strncat(filedlg.szFullFile, "^", 1); filedlg.fl = FDS_OPEN_DIALOG | FDS_CENTER; filedlg.pfnDlgProc = DirDialogProc; DosError(FERR_DISABLEHARDERR); WinFileDlg(HWND_DESKTOP, mWnd, &filedlg); DosError(FERR_ENABLEHARDERR); char* tempptr = strstr(filedlg.szFullFile, "^"); if (tempptr) *tempptr = '\0'; if (filedlg.lReturn == DID_OK) { result = PR_TRUE; if (!mDisplayDirectory) mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1"); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath(nsDependentCString(filedlg.szFullFile)); mFile.Assign(filedlg.szFullFile); } } else { PL_strncpy(filedlg.szFullFile, initialDir.get(), MAX_PATH); PL_strncat(filedlg.szFullFile, "\\", 1); PL_strncat(filedlg.szFullFile, fileBuffer.get(), MAX_PATH); filedlg.fl = FDS_CENTER; if (mMode == modeSave) { filedlg.fl |= FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB; } else if (mMode == modeOpenMultiple) { filedlg.fl |= FDS_MULTIPLESEL | FDS_OPEN_DIALOG; } else { filedlg.fl |= FDS_OPEN_DIALOG; } PMYDATA pmydata; pmydata = (PMYDATA)calloc(1, sizeof(MYDATA)); filedlg.ulUser = (ULONG)pmydata; filedlg.pfnDlgProc = FileDialogProc; PRUint32 i; PSZ *apszTypeList; apszTypeList = (PSZ *)malloc(mTitles.Length()*sizeof(PSZ)+1); for (i = 0; i < mTitles.Length(); i++) { const nsString& typeWide = mTitles[i]; nsAutoCharBuffer buffer; PRInt32 bufLength; WideCharToMultiByte(0, typeWide.get(), typeWide.Length(), buffer, bufLength); apszTypeList[i] = ToNewCString(nsDependentCString(buffer.Elements())); } apszTypeList[i] = 0; filedlg.papszITypeList = (PAPSZ)apszTypeList; PSZ *apszFilterList; apszFilterList = (PSZ *)malloc(mFilters.Length()*sizeof(PSZ)+1); for (i = 0; i < mFilters.Length(); i++) { const nsString& filterWide = mFilters[i]; apszFilterList[i] = ToNewCString(filterWide); } apszFilterList[i] = 0; pmydata->papszIFilterList = (PAPSZ)apszFilterList; pmydata->ulCurExt = mSelectedType; PRBool fileExists; do { DosError(FERR_DISABLEHARDERR); WinFileDlg(HWND_DESKTOP, mWnd, &filedlg); DosError(FERR_ENABLEHARDERR); if ((filedlg.lReturn == DID_OK) && (mMode == modeSave)) { PRFileInfo64 fileinfo64; PRStatus status = PR_GetFileInfo64(filedlg.szFullFile, &fileinfo64); if (status == PR_SUCCESS) { fileExists = PR_TRUE; } else { fileExists = PR_FALSE; } if (fileExists) { if (!gpszFDSaveCaption) { HMODULE hmod; char LoadError[CCHMAXPATH]; char loadedString[256]; int length; DosLoadModule(LoadError, CCHMAXPATH, "PMSDMRI", &hmod); length = WinLoadString((HAB)0, hmod, 1110, 256, loadedString); gpszFDSaveCaption = (char*)malloc(length+1); strcpy(gpszFDSaveCaption, loadedString); length = WinLoadString((HAB)0, hmod, 1135, 256, loadedString); gpszFDFileExists = (char*)malloc(length+1); strcpy(gpszFDFileExists, loadedString); length = WinLoadString((HAB)0, hmod, 1136, 256, loadedString); gpszFDFileReadOnly = (char*)malloc(length+1); strcpy(gpszFDFileReadOnly, loadedString); int i; for (i=0;i<256 && gpszFDFileExists[i];i++ ) { if (gpszFDFileExists[i] == '%') { gpszFDFileExists[i+1] = 's'; break; } } for (i=0;i<256 && gpszFDFileReadOnly[i];i++ ) { if (gpszFDFileReadOnly[i] == '%') { gpszFDFileReadOnly[i+1] = 's'; break; } } DosFreeModule(hmod); } char pszFullText[256+CCHMAXPATH]; FILESTATUS3 fsts3; ULONG ulResponse; DosQueryPathInfo( filedlg.szFullFile, FIL_STANDARD, &fsts3, sizeof(FILESTATUS3)); if (fsts3.attrFile & FILE_READONLY) { sprintf(pszFullText, gpszFDFileReadOnly, filedlg.szFullFile); ulResponse = WinMessageBox(HWND_DESKTOP, mWnd, pszFullText, gpszFDSaveCaption, 0, MB_OK | MB_MOVEABLE | MB_WARNING); } else { sprintf(pszFullText, gpszFDFileExists, filedlg.szFullFile); ulResponse = WinMessageBox(HWND_DESKTOP, mWnd, pszFullText, gpszFDSaveCaption, 0, MB_YESNO | MB_MOVEABLE | MB_WARNING); } if (ulResponse == MBID_YES) { fileExists = PR_FALSE; } } } } while (mMode == modeSave && fileExists && filedlg.lReturn == DID_OK); if (filedlg.lReturn == DID_OK) { result = PR_TRUE; if (mMode == modeOpenMultiple) { nsresult rv; if (filedlg.papszFQFilename) { for (ULONG i=0;i<filedlg.ulFQFCount;i++) { nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv,rv); rv = file->InitWithNativePath(nsDependentCString(*(filedlg.papszFQFilename)[i])); NS_ENSURE_SUCCESS(rv,rv); rv = mFiles.AppendObject(file); NS_ENSURE_SUCCESS(rv,rv); } WinFreeFileDlgList(filedlg.papszFQFilename); } else { nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv,rv); rv = file->InitWithNativePath(nsDependentCString(filedlg.szFullFile)); NS_ENSURE_SUCCESS(rv,rv); rv = mFiles.AppendObject(file); NS_ENSURE_SUCCESS(rv,rv); } } else { mFile.Assign(filedlg.szFullFile); } mSelectedType = (PRInt16)pmydata->ulCurExt; } for (i = 0; i < mTitles.Length(); i++) { nsMemory::Free(*(filedlg.papszITypeList[i])); } free(filedlg.papszITypeList); for (i = 0; i < mFilters.Length(); i++) { nsMemory::Free(*(pmydata->papszIFilterList[i])); } free(pmydata->papszIFilterList); free(pmydata); } if (title) nsMemory::Free( title ); if (result) { PRInt16 returnOKorReplace = returnOK; nsresult rv; // Remember last used directory. nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); file->InitWithNativePath(mFile); nsCOMPtr<nsIFile> dir; if (NS_SUCCEEDED(file->GetParent(getter_AddRefs(dir)))) { nsCOMPtr<nsILocalFile> localDir(do_QueryInterface(dir)); if (localDir) { nsCAutoString newDir; localDir->GetNativePath(newDir); if(!newDir.IsEmpty()) PL_strncpyz(mLastUsedDirectory, newDir.get(), MAX_PATH+1); // Update mDisplayDirectory with this directory, also. // Some callers rely on this. if (!mDisplayDirectory) mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1"); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) ); } } if (mMode == modeSave) { // Windows does not return resultReplace, // we must check if file already exists PRBool exists = PR_FALSE; file->Exists(&exists); if (exists) returnOKorReplace = returnReplace; } *retval = returnOKorReplace; } else { *retval = returnCancel; } return NS_OK; }
unsigned long SysDriveMap(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { char temp[MAX]; /* Entire drive map built here*/ char tmpstr[MAX]; /* Single drive entries built */ /* here */ char buf[256]; /* Give DosQFSInfo 256 bytes */ char DeviceName[3]; /* Device name or drive letter*/ /* string */ unsigned long CurDrive; /* Current drive */ unsigned long DriveMap; /* Drive map */ unsigned long Ordinal; /* Ordinal of entry in name */ /* list */ unsigned long FSAInfoLevel; /* Type of attached FSD data */ /* required */ unsigned long DataBufferLen; /* Buffer length */ unsigned long dnum; /* Disk num variable */ unsigned long start = 3; /* Initial disk num */ unsigned long Mode = USED; /* Query mode USED, FREE, */ /* LOCAL, etc */ FSQBUFFER2 DataBuffer; /* Returned data buffer */ long rc; /* OS/2 return codes */ Ordinal = (unsigned long )0; FSAInfoLevel = (unsigned long )1; temp[0] = '\0'; #ifdef DLOGGING logmessage(__func__); #endif if (numargs > 2) return INVALID_ROUTINE; if (numargs >= 1 && args[0].strptr) { if ((strlen(args[0].strptr) == 2 && args[0].strptr[1] != ':') || strlen(args[0].strptr) > 2 || strlen(args[0].strptr) == 0 || !isalpha(args[0].strptr[0])) return INVALID_ROUTINE; start = toupper(args[0].strptr[0])-'A'+1; } /* check the mode */ if (numargs == 2 && args[1].strlength != 0) { if (!stricmp(args[1].strptr, "FREE")) Mode = FREE; else if (!stricmp(args[1].strptr, "USED")) Mode = USED; else if (!stricmp(args[1].strptr, "DETACHED")) Mode = DETACHED; else if (!stricmp(args[1].strptr, "REMOTE")) Mode = REMOTE; else if (!stricmp(args[1].strptr, "LOCAL")) Mode = LOCAL; else return INVALID_ROUTINE; } /* perform the query */ DosError(0); /* Disable Hard-Error Popups */ DosQueryCurrentDisk(&CurDrive, &DriveMap); DriveMap>>=start-1; /* Shift to the first drive */ temp[0] = '\0'; /* Clear temporary buffer */ for (dnum = start; dnum <= 26; dnum++) { if (!(DriveMap&(unsigned long)1) && Mode == FREE) { sprintf(tmpstr, "%c: ", dnum+'A'-1); strcat(temp, tmpstr); } /* Hey, we have a used drive */ else if ((DriveMap&(unsigned long)1) && Mode == USED) { sprintf(tmpstr, "%c: ", dnum+'A'-1); strcat(temp, tmpstr); } else if (DriveMap&(unsigned long)1) { /* Check specific drive info */ sprintf(DeviceName, "%c:", dnum+'A'-1); DataBufferLen = sizeof DataBuffer; DosQueryFSAttach(DeviceName, Ordinal, FSAInfoLevel, &DataBuffer, &DataBufferLen); rc = DosQueryFSInfo(dnum, 2, buf, sizeof(buf)); if (rc == 67 && DataBuffer.iType == 4 && Mode == DETACHED) { /* Hey, we have a detached */ /* drive */ sprintf(tmpstr, "%c: ", dnum+'A'-1); strcat(temp, tmpstr); } else if (DataBuffer.iType == 4 && Mode == REMOTE) { sprintf(tmpstr, "%c: ", dnum+'A'-1); strcat(temp, tmpstr); } else if (DataBuffer.iType == 3 && Mode == LOCAL) { sprintf(tmpstr, "%c: ", dnum+'A'-1); strcat(temp, tmpstr); } } DriveMap>>=1; /* Shift to the next drive */ } BUILDRXSTRING(retstr, temp); /* pass back result */ if (retstr->strlength) retstr->strlength--; DosError(1); /* Enable Hard-Error Popups */ return VALID_ROUTINE; /* no error on call */ }
MRESULT EXPENTRY SwapProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) { static HWND hwndMenu = (HWND)0; switch(msg) { case WM_CREATE: { MRESULT mr = PFNWPStatic(hwnd,msg,mp1,mp2); WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID); return mr; } case WM_MOUSEMOVE: break; case WM_PRESPARAMCHANGED: { char *rootname = "SwapMon"; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLOCK_FRAME: rootname = "Clock"; break; case HARD_FRAME: rootname = "Hard"; break; case CPU_FRAME: rootname = "CPU"; break; case CLP_FRAME: rootname = "ClipMon"; break; case MEM_FRAME: rootname = "Mem"; break; case TSK_FRAME: rootname = "Task"; break; } PresParamChanged(hwnd, rootname, mp1, mp2); PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); } break; case WM_APPTERMINATENOTIFY: if(WinQueryWindowUShort(hwnd,QWS_ID) == CPU_FRAME) { if(!StartCPUThreads()) WinDestroyWindow(hwnd); } break; case WM_BUTTON1MOTIONSTART: { POINTL ptl; ptl.x = SHORT1FROMMP(mp1); ptl.y = SHORT2FROMMP(mp1); WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1L); PostMsg(hwndConfig, UM_SHOWME, MPFROM2SHORT((USHORT)ptl.x,(USHORT)ptl.y), mp2); } return MRFROMSHORT(TRUE); case WM_BUTTON2MOTIONSTART: { TRACKINFO TrackInfo; SWP Position; memset(&TrackInfo,0,sizeof(TrackInfo)); TrackInfo.cxBorder = 1 ; TrackInfo.cyBorder = 1 ; TrackInfo.cxGrid = 1 ; TrackInfo.cyGrid = 1 ; TrackInfo.cxKeyboard = 8 ; TrackInfo.cyKeyboard = 8 ; WinQueryWindowPos(hwnd,&Position); TrackInfo.rclTrack.xLeft = Position.x ; TrackInfo.rclTrack.xRight = Position.x + Position.cx ; TrackInfo.rclTrack.yBottom = Position.y ; TrackInfo.rclTrack.yTop = Position.y + Position.cy ; WinQueryWindowPos(HWND_DESKTOP,&Position); TrackInfo.rclBoundary.xLeft = Position.x ; TrackInfo.rclBoundary.xRight = Position.x + Position.cx ; TrackInfo.rclBoundary.yBottom = Position.y ; TrackInfo.rclBoundary.yTop = Position.y + Position.cy ; TrackInfo.ptlMinTrackSize.x = 0 ; TrackInfo.ptlMinTrackSize.y = 0 ; TrackInfo.ptlMaxTrackSize.x = Position.cx ; TrackInfo.ptlMaxTrackSize.y = Position.cy ; TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ; if(WinTrackRect(HWND_DESKTOP, (HPS)0, &TrackInfo)) { WinSetWindowPos(hwnd, HWND_TOP, TrackInfo.rclTrack.xLeft, TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE); switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: WinQueryWindowPos(hwnd,&swpSwap); SavePrf("SwapSwp", &swpSwap, sizeof(SWP)); break; case CLOCK_FRAME: WinQueryWindowPos(hwnd,&swpClock); SavePrf("ClockSwp", &swpClock, sizeof(SWP)); break; case HARD_FRAME: WinQueryWindowPos(hwnd,&swpHard); SavePrf("HardSwp", &swpHard, sizeof(SWP)); break; case CPU_FRAME: WinQueryWindowPos(hwnd,&swpCPU); SavePrf("CPUSwp", &swpCPU, sizeof(SWP)); break; case CLP_FRAME: WinQueryWindowPos(hwnd,&swpClip); SavePrf("ClipSwp", &swpClip, sizeof(SWP)); break; case MEM_FRAME: WinQueryWindowPos(hwnd,&swpMem); SavePrf("MemSwp", &swpMem, sizeof(SWP)); break; case TSK_FRAME: WinQueryWindowPos(hwnd,&swpTask); SavePrf("TaskSwp", &swpTask, sizeof(SWP)); break; } } } return MRFROMSHORT(TRUE); case WM_BUTTON1DOWN: WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE); return MRFROMSHORT(TRUE); case WM_BUTTON1DBLCLK: case WM_BUTTON1CLICK: if((!fNoMonClick && msg == WM_BUTTON1CLICK) || (fNoMonClick && msg == WM_BUTTON1DBLCLK)) { switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case HARD_FRAME: { ULONG ulDriveNum,ulDriveMap,x; ulDriveMon = min(ulDriveMon,26); if(!DosQCurDisk(&ulDriveNum, &ulDriveMap)) { for(x = ulDriveMon + 1;x < 26;x++) { if(ulDriveMap & (1 << x)) { ulDriveMon = x; break; } } if(x >= 26) { for(x = 3;x < ulDriveMon - 1;x++) { if(ulDriveMap & (1 << x)) { ulDriveMon = x; break; } } } SavePrf("MonDrive", &ulDriveMon, sizeof(ULONG)); } PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); } break; case CLP_FRAME: case MEM_FRAME: case TSK_FRAME: case SWAP_FRAME: case CLOCK_FRAME: case CPU_FRAME: { USHORT cmd = CPU_PULSE; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case MEM_FRAME: cmd = CLOCK_CMDLINE; break; case TSK_FRAME: cmd = CPU_KILLPROC; break; case CLP_FRAME: cmd = CLOCK_CLIPBOARD; break; case SWAP_FRAME: cmd = SWAP_LAUNCHPAD; break; case CLOCK_FRAME: cmd = CLOCK_SETTINGS; if((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0) cmd = CLOCK_CLOCK; break; } PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd,0), MPVOID); } break; } return MRFROMSHORT(TRUE); } else PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); break; case WM_CONTEXTMENU: WinInvalidateRect(hwnd, NULL, FALSE); WinSendMsg(hwnd, UM_TIMER, MPVOID, MPVOID); WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE); { USHORT id; id = WinQueryWindowUShort(hwnd,QWS_ID); hwndMenu = WinLoadMenu(HWND_DESKTOP, 0, id); if(hwndMenu) { POINTL ptl; SWP swp; ULONG ulDriveNum,ulDriveMap,x; MENUITEM mi; char s[80]; SetPresParams(hwndMenu, -1, -1, -1, helvtext); switch(id) { case CLP_FRAME: WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(CLP_APPEND,FALSE), MPFROM2SHORT(MIA_CHECKED, ((fClipAppend) ? MIA_CHECKED : 0))); break; case HARD_FRAME: if(!DosQCurDisk(&ulDriveNum, &ulDriveMap)) { mi.iPosition = 0; mi.hwndSubMenu = (HWND)0; mi.hItem = 0L; mi.afStyle = MIS_TEXT | MIS_STATIC; mi.afAttribute = MIA_FRAMED; mi.id = -1; sprintf(s, "Current drive is %c:", (char)(ulDriveMon + '@')); WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s)); mi.iPosition = MIT_END; for(x = 2;x < 26;x++) { if(ulDriveMap & (1 << x)) { if(x != ulDriveMon - 1) { mi.afStyle = MIS_TEXT; mi.afAttribute = 0; mi.id = HARD_C + (x - 2); if(fShowFreeInMenus) SetDriveText(x + 1, s); else sprintf(s, "%c:", (char)(x + 'A')); WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s)); } } } } break; case CLOCK_FRAME: WinEnableMenuItem(hwndMenu, CLOCK_VIRTUAL, fDesktops); WinEnableMenuItem(hwndMenu, CLOCK_CLIPBOARD, (ClipHwnd != (HWND)0)); break; default: break; } WinQueryWindowPos(hwnd, &swp); ptl.x = SHORT1FROMMP(mp1); ptl.y = SHORT2FROMMP(mp1); WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1L); ptl.y = max(ptl.y,swp.y + swp.cy + 4); if(!WinPopupMenu(HWND_DESKTOP, hwnd, hwndMenu, ptl.x - 4, ptl.y - 4, 0, PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1)) { WinDestroyWindow(hwndMenu); hwndMenu = (HWND)0; } } } return MRFROMSHORT(TRUE); case WM_MENUEND: WinSetFocus(HWND_DESKTOP, HWND_DESKTOP); WinDestroyWindow((HWND)mp2); if(hwndMenu == (HWND)mp2) hwndMenu = (HWND)0; return 0; case UM_SETUP: { char *rootname = "SwapMon"; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: SwapHwnd = hwnd; swaptick = 0; break; case CLOCK_FRAME: ClockHwnd = hwnd; rootname = "Clock"; break; case TSK_FRAME: TaskHwnd = hwnd; rootname = "Task"; break; case MEM_FRAME: MemHwnd = hwnd; rootname = "Mem"; break; case HARD_FRAME: HardHwnd = hwnd; rootname = "Hard"; break; case CPU_FRAME: CPUHwnd = hwnd; rootname = "CPU"; PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); break; case CLP_FRAME: ClipMonHwnd = hwnd; rootname = "ClipMon"; PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); break; } if(!RestorePresParams(hwnd,rootname)) SetPresParams(hwnd, RGB_WHITE, RGB_BLACK, RGB_BLACK, helvtext); } PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); return 0; case UM_REFRESH: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLP_FRAME: { char s[] = " Clip: [TtBbMmP] + ",*p; ULONG fmt[] = {CF_TEXT,CF_DSPTEXT, CF_BITMAP,CF_DSPBITMAP, CF_METAFILE,CF_DSPMETAFILE, CF_PALETTE,0}; ULONG x,ret; if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) { p = s + 8; for(x = 0;fmt[x];x++) { ret = WinQueryClipbrdData(WinQueryAnchorBlock(hwnd), fmt[x]); if(!ret) *p = '-'; p++; } p += 2; if(!fClipAppend) *p = 0; WinCloseClipbrd(WinQueryAnchorBlock(hwnd)); } else strcpy(s + 7, "Can't open. "); SetMonitorSize(hwnd, hwndMenu, &swpClip, s); } break; case CPU_FRAME: { char s[32]; ULONG percent,lastaverage; static BOOL lastavgset = 0; *s = 0; if(mp2) { strcpy(s," CPU: -% "); if(fAverage) strcat(s,"Avg: -%) "); } else { percent = ((MaxCount - (ULONG)mp1) * 100) / MaxCount; lastaverage = AveCPU; AveCPU = (((AveCPU * NumAveCPU) + percent) / ((ULONG)NumAveCPU + 1)); NumAveCPU++; if(!NumAveCPU) NumAveCPU = 65535; if(percent != LastPercent || (AveCPU != lastaverage && fAverage) || NumAveCPU == 1 || lastavgset != fAverage) { lastavgset = fAverage; LastPercent = percent; sprintf(s, " CPU: %lu%% ", percent); if(fAverage) sprintf(s + strlen(s), "(Avg: %lu%%) ", AveCPU); } } if(*s) SetMonitorSize(hwnd, hwndMenu, &swpCPU, s); } break; } return 0; case WM_TIMER: if(fSwapFloat && !hwndMenu) WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW); if(WinQueryWindowUShort(hwnd,QWS_ID) == CLP_FRAME) { if(!ClipHwnd) WinDestroyWindow(hwnd); else TakeClipboard(); } return 0; case UM_TIMER: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLP_FRAME: ClipMonHwnd = hwnd; WinSendMsg(hwnd, WM_TIMER, MPVOID, MPVOID); break; case CPU_FRAME: CPUHwnd = hwnd; WinSendMsg(hwnd, WM_TIMER, MPVOID, MPVOID); break; case HARD_FRAME: { char s[80]; HardHwnd = hwnd; SetDriveText(ulDriveMon, s); SetMonitorSize(hwnd, hwndMenu, &swpHard, s); } break; case SWAP_FRAME: { FILEFINDBUF3 ffb; ULONG nm = 1,fl = SWP_SIZE | SWP_SHOW | SWP_MOVE, sh,sl,nh; HDIR hdir = HDIR_CREATE; FSALLOCATE fsa; char s[128],ss[8],sss[8],mb,smb; static ULONG lastcbFile = 0; static BOOL warned = FALSE; static char SwapperDat[CCHMAXPATH] = ""; strcpy(s, " Unable to locate SWAPPER.DAT. "); SwapHwnd = hwnd; if(!*SwapperDat) FindSwapperDat(SwapperDat); if(*SwapperDat) { DosError(FERR_DISABLEHARDERR); if(!DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY, &ffb, sizeof(ffb), &nm, FIL_STANDARD)) { DosFindClose(hdir); if(ffb.cbFile != lastcbFile && lastcbFile) swaptick = 9; lastcbFile = ffb.cbFile; DosError(FERR_DISABLEHARDERR); if(!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) nm = fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector); else nm = 0; if(nm <= 32768 * 1024) { swaptick = 10; if(!warned) { SetPresParams(hwnd, RGB_RED, -1, -1, NULL); warned = TRUE; DosBeep(250,15); } } else if(warned) { PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID); warned = FALSE; } mb = MakeNumber(nm, &nh, &sl); *sss = 0; if(sl) sprintf(sss, ".%02lu", sl); smb = MakeNumber(ffb.cbFile, &sh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s, " Swap: %lu%s%cb ", sh, ss, smb); if(fShowSwapFree) sprintf(s + strlen(s), "(%lu%s%cb free) ", nh, sss, mb); } } SetMonitorSize(hwnd, hwndMenu, &swpSwap, s); } break; case TSK_FRAME: { PROCESSINFO *ppi; BUFFHEADER *pbh = NULL; MODINFO *pmi; long numprocs = -1,numthreads = -1; char s[80]; if(!DosAllocMem((PVOID)&pbh, USHRT_MAX + 4096, PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) { if(!DosQProcStatus(pbh, USHRT_MAX)) { numprocs = numthreads = 0; ppi = pbh->ppi; while(ppi->ulEndIndicator != PROCESS_END_INDICATOR ) { pmi = pbh->pmi; while(pmi && ppi->hModRef != pmi->hMod) pmi = pmi->pNext; if(pmi) { numprocs++; numthreads += ppi->usThreadCount; } ppi = (PPROCESSINFO)(ppi->ptiFirst + ppi->usThreadCount); } } DosFreeMem(pbh); sprintf(s, " Procs: %ld Thrds: %ld ", numprocs, numthreads); SetMonitorSize(hwnd, hwndMenu, &swpTask, s); } } break; case MEM_FRAME: { ULONG sh,sl,nh,amem; char s[128],ss[8],sss[8],mb,smb; strcpy(s, "Can't check virtual memory."); MemHwnd = hwnd; if(!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &amem, sizeof(amem))) { mb = MakeNumber(amem, &nh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s, " VMem: %lu%s%cb ", nh, ss, mb); } if(fShowPMem) { if(!Dos16MemAvail(&amem)) { mb = MakeNumber(amem, &nh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s + strlen(s), " PMem: %lu%s%cb ", nh, ss, mb); } } SetMonitorSize(hwnd, hwndMenu, &swpMem, s); } break; case CLOCK_FRAME: { char s[80]; DATETIME dt; ClockHwnd = hwnd; if(!DosGetDateTime(&dt)) { sprintf(s, " %0*u:%02u%s ", ((ampm) ? 0 : 2), (dt.hours % ((ampm) ? 12 : 24)) + ((ampm && !(dt.hours % 12)) ? 12 : 0), dt.minutes, ((ampm) ? (dt.hours > 11) ? "pm" : "am" : "")); if(showdate) sprintf(s + strlen(s), "%02u/%02u ", dt.month, dt.day); } else strcpy(s,"Unknown time"); SetMonitorSize(hwnd, hwndMenu, &swpClock, s); } break; } return 0; case WM_COMMAND: { BOOL ctrl,shift; ctrl = ((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0); shift = ((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0); switch(SHORT1FROMMP(mp1)) { case CLP_CLEAR: if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) { WinEmptyClipbrd(WinQueryAnchorBlock(hwnd)); WinCloseClipbrd(WinQueryAnchorBlock(hwnd)); PostMsg(hwnd, UM_REFRESH, MPVOID, MPVOID); } break; case CLP_APPEND: fClipAppend = (fClipAppend) ? FALSE : TRUE; SavePrf("ClipAppend", &fClipAppend, sizeof(BOOL)); PostMsg(hwnd, UM_REFRESH, MPVOID, MPVOID); if(ClipSetHwnd) PostMsg(ClipSetHwnd, UM_REFRESH, MPVOID, MPVOID); break; case MSE_HELP: ViewHelp(hwnd, "Monitors page"); break; case CPU_PULSE: { PROGDETAILS pgd; WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_FOCUSACTIVATE); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "PULSE.EXE"; if(WinStartApp(CPUHwnd, &pgd, NULL, NULL, 0)) { if(CPUHwnd) { closethreads = 1; DosSleep(1); PostMsg(CPUHwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); } } } break; case CPU_RESET: AveCPU = 0; NumAveCPU = 0; break; case CLOCK_VIRTUAL: case CLOCK_SWITCHLIST: case CLOCK_CMDLINE: case CLOCK_CLIPBOARD: case CLOCK_CALCULATOR: case HARD_FM2: case MSE_FRAME: { ULONG msg2 = UM_SHOWME; MPARAM mp12 = 0,mp22 = 0; HWND hwndP = hwndConfig; switch(SHORT1FROMMP(mp1)) { case CLOCK_CMDLINE: mp12 = MPFROMLONG(((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0)); msg2 = UM_CMDLINE; break; case CLOCK_CLIPBOARD: msg2 = UM_CLIPMGR; hwndP = ObjectHwnd3; break; case CLOCK_SWITCHLIST: msg2 = UM_SWITCHLIST; break; case CLOCK_VIRTUAL: msg2 = UM_VIRTUAL; break; case CLOCK_CALCULATOR: msg2 = UM_CALC; break; case HARD_FM2: msg2 = UM_STARTWIN; mp12 = MPFROM2SHORT(C_STARTFM2,0); break; } PostMsg(hwndP, msg2, mp12, mp22); } break; case CLOCK_SETTINGS: case CLOCK_CLOCK: case SWAP_LAUNCHPAD: case SWAP_WARPCENTER: case SWAP_CONNECTIONS: case SWAP_INFO: case SWAP_SETTINGS: case SWAP_SYSTEM: case SWAP_TEMPS: case SWAP_FM2: case HARD_OPEN: case CVR_COLORPALETTE: case CVR_HICOLORPALETTE: case CVR_FONTPALETTE: case CPU_KILLPROC: case CPU_HARDWARE: { char *p = "<WP_CLOCK>",*pp = defopen; char s[8]; switch(SHORT1FROMMP(mp1)) { case HARD_OPEN: sprintf(s, "%c:\\", (char)(ulDriveMon + '@')); p = s; break; case SWAP_FM2: p = "<FM3_Folder>"; break; case SWAP_TEMPS: p = "<WP_TEMPS>"; break; case SWAP_SYSTEM: p = "<WP_OS2SYS>"; break; case SWAP_SETTINGS: p = "<WP_CONFIG>"; break; case SWAP_INFO: p = "<WP_INFO>"; break; case SWAP_CONNECTIONS: p = "<WP_CONNECTIONSFOLDER>"; break; case SWAP_WARPCENTER: p = "<WP_WARPCENTER>"; break; case SWAP_LAUNCHPAD: p = "<WP_LAUNCHPAD>"; break; case CLOCK_SETTINGS: pp = setopen; break; case CVR_COLORPALETTE: p = "<WP_LORESCLRPAL>"; break; case CVR_HICOLORPALETTE: p = "<WP_HIRESCLRPAL>"; break; case CVR_FONTPALETTE: p = "<WP_FNTPAL>"; break; case CPU_KILLPROC: p = "<FM/2_KILLPROC>"; break; case CPU_HARDWARE: p = "<WP_HWMGR>"; break; } OpenObject(p, pp); } break; case HARD_VDIR: { PROGDETAILS pgd; char s[36]; sprintf(s, "/C VDIR.CMD %c:\\", (char)(ulDriveMon + '@')); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_MINIMIZE | SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "CMD.EXE"; WinStartApp((HWND)0, &pgd, s, NULL, 0); } break; case HARD_CHKDSK: { PROGDETAILS pgd; char s[8]; WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_FOCUSACTIVATE); sprintf(s, "%c:", (char)(ulDriveMon + '@')); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "PMCHKDSK.EXE"; WinStartApp((HWND)0, &pgd, s, NULL, 0); } break; default: if(SHORT1FROMMP(mp1) >= HARD_C && SHORT1FROMMP(mp1) <= HARD_C + 24) { ulDriveMon = (SHORT1FROMMP(mp1) - HARD_C) + 3; PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); if(ctrl) PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(HARD_OPEN,0), MPVOID); else if(shift) PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(HARD_VDIR,0), MPVOID); } break; } } return 0; case WM_DESTROY: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: SwapHwnd = (HWND)0; break; case CLOCK_FRAME: ClockHwnd = (HWND)0; break; case HARD_FRAME: HardHwnd = (HWND)0; break; case CPU_FRAME: closethreads = 1; DosSleep(1); CPUHwnd = (HWND)0; break; case CLP_FRAME: ClipMonHwnd = (HWND)0; break; case MEM_FRAME: MemHwnd = (HWND)0; break; case TSK_FRAME: TaskHwnd = (HWND)0; break; } break; } return PFNWPStatic(hwnd,msg,mp1,mp2); }
MRESULT Window::stdWndProc( HWND hWnd, ULONG iMessage, MPARAM mParam1, MPARAM mParam2, BOOL *returned ) { switch( iMessage ) { // case WM_FOCUSCHANGE : case WM_SETSELECTION : case WM_ACTIVATE : { if( type != Window::LISTBOX && type != Window::COMBOLISTBOX ) { focus( (BOOL)mParam1 );//SHORT1FROMMP( mParam2 ) ); } break; } case WM_SETFOCUS : { if( type != Window::LISTBOX && type != Window::COMBOLISTBOX ) focusSet( (BOOL)mParam2 ); break; } case WM_BUTTON1DOWN : { if( type == SCROLLBAR ) setFocus(); HWND hwnd = WinQueryFocus( HWND_DESKTOP ); if( mouseListener.getSize() != 0 ) { mouseButtonDown = TRUE; WinSetCapture( HWND_DESKTOP, hWnd ); WinStartTimer( Application::hab, hWndClient, 1, 50 ); Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::LEFT, AMouseEvent::DOWN ); } if( hwnd != WinQueryFocus( HWND_DESKTOP ) ) return (MRESULT)TRUE; break; } case WM_BUTTON1UP : { if( type == LISTBOX || type == COMBOLISTBOX ) { performFocusEvent( (int)WinSendMsg( (HWND)mParam2, LM_QUERYSELECTION, MPARAM(0), MPARAM(NULL) ) ); } else if( mouseListener.getSize() != 0 ) { mouseButtonDown = FALSE; WinStopTimer( Application::hab, hWndClient, 1 ); WinSetCapture( HWND_DESKTOP, NULLHANDLE ); Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::LEFT, AMouseEvent::RELEASE ); // return (MPARAM)TRUE; } break; } case WM_BUTTON2DOWN : { if( mouseListener.getSize() != 0 ) { WinSetCapture( HWND_DESKTOP, hWnd ); WinStartTimer( Application::hab, hWndClient, 1, 50 ); Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::RIGHT, AMouseEvent::DOWN ); } break; } case WM_BUTTON2UP : { if( mouseListener.getSize() != 0 ) { WinStopTimer( Application::hab, hWndClient, 1 ); WinSetCapture( HWND_DESKTOP, NULLHANDLE ); Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::RIGHT, AMouseEvent::RELEASE ); } break; } case WM_BUTTON1CLICK : { if( mouseListener.getSize() != 0 ) { // Check if triple click int newTick = WinGetCurrentTime( Application::hab ); if( newTick - lastTick <= WinQuerySysValue( HWND_DESKTOP, SV_DBLCLKTIME ) ) { Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::LEFT, AMouseEvent::TRIPLECLICK ); } else { Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::LEFT, AMouseEvent::CLICK ); } } break; } case WM_BUTTON2CLICK : { if( mouseListener.getSize() != 0 ) { Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::RIGHT, AMouseEvent::CLICK ); } break; } case WM_BUTTON1DBLCLK : { if( mouseListener.getSize() != 0 ) { Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::LEFT, AMouseEvent::DOUBLECLICK ); } lastTick = WinGetCurrentTime( Application::hab ); break; } case WM_BUTTON2DBLCLK : { if( mouseListener.getSize() != 0 ) { Point pos( SHORT1FROMMP(mParam1), SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, AMouseEvent::RIGHT, AMouseEvent::DOUBLECLICK ); } break; } case WM_MOUSEMOVE : { if( currentPointer != NULLHANDLE ) WinSetPointer( HWND_DESKTOP, currentPointer ); if( mouseListener.getSize() != 0 ) { Point pos( (SHORT)SHORT1FROMMP(mParam1), (SHORT)SHORT2FROMMP(mParam1) ); performMouseEvent( &pos, 0, AMouseEvent::MOVE ); } if( currentPointer != NULLHANDLE ) return (MPARAM)TRUE; break; } case WM_TIMER : { if( mouseButtonDown ) { POINTL ptl; WinQueryPointerPos( HWND_DESKTOP, &ptl ); WinMapWindowPoints( HWND_DESKTOP, hWnd, &ptl, 1 ); if( ptl.y < 0 || ptl.y > height ) { Point pos( ptl.x, ptl.y ); performMouseEvent( &pos, 0, AMouseEvent::MOVE ); } } break; } case WM_SIZE : { int oldWidth = width, oldHeight = height; SWP swp; WinQueryWindowPos( hWndFrame, &swp ); width = swp.cx; height = swp.cy; size( oldWidth, oldHeight ); break; } case WM_HSCROLL : { int pos = SHORT1FROMMP( mParam2 ), id = SHORT1FROMMP( mParam1 ); switch( SHORT2FROMMP( mParam2 ) ) { case SB_PAGERIGHT : { performScrollbarEvent( id, Scrollbar::PAGERIGHT, pos ); break; } case SB_PAGELEFT : { performScrollbarEvent( id, Scrollbar::PAGELEFT, pos ); break; } case SB_LINERIGHT : { performScrollbarEvent( id, Scrollbar::LINERIGHT, pos ); break; } case SB_LINELEFT : { performScrollbarEvent( id, Scrollbar::LINELEFT, pos ); break; } case SB_SLIDERTRACK : { performScrollbarEvent( id, Scrollbar::HORZTRACK, pos ); break; } case SB_SLIDERPOSITION : { performScrollbarEvent( id, Scrollbar::HORZRELEASED, pos ); break; } } break; } case WM_SYSCOMMAND : { // Check if the parent is a dialog, then chain the WM_SYSCOMMAND if( parent->getType() == DIALOG ) WinSendMsg( ((Window *)parent)->getHWND(), WM_SYSCOMMAND, mParam1, mParam2 ); break; } case WM_VSCROLL : { int id = SHORT1FROMMP( mParam1 ); Scrollbar *scrollbar = (Scrollbar *)getControl( id ); int pos; if( scrollbar ) pos = scrollbar->convertScrollPosToReal( SHORT1FROMMP( mParam2 ) ); else pos = SHORT1FROMMP( mParam2 ); switch( SHORT2FROMMP( mParam2 ) ) { case SB_PAGEDOWN : { performScrollbarEvent( id, Scrollbar::PAGEDOWN, pos ); break; } case SB_PAGEUP : { performScrollbarEvent( id, Scrollbar::PAGEUP, pos ); break; } case SB_LINEDOWN : { performScrollbarEvent( id, Scrollbar::LINEDOWN, pos ); break; } case SB_LINEUP : { performScrollbarEvent( id, Scrollbar::LINEUP, pos ); break; } case SB_SLIDERTRACK : { performScrollbarEvent( id, Scrollbar::VERTTRACK, pos ); break; } case SB_SLIDERPOSITION : { performScrollbarEvent( id, Scrollbar::VERTRELEASED, pos ); break; } } break; } case WM_MOVE : { SWP swp; WinQueryWindowPos( hWndFrame, &swp ); x = swp.x; y = swp.y; move(); break; } case WM_CLOSE : { if( close() ) break; else return (MPARAM)FALSE; } case WM_COMMAND : { if( SHORT1FROMMP( mParam2 ) == CMDSRC_PUSHBUTTON ) { Window *control = (Window *)getControl( SHORT1FROMMP(mParam1)); if( control != NULL ) { if( control->type == PUSHBUTTON ) { control->performButtonEvent( control, control->id ); return FALSE; } } else return FALSE; // In case ESC would close the dialog } break; } case WM_CHAR : { if( type == LISTBOX ) { performFocusEvent( (int)WinSendMsg( (HWND)mParam2, LM_QUERYSELECTION, MPARAM(0), MPARAM(NULL) ) ); } if( (SHORT1FROMMP( mParam1 ) & KC_KEYUP) || (SHORT1FROMMP( mParam1 ) & KC_DEADKEY) || (SHORT1FROMMP( mParam1 ) & KC_INVALIDCOMP) ) break; /* if( SHORT1FROMMP( mParam1 ) & KC_COMPOSITE ) mParam1 = MPFROM2SHORT( SHORT1FROMMP( mParam1 ) & ~KC_VIRTUALKEY, SHORT2FROMMP( mParam1 ) );*/ int modifiers = 0; if( SHORT1FROMMP( mParam1 ) & KC_SHIFT ) modifiers |= KeyDef::SHIFT; if( SHORT1FROMMP( mParam1 ) & KC_ALT ) modifiers |= KeyDef::kALT; if( SHORT1FROMMP( mParam1 ) & KC_CTRL) modifiers |= KeyDef::CTRL; if( SHORT1FROMMP( mParam1 ) & KC_VIRTUALKEY ) { int key = 0, vKey = SHORT2FROMMP( mParam2 ); // Maybe NumLock is on if( SHORT1FROMMP(mParam1) & KC_CHAR && !(vKey == VK_ENTER || vKey == VK_NEWLINE || vKey == VK_TAB || vKey == VK_BACKSPACE )) key = SHORT1FROMMP( mParam2 ); else if( vKey == VK_UP ) key = KeyDef::UP; else if( vKey == VK_DOWN ) key = KeyDef::DOWN; else if( vKey == VK_LEFT ) key = KeyDef::LEFT; else if( vKey == VK_RIGHT ) key = KeyDef::RIGHT; else if( vKey == VK_PAGEUP ) key = KeyDef::PAGEUP; else if( vKey == VK_PAGEDOWN ) key = KeyDef::PAGEDOWN; else if( vKey == VK_INSERT ) key = KeyDef::INSERT; else if( vKey == VK_DELETE ) key = KeyDef::kDELETE; else if( vKey == VK_HOME ) key = KeyDef::HOME; else if( vKey == VK_END ) key = KeyDef::END; else if( vKey == VK_ESC ) key = KeyDef::ESCAPE; else if( vKey == VK_F1 ) key = KeyDef::F1; else if( vKey == VK_F2 ) key = KeyDef::F2; else if( vKey == VK_F3 ) key = KeyDef::F3; else if( vKey == VK_F4 ) key = KeyDef::F4; else if( vKey == VK_F5 ) key = KeyDef::F5; else if( vKey == VK_F6 ) key = KeyDef::F6; else if( vKey == VK_F7 ) key = KeyDef::F7; else if( vKey == VK_F8 ) key = KeyDef::F8; else if( vKey == VK_F9 ) key = KeyDef::F9; else if( vKey == VK_F10 ) key = KeyDef::F10; else if( vKey == VK_F11 ) key = KeyDef::F11; else if( vKey == VK_F12 ) key = KeyDef::F12; else if( vKey == VK_ENTER ) key = KeyDef::ENTER; else if( vKey == VK_NEWLINE ) key = KeyDef::RETURN; else if( vKey == VK_BACKSPACE ) key = KeyDef::BACKSPACE; else if( vKey == VK_TAB ) key = KeyDef::TAB; else if( vKey == VK_BACKTAB ) { key = KeyDef::TAB; modifiers |= KeyDef::SHIFT; } else if( vKey == VK_SPACE ) key = KeyDef::SPACE; if( parent->getType() == DIALOG ) ((Dialog *)parent)->focusHotkey( key ); if( key != 0 ) if( performKeyEvent( this, modifiers, key ) ) return MPARAM(TRUE); // Do not pass up and down key to dialog if this is a combobox (would // move focus) /* if( getFilterDialogArrows() && (vKey == VK_UP || vKey == VK_DOWN) ) return (MPARAM)TRUE;*/ } else { int key = SHORT1FROMMP( mParam2 ); if( performKeyEvent( this, modifiers, key ) ) return MPARAM(TRUE); } break; } case WM_CONTROL : { Window *control = (Window *)getControl( SHORT1FROMMP(mParam1)); if( control != NULL ) { if( control->type == Window::LISTBOX || control->type == Window::COMBOLISTBOX ) { switch( SHORT2FROMMP(mParam1) ) { case LN_KILLFOCUS : control->focus( FALSE ); break; case LN_SETFOCUS : control->focus( TRUE );break; case LN_ENTER : control->performSelectionEvent( (int)WinSendMsg( (HWND)mParam2, LM_QUERYSELECTION, MPARAM(0), MPARAM(NULL) ) ); break; } } else if( control->type == Window::SCROLLBAR ) { switch( SHORT2FROMMP(mParam1) ) { case SLN_KILLFOCUS : control->focus( FALSE ); break; case SLN_SETFOCUS : control->setFocus(); break; } } else if( control->type == Window::RADIOBUTTON || control->type == Window::CHECKBOX ) { switch( SHORT2FROMMP( mParam1) ) { case BN_CLICKED : case BN_DBLCLICKED : control->performButtonEvent( control, control->id ); break; } } } break; } case DM_DRAGOVER: { PDRAGINFO pDInfo; PDRAGITEM pDItem; if( !acceptDropFiles ) return MRFROM2SHORT(DOR_NODROPOP, 0); pDInfo = (PDRAGINFO)mParam1; DrgAccessDraginfo(pDInfo); pDItem = DrgQueryDragitemPtr(pDInfo, 0); USHORT usOp = 0, usDrop = DOR_NEVERDROP; /* Inspect each item to see if it is acceptable */ ULONG ulItems = DrgQueryDragitemCount (pDInfo); for (INT i = 0; i < ulItems; i++) { pDItem = DrgQueryDragitemPtr(pDInfo, i); /* The item is acceptable only if it is copyable and the */ /* operation is a copy, or it is moveable and the operation */ /* is a move, and it can render <DRM_OS2FILE, NULL> */ if (pDItem->fsSupportedOps & DO_COPYABLE) { usOp = DO_COPY; /* Only check files, all types */ if (DrgVerifyRMF(pDItem, "DRM_OS2FILE", 0)) usDrop = DOR_DROP; else { usDrop = DOR_NEVERDROP; break; } } else { /* Must be a file but not droppable in type op */ usDrop = DOR_NODROPOP; usOp = 0; break; } } /* end for all items dragged */ DrgFreeDraginfo(pDInfo); return MRFROM2SHORT(usDrop, usOp); } case DM_DROP: { PDRAGINFO pDInfo; PDRAGITEM pDItem; pDInfo = (PDRAGINFO)mParam1; DrgAccessDraginfo(pDInfo); pDItem = DrgQueryDragitemPtr(pDInfo, 0); ULONG ulItems = DrgQueryDragitemCount (pDInfo); ULONG p; char **files; files = (char **)malloc( sizeof( char * ) * ulItems ); for (INT i=0; i < ulItems; i++) { CHAR DragSrcPath[CCHMAXPATH], DragSrcName[CCHMAXPATH]; pDItem = DrgQueryDragitemPtr(pDInfo, i); DrgQueryStrName(pDItem->hstrContainerName, sizeof(DragSrcPath), (PSZ)DragSrcPath); if (!(PSZ)DragSrcPath) break; if (DragSrcPath[(strlen(DragSrcPath)-1)] != '\\') strcat((PSZ)DragSrcPath, "\\"); /* Use the dragitem source name, it's the real name */ DrgQueryStrName(pDItem->hstrSourceName, sizeof(DragSrcName), (PSZ)DragSrcName); if (!((PSZ)DragSrcName)) break; strcat((PSZ)DragSrcPath, (PSZ)DragSrcName); FILESTATUS3 fsFile; DosError(FERR_DISABLEHARDERR); APIRET rc = DosQueryPathInfo(DragSrcPath, FIL_STANDARD, &fsFile, sizeof(FILESTATUS3)); DosError(FERR_ENABLEHARDERR); if (!rc && !(fsFile.attrFile & FILE_DIRECTORY)) { files[i] = (char *)malloc( strlen(DragSrcPath) + 1 ); strcpy( files[i], DragSrcPath ); DrgSendTransferMsg(pDItem->hwndItem, DM_ENDCONVERSATION, MPFROMLONG(pDItem->ulItemID), MPFROMLONG(DMFL_TARGETSUCCESSFUL)); } else { DosBeep(100,10); // EditorDisplay[BufNum]->DisplayMessage( pszDropNoFile ); } } filesDropped( files, ulItems ); for( i = 0; i < ulItems; i++ ) free( (void *)files[i] ); free( (void *)files ); DrgFreeDraginfo(pDInfo); break; } case WM_USER + 1 : { return (MPARAM)execFromMainThread( (int)mParam1, (void *)mParam2 ); } case WM_USER + 2 : { setFocus(); break; } } *returned = FALSE; return (MRESULT)NULL; }
int main (int argc, char *argv[]) { char logText[CCHMAXPATH]; short a; FILE *file; ULONG fl; HWND hwndClient; char text[CCHMAXPATH+10]; char title[CCHMAXPATH]; /* Create a copy of the args */ /* argv[0]: progname * argv[1]: installdir of Audio-CD-Creator * argv[2]: foldername * argv[3]: imagename * argv[4]: Parameter file */ ULONG ulDriveNum=0; ULONG ulDriveMap=0; APIRET rc; int i; rc=DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap); if(rc!=NO_ERROR) { printf("Error\n"); exit(1); } printf("Current disk: %c:\n",'A'+ulDriveNum-1); printf("Drive map:\n"); printf("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n"); for(i=0;i<26;i++) { printf(( (ulDriveMap << (31-i)) >>31) ? "y ": "- "); } printf("\n\n"); DosError(FERR_DISABLEHARDERR); for(i=2;i<26;i++) { if(( (ulDriveMap << (31-i)) >>31)) { char chrDrive[3]="A:"; BYTE fsqBuf2[sizeof(FSQBUFFER2)+3*CCHMAXPATH]={0}; PFSQBUFFER2 pfsqBuf2=(PFSQBUFFER2) &fsqBuf2; ULONG ulLength; /* Get FS */ chrDrive[0]='A'+i; ulLength=sizeof(fsqBuf2); rc=DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength); if(DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength)==NO_ERROR) { if(!strcmp(pfsqBuf2->szName+pfsqBuf2->cbName+1,"ISOFS")) { FSINFO fsInfo; rc=DosQueryFSInfo(i+1, FSIL_VOLSER, &fsInfo,sizeof(fsInfo)); printf("%s %s %d %s\n",chrDrive, pfsqBuf2->szName+pfsqBuf2->cbName+1, i+1, fsInfo.vol.szVolLabel); } } else printf("%s %s\n",chrDrive, "---"); } } DosError(FERR_ENABLEHARDERR); printf("\n\nDone"); return 0; }
/* This Proc handles the ISO image mounting */ MRESULT EXPENTRY unmountIsoDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char text[CCHMAXPATH]; char title[CCHMAXPATH]; ULONG rc; SWCNTRL swctl; PID pid; switch (msg) { case WM_INITDLG: { BOOL bDone=FALSE; int i; writeLog("Initializing dialog...\n"); /* Add switch entry */ memset(&swctl,0,sizeof(swctl)); WinQueryWindowProcess(hwnd,&pid,NULL); swctl.hwnd=hwnd; swctl.uchVisibility=SWL_VISIBLE; swctl.idProcess=pid; swctl.bProgType=PROG_DEFAULT; swctl.fbJump=SWL_JUMPABLE; WinAddSwitchEntry(&swctl); /*sprintf(text,"%d",params[4]);*/ // sprintf(text,"params[1]: %s ",params[1]); /* WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, pvSharedMem, params[4], 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE ); WinPostMsg(hwnd,WM_CLOSE,0,0); return (MRESULT) TRUE; */ /* Get free drive letters */ if((rc=DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap))!=NO_ERROR) WinPostMsg(hwnd,WM_CLOSE,0,0); DosError(FERR_DISABLEHARDERR); for(i=2;i<26;i++) { if(( (ulDriveMap << (31-i)) >>31)) { char chrDrive[3]="A:"; BYTE fsqBuf2[sizeof(FSQBUFFER2)+3*CCHMAXPATH]={0}; PFSQBUFFER2 pfsqBuf2=(PFSQBUFFER2) &fsqBuf2; ULONG ulLength; /* Get FS */ chrDrive[0]='A'+i; ulLength=sizeof(fsqBuf2); if(DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength)==NO_ERROR) { if(!strcmp(pfsqBuf2->szName+pfsqBuf2->cbName+1,"ISOFS")) { FSINFO fsInfo; if(DosQueryFSInfo(i+1, FSIL_VOLSER, &fsInfo,sizeof(fsInfo))==NO_ERROR) sprintf(text, "%s (%s)",chrDrive, fsInfo.vol.szVolLabel); else sprintf(text, "%s (unknown)",chrDrive); WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_INSERTITEM,MPFROMSHORT(LIT_END),MPFROMP(text)); } } else printf("%s %s\n",chrDrive, "---"); } } DosError(FERR_ENABLEHARDERR); /* Set dialog font to WarpSans for Warp 4 and above */ if(cwQueryOSRelease()>=40) { WinSetPresParam(hwnd, PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT), DEFAULT_DIALOG_FONT ); } if(!bHaveWindowPos) WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE); else WinSetWindowPos(hwnd,HWND_TOP,swpWindow.x, swpWindow.y, 0, 0, SWP_MOVE|SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW); return (MRESULT) TRUE; } case WM_CLOSE: WinQueryWindowPos(hwnd,&swpWindow); WinDismissDlg(hwnd,0); return FALSE; case WM_HELP: sendCommand("DISPLAYHELPPANEL=5100"); break; case WM_COMMAND: switch(SHORT1FROMMP(mp1)) { case IDPB_UNMOUNT: { /* User pressed the Unount button */ AEFS_DETACH detachparms={0}; char pszDrive[3]={0}; HOBJECT hObject; SHORT sSelected; memset(&detachparms, 0, sizeof(detachparms)); /* Get the drive letter */ sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST),MPFROMLONG(0L))); if(sSelected==LIT_NONE) break; WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMTEXT, MPFROM2SHORT(sSelected,2),MPFROMP(pszDrive)); /* Send the attachment request to the FSD. */ rc = DosFSAttach( // (PSZ) "", (PSZ) pszDrive, (PSZ) AEFS_IFS_NAME, &detachparms, sizeof(detachparms), FS_DETACH); if (rc) { DosBeep(100,400); sprintf(text, "Error while unmounting rc=%d. Make sure there're no open files on the drive.\n", rc); WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text, "ISO image unmount error", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE ); }else { WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_DELETEITEM, MPFROMSHORT(sSelected),MPFROMLONG(0L)); sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMCOUNT, MPFROMLONG(0L),MPFROMLONG(0L))); if(sSelected==0) WinEnableWindow(WinWindowFromID(hwnd,IDPB_UNMOUNT), FALSE); } break; } case IDPB_UNMOUNTCLOSE: WinPostMsg(hwnd,WM_CLOSE,0,0); break; default: break; } return (MRESULT) FALSE; default: break; } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
/** * rtR3Init worker. */ static int rtR3InitBody(uint32_t fFlags, int cArgs, char ***papszArgs, const char *pszProgramPath) { /* * Early native initialization. */ int rc = rtR3InitNativeFirst(fFlags); AssertMsgRCReturn(rc, ("rtR3InitNativeFirst failed with %Rrc\n", rc), rc); /* * Disable error popups. */ #if defined(RT_OS_OS2) /** @todo move to private code. */ DosError(FERR_DISABLEHARDERR); #endif /* * Init C runtime locale before we do anything that may end up converting * paths or we'll end up using the "C" locale for path conversion. */ setlocale(LC_CTYPE, ""); /* * The Process ID. */ #ifdef _MSC_VER g_ProcessSelf = _getpid(); /* crappy ansi compiler */ #else g_ProcessSelf = getpid(); #endif /* * Save the init flags. */ g_fInitFlags |= fFlags; #if !defined(IN_GUEST) && !defined(RT_NO_GIP) # ifdef VBOX /* * This MUST be done as the very first thing, before any file is opened. * The log is opened on demand, but the first log entries may be caused * by rtThreadInit() below. */ const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE"); if ( pszDisableHostCache != NULL && *pszDisableHostCache && strcmp(pszDisableHostCache, "0") != 0) { RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0); RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0); } # endif /* VBOX */ #endif /* !IN_GUEST && !RT_NO_GIP */ /* * Thread Thread database and adopt the caller thread as 'main'. * This must be done before everything else or else we'll call into threading * without having initialized TLS entries and suchlike. */ rc = rtThreadInit(); AssertMsgRCReturn(rc, ("Failed to initialize threads, rc=%Rrc!\n", rc), rc); #if !defined(IN_GUEST) && !defined(RT_NO_GIP) if (fFlags & RTR3INIT_FLAGS_SUPLIB) { /* * Init GIP first. * (The more time for updates before real use, the better.) */ rc = SUPR3Init(NULL); AssertMsgRCReturn(rc, ("Failed to initializable the support library, rc=%Rrc!\n", rc), rc); } #endif /* * The executable path, name and directory. Convert arguments. */ rc = rtR3InitProgramPath(pszProgramPath); AssertLogRelMsgRCReturn(rc, ("Failed to get executable directory path, rc=%Rrc!\n", rc), rc); rc = rtR3InitArgv(fFlags, cArgs, papszArgs); AssertLogRelMsgRCReturn(rc, ("Failed to convert the arguments, rc=%Rrc!\n", rc), rc); #if !defined(IN_GUEST) && !defined(RT_NO_GIP) /* * The threading is initialized we can safely sleep a bit if GIP * needs some time to update itself updating. */ if ((fFlags & RTR3INIT_FLAGS_SUPLIB) && g_pSUPGlobalInfoPage) { RTThreadSleep(20); RTTimeNanoTS(); } #endif /* * Init the program start TSes. * Do that here to be sure that the GIP time was properly updated the 1st time. */ g_u64ProgramStartNanoTS = RTTimeNanoTS(); g_u64ProgramStartMicroTS = g_u64ProgramStartNanoTS / 1000; g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000; /* * The remainder cannot easily be undone, so it has to go last. */ /* Fork and exit callbacks. */ #if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2) rc = pthread_atfork(NULL, NULL, rtR3ForkChildCallback); AssertMsg(rc == 0, ("%d\n", rc)); #endif atexit(rtR3ExitCallback); #ifdef IPRT_USE_SIG_CHILD_DUMMY /* * SIGCHLD must not be ignored (that's default), otherwise posix compliant waitpid * implementations won't work right. */ for (;;) { struct sigaction saOld; rc = sigaction(SIGCHLD, 0, &saOld); AssertMsg(rc == 0, ("%d/%d\n", rc, errno)); if ( rc != 0 || (saOld.sa_flags & SA_SIGINFO) || ( saOld.sa_handler != SIG_IGN && saOld.sa_handler != SIG_DFL) ) break; /* Try install dummy handler. */ struct sigaction saNew = saOld; saNew.sa_flags = SA_NOCLDSTOP | SA_RESTART; saNew.sa_handler = rtR3SigChildHandler; rc = sigemptyset(&saNew.sa_mask); AssertMsg(rc == 0, ("%d/%d\n", rc, errno)); struct sigaction saOld2; rc = sigaction(SIGCHLD, &saNew, &saOld2); AssertMsg(rc == 0, ("%d/%d\n", rc, errno)); if ( rc != 0 || ( saOld2.sa_handler == saOld.sa_handler && !(saOld2.sa_flags & SA_SIGINFO)) ) break; /* Race during dynamic load, restore and try again... */ sigaction(SIGCHLD, &saOld2, NULL); RTThreadYield(); } #endif /* IPRT_USE_SIG_CHILD_DUMMY */ #ifdef IPRT_WITH_ALIGNMENT_CHECKS /* * Enable alignment checks. */ const char *pszAlignmentChecks = getenv("IPRT_ALIGNMENT_CHECKS"); g_fRTAlignmentChecks = pszAlignmentChecks != NULL && pszAlignmentChecks[0] == '1' && pszAlignmentChecks[1] == '\0'; if (g_fRTAlignmentChecks) IPRT_ALIGNMENT_CHECKS_ENABLE(); #endif /* * Final native initialization. */ rc = rtR3InitNativeFinal(fFlags); AssertMsgRCReturn(rc, ("rtR3InitNativeFinal failed with %Rrc\n", rc), rc); return VINF_SUCCESS; }
void main(int argc,char *argv[]) { char *basedir, *p; FILEFINDBUF3 find; HDIR dirhandle; ULONG srch_cnt; int newdrive, urdrive, rootdir, dotdir, dotdotdir; int asking=TRUE, retcode=TRUE; while (--argc) { ++argv; if ((argv[0][0] == '/') || (argv[0][0] == '-')) { switch(toupper(argv[0][1])) { case 'Y': asking = FALSE; break; #ifdef __OS2__ case 'F': forcedel = 1; break; #endif default : printf("Invalid switch - %c\n", argv[0][1]); abort(); } } else break; } if (!argc) { puts("DELTREE2 v1.0\nRequired parameter missing"); abort(); } urdrive = getdisk(); #ifdef __OS2__ DosError(FERR_DISABLEHARDERR); #endif /* Process each command line parameter */ while (argc--) { basedir = *argv++; if (asking) { printf("Delete directory \"%s\" and all its subdirectories? [yn] ", basedir); if (!getyn()) continue; } setdisk(urdrive); srch_cnt = 1; dirhandle = HDIR_CREATE; findret = DosFindFirst(basedir, &dirhandle, MUST_HAVE_DIRECTORY, &find, sizeof(find), &srch_cnt, FIL_STANDARD); if (findret == 0) { #ifndef __OS2__ dirhandle = 1; #endif DosFindClose(dirhandle); } else continue; /* no such directory, goto next argument */ if (basedir[1] == ':') { /* Need to change drives */ newdrive = toupper(basedir[0])-'A'; if (newdrive != urdrive) { setdisk(newdrive); if (newdrive != getdisk()) continue; /* cannot switch drives, goto next argument */ } basedir+=2; } assert (NULL != (p=getcwd(NULL, MAXPATH))); dotdir = !strcmp(basedir, ".") || !strcmp(basedir, p+2); free(p); dotdotdir = !strcmp(basedir, ".."); rootdir = (!strcmp(basedir,"\\") || !strcmp(basedir,"/")); printf("Deleting %s...\n", basedir); if (rootdir) { CHDIR("\\"); retcode &= nextdir(FALSE); } else if (dotdir) { retcode &= nextdir(FALSE); } else if (dotdotdir) { CHDIR(".."); retcode &= nextdir(FALSE); } else { if (CHDIR(basedir)) continue /* cannot change directory - goto next argument */; retcode &= nextdir(FALSE); CHDIR(".."); #ifndef DBG retcode &= (0 == DosDeleteDir(basedir)); #endif } /* goto next argument */ } setdisk(urdrive); exit(retcode ? 0 : 1); }