error_handle LocalSetFileAttr( const char *name, long attr ) /**********************************************************/ { #ifdef _M_I86 return( StashErrCode( DosSetFileMode( name, attr, 0 ), OP_LOCAL ) ); #else FILESTATUS3 fileinfo; APIRET rc; rc = DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ); if( rc == 0 ) { fileinfo.attrFile = attr; rc = DosSetPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ), 0 ); } return( StashErrCode( rc, OP_LOCAL ) ); #endif }
_WCRTLINK unsigned _dos_setfileattr( const char *path, unsigned attribute ) { APIRET rc; #if defined(__WARP__) FILESTATUS3 fs; rc = DosQueryPathInfo( (PSZ)path, FIL_STANDARD, &fs, sizeof( fs ) ); if( rc == 0 ) { fs.attrFile = attribute; rc = DosSetPathInfo( (PSZ)path, FIL_STANDARD, &fs, sizeof( fs ), 0 ); } #else rc = DosSetFileMode( (PSZ)path, attribute, 0ul ); #endif if( rc ) { return( __set_errno_dos_reterr( rc ) ); } return( 0 ); }
_WCRTLINK int __F_NAME(chmod,_wchmod)( const CHAR_TYPE *pathname, int pmode ) { APIRET rc; OS_UINT attr; #ifndef _M_I86 FILESTATUS3 fs; #endif #ifdef __WIDECHAR__ char mbPath[MB_CUR_MAX * _MAX_PATH]; if( wcstombs( mbPath, pathname, sizeof( mbPath ) ) == -1 ) { mbPath[0] = '\0'; } #endif #ifdef _M_I86 rc = DosQFileMode( (PSZ)__F_NAME(pathname,mbPath), &attr, 0 ); #else rc = DosQueryPathInfo( (PSZ)__F_NAME(pathname,mbPath), FIL_STANDARD, &fs, sizeof( fs ) ); attr = fs.attrFile; #endif if( rc != 0 ) { return( __set_errno_dos( rc ) ); } attr &= ~_A_RDONLY; if( !( pmode & S_IWRITE ) ) { attr |= _A_RDONLY; } #ifdef _M_I86 rc = DosSetFileMode( (PSZ)__F_NAME(pathname,mbPath), attr, 0 ); #else fs.attrFile = attr; rc = DosSetPathInfo( (PSZ)__F_NAME(pathname,mbPath), FIL_STANDARD, &fs, sizeof( fs ), 0 ); #endif if( rc != 0 ) { return( __set_errno_dos( rc ) ); } return( 0 ); }
unsigned LocalSetFileAttr( char *name, long attr ) /********************************************/ { return( StashErrCode( DosSetFileMode( name, attr, 0 ), OP_LOCAL ) ); }
void License(int iArgCount, char *apArgument[]) { WORD Error; HFILE hDest; ULONG ulCount; ULONG ulStatus; WORD wIndex; WORD wArgIndex = 0; BOOL bTriedAccess = FALSE; WORD wLicenseCount; wLicenseCount = (WORD)atoi(abyTemp); if (wLicenseCount > 40000) { printf("\nRequest for %u licenses denied. The maximum allowed is 40,000.\n\n",wLicenseCount); return; } wIndex = 0; while (abyDestPath[wIndex] != 0) { abyDestPath[wIndex] = (BYTE)toupper(abyDestPath[wIndex]); wIndex++; } AppendPath(&abyDestPath[wDestPathLength],abyConvertFile); // DosSetFileMode(abyDestPath,0x0000,0L); if ((Error = OpenFile(abyDestPath,&hDest,&wStatus,0L,0,1,0x6192)) != 0) { printf("Cannot open %s\n to set or read license count. ",abyDestPath); bTriedAccess = TRUE; } DosChgFilePtr(hDest,oFileOffset + oCopyCount,0,&dwFilePosition); if (wLicenseCount != 0) { if ((Error = DosWrite(hDest,&(BYTE)wLicenseCount,2,&wCount)) != 0) { printf("%sWKC%04X\n",abyLicenseSourceFailed,Error | 0x8000); return; } if (wLicenseCount == 0xaaaa) printf("\n[1mCopy protection has been disabled for\n\n%s\n\n[0m",abyDestPath); else printf("\nThe License Count has been set to %u for\n\n%s\n\n",wLicenseCount,abyDestPath); } else { if ((Error = DosRead(hDest,&(BYTE)wLicenseCount,2,&wCount)) != 0) { printf("%sRKC%04X\n",abyLicenseSourceFailed,Error | 0x8000); return; } if (wLicenseCount == 0xaaaa) printf("\n[1mCopy protection is disabled for\n\n%s\n\n[0m",abyDestPath); else printf("\nThe License Count for\n\n%s = %u\n\n",abyDestPath,wLicenseCount); } DosClose(hDest); if (wLicenseCount == 0xaaaa) DosSetFileMode(abyDestPath,0x0020,0L); else DosSetFileMode(abyDestPath,0x0021,0L); }
WORD Uninstall(CHAR szSourcePath[],CHAR szDeletePath[]) { HFILE hSource; HFILE hDelete; ULONG ulCopyKey; ULONG ulCount; ULONG ulStatus; ULONG ulTemp; ULONG ulFilePosition; ULONG ulPathLength; AppendPath(&szSourcePath[strlen(szSourcePath)],szSourceFile); // DosSetFileMode(szSourcePath,0x0000,0L); if ((ulLastError = DosOpen(szSourcePath,(PHFILE)&hSource,&ulStatus,0L,0,0x01,0x61a2,0L)) != 0) return(SOURCE_FILE_OPEN); ulPathLength = strlen(szDeletePath); AppendPath(&szDeletePath[ulPathLength],szDeviceFile); /* ** read code key from driver to delete if ((wLastError = DosSetFileMode(szDeletePath,0x0000,0L)) != 0) return(DEST_FILE_MODE_SET); */ if ((wLastError = DosOpen(szDeletePath,(PHFILE)&hDelete,&ulStatus,0L,0,0x01,0x61a2,0L)) != 0) return(DEST_FILE_OPEN); DosChgFilePtr(hDelete,oFileOffset + oCopyKey,0,&ulFilePosition); if ((wLastError = DosRead(hDelete,(BYTE *)&ulCopyKey,4,&ulCount)) != 0) return(DEST_FILE_READ); DosClose(hDelete); AppendPath(&szDeletePath[ulPathLength],szHiddenFile); #ifdef this_junk if ((wLastError = DosQFileMode(szDeletePath,&ulTemp,0L)) != 0) return(HIDE_FILE_MODE_READ); if ((ulTemp & 0x0007) != 0x0007) return(HIDE_FILE_MODE); if ((wLastError = DosSetFileMode(szDeletePath,0x0000,0L)) != 0) return(HIDE_FILE_MODE_SET); #endif if ((wLastError = DosOpen(szHiddenPath,(PHFILE)&hDelete,(PUSHORT)&ulStatus,0L,0,0x01,0x61a2,0L)) != 0) return(HIDE_FILE_OPEN); DosChgFilePtr(hDelete,20,0,&ulFilePosition); if ((wLastError = DosRead(hDelete,&(BYTE)stCodeKey.ulCopyKey,4,&ulCount)) != 0) return(HIDE_FILE_READ); DosClose(hDelete); if ((wLastError = DosDelete(szHiddenPath,0L)) != 0) return(HIDE_FILE_DELETE); AppendPath(&szDeletePath[ulPathLength],szDeviceFile); if ((wLastError = DosDelete(szDeletePath,0L)) != 0) return(DEST_FILE_DELETE); if (ulCopyKey != stCodeKey.ulCopyKey) return(BAD_CODE_KEY); /* ** read copy count from .SRC file, increment it, and write it back */ DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&ulFilePosition); if ((wLastError = DosRead(hSource,&(BYTE)stCodeKey.wCopyCount,2,&ulCount)) != 0) return(CAT_SOURCE_READ); stCodeKey.wCopyCount++; DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&ulFilePosition); if ((wLastError = DosWrite(hSource,&(BYTE)stCodeKey.wCopyCount,2,&ulCount)) != 0) return(CAT_SOURCE_WRITE); DosClose(hSource); if (stCodeKey.wCopyCount > 1) { sprintf(szMessage,"There are %u %s authorized device\ndriver licenses available for installation.", stCodeKey.wCopyCount,abyDeviceFile); MessageBox(hwndClient,szMessage) }
WORD Install(CHAR szSourcePath[],CHAR szDestPath) { HFILE hSource; HFILE hDestination; WORD wCount; WORD wStatus; WORD wTemp; WORD wAttrib; WORD wIndex; DWORD dwFilePosition; WORD wDestPathLength; WORD wSourcePathLength; DosGetDateTime(&stDateTime); stCodeKey.dwCopyKey = (DWORD)stDateTime.hours; stCodeKey.dwCopyKey |= (DWORD)stDateTime.minutes << 4; stCodeKey.dwCopyKey |= (DWORD)stDateTime.seconds << 10; stCodeKey.dwCopyKey |= (DWORD)stDateTime.hundredths << 16; stCodeKey.dwCopyKey |= (DWORD)stDateTime.day << 23; stCodeKey.dwCopyKey |= (DWORD)stDateTime.month << 27; stCodeKey.dwCopyKey |= (DWORD)stDateTime.year << 31; wSourcePathLength = strlen(szSourthPath); AppendPath(&szSourcePath[wSourcePathLength)],szSourceFile); if (DosSetFileMode(abySourcePath,0x0000,0L)); if ((wLastError = DosOpen(abySourcePath,(PHFILE)&hSource,(PUSHORT)&wStatus,0L,0,0x01,0x61a2,0L)) != 0) return(SOURCE_FILE_OPEN); DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&dwFilePosition); if ((wLastError = DosRead(hSource,&(BYTE)wTemp,2,&wCount)) != 0) return(SOURCE_FILE_READ); if (wTemp == 0) return(SOURCE_NO_LICENSE); if ((wLastError = DosQFileMode(abyDestPath,&wAttrib,0L)) != 0) return(SOURCE_FILE_MODE); if ((wAttrib & 0x0010) != 0x0010) return(DEST_BAD_PATH); wDestPathLength = strlen(szDestPath); AppendPath(&szDestPath[wDestPathLength],szDeviceFile); if (wLastError = FileCopy(szSourcePath,szDestPath) != 0) return(SOURCE_FILE_COPY); if ((wLastError = DosOpen(szDestPath,(PHFILE)&hDestination,(PUSHORT)&wStatus,0L,0,1,0x6192,0L)) != 0) return(DEST_FILE_OPEN); stCodeKey.wCopyCount = 0; DosChgFilePtr(hDestination,oFileOffset + oCopyKey,0,&dwFilePosition); if ((wLastError = DosWrite(hDestination,&(BYTE)stCodeKey.dwCopyKey,6,&wCount)) != 0) return(DEST_WRITE_CODE_KEY); DosClose(hDestination); DosSetFileMode(abyDestPath,0x0021,0L); stCodeKey.wCopyCount = wTemp; AppendPath(&abyDestPath[wDestPathLength],abyHiddenFile); AppendPath(&abySourcePath[wSourcePathLength],abyHiddenFile); if (wLastError = FileCopy(abySourcePath,abyDestPath) != 0) { DosClose(hSource); AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile); DosDelete(abyDestPath,0L); return(HIDE_FILE_COPY); } if ((wLastError = DosOpen(abyDestPath,(PHFILE)&hDestination,(PUSHORT)&wStatus,0L,0,1,0x6192,0L)) != 0) { DosClose(hSource); AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile); DosDelete(abyDestPath,0L); return(HIDE_FILE_COPY); } DosChgFilePtr(hDestination,20,0,&dwFilePosition); if ((wLastError = DosWrite(hDestination,(&(BYTE)stCodeKey.dwCopyKey),20,&wCount)) != 0) { DosClose(hDestination); DosClose(hSource); AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile); DosDelete(abyDestPath,0L); return(HIDE_FILE_WRITE); } DosClose(hDestination); DosSetFileMode(abySourcePath,0x0027,0L); DosSetFileMode(abyDestPath,0x0027,0L); stCodeKey.wCopyCount--; DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&dwFilePosition); if ((wLastError = DosWrite(hSource,&(BYTE)stCodeKey.wCopyCount,2,&wCount)) != 0) { DosClose(hSource); DosSetFileMode(abyDestPath,0x0000,0L); DosDelete(abyDestPath,0L); return(SOURCE_WRITE_CODE_KEY); } DosClose(hSource); AppendPath(&abyDestPath[wDestPathLength],abyDeviceFile); if (FixConfigFile()) { printf("% successfully installed. You must use UNINST.EXE to move the\n",abyDeviceFile); printf("device driver to another machine or directory\n"); if (stCodeKey.wCopyCount != 0) { printf("\nThere are %u %s device driver licenses still\n",stCodeKey.wCopyCount,abyDeviceFile); printf("available for installation.\n\n"); } } }