1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _FSYS_HXX 24 #define _FSYS_HXX 25 26 #include <tools/solar.h> 27 #include <tools/datetime.hxx> 28 #include <tools/string.hxx> 29 #include <tools/link.hxx> 30 #include <tools/wldcrd.hxx> 31 #ifndef __ERRCODE_HXX 32 #include <tools/errcode.hxx> 33 #endif 34 #include "tools/toolsdllapi.h" 35 36 #include <cstdarg> 37 38 #define FEAT_FSYS_DOUBLESPEED 39 40 // -------------- 41 // - FSys-Types - 42 // -------------- 43 44 class DirEntry; 45 class DirEntryList; 46 class FSysSortList; 47 class FileStatList; 48 struct FileCopier_Impl; 49 class SvFileStream; 50 class BigInt; 51 52 #define FSYS_BUFSIZE 1024 53 #define FSYS_SHORTNAME_DELIMITER '@' 54 55 // FSysAccess 56 typedef int FSysAccess; 57 #define FSYS_ACCESS_FORCED 1 58 #define FSYS_ACCESS_FLOPPY FSYS_ACCESS_FORCED 59 #define FSYS_ACCESS_CACHED 2 60 61 // DirEntryKind 62 typedef int DirEntryKind; 63 #define FSYS_KIND_NONE ((DirEntryKind) 0) 64 #define FSYS_KIND_UNKNOWN FSYS_KIND_NONE 65 #define FSYS_KIND_FILE ((DirEntryKind) 1) 66 #define FSYS_KIND_DIR ((DirEntryKind) 2) 67 #define FSYS_KIND_DEV ((DirEntryKind) 4) 68 #define FSYS_KIND_BLOCK ((DirEntryKind) 8) 69 #define FSYS_KIND_CHAR ((DirEntryKind) 16) 70 #define FSYS_KIND_WILD ((DirEntryKind) 32) 71 #define FSYS_KIND_BLOCK_REMOTE ((DirEntryKind) 64) //TPF: fuer RFS 72 #define FSYS_KIND_REMOVEABLE ((DirEntryKind) 128) 73 #define FSYS_KIND_FIXED ((DirEntryKind) 256) 74 #define FSYS_KIND_REMOTE ((DirEntryKind) 512) 75 #define FSYS_KIND_RAM ((DirEntryKind) 1024) 76 #define FSYS_KIND_CDROM ((DirEntryKind) 2048) 77 #define FSYS_KIND_ALL ((DirEntryKind) 4095) 78 #define FSYS_KIND_VISIBLE ((DirEntryKind) 4096) 79 80 // FSysSort 81 typedef int FSysSort; 82 #define FSYS_SORT_NONE ((FSysSort) 0) 83 #define FSYS_SORT_SIZE ((FSysSort) 1) 84 #define FSYS_SORT_CREATED ((FSysSort) 2) 85 #define FSYS_SORT_MODIFYED ((FSysSort) 4) 86 #define FSYS_SORT_ACCESSED ((FSysSort) 8) 87 #define FSYS_SORT_ASCENDING ((FSysSort) 16) 88 #define FSYS_SORT_DESCENDING ((FSysSort) 32) 89 #define FSYS_SORT_EXT ((FSysSort) 64) 90 #define FSYS_SORT_NAME ((FSysSort) 128) 91 #define FSYS_SORT_KIND ((FSysSort) 256) 92 #define FSYS_SORT_CREATOR ((FSysSort) 512) 93 #define FSYS_SORT_END ((FSysSort)1024) 94 95 // DirEntryFlag 96 enum DirEntryFlag 97 { 98 FSYS_FLAG_NORMAL, 99 FSYS_FLAG_VOLUME, // Dir( FSYS_FLAG_VOLUME ) und GetDevice() 100 FSYS_FLAG_ABSROOT, // z.B. "a:\" oder "\" 101 FSYS_FLAG_RELROOT, // z.B. "a:", "a:." oder "." 102 FSYS_FLAG_CURRENT = FSYS_FLAG_RELROOT, // Synonym fuer FSYS_FLAG_RELROOT 103 FSYS_FLAG_PARENT, // z.B. ".." 104 FSYS_FLAG_INVALID 105 }; 106 107 // FSysPathStyle 108 enum FSysPathStyle 109 { 110 FSYS_STYLE_HOST, 111 FSYS_STYLE_FAT, 112 FSYS_STYLE_MSDOS = FSYS_STYLE_FAT, 113 FSYS_STYLE_VFAT, 114 FSYS_STYLE_WIN95 = FSYS_STYLE_VFAT, 115 FSYS_STYLE_HPFS, 116 FSYS_STYLE_OS2 = FSYS_STYLE_HPFS, 117 FSYS_STYLE_NTFS, 118 FSYS_STYLE_NWFS, 119 FSYS_STYLE_SYSV, 120 FSYS_STYLE_BSD, 121 FSYS_STYLE_UNX = FSYS_STYLE_BSD, 122 FSYS_STYLE_MAC, 123 FSYS_STYLE_DETECT, 124 FSYS_STYLE_UNKNOWN, 125 FSYS_STYLE_URL 126 }; 127 128 // FSysAction 129 typedef int FSysAction; 130 #define FSYS_ACTION_COPYFILE 0x01 // not only create hardlink 131 #define FSYS_ACTION_RECURSIVE 0x02 // deep through dircetory structure 132 #define FSYS_ACTION_USERECYCLEBIN 0x04 // move to recycle bin 133 #define FSYS_ACTION_MOVE 0x08 // delete after copy (=> move) 134 #define FSYS_ACTION_CONTINUE 0x10 // continue on error 135 #define FSYS_ACTION_KEEP_EXISTING 0x20 // do not overwrite objects in 136 // target folder in case of name 137 // clashes 138 #define FSYS_ACTION_STANDARD 0 139 140 // Fuer RFS 141 #define RFS_IDENTIFIER "-rfs-" 142 #define RFS_LOWER "-rfs-" 143 #define RFS_UPPER "-RFS-" 144 145 typedef sal_uIntPtr FSysError; 146 147 // FSysExact 148 enum FSysExact 149 { 150 FSYS_NOTEXACT, 151 FSYS_EXACT 152 }; 153 154 // ------------ 155 // - Char-Set - 156 // ------------ 157 158 // Was different for WIN, no longer needed... 159 #define GUI2FSYS(s) s 160 #define FSYS2GUI(s) s 161 162 163 // ------------ 164 // - FileStat - 165 // ------------ 166 167 struct dirent; 168 class TOOLS_DLLPUBLIC FileStat 169 { 170 friend class CORmFSys; 171 friend class Dir; 172 friend struct DirReader_Impl; 173 friend void ImpInitFileStat( FileStat&, dirent* ); 174 175 sal_uIntPtr nError; 176 DirEntryKind nKindFlags; 177 sal_uIntPtr nSize; 178 String aCreator; 179 String aType; 180 Date aDateCreated; 181 Time aTimeCreated; 182 Date aDateModified; 183 Time aTimeModified; 184 Date aDateAccessed; 185 Time aTimeAccessed; 186 private: 187 TOOLS_DLLPRIVATE void ImpInit( void* ); 188 189 protected: 190 // Implementation 191 FileStat( const void *pInfo, // CInfoPBRec 192 const void *pVolInfo ); // ParamBlockRec 193 194 public: 195 FileStat(); 196 FileStat( const DirEntry& rDirEntry, 197 FSysAccess nAccess = FSYS_ACCESS_FLOPPY ); 198 sal_Bool Update( const DirEntry& rDirEntry, 199 sal_Bool bForceAccess = sal_True ); 200 GetError() const201 sal_uIntPtr GetError() const { return ERRCODE_TOERROR(nError); } GetErrorCode() const202 sal_uIntPtr GetErrorCode() const { return nError; } 203 GetSize() const204 sal_uIntPtr GetSize() const { return nSize; } 205 GetKind() const206 DirEntryKind GetKind() const { return nKindFlags; } 207 sal_Bool IsKind( DirEntryKind nKind ) const; 208 GetType() const209 String GetType() const { return aType; } GetCreator() const210 String GetCreator() const { return aCreator; } 211 DateCreated() const212 Date DateCreated() const { return aDateCreated; } TimeCreated() const213 Time TimeCreated() const { return aTimeCreated; } DateModified() const214 Date DateModified() const { return aDateModified; } TimeModified() const215 Time TimeModified() const { return aTimeModified; } DateAccessed() const216 Date DateAccessed() const { return aDateAccessed; } TimeAccessed() const217 Time TimeAccessed() const { return aTimeAccessed; } 218 sal_Bool IsYounger( const FileStat& rIsOlder ) const; 219 220 #define TF_FSYS_READONLY_FLAG 221 static sal_uIntPtr SetReadOnlyFlag( const DirEntry &rEntry, sal_Bool bRO = sal_True ); 222 static sal_Bool GetReadOnlyFlag( const DirEntry &rEntry ); 223 static sal_Bool HasReadOnlyFlag(); 224 225 static ErrCode QueryDiskSpace( const String &rPath, 226 BigInt &rFreeBytes, BigInt &rTotalBytes ); 227 228 static void SetDateTime( const String& rFileName, 229 const DateTime& rNewDateTime ); 230 }; 231 232 // ------------ 233 // - DirEntry - 234 // ------------ 235 236 class DirEntryStack; 237 238 const char* ImpCheckDirEntry( const void* p ); 239 240 class TOOLS_DLLPUBLIC DirEntry 241 { 242 friend struct DirReader_Impl; 243 friend class FileCopier; 244 245 #ifdef FEAT_FSYS_DOUBLESPEED 246 FileStat* pStat; // optional 247 #endif 248 ByteString aName; 249 DirEntry* pParent; 250 sal_uIntPtr nError; 251 DirEntryFlag eFlag; 252 253 private: 254 TOOLS_DLLPRIVATE DirEntry( const ByteString& rInitName, 255 DirEntryFlag aDirFlag, 256 FSysPathStyle eStyle ); 257 258 //#if 0 // _SOLAR__PRIVATE 259 260 friend class Dir; 261 friend class FileStat; 262 friend const char* ImpCheckDirEntry( const void* p ); 263 264 TOOLS_DLLPRIVATE FSysError ImpParseName( const ByteString& rIntiName, 265 FSysPathStyle eParser ); 266 TOOLS_DLLPRIVATE FSysError ImpParseOs2Name( const ByteString& rPfad, 267 FSysPathStyle eStyle ); 268 TOOLS_DLLPRIVATE FSysError ImpParseUnixName( const ByteString& rPfad, 269 FSysPathStyle eStyle ); 270 TOOLS_DLLPRIVATE sal_uInt16 ImpTryUrl( DirEntryStack& rStack, const String& rPfad, FSysPathStyle eStyle ); 271 TOOLS_DLLPRIVATE const DirEntry* ImpGetTopPtr() const; 272 TOOLS_DLLPRIVATE DirEntry* ImpGetTopPtr(); 273 TOOLS_DLLPRIVATE DirEntry* ImpGetPreTopPtr(); 274 TOOLS_DLLPRIVATE sal_Bool ImpToRel( String aStart ); 275 276 protected: 277 void ImpTrim( FSysPathStyle eStyle ); 278 const ByteString& ImpTheName() const; ImpTheFlag() const279 DirEntryFlag ImpTheFlag() const { return eFlag; }; 280 DirEntry* ImpChangeParent( DirEntry* pNewParent, sal_Bool bNormalize = sal_True ); ImpGetParent()281 DirEntry* ImpGetParent() { return pParent; } 282 #ifdef FEAT_FSYS_DOUBLESPEED ImpGetStat() const283 FileStat* ImpGetStat() const { return pStat; } ImpSetStat(FileStat * p)284 void ImpSetStat( FileStat *p ) { pStat = p; } 285 #endif 286 287 //#endif 288 289 protected: SetError(sal_uIntPtr nErr)290 void SetError( sal_uIntPtr nErr ) { nError = nErr; } GetParent()291 DirEntry* GetParent() { return pParent; } 292 public: 293 DirEntry( DirEntryFlag aDirFlag = FSYS_FLAG_CURRENT ); 294 DirEntry( const DirEntry& rEntry ); 295 DirEntry( const ByteString& rInitName, 296 FSysPathStyle eParser = FSYS_STYLE_HOST ); 297 DirEntry( const String& rInitName, 298 FSysPathStyle eParser = FSYS_STYLE_HOST ); 299 ~DirEntry(); 300 301 sal_Bool IsLongNameOnFAT() const; 302 sal_Bool IsCaseSensitive (FSysPathStyle eFormatter = FSYS_STYLE_HOST) const; 303 GetError() const304 sal_uIntPtr GetError() const { return nError; } 305 sal_Bool IsValid() const; GetFlag() const306 DirEntryFlag GetFlag() const { return eFlag; }; 307 308 void SetExtension( const String& rExt, char cSep = '.' ); 309 String GetExtension( char cSep = '.' ) const; 310 String CutExtension( char cSep = '.' ); 311 void SetName( const String& rName, FSysPathStyle eFormatter = FSYS_STYLE_HOST ); GetNameDirect() const312 inline const String GetNameDirect() const { return String(aName, osl_getThreadTextEncoding()); } 313 String GetName( FSysPathStyle eFormatter = FSYS_STYLE_HOST ) const; 314 String CutName( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); 315 void SetBase( const String& rBase, char cSep = '.' ); 316 String GetBase(char cSep = '.' ) const; 317 DirEntry GetPath() const; 318 DirEntry GetDevice() const; 319 String GetVolume() const; 320 String GetFull( FSysPathStyle eFormatter = FSYS_STYLE_HOST, 321 sal_Bool bWithDelimiter = sal_False, 322 sal_uInt16 nMaxChars = STRING_MAXLEN ) const; 323 324 DirEntry TempName( DirEntryKind = FSYS_KIND_NONE ) const; 325 static const DirEntry& SetTempNameBase( const String &rBaseName ); 326 sal_Bool MakeShortName( const String& rLongName, 327 DirEntryKind eCreateKind = FSYS_KIND_NONE, 328 sal_Bool bUseTilde = sal_True, 329 FSysPathStyle eStyle = FSYS_STYLE_DETECT ); 330 331 bool IsAbs() const; 332 sal_Bool ToAbs(); 333 sal_Bool Find( const String& rPfad, char cDelim = 0 ); 334 sal_Bool ToRel(); 335 sal_Bool ToRel( const DirEntry& rRefDir ); 336 sal_uInt16 CutRelParents(); 337 338 sal_Bool SetCWD( sal_Bool bSloppy = sal_False ) const; 339 sal_Bool MakeDir( sal_Bool bSloppy = sal_False ) const; 340 sal_Bool Exists( FSysAccess nAccess = FSYS_ACCESS_FLOPPY ) const; 341 sal_Bool First(); 342 343 sal_uInt16 Level() const; 344 const DirEntry& operator []( sal_uInt16 nParentLevel ) const; 345 sal_Bool Contains( const DirEntry &rSubEntry ) const; 346 347 FSysError CopyTo( const DirEntry& rDestDir, 348 FSysAction nActions = FSYS_ACTION_STANDARD ) const; 349 FSysError MoveTo( const DirEntry& rDestDir ) const; 350 FSysError Kill( FSysAction nActions = FSYS_ACTION_STANDARD ) const; 351 352 DirEntry& operator =( const DirEntry& rOrigDir ); 353 DirEntry operator +( const DirEntry& rSubDir ) const; 354 DirEntry& operator +=( const DirEntry& rSubDir ); 355 sal_Bool operator ==( const DirEntry& rAnotherDir ) const; operator !=(const DirEntry & rAnotherDir) const356 sal_Bool operator !=( const DirEntry& rAnotherDir ) const 357 { return !(DirEntry::operator==( rAnotherDir )); } 358 359 StringCompare NameCompare( const DirEntry &rWith ) const; NameCompareDirect(const DirEntry & rWith) const360 inline StringCompare NameCompareDirect( const DirEntry &rWith ) const 361 { 362 #ifdef UNX 363 return rWith.aName.CompareTo( aName ); 364 #else 365 return rWith.aName.CompareIgnoreCaseToAscii( aName ); 366 #endif 367 } 368 369 static String GetAccessDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); 370 static String GetSearchDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); 371 static sal_uInt16 GetMaxNameLen( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); 372 static FSysPathStyle GetPathStyle( const String &rDevice ); 373 static String ConvertNameToSystem( const String & rName ); 374 static String ConvertSystemToName( const String & rName ); 375 static sal_Bool IsRFSAvailable(); 376 }; 377 378 // -------------- 379 // - FileCopier - 380 // -------------- 381 382 class TOOLS_DLLPUBLIC FileCopier 383 { 384 DirEntry aSource; 385 DirEntry aTarget; 386 sal_uIntPtr nBytesTotal; 387 sal_uIntPtr nBytesCopied; 388 Link aProgressLink; 389 sal_uInt16 nBlockSize; 390 FileCopier_Impl* pImp; 391 392 private: 393 TOOLS_DLLPRIVATE FSysError DoCopy_Impl( 394 const DirEntry &rSource, const DirEntry &rTarget ); 395 396 protected: 397 virtual sal_Bool Progress(); 398 virtual ErrCode Error( ErrCode eErr, 399 const DirEntry *pSource, const DirEntry *pTarget ); 400 401 public: 402 FileCopier(); 403 FileCopier( const DirEntry &rSource, 404 const DirEntry &rTarget ); 405 FileCopier( const FileCopier &rCopier ); 406 virtual ~FileCopier(); 407 408 FileCopier& operator = ( const FileCopier &rCopier ); 409 SetBlockSize(sal_uInt16 nBytes)410 void SetBlockSize( sal_uInt16 nBytes ) { nBlockSize = nBytes; } GetBlockSize() const411 sal_uInt16 GetBlockSize() const { return nBlockSize; } 412 GetBytesTotal() const413 sal_uIntPtr GetBytesTotal() const { return nBytesTotal; } GetBytesCopied() const414 sal_uIntPtr GetBytesCopied() const { return nBytesCopied; } 415 SetSource(const DirEntry & rSource)416 void SetSource( const DirEntry &rSource ) { aSource = rSource; } SetTarget(const DirEntry & rTarget)417 void SetTarget( const DirEntry &rTarget ) { aTarget = rTarget; } GetSource() const418 const DirEntry& GetSource() const { return aSource; } GetTarget() const419 const DirEntry& GetTarget() const { return aTarget; } 420 421 FSysError Execute( FSysAction nActions = FSYS_ACTION_STANDARD ); 422 FSysError ExecuteExact( FSysAction nActions = FSYS_ACTION_STANDARD, 423 FSysExact eExact = FSYS_NOTEXACT); 424 425 const DirEntry* GetErrorSource() const; 426 const DirEntry* GetErrorTarget() const; 427 ErrCode GetError() const; 428 SetProgressHdl(const Link & rLink)429 void SetProgressHdl( const Link& rLink ) { aProgressLink = rLink; } GetProgressHdl() const430 const Link& GetProgressHdl() const { return aProgressLink; } 431 void SetErrorHdl( const Link& rLink ); 432 const Link& GetErrorHdl() const; 433 }; 434 435 // ------- 436 // - Dir - 437 // ------- 438 439 struct DirReader_Impl; 440 class TOOLS_DLLPUBLIC Dir : public DirEntry 441 { 442 friend struct DirReader_Impl; 443 friend class CORmFSys; 444 445 DirReader_Impl* pReader; // systemabhaengig 446 DirEntryList* pLst; 447 FSysSortList* pSortLst; // NULL, wenn kein Sort gefordert 448 FileStatList* pStatLst; // NULL, wenn keine Stat's benoetigt 449 WildCard aNameMask; 450 DirEntryKind eAttrMask; 451 452 private: 453 TOOLS_DLLPRIVATE Dir( const Dir& ); // not allowed 454 TOOLS_DLLPRIVATE Dir& operator=( const Dir& ); // not allowed 455 456 #ifdef _DIR_CXX 457 TOOLS_DLLPRIVATE FSysError ImpSetSort( std::va_list pArgs, FSysSort nSort ); 458 TOOLS_DLLPRIVATE void Construct( DirEntryKind nKind = FSYS_KIND_DIR|FSYS_KIND_FILE ); 459 #endif 460 461 #ifndef _TOOLS_HXX 462 protected: 463 sal_Bool ImpInsertPointReached( const DirEntry& rIsSmaller, 464 const FileStat& rNewStat, 465 sal_uIntPtr nCurPos, 466 sal_uIntPtr nSortIndex ) const; 467 void ImpSortedInsert( const DirEntry *pNewEntry, 468 const FileStat *pNewStat ); 469 #endif 470 471 public: 472 Dir(); 473 Dir( const DirEntry& rDirEntry, 474 DirEntryKind nKind = FSYS_KIND_ALL ); 475 Dir( const DirEntry& rDirEntry, 476 DirEntryKind nKind, 477 FSysSort nSort, ... ); 478 ~Dir(); 479 GetNameMask() const480 const WildCard& GetNameMask() const { return aNameMask; } 481 482 FSysError SetSort( FSysSort nSort, ... ); 483 484 void Reset(); 485 sal_uInt16 Scan( sal_uInt16 nCount = 5 ); 486 sal_uInt16 Count( sal_Bool bUpdated = sal_True ) const; 487 sal_Bool Update(); 488 489 Dir& operator +=( const Dir& rDir ); 490 DirEntry& operator []( sal_uInt16 nIndex ) const; 491 }; 492 493 // we don't need this stuff for bootstraping 494 #ifndef BOOTSTRAP 495 496 //======================================================================== 497 498 /** FSysRedirector is an abstract base class for a hook to redirect 499 mirrored directory trees. 500 501 <P>One instance of a subclass can be instanciated and registered 502 using the method FSysRedirector::Register(FSysRedirector*). 503 */ 504 505 class FSysRedirector 506 { 507 static FSysRedirector* _pRedirector; 508 static sal_Bool _bEnabled; 509 510 public: 511 /** This method must called with the one and only instance of the 512 subclass which implements the redirection. 513 514 <P>It must be called with 0 when the instance is destroyed. 515 */ 516 static void Register( FSysRedirector *pRedirector ); 517 518 //----------------------------------------------------------------------- 519 /** This method returns the currently registererd instance of 520 a subclass which implements the redirection. 521 522 <P>If no redirector is registered, it returns 0. 523 */ 524 static FSysRedirector* Redirector(); 525 526 //----------------------------------------------------------------------- 527 /** This method is to be used to redirect a file system path. 528 529 <P>It will not redirect while redirection is disabled. 530 531 <P>It may block while another thread is accessing the redirector 532 or another thread has disabled redirections. 533 534 @param String &rPath<BR> 535 This inout-argument accepts a file:-URL even as a native 536 file system path name to redirect in 'rPath'. It returns the 537 redirected (modified) path too, which can be of both formats 538 too. 539 540 @return sal_Bool<BR> 541 sal_True, if the path is redirected 542 sal_False, if the path is not redirected (unchanged) 543 */ 544 static void DoRedirect( String &rPath ); 545 }; 546 547 #endif // BOOTSTRP 548 549 //======================================================================== 550 551 void FSysEnableSysErrorBox( sal_Bool bEnable ); 552 553 //======================================================================== 554 555 #if defined(DBG_UTIL) 556 void FSysTest(); 557 #endif 558 559 #endif // #ifndef _FSYS_HXX 560 561