HB_BOOL hb_fileAttrGet( const char * pszFileName, HB_FATTR * pulAttr ) { int i = s_fileFindDrv( pszFileName ); if( i >= 0 ) return s_pFileTypes[ i ]->AttrGet( s_pFileTypes[ i ], pszFileName, pulAttr ); return hb_fsGetAttr( pszFileName, pulAttr ); }
static HB_BOOL s_fileAttrGet( PHB_FILE_FUNCS pFuncs, const char * pszFileName, HB_FATTR * pnAttr ) { HB_SYMBOL_UNUSED( pFuncs ); return hb_fsGetAttr( pszFileName, pnAttr ); }
static int hb_zipStoreFile( zipFile hZip, const char * szFileName, const char * szName, const char * szPassword, const char * szComment ) { char * szZipName, * pString; HB_FHANDLE hFile; HB_SIZE nLen; HB_FATTR ulExtAttr; zip_fileinfo zfi; int iResult; HB_BOOL fError; HB_BOOL fText; HB_U32 ulCRC; if( szName ) { /* change path separators to '/' */ szZipName = hb_strdup( szName ); nLen = strlen( szZipName ); pString = szZipName; while( nLen-- ) { if( pString[ nLen ] == '\\' ) pString[ nLen ] = '/'; } } else { /* get file name */ szZipName = hb_strdup( szFileName ); nLen = strlen( szZipName ); pString = szZipName; while( nLen-- ) { if( pString[ nLen ] == '/' || pString[ nLen ] == '\\' ) { memmove( szZipName, &pString[ nLen + 1 ], strlen( szZipName ) - nLen ); break; } } } memset( &zfi, 0, sizeof( zfi ) ); fError = HB_FALSE; ulExtAttr = 0; #if defined( HB_OS_WIN ) { LPTSTR lpFileNameFree; LPCTSTR lpFileName = HB_FSNAMECONV( szFileName, &lpFileNameFree ); DWORD attr = GetFileAttributes( lpFileName ); if( attr != INVALID_FILE_ATTRIBUTES ) { ulExtAttr = hb_translateExtAttr( szFileName, attr & ( FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE ) ); } else fError = HB_TRUE; if( lpFileNameFree ) hb_xfree( lpFileNameFree ); } #elif defined( HB_OS_UNIX ) { struct stat statbuf; struct tm st; char * pszFree; if( stat( hb_fsNameConv( szFileName, &pszFree ), &statbuf ) == 0 ) { if( S_ISDIR( statbuf.st_mode ) ) { ulExtAttr |= 0x40000000; ulExtAttr |= 0x10; /* FILE_ATTRIBUTE_DIRECTORY */ } else { ulExtAttr |= 0x80000000; ulExtAttr |= 0x20; /* FILE_ATTRIBUTE_ARCHIVE */ } ulExtAttr |= ( ( statbuf.st_mode & S_IXOTH ) ? 0x00010000 : 0 ) | ( ( statbuf.st_mode & S_IWOTH ) ? 0x00020000 : 0 ) | ( ( statbuf.st_mode & S_IROTH ) ? 0x00040000 : 0 ) | ( ( statbuf.st_mode & S_IXGRP ) ? 0x00080000 : 0 ) | ( ( statbuf.st_mode & S_IWGRP ) ? 0x00100000 : 0 ) | ( ( statbuf.st_mode & S_IRGRP ) ? 0x00200000 : 0 ) | ( ( statbuf.st_mode & S_IXUSR ) ? 0x00400000 : 0 ) | ( ( statbuf.st_mode & S_IWUSR ) ? 0x00800000 : 0 ) | ( ( statbuf.st_mode & S_IRUSR ) ? 0x01000000 : 0 ); # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &statbuf.st_mtime, &st ); # else st = *localtime( &statbuf.st_mtime ); # endif zfi.tmz_date.tm_sec = st.tm_sec; zfi.tmz_date.tm_min = st.tm_min; zfi.tmz_date.tm_hour = st.tm_hour; zfi.tmz_date.tm_mday = st.tm_mday; zfi.tmz_date.tm_mon = st.tm_mon; zfi.tmz_date.tm_year = st.tm_year; } else fError = HB_TRUE; if( pszFree ) hb_xfree( pszFree ); } #elif defined( HB_OS_DOS ) { # if defined( __DJGPP__ ) || defined( __RSX32__ ) || defined( __GNUC__ ) int attr; char * pszFree; attr = _chmod( hb_fsNameConv( szFileName, &pszFree ), 0, 0 ); if( pszFree ) hb_xfree( pszFree ); if( attr != -1 ) # else HB_FATTR attr; if( hb_fsGetAttr( szFileName, &attr ) ) # endif { ulExtAttr = attr & ( HB_FA_READONLY | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY | HB_FA_ARCHIVE ); ulExtAttr = hb_translateExtAttr( szFileName, ulExtAttr ); } else fError = HB_TRUE; } #elif defined( HB_OS_OS2 ) { FILESTATUS3 fs3; APIRET ulrc; HB_FATTR ulAttr; char * pszFree; ulrc = DosQueryPathInfo( ( PCSZ ) hb_fsNameConv( szFileName, &pszFree ), FIL_STANDARD, &fs3, sizeof( fs3 ) ); if( pszFree ) hb_xfree( pszFree ); if( ulrc == NO_ERROR ) { ulAttr = 0; if( fs3.attrFile & FILE_READONLY ) ulAttr |= HB_FA_READONLY; if( fs3.attrFile & FILE_HIDDEN ) ulAttr |= HB_FA_HIDDEN; if( fs3.attrFile & FILE_SYSTEM ) ulAttr |= HB_FA_SYSTEM; if( fs3.attrFile & FILE_DIRECTORY ) ulAttr |= HB_FA_DIRECTORY; if( fs3.attrFile & FILE_ARCHIVED ) ulAttr |= HB_FA_ARCHIVE; ulExtAttr = hb_translateExtAttr( szFileName, ulAttr ); zfi.tmz_date.tm_sec = fs3.ftimeLastWrite.twosecs * 2; zfi.tmz_date.tm_min = fs3.ftimeLastWrite.minutes; zfi.tmz_date.tm_hour = fs3.ftimeLastWrite.hours; zfi.tmz_date.tm_mday = fs3.fdateLastWrite.day; zfi.tmz_date.tm_mon = fs3.fdateLastWrite.month; zfi.tmz_date.tm_year = fs3.fdateLastWrite.year + 1980; } else fError = HB_TRUE; } #else { HB_FATTR attr; if( ! hb_fsGetAttr( szFileName, &attr ) ) ulExtAttr = 0x81B60020; /* FILE_ATTRIBUTE_ARCHIVE | rw-rw-rw- */ else { ulExtAttr = attr & ( HB_FA_READONLY | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY | HB_FA_ARCHIVE ); ulExtAttr = hb_translateExtAttr( szFileName, ulExtAttr ); } } #endif if( fError ) { hb_xfree( szZipName ); return -200; } fText = HB_FALSE; ulCRC = 0; zfi.external_fa = ulExtAttr; /* TODO: zip.exe test: 0 for binary file, 1 for text. Does not depend on extension. We should analyse content of file to determine this??? */ zfi.internal_fa = 0; if( ulExtAttr & 0x40000000 ) { iResult = zipOpenNewFileInZip3( hZip, szZipName, &zfi, NULL, 0, NULL, 0, szComment, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, szPassword, ulCRC ); if( iResult == 0 ) zipCloseFileInZip( hZip ); } else { hFile = hb_fsOpen( szFileName, FO_READ ); if( hFile != FS_ERROR ) { #if defined( HB_OS_WIN ) { FILETIME ftutc, ft; SYSTEMTIME st; if( GetFileTime( ( HANDLE ) hb_fsGetOsHandle( hFile ), NULL, NULL, &ftutc ) && FileTimeToLocalFileTime( &ftutc, &ft ) && FileTimeToSystemTime( &ft, &st ) ) { zfi.tmz_date.tm_sec = st.wSecond; zfi.tmz_date.tm_min = st.wMinute; zfi.tmz_date.tm_hour = st.wHour; zfi.tmz_date.tm_mday = st.wDay; zfi.tmz_date.tm_mon = st.wMonth - 1; zfi.tmz_date.tm_year = st.wYear; } } #endif if( szPassword ) { if( hb_zipGetFileInfo( szFileName, &ulCRC, &fText ) ) zfi.internal_fa = fText ? 1 : 0; } iResult = zipOpenNewFileInZip3( hZip, szZipName, &zfi, NULL, 0, NULL, 0, szComment, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, szPassword, ulCRC ); if( iResult == 0 ) { pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE ); while( ( nLen = hb_fsReadLarge( hFile, pString, HB_Z_IOBUF_SIZE ) ) > 0 ) zipWriteInFileInZip( hZip, pString, ( unsigned ) nLen ); hb_xfree( pString ); zipCloseFileInZip( hZip ); } hb_fsClose( hFile ); } else iResult = -200 - hb_fsError(); } hb_xfree( szZipName ); return iResult; }