📄 qfileinfo_win.cpp
字号:
psl->Release(); } } ); return fileLinked;#else return QString();#endif // QT_NO_COMPONENT}Q_EXPORT int qt_ntfs_permission_lookup = 1;QString QFileInfo::owner() const{ if ( ( qt_ntfs_permission_lookup > 0 ) && ( qWinVersion() == Qt::WV_2000 || qWinVersion() == Qt::WV_XP ) ) { PSID pOwner = 0; PSECURITY_DESCRIPTOR pSD; QString name; resolveLibs(); if ( ptrGetNamedSecurityInfoW && ptrLookupAccountSidW ) { if ( ptrGetNamedSecurityInfoW( (wchar_t*)fn.ucs2(), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, &pOwner, NULL, NULL, NULL, &pSD ) == ERROR_SUCCESS ) { DWORD lowner = 0, ldomain = 0; SID_NAME_USE use; // First call, to determine size of the strings (with '\0'). ptrLookupAccountSidW( NULL, pOwner, NULL, &lowner, NULL, &ldomain, &use ); TCHAR *owner = new TCHAR[lowner]; TCHAR *domain = new TCHAR[ldomain]; // Second call, size is without '\0' if ( ptrLookupAccountSidW( NULL, pOwner, (LPWSTR)owner, &lowner, (LPWSTR)domain, &ldomain, &use ) ) { name = qt_winQString(owner); } LocalFree( pSD ); delete [] owner; delete [] domain; } } return name; } else return QString::null;}static const uint nobodyID = (uint) -2;uint QFileInfo::ownerId() const{ return nobodyID;}QString QFileInfo::group() const{ if ( ( qt_ntfs_permission_lookup > 0 ) && ( qWinVersion() == Qt::WV_2000 || qWinVersion() == Qt::WV_XP ) ) { PSID pGroup = 0; PSECURITY_DESCRIPTOR pSD; QString name; resolveLibs(); if ( ptrGetNamedSecurityInfoW && ptrLookupAccountSidW ) { if ( ptrGetNamedSecurityInfoW( (wchar_t*)fn.ucs2(), SE_FILE_OBJECT, GROUP_SECURITY_INFORMATION, NULL, &pGroup, NULL, NULL, &pSD ) == ERROR_SUCCESS ) { DWORD lgroup = 0, ldomain = 0; SID_NAME_USE use; // First call, to determine size of the strings (with '\0'). ptrLookupAccountSidW( NULL, pGroup, NULL, &lgroup, NULL, &ldomain, &use ); TCHAR *group = new TCHAR[lgroup]; TCHAR *domain = new TCHAR[ldomain]; // Second call, size is without '\0' if ( ptrLookupAccountSidW( NULL, pGroup, (LPWSTR)group, &lgroup, (LPWSTR)domain, &ldomain, &use ) ) { name = qt_winQString(group); } LocalFree( pSD ); delete [] group; delete [] domain; } } return name; } else return QString::null;}uint QFileInfo::groupId() const{ return nobodyID;}bool QFileInfo::permission( int p ) const{ if ( ( qt_ntfs_permission_lookup > 0 ) && ( qWinVersion() == Qt::WV_2000 || qWinVersion() == Qt::WV_XP ) ) { PSID pOwner = 0; PSID pGroup = 0; PACL pDacl; PSECURITY_DESCRIPTOR pSD; ACCESS_MASK access_mask; enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 }; resolveLibs(); if ( ptrGetNamedSecurityInfoW && ptrAllocateAndInitializeSid && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW && ptrFreeSid ) { DWORD res = ptrGetNamedSecurityInfoW( (wchar_t*)fn.ucs2(), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, &pOwner, &pGroup, &pDacl, 0, &pSD ); if ( res == ERROR_SUCCESS ) { TRUSTEE_W trustee; if ( p & ( ReadUser | WriteUser | ExeUser) ) { if ( ptrGetEffectiveRightsFromAclW( pDacl, ¤tUserTrusteeW, &access_mask ) != ERROR_SUCCESS ) access_mask = (ACCESS_MASK)-1; if ( ( p & ReadUser ) && !( access_mask & ReadMask ) || ( p & WriteUser ) && !( access_mask & WriteMask ) || ( p & ExeUser ) && !( access_mask & ExecMask ) ) { LocalFree( pSD ); return FALSE; } } if ( p & ( ReadOwner | WriteOwner | ExeOwner) ) { ptrBuildTrusteeWithSidW( &trustee, pOwner ); if ( ptrGetEffectiveRightsFromAclW( pDacl, &trustee, &access_mask ) != ERROR_SUCCESS ) access_mask = (ACCESS_MASK)-1; if ( ( p & ReadOwner ) && !( access_mask & ReadMask ) || ( p & WriteOwner ) && !( access_mask & WriteMask ) || ( p & ExeOwner ) && !( access_mask & ExecMask ) ) { LocalFree( pSD ); return FALSE; } } if ( p & ( ReadGroup | WriteGroup | ExeGroup) ) { ptrBuildTrusteeWithSidW( &trustee, pGroup ); if ( ptrGetEffectiveRightsFromAclW( pDacl, &trustee, &access_mask ) != ERROR_SUCCESS ) access_mask = (ACCESS_MASK)-1; if ( ( p & ReadGroup ) && !( access_mask & ReadMask ) || ( p & WriteGroup ) && !( access_mask & WriteMask ) || ( p & ExeGroup ) && !( access_mask & ExecMask ) ) { LocalFree( pSD ); return FALSE; } } if ( p & ( ReadOther | WriteOther | ExeOther) ) { // Create SID for Everyone (World) SID_IDENTIFIER_AUTHORITY worldAuth = { SECURITY_WORLD_SID_AUTHORITY }; PSID pWorld = 0; if ( ptrAllocateAndInitializeSid( &worldAuth, 1, SECURITY_WORLD_RID, 0,0,0,0,0,0,0, &pWorld ) ) { ptrBuildTrusteeWithSidW( &trustee, pWorld ); if ( ptrGetEffectiveRightsFromAclW( pDacl, &trustee, &access_mask ) != ERROR_SUCCESS ) access_mask = (ACCESS_MASK)-1; // ### if ( ( p & ReadOther ) && !( access_mask & ReadMask ) || ( p & WriteOther ) && !( access_mask & WriteMask ) || ( p & ExeOther ) && !( access_mask & ExecMask ) ) { LocalFree( pSD ); return FALSE; } } ptrFreeSid( pWorld ); } LocalFree( pSD ); } } } // just check if it's ReadOnly QT_WA( { if ( p & ( WriteOwner | WriteUser | WriteGroup | WriteOther ) ) { DWORD attr = GetFileAttributes( (TCHAR*)fn.ucs2() ); if ( attr & FILE_ATTRIBUTE_READONLY ) return FALSE; } } , { if ( p & ( WriteOwner | WriteUser | WriteGroup | WriteOther ) ) { DWORD attr = GetFileAttributesA( fn.local8Bit() ); if ( attr & FILE_ATTRIBUTE_READONLY ) return FALSE; } } ); return TRUE;}void QFileInfo::doStat() const{ if ( fn.isEmpty() ) return; UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS); QFileInfo *that = ((QFileInfo*)this); // mutable function if ( !that->fic ) that->fic = new QFileInfoCache; QT_STATBUF *b = &that->fic->st; int r; QT_WA( { r = QT_TSTAT((TCHAR*)fn.ucs2(), (QT_STATBUF4TSTAT*)b); } , { r = QT_STAT(qt_win95Name(fn), b); } ); if ( r!=0 ) { bool is_dir=FALSE; if ( fn[0] == '/' && fn[1] == '/' || fn[0] == '\\' && fn[1] == '\\' ) { // UNC - stat doesn't work for all cases (Windows bug) int s = fn.find(fn[0],2); if ( s > 0 ) { // "\\server\..." s = fn.find(fn[0],s+1); if ( s > 0 ) { // "\\server\share\..." if ( fn[s+1] ) { // "\\server\share\notfound" } else { // "\\server\share\" is_dir=TRUE; } } else { // "\\server\share" is_dir=TRUE; } } else { // "\\server" is_dir=TRUE; } } if ( is_dir ) { // looks like a UNC dir, is a dir. memset(b,0,sizeof(*b)); b->st_mode = QT_STAT_DIR; b->st_nlink = 1; r = 0; } } if ( r != 0 ) { delete that->fic; that->fic = 0; } SetErrorMode(oldmode);}QString QFileInfo::dirPath( bool absPath ) const{ QString s; if ( absPath ) s = absFilePath(); else s = fn; int pos = s.findRev( '/' ); if ( pos == -1 ) { if ( s[ 2 ] == '/' ) return s.left( 3 ); if ( s[ 1 ] == ':' ) { if ( absPath ) return s.left( 2 ) + "/"; return s.left( 2 ); } return QString::fromLatin1("."); } else { if ( pos == 0 ) return QString::fromLatin1( "/" ); if ( pos == 2 && s[ 1 ] == ':' && s[ 2 ] == '/') pos++; return s.left( pos ); }}QString QFileInfo::fileName() const{ int p = fn.findRev( '/' ); if ( p == -1 ) { int p = fn.findRev( ':' ); if ( p != -1 ) return fn.mid( p + 1 ); return fn; } else { return fn.mid( p + 1 ); }}/*! Returns TRUE if the file is hidden; otherwise returns FALSE. On Unix-like operating systems, including Mac OS X, a file is hidden if its name begins with ".". On Windows a file is hidden if its hidden attribute is set.*/bool QFileInfo::isHidden() const{ QT_WA( { return GetFileAttributesW( (TCHAR*)fn.ucs2() ) & FILE_ATTRIBUTE_HIDDEN; } , { return GetFileAttributesA( fn.local8Bit() ) & FILE_ATTRIBUTE_HIDDEN; } );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -