LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/tools - fsys.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 2 50.0 %
Date: 2012-12-27 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _FSYS_HXX
      20             : #define _FSYS_HXX
      21             : 
      22             : #include <tools/solar.h>
      23             : #include <tools/datetime.hxx>
      24             : #include <tools/string.hxx>
      25             : #include <tools/link.hxx>
      26             : #include <tools/wldcrd.hxx>
      27             : #include <tools/errcode.hxx>
      28             : #include "tools/toolsdllapi.h"
      29             : 
      30             : #include <cstdarg>
      31             : #include <vector>
      32             : 
      33             : #define FEAT_FSYS_DOUBLESPEED
      34             : 
      35             : // FSys-Types
      36             : class DirEntry;
      37             : class FileStat;
      38             : struct FileCopier_Impl;
      39             : class SvFileStream;
      40             : class BigInt;
      41             : 
      42             : typedef ::std::vector< DirEntry* > DirEntryList;
      43             : typedef ::std::vector< FileStat* > FileStatList;
      44             : 
      45             : #define FSYS_SHORTNAME_DELIMITER    '@'
      46             : 
      47             : // FSysAccess
      48             : typedef int FSysAccess;
      49             : #define FSYS_ACCESS_FORCED          1
      50             : #define FSYS_ACCESS_FLOPPY          FSYS_ACCESS_FORCED
      51             : #define FSYS_ACCESS_CACHED          2
      52             : 
      53             : // DirEntryKind
      54             : typedef int DirEntryKind;
      55             : #define FSYS_KIND_NONE              ((DirEntryKind)     0)
      56             : #define FSYS_KIND_UNKNOWN           FSYS_KIND_NONE
      57             : #define FSYS_KIND_FILE              ((DirEntryKind)     1)
      58             : #define FSYS_KIND_DIR               ((DirEntryKind)     2)
      59             : #define FSYS_KIND_DEV               ((DirEntryKind)     4)
      60             : #define FSYS_KIND_BLOCK             ((DirEntryKind)     8)
      61             : #define FSYS_KIND_CHAR              ((DirEntryKind)    16)
      62             : #define FSYS_KIND_WILD              ((DirEntryKind)    32)
      63             : #define FSYS_KIND_BLOCK_REMOTE      ((DirEntryKind)    64)
      64             : #define FSYS_KIND_REMOVEABLE        ((DirEntryKind)   128)
      65             : #define FSYS_KIND_FIXED             ((DirEntryKind)   256)
      66             : #define FSYS_KIND_REMOTE            ((DirEntryKind)   512)
      67             : #define FSYS_KIND_RAM               ((DirEntryKind)  1024)
      68             : #define FSYS_KIND_CDROM             ((DirEntryKind)  2048)
      69             : #define FSYS_KIND_ALL               ((DirEntryKind)  4095)
      70             : #define FSYS_KIND_VISIBLE           ((DirEntryKind)  4096)
      71             : 
      72             : // FSysSort
      73             : typedef int FSysSort;
      74             : #define FSYS_SORT_NONE              ((FSysSort)   0)
      75             : #define FSYS_SORT_SIZE              ((FSysSort)   1)
      76             : #define FSYS_SORT_CREATED           ((FSysSort)   2)
      77             : #define FSYS_SORT_MODIFYED          ((FSysSort)   4)
      78             : #define FSYS_SORT_ACCESSED          ((FSysSort)   8)
      79             : #define FSYS_SORT_ASCENDING         ((FSysSort)  16)
      80             : #define FSYS_SORT_DESCENDING        ((FSysSort)  32)
      81             : #define FSYS_SORT_EXT               ((FSysSort)  64)
      82             : #define FSYS_SORT_NAME              ((FSysSort) 128)
      83             : #define FSYS_SORT_KIND              ((FSysSort) 256)
      84             : #define FSYS_SORT_CREATOR           ((FSysSort) 512)
      85             : #define FSYS_SORT_END               ((FSysSort)1024)
      86             : typedef ::std::vector< FSysSort > FSysSortList;
      87             : 
      88             : // DirEntryFlag
      89             : enum DirEntryFlag
      90             : {
      91             :     FSYS_FLAG_NORMAL,
      92             :     FSYS_FLAG_VOLUME,                      // Dir( FSYS_FLAG_VOLUME ) and GetDevice()
      93             :     FSYS_FLAG_ABSROOT,                     // e.g. "a:\" or "\"
      94             :     FSYS_FLAG_RELROOT,                     // e.g. "a:", "a:." or "."
      95             :     FSYS_FLAG_CURRENT = FSYS_FLAG_RELROOT, // Synonym for FSYS_FLAG_RELROOT
      96             :     FSYS_FLAG_PARENT,                      // e.g. ".."
      97             :     FSYS_FLAG_INVALID
      98             : };
      99             : 
     100             : // FSysPathStyle
     101             : enum FSysPathStyle
     102             : {
     103             :     FSYS_STYLE_HOST,
     104             :     FSYS_STYLE_NTFS,
     105             :     FSYS_STYLE_BSD,
     106             :     FSYS_STYLE_UNX = FSYS_STYLE_BSD,
     107             :     FSYS_STYLE_DETECT,
     108             : };
     109             : 
     110             : // FSysAction
     111             : typedef int FSysAction;
     112             : #define FSYS_ACTION_COPYFILE        0x01    // not only create hardlink
     113             : #define FSYS_ACTION_RECURSIVE       0x02    // deep through dircetory structure
     114             : #define FSYS_ACTION_USERECYCLEBIN   0x04    // move to recycle bin
     115             : #define FSYS_ACTION_MOVE            0x08    // delete after copy (=> move)
     116             : #define FSYS_ACTION_CONTINUE        0x10    // continue on error
     117             : #define FSYS_ACTION_KEEP_EXISTING   0x20    // do not overwrite objects in
     118             :                                             // target folder in case of name
     119             :                                             // clashes
     120             : #define FSYS_ACTION_STANDARD        0
     121             : 
     122             : // RFS
     123             : #define RFS_IDENTIFIER  "-rfs-"
     124             : 
     125             : typedef sal_uIntPtr FSysError;
     126             : 
     127             : // FSysExact
     128             : enum FSysExact
     129             : {
     130             :     FSYS_NOTEXACT,
     131             :     FSYS_EXACT
     132             : };
     133             : 
     134             : // FileStat
     135             : struct dirent;
     136             : 
     137        9410 : class TOOLS_DLLPUBLIC FileStat
     138             : {
     139             :     friend class    Dir;
     140             :     friend struct   DirReader_Impl;
     141             :     friend void     ImpInitFileStat( FileStat&, dirent* );
     142             : 
     143             :     sal_uIntPtr     nError;
     144             :     DirEntryKind    nKindFlags;
     145             :     sal_uIntPtr     nSize;
     146             :     String          aCreator;
     147             :     String          aType;
     148             :     Date            aDateCreated;
     149             :     Time            aTimeCreated;
     150             :     Date            aDateModified;
     151             :     Time            aTimeModified;
     152             :     Date            aDateAccessed;
     153             :     Time            aTimeAccessed;
     154             : 
     155             : private:
     156             :     TOOLS_DLLPRIVATE void ImpInit( void* );
     157             : 
     158             : protected:
     159             :                     // Implementation
     160             :                     FileStat( SAL_UNUSED_PARAMETER const void *pInfo ); // CInfoPBRec
     161             : 
     162             : public:
     163             :                     FileStat( const DirEntry& rDirEntry,
     164             :                               FSysAccess nAccess = FSYS_ACCESS_FLOPPY );
     165             :     sal_Bool        Update( const DirEntry& rDirEntry,
     166             :                             sal_Bool bForceAccess = sal_True );
     167             : 
     168             :     sal_uIntPtr     GetError() const { return ERRCODE_TOERROR(nError); }
     169             :     sal_uIntPtr     GetErrorCode() const { return nError; }
     170             : 
     171             :     sal_uIntPtr     GetSize() const { return nSize; }
     172             : 
     173           0 :     DirEntryKind    GetKind() const { return nKindFlags; }
     174             :     sal_Bool        IsKind( DirEntryKind nKind ) const;
     175             : 
     176             :     String          GetType() const { return aType; }
     177             :     String          GetCreator() const { return aCreator; }
     178             : 
     179             :     Date            DateCreated() const  { return aDateCreated;  }
     180             :     Time            TimeCreated() const  { return aTimeCreated;  }
     181             :     Date            DateModified() const { return aDateModified; }
     182             :     Time            TimeModified() const { return aTimeModified; }
     183             :     Date            DateAccessed() const { return aDateAccessed; }
     184             :     Time            TimeAccessed() const { return aTimeAccessed; }
     185             : 
     186             :     static sal_uIntPtr SetReadOnlyFlag( const DirEntry &rEntry, sal_Bool bRO = sal_True );
     187             :     static sal_Bool GetReadOnlyFlag( const DirEntry &rEntry );
     188             : };
     189             : 
     190             : // DirEntry
     191             : 
     192             : class DirEntryStack;
     193             : 
     194             : const char* ImpCheckDirEntry( const void* p );
     195             : 
     196             : class TOOLS_DLLPUBLIC DirEntry
     197             : {
     198             : friend struct DirReader_Impl;
     199             : friend class FileCopier;
     200             : 
     201             : #ifdef FEAT_FSYS_DOUBLESPEED
     202             :     FileStat*           pStat;      // optional
     203             : #endif
     204             :     rtl::OString        aName;
     205             :     DirEntry*           pParent;
     206             :     sal_uIntPtr         nError;
     207             :     DirEntryFlag        eFlag;
     208             : 
     209             : private:
     210             :     TOOLS_DLLPRIVATE    DirEntry( const rtl::OString& rInitName,
     211             :                                   DirEntryFlag aDirFlag );
     212             : 
     213             :     friend class Dir;
     214             :     friend class FileStat;
     215             :     friend const char* ImpCheckDirEntry( const void* p );
     216             : 
     217             :     TOOLS_DLLPRIVATE FSysError       ImpParseName( const rtl::OString& rIntiName );
     218             :     TOOLS_DLLPRIVATE const DirEntry* ImpGetTopPtr() const;
     219             :     TOOLS_DLLPRIVATE DirEntry*       ImpGetTopPtr();
     220             : 
     221             : protected:
     222             :     void                ImpTrim();
     223             :     const rtl::OString& ImpTheName() const;
     224             :     DirEntryFlag        ImpTheFlag() const { return eFlag; };
     225             :     DirEntry*           ImpChangeParent( DirEntry* pNewParent, sal_Bool bNormalize = sal_True );
     226             :     DirEntry*           ImpGetParent() { return pParent; }
     227             : #ifdef FEAT_FSYS_DOUBLESPEED
     228             :     FileStat*           ImpGetStat() const { return pStat; }
     229             :     void                ImpSetStat( FileStat *p ) { pStat = p; }
     230             : #endif
     231             : 
     232             : protected:
     233             :     void                SetError( sal_uIntPtr nErr ) { nError = nErr; }
     234             :     DirEntry*           GetParent() { return pParent; }
     235             : 
     236             : public:
     237             :                         DirEntry( DirEntryFlag aDirFlag = FSYS_FLAG_CURRENT );
     238             :                         DirEntry( const DirEntry& rEntry );
     239             :                         DirEntry( const rtl::OString& rInitName,
     240             :                                    FSysPathStyle eParser = FSYS_STYLE_HOST );
     241             :                         DirEntry( const String& rInitName,
     242             :                                    FSysPathStyle eParser = FSYS_STYLE_HOST );
     243             :                         ~DirEntry();
     244             : 
     245             :     sal_uIntPtr         GetError() const { return nError; }
     246             :     sal_Bool            IsValid() const;
     247             :     DirEntryFlag        GetFlag() const { return eFlag; };
     248             : 
     249             :     void                SetExtension( const String& rExt, char cSep = '.' );
     250             :     String              GetExtension( char cSep = '.' ) const;
     251             :     void                SetName( const String& rName, FSysPathStyle eFormatter = FSYS_STYLE_HOST );
     252             :     const String        GetNameDirect() const
     253             :     {
     254             :         return rtl::OStringToOUString(aName, osl_getThreadTextEncoding());
     255             :     }
     256             :     String              GetName( FSysPathStyle eFormatter = FSYS_STYLE_HOST ) const;
     257             :     String              CutName( FSysPathStyle eFormatter = FSYS_STYLE_HOST );
     258             :     String              GetBase(char cSep = '.' ) const;
     259             :     DirEntry            GetPath() const;
     260             :     DirEntry            GetDevice() const;
     261             :     String              GetVolume() const;
     262             :     String              GetFull( FSysPathStyle eFormatter = FSYS_STYLE_HOST,
     263             :                                  sal_Bool bWithDelimiter = sal_False,
     264             :                                  sal_uInt16 nMaxChars = STRING_MAXLEN ) const;
     265             : 
     266             :     DirEntry            TempName( DirEntryKind = FSYS_KIND_NONE ) const;
     267             :     sal_Bool            MakeShortName( const String& rLongName,
     268             :                                        DirEntryKind eCreateKind = FSYS_KIND_NONE,
     269             :                                        sal_Bool bUseTilde = sal_True,
     270             :                                        FSysPathStyle eStyle = FSYS_STYLE_DETECT );
     271             : 
     272             :     bool                IsAbs() const;
     273             :     sal_Bool            ToAbs();
     274             :     sal_Bool            Find( const String& rPfad, char cDelim = 0 );
     275             : 
     276             :     sal_Bool            SetCWD( sal_Bool bSloppy = sal_False ) const;
     277             :     sal_Bool            MakeDir( sal_Bool bSloppy = sal_False ) const;
     278             :     sal_Bool            Exists( FSysAccess nAccess = FSYS_ACCESS_FLOPPY ) const;
     279             :     sal_Bool            First();
     280             : 
     281             :     sal_uInt16          Level() const;
     282             :     const DirEntry&     operator []( sal_uInt16 nParentLevel ) const;
     283             :     sal_Bool            Contains( const DirEntry &rSubEntry ) const;
     284             : 
     285             :     FSysError           CopyTo( const DirEntry& rDestDir,
     286             :                                 FSysAction nActions = FSYS_ACTION_STANDARD ) const;
     287             :     FSysError           MoveTo( const DirEntry& rDestDir ) const;
     288             :     FSysError           Kill( FSysAction nActions = FSYS_ACTION_STANDARD ) const;
     289             : 
     290             :     DirEntry&           operator =( const DirEntry& rOrigDir );
     291             :     DirEntry            operator +( const DirEntry& rSubDir ) const;
     292             :     DirEntry&           operator +=( const DirEntry& rSubDir );
     293             :     sal_Bool            operator ==( const DirEntry& rAnotherDir ) const;
     294             :     sal_Bool            operator !=( const DirEntry& rAnotherDir ) const
     295             :                             { return !(DirEntry::operator==( rAnotherDir )); }
     296             : 
     297             :     inline sal_Int32 NameCompareDirect( const DirEntry &rWith ) const
     298             :     {
     299             : #ifdef UNX
     300             :         return rWith.aName.compareTo(aName);
     301             : #else
     302             :         rtl::OString aThis(rtl::OString(aName).toAsciiLowerCase());
     303             :         rtl::OString aWith(rtl::OString(rWith.aName).toAsciiLowerCase());
     304             :         return aWith.compareTo(aThis);
     305             : #endif
     306             :     }
     307             : 
     308             :     static String       GetAccessDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST );
     309             :     static String       GetSearchDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST );
     310             : };
     311             : 
     312             : // FileCopier (a private impl. detail of tools/)
     313             : 
     314             : class FileCopier
     315             : {
     316             :     DirEntry            aSource;
     317             :     DirEntry            aTarget;
     318             :     sal_uIntPtr         nBytesTotal;
     319             :     sal_uIntPtr         nBytesCopied;
     320             :     Link                aProgressLink;
     321             :     sal_uInt16          nBlockSize;
     322             :     FileCopier_Impl*    pImp;
     323             : 
     324             : private:
     325             :     TOOLS_DLLPRIVATE FSysError DoCopy_Impl(
     326             :         const DirEntry &rSource, const DirEntry &rTarget );
     327             : 
     328             : protected:
     329             :     virtual sal_Bool    Progress();
     330             :     virtual ErrCode     Error( ErrCode eErr,
     331             :                                const DirEntry *pSource, const DirEntry *pTarget );
     332             : 
     333             : public:
     334             :                         FileCopier( const DirEntry &rSource,
     335             :                                     const DirEntry &rTarget );
     336             :                         FileCopier( const FileCopier &rCopier );
     337             :                         virtual ~FileCopier();
     338             : 
     339             :     FileCopier&         operator =( const FileCopier &rCopier );
     340             : 
     341             :     void                SetBlockSize( sal_uInt16 nBytes ) { nBlockSize = nBytes; }
     342             :     sal_uInt16          GetBlockSize() const { return nBlockSize; }
     343             : 
     344             :     sal_uIntPtr         GetBytesTotal() const { return nBytesTotal; }
     345             :     sal_uIntPtr         GetBytesCopied() const { return nBytesCopied; }
     346             : 
     347             :     void                SetSource( const DirEntry &rSource ) { aSource = rSource; }
     348             :     void                SetTarget( const DirEntry &rTarget ) { aTarget = rTarget; }
     349             :     const DirEntry&     GetSource() const { return aSource; }
     350             :     const DirEntry&     GetTarget() const { return aTarget; }
     351             : 
     352             :     FSysError           Execute( FSysAction nActions = FSYS_ACTION_STANDARD );
     353             :     FSysError           ExecuteExact( FSysAction nActions = FSYS_ACTION_STANDARD,
     354             :                                       FSysExact  eExact = FSYS_NOTEXACT);
     355             : 
     356             :     void                SetProgressHdl( const Link& rLink ) { aProgressLink = rLink; }
     357             :     const Link&         GetProgressHdl() const { return aProgressLink; }
     358             : };
     359             : 
     360             : // Dir
     361             : 
     362             : struct DirReader_Impl;
     363             : class TOOLS_DLLPUBLIC Dir : public DirEntry
     364             : {
     365             :     friend struct DirReader_Impl;
     366             : 
     367             :     DirReader_Impl* pReader;        // is system-dependent
     368             :     DirEntryList*   pLst;
     369             :     FSysSortList*   pSortLst;       // NULL if no sorting requested
     370             :     FileStatList*   pStatLst;       // NULL if no stats requested
     371             :     WildCard        aNameMask;
     372             :     DirEntryKind eAttrMask;
     373             : 
     374             : private:
     375             :     TOOLS_DLLPRIVATE        Dir( const Dir& );        // not allowed
     376             :     TOOLS_DLLPRIVATE Dir&   operator =( const Dir& ); // not allowed
     377             : 
     378             : #ifdef _DIR_CXX
     379             :     TOOLS_DLLPRIVATE void   Construct( DirEntryKind nKind = FSYS_KIND_DIR|FSYS_KIND_FILE );
     380             : #endif
     381             : 
     382             : #ifndef _TOOLS_HXX
     383             : protected:
     384             :     sal_Bool            ImpInsertPointReached( const DirEntry& rIsSmaller,
     385             :                                            const FileStat& rNewStat,
     386             :                                            size_t nCurPos,
     387             :                                            size_t nSortIndex ) const;
     388             :     void            ImpSortedInsert( const DirEntry *pNewEntry,
     389             :                                      const FileStat *pNewStat );
     390             : #endif
     391             : 
     392             : public:
     393             :                     Dir( const DirEntry& rDirEntry,
     394             :                          DirEntryKind nKind = FSYS_KIND_ALL );
     395             :                     ~Dir();
     396             : 
     397             :     void            Reset();
     398             :     sal_uInt16          Scan( sal_uInt16 nCount = 5 );
     399             :     size_t          Count( sal_Bool bUpdated = sal_True ) const;
     400             : 
     401             :     Dir&            operator +=( const Dir& rDir );
     402             :     DirEntry&       operator []( size_t nIndex ) const;
     403             : };
     404             : 
     405             : #if defined(DBG_UTIL)
     406             : void FSysTest();
     407             : #endif
     408             : 
     409             : #endif
     410             : 
     411             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10