1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_tools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifdef _MSC_VER 32*cdf0e10cSrcweir #pragma warning (push,1) 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include <stdio.h> 35*cdf0e10cSrcweir #include <ctype.h> 36*cdf0e10cSrcweir #include <limits.h> 37*cdf0e10cSrcweir #ifdef _MSC_VER 38*cdf0e10cSrcweir #pragma warning (pop) 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "wntmsc.hxx" 42*cdf0e10cSrcweir #include <tools/errinf.hxx> 43*cdf0e10cSrcweir #include <tools/debug.hxx> 44*cdf0e10cSrcweir #include <tools/list.hxx> 45*cdf0e10cSrcweir #include <tools/wldcrd.hxx> 46*cdf0e10cSrcweir #include <tools/fsys.hxx> 47*cdf0e10cSrcweir #include <tools/bigint.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir DECLARE_LIST( DirEntryList, DirEntry* ); 50*cdf0e10cSrcweir DECLARE_LIST( FSysSortList, FSysSort* ); 51*cdf0e10cSrcweir DECLARE_LIST( FileStatList, FileStat* ); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir int Sys2SolarError_Impl( int nSysErr ); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir static sal_Bool bLastCaseSensitive = sal_False; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //-------------------------------------------------------------------- 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir ByteString Upper_Impl( const ByteString &rStr ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir ByteString aRet( rStr.GetBuffer() ); // es muss ein neuer String entstehen! 62*cdf0e10cSrcweir CharUpperBuff( (char*) aRet.GetBuffer(), aRet.Len() ); 63*cdf0e10cSrcweir return aRet; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //-------------------------------------------------------------------- 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir DIR *opendir( const char* pPfad ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir DIR *pDir = new DIR; 71*cdf0e10cSrcweir if ( pDir ) 72*cdf0e10cSrcweir pDir->p = (char*) pPfad; 73*cdf0e10cSrcweir return pDir; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir struct dirent *readdir( DIR *pDir ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir bool bOk = false; 79*cdf0e10cSrcweir if ( pDir->p ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir char *pBuf = new char[ strlen( pDir->p ) + 5 ]; 82*cdf0e10cSrcweir if ( pBuf ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir // *.* dahinter, ggf mit "\\" abtrennen (falls nicht schon da) 85*cdf0e10cSrcweir strcpy( pBuf, pDir->p ); 86*cdf0e10cSrcweir strcat( pBuf, "\\*.*" + ( *(pBuf + strlen( pBuf ) - 1 ) == '\\' ) ); 87*cdf0e10cSrcweir CharUpperBuff( pBuf, strlen(pBuf) ); 88*cdf0e10cSrcweir pDir->h = FindFirstFile( pBuf, &pDir->aDirEnt ); 89*cdf0e10cSrcweir bOk = pDir->h != INVALID_HANDLE_VALUE; 90*cdf0e10cSrcweir pDir->p = NULL; 91*cdf0e10cSrcweir delete [] pBuf; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir else 94*cdf0e10cSrcweir pDir->h = INVALID_HANDLE_VALUE; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir else 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir bOk = FindNextFile( pDir->h, &pDir->aDirEnt ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return bOk ? &pDir->aDirEnt : NULL; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir int closedir( DIR *pDir ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir sal_Bool bOk = sal_False; 107*cdf0e10cSrcweir if ( pDir ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir bOk = 0 != pDir->p || FindClose( pDir->h ); 110*cdf0e10cSrcweir delete pDir; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir return bOk; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir /************************************************************************* 116*cdf0e10cSrcweir |* 117*cdf0e10cSrcweir |* DirEntry::GetPathStyle() const 118*cdf0e10cSrcweir |* 119*cdf0e10cSrcweir |* Beschreibung 120*cdf0e10cSrcweir |* Ersterstellung MI 11.05.95 121*cdf0e10cSrcweir |* Letzte Aenderung MI 11.05.95 122*cdf0e10cSrcweir |* 123*cdf0e10cSrcweir *************************************************************************/ 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir ErrCode GetPathStyle_Impl( const String &rDevice, FSysPathStyle &rStyle ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ByteString aRootDir(rDevice, osl_getThreadTextEncoding()); 128*cdf0e10cSrcweir if ( aRootDir.Len() && aRootDir.GetBuffer()[aRootDir.Len()-1] != '\\' ) 129*cdf0e10cSrcweir aRootDir += '\\'; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir char sVolumeName[256]; 132*cdf0e10cSrcweir char sFileSysName[16]; 133*cdf0e10cSrcweir DWORD nSerial[2]; 134*cdf0e10cSrcweir DWORD nMaxCompLen[2]; 135*cdf0e10cSrcweir DWORD nFlags[2]; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // Windows95 hat VFAT, WindowsNT nicht 138*cdf0e10cSrcweir DWORD nVer = GetVersion(); 139*cdf0e10cSrcweir sal_Bool bW95 = ( nVer & 0xFF ) >= 4; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir FSysFailOnErrorImpl(); 142*cdf0e10cSrcweir rStyle = FSYS_STYLE_UNKNOWN; 143*cdf0e10cSrcweir if ( GetVolumeInformation( 144*cdf0e10cSrcweir (char*) aRootDir.GetBuffer(), 145*cdf0e10cSrcweir sVolumeName, 256, (LPDWORD) &nSerial, (LPDWORD) &nMaxCompLen, 146*cdf0e10cSrcweir (LPDWORD) &nFlags, sFileSysName, 16 ) ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir // FAT/VFAT? 149*cdf0e10cSrcweir if ( 0 == strcmp( "FAT", sFileSysName ) ) 150*cdf0e10cSrcweir rStyle = bW95 ? FSYS_STYLE_VFAT : FSYS_STYLE_FAT; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // NTFS? 153*cdf0e10cSrcweir else if ( 0 == strcmp( "NTFS", sFileSysName ) ) 154*cdf0e10cSrcweir rStyle = FSYS_STYLE_NTFS; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // HPFS? 157*cdf0e10cSrcweir else if ( 0 == strcmp( "HPFS", sFileSysName ) ) 158*cdf0e10cSrcweir rStyle = FSYS_STYLE_HPFS; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // NWCOMPA/NWFS? 161*cdf0e10cSrcweir else if ( 0 == strncmp( "NW", sFileSysName, 2 ) ) 162*cdf0e10cSrcweir rStyle = FSYS_STYLE_NWFS; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir return ERRCODE_NONE; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir return ERRCODE_IO_INVALIDDEVICE; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir FSysPathStyle DirEntry::GetPathStyle( const String &rDevice ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir FSysPathStyle eStyle; 174*cdf0e10cSrcweir GetPathStyle_Impl( rDevice, eStyle ); 175*cdf0e10cSrcweir return eStyle; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir /************************************************************************* 179*cdf0e10cSrcweir |* 180*cdf0e10cSrcweir |* DirEntry::IsCaseSensitive() 181*cdf0e10cSrcweir |* 182*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 183*cdf0e10cSrcweir |* Ersterstellung MI 10.06.93 184*cdf0e10cSrcweir |* Letzte Aenderung TPF 26.02.1999 185*cdf0e10cSrcweir |* 186*cdf0e10cSrcweir *************************************************************************/ 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir sal_Bool DirEntry::IsCaseSensitive( FSysPathStyle eFormatter ) const 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir if (eFormatter==FSYS_STYLE_HOST) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir /* 194*cdf0e10cSrcweir DirEntry aRoot(*this); 195*cdf0e10cSrcweir aRoot.ToAbs(); 196*cdf0e10cSrcweir aRoot = aRoot[Level()-1]; 197*cdf0e10cSrcweir String aRootDir = aRoot.GetFull(FSYS_STYLE_HOST, sal_True); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir char sVolumeName[256]; 200*cdf0e10cSrcweir DWORD nVolumeSerial; 201*cdf0e10cSrcweir DWORD nMaxCompLen; 202*cdf0e10cSrcweir DWORD nFlags; 203*cdf0e10cSrcweir char sFileSysName[16]; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir if ( GetVolumeInformation( (char*) aRootDir.GetStr(), 206*cdf0e10cSrcweir sVolumeName, 207*cdf0e10cSrcweir 256, 208*cdf0e10cSrcweir (LPDWORD) &nVolumeSerial, 209*cdf0e10cSrcweir (LPDWORD) &nMaxCompLen, 210*cdf0e10cSrcweir (LPDWORD) &nFlags, 211*cdf0e10cSrcweir sFileSysName, 212*cdf0e10cSrcweir 16 )) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir return (nFlags & FS_CASE_SENSITIVE) ? sal_True : sal_False; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir else 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir return sal_False; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir */ 221*cdf0e10cSrcweir // 222*cdf0e10cSrcweir // guter versuch, aber FS_CASE_SENSITIVE ist D?nnsinn in T?ten: 223*cdf0e10cSrcweir // 224*cdf0e10cSrcweir // sFileSysName FS_CASE_SENSITIVE 225*cdf0e10cSrcweir // FAT sal_False 226*cdf0e10cSrcweir // NTFS sal_True !!! 227*cdf0e10cSrcweir // NWCompat sal_False 228*cdf0e10cSrcweir // Samba sal_False 229*cdf0e10cSrcweir // 230*cdf0e10cSrcweir // NT spricht auch NTFS lediglich case preserving an, also ist unter NT alles case insensitiv 231*cdf0e10cSrcweir // 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir return sal_False; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir else 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir sal_Bool isCaseSensitive = sal_False; // ich bin unter win32, also ist der default case insensitiv 238*cdf0e10cSrcweir switch ( eFormatter ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir case FSYS_STYLE_MAC: 241*cdf0e10cSrcweir case FSYS_STYLE_FAT: 242*cdf0e10cSrcweir case FSYS_STYLE_VFAT: 243*cdf0e10cSrcweir case FSYS_STYLE_NTFS: 244*cdf0e10cSrcweir case FSYS_STYLE_NWFS: 245*cdf0e10cSrcweir case FSYS_STYLE_HPFS: 246*cdf0e10cSrcweir case FSYS_STYLE_DETECT: 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir isCaseSensitive = sal_False; 249*cdf0e10cSrcweir break; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir case FSYS_STYLE_SYSV: 252*cdf0e10cSrcweir case FSYS_STYLE_BSD: 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir isCaseSensitive = sal_True; 255*cdf0e10cSrcweir break; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir default: 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir isCaseSensitive = sal_False; // ich bin unter win32, also ist der default case insensitiv 260*cdf0e10cSrcweir break; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir return isCaseSensitive; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir /************************************************************************* 268*cdf0e10cSrcweir |* 269*cdf0e10cSrcweir |* DirEntry::ToAbs() 270*cdf0e10cSrcweir |* 271*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 272*cdf0e10cSrcweir |* Ersterstellung MI 26.04.91 273*cdf0e10cSrcweir |* Letzte Aenderung MA 02.12.91 274*cdf0e10cSrcweir |* 275*cdf0e10cSrcweir *************************************************************************/ 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir sal_Bool DirEntry::ToAbs() 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir if ( FSYS_FLAG_VOLUME == eFlag ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir eFlag = FSYS_FLAG_ABSROOT; 284*cdf0e10cSrcweir return sal_True; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir if ( IsAbs() ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir return sal_True; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir char sBuf[256]; 294*cdf0e10cSrcweir char *pOld; 295*cdf0e10cSrcweir ByteString aFullName( GetFull(), osl_getThreadTextEncoding() ); 296*cdf0e10cSrcweir FSysFailOnErrorImpl(); 297*cdf0e10cSrcweir if ( GetFullPathName((char*)aFullName.GetBuffer(),256,sBuf,&pOld) > 511 ) 298*cdf0e10cSrcweir return sal_False; 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir *this = DirEntry( String(sBuf, osl_getThreadTextEncoding() )); 301*cdf0e10cSrcweir return sal_True; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir /************************************************************************* 306*cdf0e10cSrcweir |* 307*cdf0e10cSrcweir |* DirEntry::GetVolume() 308*cdf0e10cSrcweir |* 309*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 310*cdf0e10cSrcweir |* Ersterstellung MI 27.08.92 311*cdf0e10cSrcweir |* Letzte Aenderung MI 28.08.92 312*cdf0e10cSrcweir |* 313*cdf0e10cSrcweir *************************************************************************/ 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir String DirEntry::GetVolume() const 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir String aRet; 320*cdf0e10cSrcweir const DirEntry *pTop = ImpGetTopPtr(); 321*cdf0e10cSrcweir ByteString aName = ByteString( pTop->aName ).ToLowerAscii(); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir if ( ( pTop->eFlag == FSYS_FLAG_ABSROOT || 324*cdf0e10cSrcweir pTop->eFlag == FSYS_FLAG_RELROOT || 325*cdf0e10cSrcweir pTop->eFlag == FSYS_FLAG_VOLUME ) 326*cdf0e10cSrcweir && aName != "a:" && aName != "b:" && Exists() ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir char sFileSysName[256]; 329*cdf0e10cSrcweir char sVolumeName[256]; 330*cdf0e10cSrcweir DWORD nVolumeNameLen = 256; 331*cdf0e10cSrcweir DWORD nSerial[2]; 332*cdf0e10cSrcweir DWORD nMaxCompLen[2]; 333*cdf0e10cSrcweir DWORD nFlags[2]; 334*cdf0e10cSrcweir ByteString aRootDir = pTop->aName; 335*cdf0e10cSrcweir FSysFailOnErrorImpl(); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // Network-Device zuerst probieren wegen langsamer Samba-Drives 338*cdf0e10cSrcweir if ( !WNetGetConnection( (char*) aRootDir.GetBuffer(), 339*cdf0e10cSrcweir sVolumeName, &nVolumeNameLen ) ) 340*cdf0e10cSrcweir aRet = String( sVolumeName, osl_getThreadTextEncoding()); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir // dann den VolumeNamen fuer lokale Drives 343*cdf0e10cSrcweir if ( aRet.Len() == 0 ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir aRootDir += "\\"; 346*cdf0e10cSrcweir if ( GetVolumeInformation( (char*) aRootDir.GetBuffer(), 347*cdf0e10cSrcweir sVolumeName, 256, 348*cdf0e10cSrcweir (LPDWORD) &nSerial, (LPDWORD) &nMaxCompLen, 349*cdf0e10cSrcweir (LPDWORD) &nFlags, sFileSysName, 256 ) ) 350*cdf0e10cSrcweir aRet = String( sVolumeName, osl_getThreadTextEncoding()); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir return aRet; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir /************************************************************************* 358*cdf0e10cSrcweir |* 359*cdf0e10cSrcweir |* DirEntry::SetCWD() 360*cdf0e10cSrcweir |* 361*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 362*cdf0e10cSrcweir |* Ersterstellung MI 26.04.91 363*cdf0e10cSrcweir |* Letzte Aenderung MI 21.05.92 364*cdf0e10cSrcweir |* 365*cdf0e10cSrcweir *************************************************************************/ 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir sal_Bool DirEntry::SetCWD( sal_Bool bSloppy ) const 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir FSysFailOnErrorImpl(); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir if ( eFlag == FSYS_FLAG_CURRENT && !aName.Len() ) 374*cdf0e10cSrcweir return sal_True; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir if ( SetCurrentDirectory(ByteString(GetFull(), osl_getThreadTextEncoding()).GetBuffer()) ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir return sal_True; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir if ( bSloppy && pParent && 382*cdf0e10cSrcweir SetCurrentDirectory(ByteString(pParent->GetFull(), osl_getThreadTextEncoding()).GetBuffer()) ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir return sal_True; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir return sal_False; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir //------------------------------------------------------------------------- 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir USHORT DirReader_Impl::Init() 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir // Block-Devices auflisten? 395*cdf0e10cSrcweir if ( pDir->eAttrMask & FSYS_KIND_BLOCK ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir // CWD merken 398*cdf0e10cSrcweir DirEntry aCurrentDir; 399*cdf0e10cSrcweir aCurrentDir.ToAbs(); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // einzeln auf Existenz und Masken-konformit"at pr"ufen 402*cdf0e10cSrcweir USHORT nRead = 0; 403*cdf0e10cSrcweir char sDrive[3] = { '?', ':', 0 }; 404*cdf0e10cSrcweir char sRoot[4] = { '?', ':', '\\', 0 }; 405*cdf0e10cSrcweir for ( char c = 'a'; c <= 'z'; c++ ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir sDrive[0] = c; 408*cdf0e10cSrcweir sRoot[0] = c; 409*cdf0e10cSrcweir DirEntry* pDrive = new DirEntry( sDrive, FSYS_FLAG_VOLUME, FSYS_STYLE_HOST ); 410*cdf0e10cSrcweir if ( pDir->aNameMask.Matches( String( ByteString(sDrive), osl_getThreadTextEncoding())) && GetDriveType( sRoot ) != 1 ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir if ( pDir->pStatLst ) //Status fuer Sort gewuenscht? 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir FileStat *pNewStat = new FileStat( *pDrive ); 415*cdf0e10cSrcweir pDir->ImpSortedInsert( pDrive, pNewStat ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir else 418*cdf0e10cSrcweir pDir->ImpSortedInsert( pDrive, NULL ); 419*cdf0e10cSrcweir ++nRead; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir else 422*cdf0e10cSrcweir delete pDrive; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir // CWD restaurieren 426*cdf0e10cSrcweir aCurrentDir.SetCWD(); 427*cdf0e10cSrcweir return nRead; 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir return 0; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir //------------------------------------------------------------------------- 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir USHORT DirReader_Impl::Read() 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir // Directories und Files auflisten? 438*cdf0e10cSrcweir if ( ( pDir->eAttrMask & FSYS_KIND_DIR || 439*cdf0e10cSrcweir pDir->eAttrMask & FSYS_KIND_FILE ) && 440*cdf0e10cSrcweir ( ( pDosEntry = readdir( pDosDir ) ) != NULL ) ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir // Gross/Kleinschreibung nicht beruecksichtigen 443*cdf0e10cSrcweir ByteString aLowerName = pDosEntry->d_name; 444*cdf0e10cSrcweir CharLowerBuff( (char*) aLowerName.GetBuffer(), aLowerName.Len() ); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // Flags pruefen 447*cdf0e10cSrcweir sal_Bool bIsDirAndWantsDir = 448*cdf0e10cSrcweir ( ( pDir->eAttrMask & FSYS_KIND_DIR ) && 449*cdf0e10cSrcweir #ifdef ICC 450*cdf0e10cSrcweir ( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") || 451*cdf0e10cSrcweir strcmp(pDosEntry->d_name,"..")) ) ); 452*cdf0e10cSrcweir #else 453*cdf0e10cSrcweir ( pDosEntry->d_type & DOS_DIRECT ) ); 454*cdf0e10cSrcweir #endif 455*cdf0e10cSrcweir sal_Bool bIsFileAndWantsFile = 456*cdf0e10cSrcweir ( ( pDir->eAttrMask & FSYS_KIND_FILE ) && 457*cdf0e10cSrcweir #ifdef ICC 458*cdf0e10cSrcweir !( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") || 459*cdf0e10cSrcweir strcmp(pDosEntry->d_name,"..")) ) && 460*cdf0e10cSrcweir #else 461*cdf0e10cSrcweir !( pDosEntry->d_type & DOS_DIRECT ) && 462*cdf0e10cSrcweir #endif 463*cdf0e10cSrcweir !( pDosEntry->d_type & DOS_VOLUMEID ) ); 464*cdf0e10cSrcweir sal_Bool bIsHidden = (pDosEntry->d_type & _A_HIDDEN) != 0; 465*cdf0e10cSrcweir sal_Bool bWantsHidden = 0 == ( pDir->eAttrMask & FSYS_KIND_VISIBLE ); 466*cdf0e10cSrcweir if ( ( bIsDirAndWantsDir || bIsFileAndWantsFile ) && 467*cdf0e10cSrcweir ( bWantsHidden || !bIsHidden ) && 468*cdf0e10cSrcweir pDir->aNameMask.Matches( String(aLowerName, osl_getThreadTextEncoding()) ) ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir #ifdef DBG_UTIL 471*cdf0e10cSrcweir DbgOutf( "%s %s flags:%x found", 472*cdf0e10cSrcweir pDosEntry->d_name, 473*cdf0e10cSrcweir bIsFileAndWantsFile ? "file" : "dir", 474*cdf0e10cSrcweir pDosEntry->d_type ); 475*cdf0e10cSrcweir #endif 476*cdf0e10cSrcweir DirEntryFlag eFlag = 477*cdf0e10cSrcweir 0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT 478*cdf0e10cSrcweir : 0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT 479*cdf0e10cSrcweir : FSYS_FLAG_NORMAL; 480*cdf0e10cSrcweir DirEntry *pTemp = new DirEntry( ByteString(pDosEntry->d_name), 481*cdf0e10cSrcweir eFlag, FSYS_STYLE_NTFS ); 482*cdf0e10cSrcweir #ifdef FEAT_FSYS_DOUBLESPEED 483*cdf0e10cSrcweir pTemp->ImpSetStat( new FileStat( (void*) pDosDir, (void*) 0 ) ); 484*cdf0e10cSrcweir #endif 485*cdf0e10cSrcweir if ( pParent ) 486*cdf0e10cSrcweir pTemp->ImpChangeParent( new DirEntry( *pParent ), sal_False ); 487*cdf0e10cSrcweir if ( pDir->pStatLst ) //Status fuer Sort gewuenscht? 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir FileStat *pNewStat = new FileStat( (void*) pDosDir, (void*) 0 ); 490*cdf0e10cSrcweir pDir->ImpSortedInsert( pTemp, pNewStat ); 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir else 493*cdf0e10cSrcweir pDir->ImpSortedInsert( pTemp, NULL ); 494*cdf0e10cSrcweir return 1; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir #ifdef DBG_UTIL 497*cdf0e10cSrcweir else 498*cdf0e10cSrcweir DbgOutf( "%s flags:%x skipped", 499*cdf0e10cSrcweir pDosEntry->d_name, 500*cdf0e10cSrcweir pDosEntry->d_type ); 501*cdf0e10cSrcweir #endif 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir else 505*cdf0e10cSrcweir bReady = sal_True; 506*cdf0e10cSrcweir return 0; 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir /************************************************************************* 510*cdf0e10cSrcweir |* 511*cdf0e10cSrcweir |* InitFileStat() 512*cdf0e10cSrcweir |* 513*cdf0e10cSrcweir |* Beschreibung gemeinsamer Teil der Ctoren fuer FileStat 514*cdf0e10cSrcweir |* Ersterstellung MI 28.08.92 515*cdf0e10cSrcweir |* Letzte Aenderung MI 28.08.92 516*cdf0e10cSrcweir |* 517*cdf0e10cSrcweir *************************************************************************/ 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir void FileStat::ImpInit( void* p ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir _WIN32_FIND_DATAA *pDirEnt = (_WIN32_FIND_DATAA*) p; 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir nError = FSYS_ERR_OK; 524*cdf0e10cSrcweir nSize = pDirEnt->nFileSizeLow; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir SYSTEMTIME aSysTime; 527*cdf0e10cSrcweir FILETIME aLocTime; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir // use the last write date / time when the creation date / time isn't set 530*cdf0e10cSrcweir if ( ( pDirEnt->ftCreationTime.dwLowDateTime == 0 ) && 531*cdf0e10cSrcweir ( pDirEnt->ftCreationTime.dwHighDateTime == 0 ) ) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir pDirEnt->ftCreationTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime; 534*cdf0e10cSrcweir pDirEnt->ftCreationTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime; 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir // use the last write date / time when the last accessed date / time isn't set 538*cdf0e10cSrcweir if ( ( pDirEnt->ftLastAccessTime.dwLowDateTime == 0 ) && 539*cdf0e10cSrcweir ( pDirEnt->ftLastAccessTime.dwHighDateTime == 0 ) ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir pDirEnt->ftLastAccessTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime; 542*cdf0e10cSrcweir pDirEnt->ftLastAccessTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime; 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir FileTimeToLocalFileTime( &pDirEnt->ftCreationTime, &aLocTime ); 546*cdf0e10cSrcweir FileTimeToSystemTime( &aLocTime, &aSysTime ); 547*cdf0e10cSrcweir aDateCreated = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); 548*cdf0e10cSrcweir aTimeCreated = Time( aSysTime.wHour, aSysTime.wMinute, 549*cdf0e10cSrcweir aSysTime.wSecond, 0 ); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir FileTimeToLocalFileTime( &pDirEnt->ftLastWriteTime, &aLocTime ); 552*cdf0e10cSrcweir FileTimeToSystemTime( &aLocTime, &aSysTime ); 553*cdf0e10cSrcweir aDateModified = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); 554*cdf0e10cSrcweir aTimeModified = Time( aSysTime.wHour, aSysTime.wMinute, 555*cdf0e10cSrcweir aSysTime.wSecond, 0 ); 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir FileTimeToLocalFileTime( &pDirEnt->ftLastAccessTime, &aLocTime ); 558*cdf0e10cSrcweir FileTimeToSystemTime( &aLocTime, &aSysTime ); 559*cdf0e10cSrcweir aDateAccessed = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); 560*cdf0e10cSrcweir aTimeAccessed = Time( aSysTime.wHour, aSysTime.wMinute, 561*cdf0e10cSrcweir aSysTime.wSecond, 0 ); 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir nKindFlags = FSYS_KIND_FILE; 564*cdf0e10cSrcweir if ( pDirEnt->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) 565*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DIR; 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir /************************************************************************* 569*cdf0e10cSrcweir |* 570*cdf0e10cSrcweir |* FileStat::FileStat() 571*cdf0e10cSrcweir |* 572*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 573*cdf0e10cSrcweir |* Ersterstellung MI 27.08.92 574*cdf0e10cSrcweir |* Letzte Aenderung MI 28.08.92 575*cdf0e10cSrcweir |* 576*cdf0e10cSrcweir *************************************************************************/ 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir FileStat::FileStat( const void *pInfo, // struct dirent 579*cdf0e10cSrcweir const void * ): // dummy 580*cdf0e10cSrcweir aDateCreated(0), 581*cdf0e10cSrcweir aTimeCreated(0), 582*cdf0e10cSrcweir aDateModified(0), 583*cdf0e10cSrcweir aTimeModified(0), 584*cdf0e10cSrcweir aDateAccessed(0), 585*cdf0e10cSrcweir aTimeAccessed(0) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir ImpInit( ( (dirent*) pInfo ) ); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir /************************************************************************* 591*cdf0e10cSrcweir |* 592*cdf0e10cSrcweir |* FileStat::Update() 593*cdf0e10cSrcweir |* 594*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 595*cdf0e10cSrcweir |* Ersterstellung MI 27.08.92 596*cdf0e10cSrcweir |* Letzte Aenderung MI 28.08.92 597*cdf0e10cSrcweir |* 598*cdf0e10cSrcweir *************************************************************************/ 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir #ifdef _MSC_VER 601*cdf0e10cSrcweir #pragma warning(push, 1) 602*cdf0e10cSrcweir #pragma warning(disable: 4917) 603*cdf0e10cSrcweir #endif 604*cdf0e10cSrcweir #include <shlobj.h> 605*cdf0e10cSrcweir #ifdef _MSC_VER 606*cdf0e10cSrcweir #pragma warning(pop) 607*cdf0e10cSrcweir #endif 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir #ifdef UNICODE 610*cdf0e10cSrcweir #define lstrchr wcschr 611*cdf0e10cSrcweir #define lstrncmp wcsncmp 612*cdf0e10cSrcweir #else 613*cdf0e10cSrcweir #define lstrchr strchr 614*cdf0e10cSrcweir #define lstrncmp strncmp 615*cdf0e10cSrcweir #endif 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir //--------------------------------------------------------------------------- 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir void SHFreeMem( void *p ) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir LPMALLOC pMalloc = NULL; 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir if ( SUCCEEDED(SHGetMalloc(&pMalloc)) ) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir pMalloc->Free( p ); 626*cdf0e10cSrcweir pMalloc->Release(); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir //--------------------------------------------------------------------------- 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir HRESULT SHGetIDListFromPath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl ) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir if ( IsBadWritePtr(ppidl, sizeof(LPITEMIDLIST)) ) 635*cdf0e10cSrcweir return E_INVALIDARG; 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir LPSHELLFOLDER pDesktopFolder = NULL; 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder ); 640*cdf0e10cSrcweir if ( FAILED(hResult) ) 641*cdf0e10cSrcweir return hResult; 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir ULONG chEaten = lstrlen( pszPath ); 644*cdf0e10cSrcweir DWORD dwAttributes = FILE_ATTRIBUTE_DIRECTORY; 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir #ifdef UNICODE 647*cdf0e10cSrcweir LPOLESTR wszPath = pszPath; 648*cdf0e10cSrcweir #else 649*cdf0e10cSrcweir WCHAR wszPath[MAX_PATH]; 650*cdf0e10cSrcweir MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszPath, -1, wszPath, MAX_PATH ); 651*cdf0e10cSrcweir #endif 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir hResult = pDesktopFolder->ParseDisplayName( hwndOwner, (LPBC)NULL, wszPath, &chEaten, ppidl, &dwAttributes ); 654*cdf0e10cSrcweir pDesktopFolder->Release(); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir return hResult; 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir //--------------------------------------------------------------------------- 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir HRESULT SHGetFolderFromIDList( LPCITEMIDLIST pidl, LPSHELLFOLDER *ppFolder ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir if ( IsBadWritePtr(ppFolder, sizeof(LPSHELLFOLDER)) ) 664*cdf0e10cSrcweir return E_INVALIDARG; 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir *ppFolder = NULL; 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir LPSHELLFOLDER pDesktopFolder = NULL; 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder ); 671*cdf0e10cSrcweir if ( FAILED(hResult) ) 672*cdf0e10cSrcweir return hResult; 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir hResult = pDesktopFolder->BindToObject( pidl, (LPBC)NULL, IID_IShellFolder, (LPVOID *)ppFolder ); 675*cdf0e10cSrcweir pDesktopFolder->Release(); 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir return hResult; 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir //--------------------------------------------------------------------------- 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir HRESULT SHResolvePath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir // If hwndOwner is NULL, use the desktop window, because dialogs need a parent 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir #ifdef BOOTSTRAP 687*cdf0e10cSrcweir return NO_ERROR; 688*cdf0e10cSrcweir #else 689*cdf0e10cSrcweir if ( !hwndOwner ) 690*cdf0e10cSrcweir hwndOwner = GetDesktopWindow(); 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir HRESULT hResult = NOERROR; 693*cdf0e10cSrcweir LPTSTR pszPathCopy; 694*cdf0e10cSrcweir LPTSTR pszTrailingPath; 695*cdf0e10cSrcweir TCHAR cBackup = 0; 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir // First make a copy of the path 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir pszPathCopy = new TCHAR[lstrlen(pszPath) + 1]; 700*cdf0e10cSrcweir if ( pszPathCopy ) 701*cdf0e10cSrcweir lstrcpy( pszPathCopy, pszPath ); 702*cdf0e10cSrcweir else 703*cdf0e10cSrcweir return E_OUTOFMEMORY; 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir // Determine the first token 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir if ( !lstrncmp( pszPathCopy, "\\\\", 2 ) ) 708*cdf0e10cSrcweir pszTrailingPath = lstrchr( pszPathCopy + 2, '\\' ); 709*cdf0e10cSrcweir else 710*cdf0e10cSrcweir pszTrailingPath = lstrchr( pszPathCopy, '\\' ); 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir // Now scan the path tokens 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir while ( SUCCEEDED(hResult) ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir if ( pszTrailingPath ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir cBackup = *(++pszTrailingPath); 719*cdf0e10cSrcweir *pszTrailingPath = 0; 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir LPITEMIDLIST pidl = NULL; 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir // Make item ID list from leading path 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir hResult = SHGetIDListFromPath( hwndOwner, pszPathCopy, &pidl ); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir // if path exists try to open it as folder 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir // Only open the folder if it was not the last token 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir if ( pszTrailingPath ) 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir LPSHELLFOLDER pFolder; 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir // Create a folder instance 739*cdf0e10cSrcweir hResult = SHGetFolderFromIDList( pidl, &pFolder); 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir // Is it a folder ? 742*cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir // No try to instantiate an enumerator. 745*cdf0e10cSrcweir // This should popup a login dialog if any 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir LPENUMIDLIST pEnum = NULL; 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir hResult = pFolder->EnumObjects( hwndOwner, 750*cdf0e10cSrcweir SHCONTF_NONFOLDERS | SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, 751*cdf0e10cSrcweir &pEnum ); 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir // Release the enumerator interface 754*cdf0e10cSrcweir if ( SUCCEEDED(hResult) ) 755*cdf0e10cSrcweir pEnum->Release(); 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir // Release the folder interface 758*cdf0e10cSrcweir pFolder->Release(); 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir SHFreeMem( pidl ); 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir else // It was the last token 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir if ( ppidl ) 766*cdf0e10cSrcweir *ppidl = pidl; 767*cdf0e10cSrcweir else 768*cdf0e10cSrcweir SHFreeMem( pidl ); 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir // Forward to next token 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir if ( pszTrailingPath ) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir *pszTrailingPath = cBackup; 778*cdf0e10cSrcweir pszTrailingPath = lstrchr( pszTrailingPath, '\\' ); 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir else 781*cdf0e10cSrcweir break; 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir // Free the working copy of the path 785*cdf0e10cSrcweir delete pszPathCopy; 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir // NOERROR or OLE error code 788*cdf0e10cSrcweir return hResult; 789*cdf0e10cSrcweir #endif 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir //--------------------------------------------------------------------------- 793*cdf0e10cSrcweir // The Wrapper 794*cdf0e10cSrcweir //--------------------------------------------------------------------------- 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir sal_Bool Exists_Impl( const ByteString & crPath ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir // We do not know if OLE was initialized for this thread 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir CoInitialize( NULL ); 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir sal_Bool bSuccess = SUCCEEDED( SHResolvePath(NULL, crPath.GetBuffer(), NULL) ); 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir CoUninitialize(); 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir return bSuccess; 807*cdf0e10cSrcweir } 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir //--------------------------------------------------------------------------- 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir sal_Bool FileStat::Update( const DirEntry& rDirEntry, sal_Bool bForceAccess ) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir nSize = 0; 814*cdf0e10cSrcweir nKindFlags = 0; 815*cdf0e10cSrcweir aCreator.Erase(); 816*cdf0e10cSrcweir aType.Erase(); 817*cdf0e10cSrcweir aDateCreated = Date(0); 818*cdf0e10cSrcweir aTimeCreated = Time(0); 819*cdf0e10cSrcweir aDateModified = Date(0); 820*cdf0e10cSrcweir aTimeModified = Time(0); 821*cdf0e10cSrcweir aDateAccessed = Date(0); 822*cdf0e10cSrcweir aTimeAccessed = Time(0); 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir if ( !rDirEntry.IsValid() ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir nError = FSYS_ERR_UNKNOWN; 827*cdf0e10cSrcweir nKindFlags = 0; 828*cdf0e10cSrcweir return sal_False; 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir // Sonderbehandlung falls es sich um eine Root ohne Laufwerk handelt 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir if ( !rDirEntry.aName.Len() && rDirEntry.eFlag == FSYS_FLAG_ABSROOT ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DIR; 836*cdf0e10cSrcweir nError = FSYS_ERR_OK; 837*cdf0e10cSrcweir return sal_True; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir // keine Error-Boxen anzeigen 841*cdf0e10cSrcweir FSysFailOnErrorImpl(); 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir // Redirect 844*cdf0e10cSrcweir String aPath( rDirEntry.GetFull() ); 845*cdf0e10cSrcweir #ifndef BOOTSTRAP 846*cdf0e10cSrcweir FSysRedirector::DoRedirect( aPath ); 847*cdf0e10cSrcweir #endif 848*cdf0e10cSrcweir DirEntry aDirEntry( aPath ); 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir // ist ein Medium im Laufwerk? 851*cdf0e10cSrcweir HACK("wie?") 852*cdf0e10cSrcweir sal_Bool bAccess = sal_True; 853*cdf0e10cSrcweir const DirEntry *pTop = aDirEntry.ImpGetTopPtr(); 854*cdf0e10cSrcweir ByteString aName = ByteString(pTop->aName).ToLowerAscii(); 855*cdf0e10cSrcweir if ( !bForceAccess && 856*cdf0e10cSrcweir ( pTop->eFlag == FSYS_FLAG_ABSROOT || 857*cdf0e10cSrcweir pTop->eFlag == FSYS_FLAG_RELROOT || 858*cdf0e10cSrcweir pTop->eFlag == FSYS_FLAG_VOLUME ) ) 859*cdf0e10cSrcweir if ( aName == "a:" || aName == "b:" ) 860*cdf0e10cSrcweir bAccess = sal_False; 861*cdf0e10cSrcweir else 862*cdf0e10cSrcweir DBG_TRACE( "FSys: will access removable device!" ); 863*cdf0e10cSrcweir if ( bAccess && ( aName == "a:" || aName == "b:" ) ) { 864*cdf0e10cSrcweir DBG_WARNING( "floppy will clatter" ); 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir // Sonderbehandlung, falls es sich um ein Volume handelt 868*cdf0e10cSrcweir if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME || 869*cdf0e10cSrcweir aDirEntry.eFlag == FSYS_FLAG_ABSROOT ) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) 872*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DEV | ( aDirEntry.aName.Len() == 2 873*cdf0e10cSrcweir ? FSYS_KIND_BLOCK 874*cdf0e10cSrcweir : FSYS_KIND_CHAR ); 875*cdf0e10cSrcweir else 876*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DIR; 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir if ( !bAccess ) 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) 881*cdf0e10cSrcweir nKindFlags |= FSYS_KIND_REMOVEABLE; 882*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 883*cdf0e10cSrcweir nKindFlags = 0; 884*cdf0e10cSrcweir return sal_False; 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir ByteString aRootDir = aDirEntry.aName; 888*cdf0e10cSrcweir aRootDir += ByteString( "\\" ); 889*cdf0e10cSrcweir UINT nType = GetDriveType( (char *) aRootDir.GetBuffer() ); //TPF: 2i 890*cdf0e10cSrcweir if ( nType == 1 || nType == 0 ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 893*cdf0e10cSrcweir nKindFlags = 0; 894*cdf0e10cSrcweir return sal_False; 895*cdf0e10cSrcweir } 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) 898*cdf0e10cSrcweir nKindFlags = nKindFlags | 899*cdf0e10cSrcweir ( ( nType == DRIVE_REMOVABLE ) ? FSYS_KIND_REMOVEABLE : 0 ) | 900*cdf0e10cSrcweir ( ( nType == DRIVE_FIXED ) ? FSYS_KIND_FIXED : 0 ) | 901*cdf0e10cSrcweir ( ( nType == DRIVE_REMOTE ) ? FSYS_KIND_REMOTE : 0 ) | 902*cdf0e10cSrcweir ( ( nType == DRIVE_RAMDISK ) ? FSYS_KIND_RAM : 0 ) | 903*cdf0e10cSrcweir ( ( nType == DRIVE_CDROM ) ? FSYS_KIND_CDROM : 0 ) | 904*cdf0e10cSrcweir ( ( nType == 0 ) ? FSYS_KIND_UNKNOWN : 0 ); 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir nError = ERRCODE_NONE; 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir return sal_True; 909*cdf0e10cSrcweir } 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir // Statusinformation vom Betriebssystem holen 912*cdf0e10cSrcweir HANDLE h; //() 913*cdf0e10cSrcweir _WIN32_FIND_DATAA aEntry = {}; 914*cdf0e10cSrcweir DirEntry aAbsEntry( aDirEntry ); 915*cdf0e10cSrcweir if ( bAccess && aAbsEntry.ToAbs() ) 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir // im Namen k"onnen auch ';*?' als normale Zeichen vorkommen 918*cdf0e10cSrcweir ByteString aFilePath( aAbsEntry.GetFull(), osl_getThreadTextEncoding() ); 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir // MI: dann gehen Umlaute auf Novell-Servern nicht / wozu ueberhaupt 921*cdf0e10cSrcweir // CharUpperBuff( (char*) aFilePath.GetStr(), aFilePath.Len() ); 922*cdf0e10cSrcweir DBG_TRACE1( "FileStat: %s", aFilePath.GetBuffer() ); 923*cdf0e10cSrcweir h = aFilePath.Len() < 230 924*cdf0e10cSrcweir // die Win32-API ist hier sehr schwammig 925*cdf0e10cSrcweir ? FindFirstFile( (char *) aFilePath.GetBuffer(), &aEntry )//TPF: 2i 926*cdf0e10cSrcweir : INVALID_HANDLE_VALUE; 927*cdf0e10cSrcweir 928*cdf0e10cSrcweir if ( INVALID_HANDLE_VALUE != h ) 929*cdf0e10cSrcweir { 930*cdf0e10cSrcweir if ( !( aEntry.dwFileAttributes & 0x40 ) ) // com1: etc. e.g. not encrypted (means normal) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir ByteString aUpperName = Upper_Impl(ByteString(aAbsEntry.GetName(), osl_getThreadTextEncoding())); 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir // HRO: #74051# Compare also with short alternate filename 935*cdf0e10cSrcweir if ( aUpperName != Upper_Impl( aEntry.cFileName ) && aUpperName != Upper_Impl( aEntry.cAlternateFileName ) ) 936*cdf0e10cSrcweir h = INVALID_HANDLE_VALUE; 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir } 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir if ( INVALID_HANDLE_VALUE == h ) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir DWORD dwError = GetLastError(); 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir if ( ERROR_BAD_NET_NAME == dwError ) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir nKindFlags = FSYS_KIND_UNKNOWN; 947*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 948*cdf0e10cSrcweir return sal_False; 949*cdf0e10cSrcweir } 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir // UNC-Volume? 952*cdf0e10cSrcweir DirEntry *pTop = aAbsEntry.ImpGetTopPtr(); 953*cdf0e10cSrcweir if ( pTop->GetFlag() == FSYS_FLAG_ABSROOT && 954*cdf0e10cSrcweir ( pTop->aName.Len() > 1 && (pTop->aName.GetBuffer()[1] != ':' )) ) 955*cdf0e10cSrcweir { 956*cdf0e10cSrcweir if ( bForceAccess ) 957*cdf0e10cSrcweir { 958*cdf0e10cSrcweir if ( Exists_Impl( aFilePath ) ) 959*cdf0e10cSrcweir { 960*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DIR|FSYS_KIND_REMOTE; 961*cdf0e10cSrcweir nError = FSYS_ERR_OK; 962*cdf0e10cSrcweir return sal_True; 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir else 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir nKindFlags = FSYS_KIND_UNKNOWN; 967*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 968*cdf0e10cSrcweir return sal_False; 969*cdf0e10cSrcweir } 970*cdf0e10cSrcweir } 971*cdf0e10cSrcweir } 972*cdf0e10cSrcweir } 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir else 975*cdf0e10cSrcweir h = INVALID_HANDLE_VALUE; 976*cdf0e10cSrcweir 977*cdf0e10cSrcweir if ( h == INVALID_HANDLE_VALUE ) 978*cdf0e10cSrcweir { 979*cdf0e10cSrcweir // Sonderbehandlung falls es sich um eine Wildcard handelt 980*cdf0e10cSrcweir ByteString aTempName( aDirEntry.GetName(), osl_getThreadTextEncoding() ); 981*cdf0e10cSrcweir if ( strchr( aTempName.GetBuffer(), '?' ) || 982*cdf0e10cSrcweir strchr( aTempName.GetBuffer(), '*' ) || 983*cdf0e10cSrcweir strchr( aTempName.GetBuffer(), ';' ) ) 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir nKindFlags = FSYS_KIND_WILD; 986*cdf0e10cSrcweir nError = FSYS_ERR_OK; 987*cdf0e10cSrcweir return sal_True; 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir 990*cdf0e10cSrcweir if ( bAccess ) 991*cdf0e10cSrcweir { 992*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 993*cdf0e10cSrcweir nKindFlags = FSYS_KIND_UNKNOWN; 994*cdf0e10cSrcweir } 995*cdf0e10cSrcweir else 996*cdf0e10cSrcweir nKindFlags = FSYS_KIND_REMOVEABLE; 997*cdf0e10cSrcweir } 998*cdf0e10cSrcweir else 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir ImpInit( &aEntry ); 1001*cdf0e10cSrcweir FindClose( h ); 1002*cdf0e10cSrcweir } 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir if ( 0 != nError ) 1005*cdf0e10cSrcweir nKindFlags = 0; 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir return 0 == nError; 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir } 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir sal_Bool IsRedirectable_Impl( const ByteString &rPath ) 1012*cdf0e10cSrcweir { 1013*cdf0e10cSrcweir if ( rPath.Len() >= 3 && ':' == rPath.GetBuffer()[1] ) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir ByteString aVolume = rPath.Copy( 0, 3 ); 1016*cdf0e10cSrcweir UINT nType = GetDriveType( (char *) aVolume.GetBuffer() ); 1017*cdf0e10cSrcweir SetLastError( ERROR_SUCCESS ); 1018*cdf0e10cSrcweir return DRIVE_FIXED != nType; 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir return sal_False; 1021*cdf0e10cSrcweir } 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir /************************************************************************* 1024*cdf0e10cSrcweir |* 1025*cdf0e10cSrcweir |* TempDirImpl() 1026*cdf0e10cSrcweir |* 1027*cdf0e10cSrcweir |* Beschreibung liefert den Namens des Directories fuer temporaere 1028*cdf0e10cSrcweir |* Dateien 1029*cdf0e10cSrcweir |* Ersterstellung MI 16.03.94 1030*cdf0e10cSrcweir |* Letzte Aenderung MI 16.03.94 1031*cdf0e10cSrcweir |* 1032*cdf0e10cSrcweir *************************************************************************/ 1033*cdf0e10cSrcweir 1034*cdf0e10cSrcweir const char* TempDirImpl( char *pBuf ) 1035*cdf0e10cSrcweir { 1036*cdf0e10cSrcweir if ( !GetTempPath( MAX_PATH, pBuf ) && 1037*cdf0e10cSrcweir !GetWindowsDirectory( pBuf, MAX_PATH ) && 1038*cdf0e10cSrcweir !GetEnvironmentVariable( "HOMEPATH", pBuf, MAX_PATH ) ) 1039*cdf0e10cSrcweir return 0; 1040*cdf0e10cSrcweir 1041*cdf0e10cSrcweir return pBuf; 1042*cdf0e10cSrcweir } 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir //======================================================================= 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir ErrCode FileStat::QueryDiskSpace( const String &rPath, 1047*cdf0e10cSrcweir BigInt &rFreeBytes, BigInt &rTotalBytes ) 1048*cdf0e10cSrcweir { 1049*cdf0e10cSrcweir DWORD nSectorsPerCluster; /* address of sectors per cluster */ 1050*cdf0e10cSrcweir DWORD nBytesPerSector; /* address of bytes per sector */ 1051*cdf0e10cSrcweir DWORD nFreeClusters; /* address of number of free clusters */ 1052*cdf0e10cSrcweir DWORD nClusters; /* address of total number of clusters */ 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir ByteString aVol( DirEntry(rPath).ImpGetTopPtr()->GetName(), osl_getThreadTextEncoding()); 1055*cdf0e10cSrcweir bool bOK = GetDiskFreeSpace( aVol.GetBuffer(), 1056*cdf0e10cSrcweir &nSectorsPerCluster, &nBytesPerSector, 1057*cdf0e10cSrcweir &nFreeClusters, &nClusters ); 1058*cdf0e10cSrcweir if ( !bOK ) 1059*cdf0e10cSrcweir return Sys2SolarError_Impl( GetLastError() ); 1060*cdf0e10cSrcweir 1061*cdf0e10cSrcweir BigInt aBytesPerCluster( BigInt(nSectorsPerCluster) * 1062*cdf0e10cSrcweir BigInt(nBytesPerSector) ); 1063*cdf0e10cSrcweir rFreeBytes = aBytesPerCluster * BigInt(nFreeClusters); 1064*cdf0e10cSrcweir rTotalBytes = aBytesPerCluster * BigInt(nClusters); 1065*cdf0e10cSrcweir return 0; 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir 1068*cdf0e10cSrcweir //========================================================================= 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir void FSysEnableSysErrorBox( sal_Bool bEnable ) 1071*cdf0e10cSrcweir { // Preserve other Bits!! 1072*cdf0e10cSrcweir sal_uInt32 nErrorMode = SetErrorMode( bEnable ? 0 : SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX ); 1073*cdf0e10cSrcweir if ( bEnable ) 1074*cdf0e10cSrcweir nErrorMode &= ~(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); 1075*cdf0e10cSrcweir else 1076*cdf0e10cSrcweir nErrorMode |= (SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); 1077*cdf0e10cSrcweir SetErrorMode( nErrorMode ); 1078*cdf0e10cSrcweir } 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir 1082