static int s_MessageBoxTimeout( IN HWND hWnd, IN LPCTSTR lpText, IN LPCTSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds ) { /* undocumented Windows API */ typedef int ( __stdcall * _HB_MSGBOXTOUT )( IN HWND hWnd, IN LPCTSTR lpText, IN LPCTSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds ); static _HB_MSGBOXTOUT s_pMessageBoxTimeout = ( _HB_MSGBOXTOUT ) -1; if( s_pMessageBoxTimeout == ( _HB_MSGBOXTOUT ) -1 ) { HMODULE hModule = GetModuleHandle( TEXT( "user32.dll" ) ); s_pMessageBoxTimeout = hModule == NULL ? NULL : ( _HB_MSGBOXTOUT ) HB_WINAPI_GETPROCADDRESST( hModule, "MessageBoxTimeout" ); } return s_pMessageBoxTimeout ? s_pMessageBoxTimeout( hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds ) : #if ! defined( HB_OS_WIN_CE ) MessageBoxEx( hWnd, lpText, lpCaption, uType, wLanguageId ); #else MessageBox( hWnd, lpText, lpCaption, uType ); #endif }
static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) { #if ! defined( HB_OS_WIN_CE ) BOOL bFlag; DWORD dwNeeded = 0; HANDLE hPrinter = NULL; PRINTER_INFO_2 * ppi2 = NULL; LPTSTR pBuffer = NULL; /* If Windows 95 or 98, use SetPrinter. */ if( hb_iswin9x() ) { /* Open this printer so you can get information about it. */ bFlag = OpenPrinter( ( LPTSTR ) lpPrinterName, &hPrinter, NULL ); if( ! bFlag || ! hPrinter ) return HB_FALSE; /* The first GetPrinter() tells you how big our buffer must be to hold ALL of PRINTER_INFO_2. Note that this will typically return FALSE. This only means that the buffer (the 3rd parameter) was not filled in. You do not want it filled in here. */ SetLastError( 0 ); bFlag = GetPrinter( hPrinter, 2, 0, 0, &dwNeeded ); if( ! bFlag ) { if( ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) || ( dwNeeded == 0 ) ) { ClosePrinter( hPrinter ); return HB_FALSE; } } /* Allocate enough space for PRINTER_INFO_2. */ ppi2 = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); /* The second GetPrinter() will fill in all the current information so that all you have to do is modify what you are interested in. */ bFlag = GetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, dwNeeded, &dwNeeded ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } /* Set default printer attribute for this printer. */ ppi2->Attributes |= PRINTER_ATTRIBUTE_DEFAULT; bFlag = SetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, 0 ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } /* Tell all open programs that this change occurred. Allow each program 1 second to handle this message. */ SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0L, ( LPARAM ) ( LPCTSTR ) TEXT( "windows" ), SMTO_NORMAL, 1000, NULL ); } /* If Windows NT, use the SetDefaultPrinter API for Windows 2000, or WriteProfileString for version 4.0 and earlier. */ else if( hb_iswinnt() ) { if( hb_iswin2k() ) /* Windows 2000 or later (use explicit call) */ { HMODULE hWinSpool; typedef BOOL ( WINAPI * DEFPRINTER )( LPCTSTR ); /* stops warnings */ DEFPRINTER fnSetDefaultPrinter; hWinSpool = hbwapi_LoadLibrarySystem( TEXT( "winspool.drv" ) ); if( ! hWinSpool ) return HB_FALSE; fnSetDefaultPrinter = ( DEFPRINTER ) HB_WINAPI_GETPROCADDRESST( hWinSpool, "SetDefaultPrinter" ); if( ! fnSetDefaultPrinter ) { FreeLibrary( hWinSpool ); return HB_FALSE; } bFlag = ( *fnSetDefaultPrinter )( lpPrinterName ); FreeLibrary( hWinSpool ); if( ! bFlag ) return HB_FALSE; } else /* NT4.0 or earlier */ { HB_ISIZ nStrLen; /* Open this printer so you can get information about it. */ bFlag = OpenPrinter( ( LPTSTR ) lpPrinterName, &hPrinter, NULL ); if( ! bFlag || ! hPrinter ) return HB_FALSE; /* The first GetPrinter() tells you how big our buffer must be to hold ALL of PRINTER_INFO_2. Note that this will typically return FALSE. This only means that the buffer (the 3rd parameter) was not filled in. You do not want it filled in here. */ SetLastError( 0 ); bFlag = GetPrinter( hPrinter, 2, 0, 0, &dwNeeded ); if( ! bFlag ) { if( ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) || ( dwNeeded == 0 ) ) { ClosePrinter( hPrinter ); return HB_FALSE; } } /* Allocate enough space for PRINTER_INFO_2. */ ppi2 = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); /* The second GetPrinter() fills in all the current information. */ bFlag = GetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, dwNeeded, &dwNeeded ); if( ( ! bFlag ) || ( ! ppi2->pDriverName ) || ( ! ppi2->pPortName ) ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } nStrLen = hbwapi_tstrlen( lpPrinterName ) + hbwapi_tstrlen( ppi2->pDriverName ) + hbwapi_tstrlen( ppi2->pPortName ) + 2; /* Allocate buffer big enough for concatenated string. String will be in form "printername,drivername,portname". */ pBuffer = ( LPTSTR ) hb_xgrab( ( nStrLen + 1 ) * sizeof( TCHAR ) ); pBuffer[ 0 ] = TEXT( '\0' ); /* Build string in form "printername,drivername,portname". */ hbwapi_tstrncat( pBuffer, lpPrinterName, nStrLen ); hbwapi_tstrncat( pBuffer, TEXT( "," ), nStrLen ); hbwapi_tstrncat( pBuffer, ppi2->pDriverName, nStrLen ); hbwapi_tstrncat( pBuffer, TEXT( "," ), nStrLen ); hbwapi_tstrncat( pBuffer, ppi2->pPortName, nStrLen ); /* Set the default printer in win.ini and registry. */ bFlag = WriteProfileString( TEXT( "windows" ), TEXT( "device" ), pBuffer ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); hb_xfree( pBuffer ); return HB_FALSE; } } /* Tell all open programs that this change occurred. Allow each app 1 second to handle this message. */ SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L, SMTO_NORMAL, 1000, NULL ); } /* Clean up. */ if( hPrinter ) ClosePrinter( hPrinter ); if( ppi2 ) hb_xfree( ppi2 ); if( pBuffer ) hb_xfree( pBuffer ); return HB_TRUE; #else HB_SYMBOL_UNUSED( lpPrinterName ); return HB_FALSE; #endif }
double hb_fsDiskSpace( const char * pszPath, HB_USHORT uiType ) { char szPathBuf[ 2 ]; double dSpace = 0.0; if( uiType > HB_DISK_TOTAL ) uiType = HB_DISK_AVAIL; if( ! pszPath ) { szPathBuf[ 0 ] = HB_OS_PATH_DELIM_CHR; szPathBuf[ 1 ] = '\0'; pszPath = szPathBuf; } #if defined( HB_OS_WIN ) { LPCTSTR lpPath; LPTSTR lpFree; lpPath = HB_FSNAMECONV( pszPath, &lpFree ); { UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); HB_BOOL fResult; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) /* NOTE: We need to call this function dynamically to maintain support Win95 first edition. It was introduced in Win95B (aka OSR2) [vszakats] */ typedef BOOL ( WINAPI * P_GDFSE )( LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER ); static P_GDFSE s_pGetDiskFreeSpaceEx = NULL; static HB_BOOL s_fInit = HB_FALSE; if( ! s_fInit ) { HMODULE hModule = GetModuleHandle( HB_WINAPI_KERNEL32_DLL() ); if( hModule ) s_pGetDiskFreeSpaceEx = ( P_GDFSE ) HB_WINAPI_GETPROCADDRESST( hModule, "GetDiskFreeSpaceEx" ); s_fInit = HB_TRUE; } if( ! s_pGetDiskFreeSpaceEx ) { DWORD dwSectorsPerCluster; DWORD dwBytesPerSector; DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; fResult = GetDiskFreeSpace( lpPath, &dwSectorsPerCluster, &dwBytesPerSector, &dwNumberOfFreeClusters, &dwTotalNumberOfClusters ) ? HB_TRUE : HB_FALSE; hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) dwTotalNumberOfClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; } } } else #endif { #if defined( _MSC_VER ) || defined( __LCC__ ) || \ ( defined( __GNUC__ ) && ! defined( __RSXNT__ ) ) # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).LowPart + \ ( double ) (v).HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #else /* NOTE: Borland doesn't seem to deal with the un-named struct that is part of ULARGE_INTEGER [pt] */ # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).u.LowPart + \ ( double ) (v).u.HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #endif ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) fResult = s_pGetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #else fResult = GetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #endif hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); break; case HB_DISK_FREE: dSpace = HB_GET_LARGE_UINT( i64FreeBytes ); break; case HB_DISK_TOTAL: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ); break; case HB_DISK_USED: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) - HB_GET_LARGE_UINT( i64FreeBytes ); break; } } } SetErrorMode( uiErrMode ); } if( lpFree ) hb_xfree( lpFree ); } #elif defined( HB_OS_DOS ) || defined( HB_OS_OS2 ) { HB_USHORT uiDrive; uiDrive = pszPath == NULL || pszPath[ 0 ] == 0 || pszPath[ 1 ] != HB_OS_DRIVE_DELIM_CHR ? 0 : ( pszPath[ 0 ] >= 'A' && pszPath[ 0 ] <= 'Z' ? pszPath[ 0 ] - 'A' + 1 : ( pszPath[ 0 ] >= 'a' && pszPath[ 0 ] <= 'z' ? pszPath[ 0 ] - 'a' + 1 : 0 ) ); #if defined( HB_OS_DOS ) for( ;; ) { union REGS regs; regs.HB_XREGS.dx = uiDrive; regs.h.ah = 0x36; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.ax != 0xFFFF ) { HB_USHORT uiClusterTotal = regs.HB_XREGS.dx; HB_USHORT uiClusterFree = regs.HB_XREGS.bx; HB_USHORT uiSecPerCluster = regs.HB_XREGS.ax; HB_USHORT uiSectorSize = regs.HB_XREGS.cx; switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) uiClusterTotal * ( double ) uiSecPerCluster * ( double ) uiSectorSize; if( uiType == HB_DISK_USED ) dSpace -= ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; } } else { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) == E_RETRY ) continue; } break; } #else /* HB_OS_OS2 */ { struct _FSALLOCATE fsa; APIRET rc; /* Query level 1 info from filesystem */ while( ( rc = DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) ) != NO_ERROR ) { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) != E_RETRY ) break; } hb_fsSetError( ( HB_ERRCODE ) rc ); if( rc == NO_ERROR ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) fsa.cUnit * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; } } } #endif } #elif defined( HB_OS_UNIX ) && \ !( defined( __WATCOMC__ ) || defined( __CEGCC__ ) || defined( HB_OS_SYMBIAN ) ) { #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) struct statfs sf; #else struct statvfs sf; #endif char * pszFree; pszPath = hb_fsNameConv( pszPath, &pszFree ); #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) if( statfs( pszPath, &sf ) == 0 ) #else if( statvfs( pszPath, &sf ) == 0 ) #endif { switch( uiType ) { case HB_DISK_AVAIL: dSpace = ( double ) sf.f_bavail * ( double ) sf.f_bsize; break; case HB_DISK_FREE: dSpace = ( double ) sf.f_bfree * ( double ) sf.f_bsize; break; case HB_DISK_USED: dSpace = ( double ) ( sf.f_blocks - sf.f_bfree ) * ( double ) sf.f_bsize; break; case HB_DISK_TOTAL: dSpace = ( double ) sf.f_blocks * ( double ) sf.f_bsize; break; } hb_fsSetIOError( HB_TRUE, 0 ); } else hb_fsSetIOError( HB_FALSE, 0 ); if( pszFree ) hb_xfree( pszFree ); } #else { int iTODO; HB_SYMBOL_UNUSED( uiType ); } #endif return dSpace; }
HB_BOOL hb_fsLink( const char * pszExisting, const char * pszNewFile ) { HB_BOOL fResult; if( pszExisting && pszNewFile ) { hb_vmUnlock(); #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) { typedef BOOL ( WINAPI * _HB_CREATEHARDLINK )( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES ); static _HB_CREATEHARDLINK s_pCreateHardLink = NULL; if( ! s_pCreateHardLink ) { HMODULE hModule = GetModuleHandle( TEXT( "kernel32.dll" ) ); if( hModule ) s_pCreateHardLink = ( _HB_CREATEHARDLINK ) HB_WINAPI_GETPROCADDRESST( hModule, "CreateHardLink" ); } if( s_pCreateHardLink ) { LPCTSTR lpFileName, lpExistingFileName; LPTSTR lpFileNameFree, lpExistingFileNameFree; lpFileName = HB_FSNAMECONV( pszNewFile, &lpFileNameFree ); lpExistingFileName = HB_FSNAMECONV( pszExisting, &lpExistingFileNameFree ); fResult = s_pCreateHardLink( lpFileName, lpExistingFileName, NULL ) != 0; hb_fsSetIOError( fResult, 0 ); if( lpFileNameFree ) hb_xfree( lpFileNameFree ); if( lpExistingFileNameFree ) hb_xfree( lpExistingFileNameFree ); } else { hb_fsSetError( 1 ); fResult = HB_FALSE; } } #elif defined( HB_OS_UNIX ) { char * pszExistingFree; char * pszNewFileFree; pszExisting = hb_fsNameConv( pszExisting, &pszExistingFree ); pszNewFile = hb_fsNameConv( pszNewFile, &pszNewFileFree ); fResult = ( link( pszExisting, pszNewFile ) == 0 ); hb_fsSetIOError( fResult, 0 ); if( pszExistingFree ) hb_xfree( pszExistingFree ); if( pszNewFileFree ) hb_xfree( pszNewFileFree ); } #else { hb_fsSetError( 1 ); fResult = HB_FALSE; } #endif hb_vmLock(); } else { hb_fsSetError( 2 ); fResult = HB_FALSE; } return fResult; }
/* NOTE: Caller must free the pointer, if not NULL */ char * hb_fsLinkRead( const char * pszFile ) { char * pszLink = NULL; if( pszFile ) { hb_vmUnlock(); #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) { typedef DWORD ( WINAPI * _HB_GETFINALPATHNAMEBYHANDLE )( HANDLE, LPTSTR, DWORD, DWORD ); static _HB_GETFINALPATHNAMEBYHANDLE s_pGetFinalPathNameByHandle = NULL; #ifndef VOLUME_NAME_DOS #define VOLUME_NAME_DOS 0x0 #endif #ifndef VOLUME_NAME_GUID #define VOLUME_NAME_GUID 0x1 #endif #ifndef VOLUME_NAME_NT #define VOLUME_NAME_NT 0x2 #endif #ifndef VOLUME_NAME_NONE #define VOLUME_NAME_NONE 0x4 #endif #ifndef FILE_NAME_NORMALIZED #define FILE_NAME_NORMALIZED 0x0 #endif #ifndef FILE_NAME_OPENED #define FILE_NAME_OPENED 0x8 #endif if( ! s_pGetFinalPathNameByHandle ) { HMODULE hModule = GetModuleHandle( TEXT( "kernel32.dll" ) ); if( hModule ) s_pGetFinalPathNameByHandle = ( _HB_GETFINALPATHNAMEBYHANDLE ) HB_WINAPI_GETPROCADDRESST( hModule, "GetFinalPathNameByHandle" ); } if( s_pGetFinalPathNameByHandle ) { LPCTSTR lpFileName; LPTSTR lpFileNameFree; HANDLE hFile; DWORD dwAttr; HB_BOOL fDir; lpFileName = HB_FSNAMECONV( pszFile, &lpFileNameFree ); dwAttr = GetFileAttributes( lpFileName ); fDir = ( dwAttr != INVALID_FILE_ATTRIBUTES ) && ( dwAttr & FILE_ATTRIBUTE_DIRECTORY ); hFile = CreateFile( lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, fDir ? ( FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS ) : FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) hb_fsSetIOError( HB_FALSE, 0 ); else { DWORD size; TCHAR lpLink[ HB_PATH_MAX ]; size = s_pGetFinalPathNameByHandle( hFile, lpLink, HB_PATH_MAX, VOLUME_NAME_DOS ); if( size < HB_PATH_MAX ) { if( size > 0 ) { lpLink[ size ] = TEXT( '\0' ); pszLink = HB_OSSTRDUP( lpLink ); } hb_fsSetIOError( HB_TRUE, 0 ); } else hb_fsSetError( 9 ); } if( lpFileNameFree ) hb_xfree( lpFileNameFree ); } else hb_fsSetError( 1 ); } #elif defined( HB_OS_UNIX ) { char * pszFileFree; size_t size; pszFile = hb_fsNameConv( pszFile, &pszFileFree ); pszLink = ( char * ) hb_xgrab( HB_PATH_MAX + 1 ); size = readlink( pszFile, pszLink, HB_PATH_MAX ); hb_fsSetIOError( size != ( size_t ) -1, 0 ); if( size == ( size_t ) -1 ) { hb_xfree( pszLink ); pszLink = NULL; } else { pszLink[ size ] = '\0'; /* Convert from OS codepage */ pszLink = ( char * ) HB_UNCONST( hb_osDecodeCP( pszLink, NULL, NULL ) ); } if( pszFileFree ) hb_xfree( pszFileFree ); } #else { hb_fsSetError( 1 ); } #endif hb_vmLock(); } else hb_fsSetError( 2 ); return pszLink; }
HB_BOOL hb_fsLinkSym( const char * pszTarget, const char * pszNewFile ) { HB_BOOL fResult; if( pszTarget && pszNewFile ) { hb_vmUnlock(); #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) { typedef BOOL ( WINAPI * _HB_CREATESYMBOLICLINK )( LPCTSTR, LPCTSTR, DWORD ); static _HB_CREATESYMBOLICLINK s_pCreateSymbolicLink = NULL; #ifndef SYMBOLIC_LINK_FLAG_DIRECTORY #define SYMBOLIC_LINK_FLAG_DIRECTORY 0x1 #endif if( ! s_pCreateSymbolicLink ) { HMODULE hModule = GetModuleHandle( TEXT( "kernel32.dll" ) ); if( hModule ) s_pCreateSymbolicLink = ( _HB_CREATESYMBOLICLINK ) HB_WINAPI_GETPROCADDRESST( hModule, "CreateSymbolicLink" ); } if( s_pCreateSymbolicLink ) { LPCTSTR lpSymlinkFileName, lpTargetFileName; LPTSTR lpSymlinkFileNameFree, lpTargetFileNameFree; DWORD dwAttr; HB_BOOL fDir; lpSymlinkFileName = HB_FSNAMECONV( pszNewFile, &lpSymlinkFileNameFree ); lpTargetFileName = HB_FSNAMECONV( pszTarget, &lpTargetFileNameFree ); dwAttr = GetFileAttributes( lpTargetFileName ); fDir = ( dwAttr != INVALID_FILE_ATTRIBUTES ) && ( dwAttr & FILE_ATTRIBUTE_DIRECTORY ); fResult = s_pCreateSymbolicLink( lpSymlinkFileName, lpTargetFileName, fDir ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0 ) != 0; hb_fsSetIOError( fResult, 0 ); if( lpSymlinkFileNameFree ) hb_xfree( lpSymlinkFileNameFree ); if( lpTargetFileNameFree ) hb_xfree( lpTargetFileNameFree ); } else { hb_fsSetError( 1 ); fResult = HB_FALSE; } } #elif defined( HB_OS_UNIX ) { char * pszTargetFree; char * pszNewFileFree; pszTarget = hb_fsNameConv( pszTarget, &pszTargetFree ); pszNewFile = hb_fsNameConv( pszNewFile, &pszNewFileFree ); fResult = ( symlink( pszTarget, pszNewFile ) == 0 ); hb_fsSetIOError( fResult, 0 ); if( pszTargetFree ) hb_xfree( pszTargetFree ); if( pszNewFileFree ) hb_xfree( pszNewFileFree ); } #else { hb_fsSetError( 1 ); fResult = HB_FALSE; } #endif hb_vmLock(); } else { hb_fsSetError( 2 ); fResult = HB_FALSE; } return fResult; }
static void hb_GetDefaultPrinter( PHB_ITEM pPrinterName ) { #if ! defined( HB_OS_WIN_CE ) HB_BOOL bResult = HB_FALSE; hb_itemPutC( pPrinterName, NULL ); if( hb_iswin2k() ) /* Windows 2000 or later */ { typedef BOOL( WINAPI * DEFPRINTER ) ( LPTSTR, LPDWORD ); HMODULE hWinSpool = hbwapi_LoadLibrarySystem( TEXT( "winspool.drv" ) ); if( hWinSpool ) { DEFPRINTER fnGetDefaultPrinter = ( DEFPRINTER ) HB_WINAPI_GETPROCADDRESST( hWinSpool, "GetDefaultPrinter" ); if( fnGetDefaultPrinter ) { TCHAR lpPrinterName[ 256 ]; DWORD dwSize = HB_SIZEOFARRAY( lpPrinterName ) - 1; bResult = ( *fnGetDefaultPrinter )( lpPrinterName, &dwSize ); HB_ITEMPUTSTR( pPrinterName, lpPrinterName ); } FreeLibrary( hWinSpool ); } } if( ! bResult ) /* Win9x and Windows NT 4.0 or earlier & 2000+ if necessary for some reason i.e. dll could not load! */ { TCHAR lpPrinterName[ 256 ]; DWORD dwSize = GetProfileString( TEXT( "windows" ), TEXT( "device" ), TEXT( "" ), lpPrinterName, ( DWORD ) HB_SIZEOFARRAY( lpPrinterName ) - 1 ); if( dwSize && dwSize < HB_SIZEOFARRAY( lpPrinterName ) ) { dwSize = 0; while( lpPrinterName[ dwSize ] != '\0' && lpPrinterName[ dwSize ] != ',' ) dwSize++; lpPrinterName[ dwSize ] = '\0'; bResult = HB_TRUE; HB_ITEMPUTSTRLEN( pPrinterName, lpPrinterName, dwSize ); } } if( ! bResult && hb_iswin9x() ) { /* This option should never be required but is included because of this article https://support.microsoft.com/kb/246772 This option will not enumerate any network printers. From the SDK technical reference for EnumPrinters(); If Level is 2 or 5, Name is a pointer to a null-terminated string that specifies the name of a server whose printers are to be enumerated. If this string is NULL, then the function enumerates the printers installed on the local machine. */ DWORD dwNeeded = 0, dwReturned = 0; EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, NULL, 0, &dwNeeded, &dwReturned ); if( dwNeeded ) { PRINTER_INFO_2 * pPrinterInfo = ( PRINTER_INFO_2 * ) hb_xgrabz( dwNeeded ); if( EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, ( LPBYTE ) pPrinterInfo, dwNeeded, &dwNeeded, &dwReturned ) && dwReturned ) HB_ITEMPUTSTR( pPrinterName, pPrinterInfo->pPrinterName ); hb_xfree( pPrinterInfo ); } } #else hb_itemPutC( pPrinterName, NULL ); #endif }
HB_FOFFSET hb_fsFSize( const char * pszFileName, HB_BOOL bUseDirEntry ) { if( bUseDirEntry ) { #if defined( HB_OS_WIN ) typedef BOOL ( WINAPI * _HB_GETFILEATTRIBUTESEX )( LPCTSTR, GET_FILEEX_INFO_LEVELS, LPVOID ); static _HB_GETFILEATTRIBUTESEX s_pGetFileAttributesEx = ( _HB_GETFILEATTRIBUTESEX ) -1; if( s_pGetFileAttributesEx == ( _HB_GETFILEATTRIBUTESEX ) -1 ) { HMODULE hModule = GetModuleHandle( TEXT( "kernel32.dll" ) ); if( hModule ) s_pGetFileAttributesEx = ( _HB_GETFILEATTRIBUTESEX ) HB_WINAPI_GETPROCADDRESST( hModule, "GetFileAttributesEx" ); else s_pGetFileAttributesEx = NULL; } if( s_pGetFileAttributesEx ) { LPCTSTR lpFileName; LPTSTR lpFree; WIN32_FILE_ATTRIBUTE_DATA attrex; HB_BOOL fResult; lpFileName = HB_FSNAMECONV( pszFileName, &lpFree ); memset( &attrex, 0, sizeof( attrex ) ); fResult = s_pGetFileAttributesEx( lpFileName, GetFileExInfoStandard, &attrex ) && ( attrex.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0; hb_fsSetIOError( fResult, 0 ); if( lpFree ) hb_xfree( lpFree ); if( fResult ) return ( HB_FOFFSET ) attrex.nFileSizeLow + ( ( HB_FOFFSET ) attrex.nFileSizeHigh << 32 ); } else { PHB_FFIND ffind = hb_fsFindFirst( pszFileName, HB_FA_ALL ); hb_fsSetIOError( ffind != NULL, 0 ); if( ffind ) { HB_FOFFSET size = ffind->size; hb_fsFindClose( ffind ); return size; } } #elif defined( HB_USE_LARGEFILE64 ) char * pszFree; HB_BOOL fResult; struct stat64 statbuf; pszFileName = hb_fsNameConv( pszFileName, &pszFree ); statbuf.st_size = 0; hb_vmUnlock(); fResult = stat64( pszFileName, &statbuf ) == 0; hb_fsSetIOError( fResult, 0 ); hb_vmLock(); if( pszFree ) hb_xfree( pszFree ); if( fResult ) return ( HB_FOFFSET ) statbuf.st_size; #else char * pszFree; HB_BOOL fResult; struct stat statbuf; pszFileName = hb_fsNameConv( pszFileName, &pszFree ); statbuf.st_size = 0; hb_vmUnlock(); fResult = stat( ( char * ) pszFileName, &statbuf ) == 0; hb_fsSetIOError( fResult, 0 ); hb_vmLock(); if( pszFree ) hb_xfree( pszFree ); if( fResult ) return ( HB_FOFFSET ) statbuf.st_size; #endif } else { HB_FHANDLE hFileHandle = hb_fsOpen( pszFileName, FO_READ | FO_COMPAT ); if( hFileHandle != FS_ERROR ) { HB_FOFFSET nPos = hb_fsSeekLarge( hFileHandle, 0, FS_END ); hb_fsClose( hFileHandle ); return nPos; } } return 0; }