From 75e014c30753f635ddc74cdb654a8342049a114b Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Thu, 4 Apr 2013 21:40:03 +0200 Subject: fdo#61514 clean obsolete tools/ filesystem abstraction Change-Id: I7d1d5eca43d0b0f9a013e31383abc574a7b15f93 --- tools/Library_tl.mk | 4 - tools/Package_inc.mk | 1 - tools/inc/tools/fsys.hxx | 335 --------- tools/source/fsys/comdep.cxx | 32 - tools/source/fsys/comdep.hxx | 98 --- tools/source/fsys/dirent.cxx | 1627 ---------------------------------------- tools/source/fsys/fstat.cxx | 133 ---- tools/source/fsys/tdir.cxx | 416 ---------- tools/source/fsys/tempfile.cxx | 1 - tools/source/fsys/unx.cxx | 366 --------- tools/source/fsys/unx.hxx | 74 -- tools/source/fsys/wntmsc.cxx | 770 ------------------- tools/source/fsys/wntmsc.hxx | 67 -- 13 files changed, 3924 deletions(-) delete mode 100644 tools/inc/tools/fsys.hxx delete mode 100644 tools/source/fsys/comdep.cxx delete mode 100644 tools/source/fsys/comdep.hxx delete mode 100644 tools/source/fsys/dirent.cxx delete mode 100644 tools/source/fsys/fstat.cxx delete mode 100644 tools/source/fsys/tdir.cxx delete mode 100644 tools/source/fsys/unx.cxx delete mode 100644 tools/source/fsys/unx.hxx delete mode 100644 tools/source/fsys/wntmsc.cxx delete mode 100644 tools/source/fsys/wntmsc.hxx (limited to 'tools') diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index cf29effe82fb..a48117e194f8 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -49,10 +49,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\ tools/source/datetime/tdate \ tools/source/datetime/ttime \ tools/source/debug/debug \ - tools/source/fsys/comdep \ - tools/source/fsys/dirent \ - tools/source/fsys/fstat \ - tools/source/fsys/tdir \ tools/source/fsys/tempfile \ tools/source/fsys/urlobj \ tools/source/fsys/wldcrd \ diff --git a/tools/Package_inc.mk b/tools/Package_inc.mk index 5557b12cfbd1..6d6f402d3358 100644 --- a/tools/Package_inc.mk +++ b/tools/Package_inc.mk @@ -36,7 +36,6 @@ $(eval $(call gb_Package_add_file,tools_inc,inc/tools/extendapplicationenvironme $(eval $(call gb_Package_add_file,tools_inc,inc/tools/fldunit.hxx,tools/fldunit.hxx)) $(eval $(call gb_Package_add_file,tools_inc,inc/tools/fontenum.hxx,tools/fontenum.hxx)) $(eval $(call gb_Package_add_file,tools_inc,inc/tools/fract.hxx,tools/fract.hxx)) -$(eval $(call gb_Package_add_file,tools_inc,inc/tools/fsys.hxx,tools/fsys.hxx)) $(eval $(call gb_Package_add_file,tools_inc,inc/tools/gen.hxx,tools/gen.hxx)) $(eval $(call gb_Package_add_file,tools_inc,inc/tools/getprocessworkingdir.hxx,tools/getprocessworkingdir.hxx)) $(eval $(call gb_Package_add_file,tools_inc,inc/tools/globname.hxx,tools/globname.hxx)) diff --git a/tools/inc/tools/fsys.hxx b/tools/inc/tools/fsys.hxx deleted file mode 100644 index e135a76957c4..000000000000 --- a/tools/inc/tools/fsys.hxx +++ /dev/null @@ -1,335 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef _FSYS_HXX -#define _FSYS_HXX - -#include -#include -#include -#include -#include -#include -#include "tools/toolsdllapi.h" - -#include -#include - -// FSys-Types -class DirEntry; -class FileStat; -class SvFileStream; -class BigInt; - -typedef ::std::vector< DirEntry* > DirEntryList; -typedef ::std::vector< FileStat* > FileStatList; - -// DirEntryKind -typedef int DirEntryKind; -#define FSYS_KIND_NONE ((DirEntryKind) 0) -#define FSYS_KIND_UNKNOWN FSYS_KIND_NONE -#define FSYS_KIND_FILE ((DirEntryKind) 1) -#define FSYS_KIND_DIR ((DirEntryKind) 2) -#define FSYS_KIND_DEV ((DirEntryKind) 4) -#define FSYS_KIND_BLOCK ((DirEntryKind) 8) -#define FSYS_KIND_CHAR ((DirEntryKind) 16) -#define FSYS_KIND_WILD ((DirEntryKind) 32) -#define FSYS_KIND_BLOCK_REMOTE ((DirEntryKind) 64) -#define FSYS_KIND_REMOVEABLE ((DirEntryKind) 128) -#define FSYS_KIND_FIXED ((DirEntryKind) 256) -#define FSYS_KIND_REMOTE ((DirEntryKind) 512) -#define FSYS_KIND_RAM ((DirEntryKind) 1024) -#define FSYS_KIND_CDROM ((DirEntryKind) 2048) -#define FSYS_KIND_ALL ((DirEntryKind) 4095) -#define FSYS_KIND_VISIBLE ((DirEntryKind) 4096) - -// FSysSort -typedef int FSysSort; -#define FSYS_SORT_NONE ((FSysSort) 0) -#define FSYS_SORT_SIZE ((FSysSort) 1) -#define FSYS_SORT_CREATED ((FSysSort) 2) -#define FSYS_SORT_MODIFYED ((FSysSort) 4) -#define FSYS_SORT_ACCESSED ((FSysSort) 8) -#define FSYS_SORT_ASCENDING ((FSysSort) 16) -#define FSYS_SORT_DESCENDING ((FSysSort) 32) -#define FSYS_SORT_EXT ((FSysSort) 64) -#define FSYS_SORT_NAME ((FSysSort) 128) -#define FSYS_SORT_KIND ((FSysSort) 256) -#define FSYS_SORT_CREATOR ((FSysSort) 512) -#define FSYS_SORT_END ((FSysSort)1024) -typedef ::std::vector< FSysSort > FSysSortList; - -// DirEntryFlag -enum DirEntryFlag -{ - FSYS_FLAG_NORMAL, - FSYS_FLAG_VOLUME, // Dir( FSYS_FLAG_VOLUME ) and GetDevice() - FSYS_FLAG_ABSROOT, // e.g. "a:\" or "\" - FSYS_FLAG_RELROOT, // e.g. "a:", "a:." or "." - FSYS_FLAG_CURRENT = FSYS_FLAG_RELROOT, // Synonym for FSYS_FLAG_RELROOT - FSYS_FLAG_PARENT, // e.g. ".." - FSYS_FLAG_INVALID -}; - -// FSysPathStyle -enum FSysPathStyle -{ - FSYS_STYLE_HOST, - FSYS_STYLE_NTFS, - FSYS_STYLE_BSD, - FSYS_STYLE_UNX = FSYS_STYLE_BSD, - FSYS_STYLE_DETECT, -}; - -// FSysAccess -typedef int FSysAccess; -#define FSYS_ACCESS_CACHED 2 -#define FSYS_ACCESS_FORCED 1 -#define FSYS_ACCESS_FLOPPY FSYS_ACCESS_FORCED - -// FSysAction -typedef int FSysAction; -#define FSYS_ACTION_RECURSIVE 0x02 // deep through dircetory structure -#define FSYS_ACTION_USERECYCLEBIN 0x04 // move to recycle bin -#define FSYS_ACTION_STANDARD 0 - -// RFS -#define RFS_IDENTIFIER "-rfs-" - -typedef sal_uIntPtr FSysError; - -// FileStat -struct dirent; - -class TOOLS_DLLPUBLIC FileStat -{ - friend class Dir; - friend struct DirReader_Impl; - friend void ImpInitFileStat( FileStat&, dirent* ); - - sal_uIntPtr nError; - DirEntryKind nKindFlags; - sal_uIntPtr nSize; - String aCreator; - String aType; - Date aDateCreated; - Time aTimeCreated; - Date aDateModified; - Time aTimeModified; - Date aDateAccessed; - Time aTimeAccessed; - -private: - TOOLS_DLLPRIVATE void ImpInit( void* ); - -protected: - // Implementation - FileStat( SAL_UNUSED_PARAMETER const void *pInfo ); // CInfoPBRec - -public: - FileStat( const DirEntry& rDirEntry, - FSysAccess nAccess = FSYS_ACCESS_FLOPPY ); - sal_Bool Update( const DirEntry& rDirEntry, - sal_Bool bForceAccess = sal_True ); - - sal_uIntPtr GetError() const { return ERRCODE_TOERROR(nError); } - sal_uIntPtr GetErrorCode() const { return nError; } - - sal_uIntPtr GetSize() const { return nSize; } - - DirEntryKind GetKind() const { return nKindFlags; } - sal_Bool IsKind( DirEntryKind nKind ) const; - - String GetType() const { return aType; } - String GetCreator() const { return aCreator; } - - Date DateCreated() const { return aDateCreated; } - Time TimeCreated() const { return aTimeCreated; } - Date DateModified() const { return aDateModified; } - Time TimeModified() const { return aTimeModified; } - Date DateAccessed() const { return aDateAccessed; } - Time TimeAccessed() const { return aTimeAccessed; } - - static sal_uIntPtr SetReadOnlyFlag( const DirEntry &rEntry, sal_Bool bRO = sal_True ); - static sal_Bool GetReadOnlyFlag( const DirEntry &rEntry ); -}; - -// DirEntry - -class DirEntryStack; - -const char* ImpCheckDirEntry( const void* p ); - -class TOOLS_DLLPUBLIC DirEntry -{ -friend struct DirReader_Impl; - - FileStat* pStat; // optional - - rtl::OString aName; - DirEntry* pParent; - sal_uIntPtr nError; - DirEntryFlag eFlag; - -private: - TOOLS_DLLPRIVATE DirEntry( const rtl::OString& rInitName, - DirEntryFlag aDirFlag ); - - friend class Dir; - friend class FileStat; - friend const char* ImpCheckDirEntry( const void* p ); - - TOOLS_DLLPRIVATE FSysError ImpParseName( const rtl::OString& rIntiName ); - TOOLS_DLLPRIVATE const DirEntry* ImpGetTopPtr() const; - TOOLS_DLLPRIVATE DirEntry* ImpGetTopPtr(); - -protected: - void ImpTrim(); - const rtl::OString& ImpTheName() const; - DirEntryFlag ImpTheFlag() const { return eFlag; }; - DirEntry* ImpChangeParent( DirEntry* pNewParent, sal_Bool bNormalize = sal_True ); - DirEntry* ImpGetParent() { return pParent; } - - FileStat* ImpGetStat() const { return pStat; } - void ImpSetStat( FileStat *p ) { pStat = p; } - -protected: - void SetError( sal_uIntPtr nErr ) { nError = nErr; } - DirEntry* GetParent() { return pParent; } - -public: - DirEntry( DirEntryFlag aDirFlag = FSYS_FLAG_CURRENT ); - DirEntry( const DirEntry& rEntry ); - DirEntry( const rtl::OString& rInitName, - FSysPathStyle eParser = FSYS_STYLE_HOST ); - DirEntry( const String& rInitName, - FSysPathStyle eParser = FSYS_STYLE_HOST ); - ~DirEntry(); - - sal_uIntPtr GetError() const { return nError; } - sal_Bool IsValid() const; - DirEntryFlag GetFlag() const { return eFlag; }; - - void SetExtension( const String& rExt, char cSep = '.' ); - String GetExtension( char cSep = '.' ) const; - void SetName( const String& rName, FSysPathStyle eFormatter = FSYS_STYLE_HOST ); - String GetName( FSysPathStyle eFormatter = FSYS_STYLE_HOST ) const; - String CutName( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); - String GetBase(char cSep = '.' ) const; - DirEntry GetPath() const; - DirEntry GetDevice() const; - String GetVolume() const; - String GetFull( FSysPathStyle eFormatter = FSYS_STYLE_HOST, - sal_Bool bWithDelimiter = sal_False, - sal_uInt16 nMaxChars = STRING_MAXLEN ) const; - - DirEntry TempName( DirEntryKind = FSYS_KIND_NONE ) const; - sal_Bool MakeShortName( const String& rLongName, - DirEntryKind eCreateKind = FSYS_KIND_NONE, - sal_Bool bUseTilde = sal_True, - FSysPathStyle eStyle = FSYS_STYLE_DETECT ); - - bool IsAbs() const; - sal_Bool ToAbs(); - sal_Bool Find( const String& rPfad, char cDelim = 0 ); - - sal_Bool SetCWD( sal_Bool bSloppy = sal_False ) const; - sal_Bool MakeDir( sal_Bool bSloppy = sal_False ) const; - sal_Bool Exists( FSysAccess nAccess = FSYS_ACCESS_FLOPPY ) const; - sal_Bool First(); - - sal_uInt16 Level() const; - const DirEntry& operator []( sal_uInt16 nParentLevel ) const; - sal_Bool Contains( const DirEntry &rSubEntry ) const; - - FSysError Kill( FSysAction nActions = FSYS_ACTION_STANDARD ) const; - - DirEntry& operator =( const DirEntry& rOrigDir ); - DirEntry operator +( const DirEntry& rSubDir ) const; - DirEntry& operator +=( const DirEntry& rSubDir ); - sal_Bool operator ==( const DirEntry& rAnotherDir ) const; - sal_Bool operator !=( const DirEntry& rAnotherDir ) const - { return !(DirEntry::operator==( rAnotherDir )); } - - inline sal_Int32 NameCompareDirect( const DirEntry &rWith ) const - { -#ifdef UNX - return rWith.aName.compareTo(aName); -#else - rtl::OString aThis(rtl::OString(aName).toAsciiLowerCase()); - rtl::OString aWith(rtl::OString(rWith.aName).toAsciiLowerCase()); - return aWith.compareTo(aThis); -#endif - } - - static String GetAccessDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); - static String GetSearchDelimiter( FSysPathStyle eFormatter = FSYS_STYLE_HOST ); -}; - -// Dir - -struct DirReader_Impl; -class TOOLS_DLLPUBLIC Dir : public DirEntry -{ - friend struct DirReader_Impl; - - DirReader_Impl* pReader; // is system-dependent - DirEntryList* pLst; - FSysSortList* pSortLst; // NULL if no sorting requested - FileStatList* pStatLst; // NULL if no stats requested - WildCard aNameMask; - DirEntryKind eAttrMask; - -private: - TOOLS_DLLPRIVATE Dir( const Dir& ); // not allowed - TOOLS_DLLPRIVATE Dir& operator =( const Dir& ); // not allowed - -#ifdef _DIR_CXX - TOOLS_DLLPRIVATE void Construct( DirEntryKind nKind = FSYS_KIND_DIR|FSYS_KIND_FILE ); -#endif - -#ifndef _TOOLS_HXX -protected: - sal_Bool ImpInsertPointReached( const DirEntry& rIsSmaller, - const FileStat& rNewStat, - size_t nCurPos, - size_t nSortIndex ) const; - void ImpSortedInsert( const DirEntry *pNewEntry, - const FileStat *pNewStat ); -#endif - -public: - Dir( const DirEntry& rDirEntry, - DirEntryKind nKind = FSYS_KIND_ALL ); - ~Dir(); - - void Reset(); - sal_uInt16 Scan( sal_uInt16 nCount = 5 ); - size_t Count( sal_Bool bUpdated = sal_True ) const; - - Dir& operator +=( const Dir& rDir ); - DirEntry& operator []( size_t nIndex ) const; -}; - -#if defined(DBG_UTIL) -void FSysTest(); -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/comdep.cxx b/tools/source/fsys/comdep.cxx deleted file mode 100644 index 5366feb6191c..000000000000 --- a/tools/source/fsys/comdep.cxx +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "comdep.hxx" -#include -#include - -DBG_NAMEEX( DirEntry ) - -#if defined UNX -#include "unx.cxx" -#elif defined WNT -#include "wntmsc.cxx" -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/comdep.hxx b/tools/source/fsys/comdep.hxx deleted file mode 100644 index 2b1e135f394b..000000000000 --- a/tools/source/fsys/comdep.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef _COMDEP_HXX -#define _COMDEP_HXX - -#include - -#define ACCESSDELIM(e) ( ( e == FSYS_STYLE_NTFS ) ? "\\" : "/" ) -#define ACCESSDELIM_C(e)(char)\ - ( ( e == FSYS_STYLE_NTFS ) ? '\\' : '/' ) -#define SEARCHDELIM(e) ( (e == FSYS_STYLE_BSD) ? ":" : ";" ) -#define ACTPARENT(e) ".." -#define ACTCURRENT(e) "." - -#if defined UNX -#include "unx.hxx" -#elif defined WNT -#include "wntmsc.hxx" -#endif - -#ifndef LINUX -DIR *opendir( const char* pPfad ); -dirent *readdir( DIR *pDir ); -int closedir( DIR *pDir ); -char *volumeid( const char* pPfad ); -#endif - -struct DirReader_Impl -{ - Dir* pDir; - DIR* pDosDir; - dirent* pDosEntry; - DirEntry* pParent; - String aPath; - rtl::OString aBypass; - sal_Bool bReady; - sal_Bool bInUse; - - DirReader_Impl( Dir &rDir ) - : pDir( &rDir ), - pDosEntry( 0 ), - pParent( 0 ), - aPath(rDir.GetFull()), - bReady ( sal_False ), - bInUse( sal_False ) - { - - // only use the String from Member-Var - -#if defined(UNX) // for further explanation see DirReader_Impl::Read() in unx.cxx - pDosDir = NULL; -#else - aBypass = rtl::OUStringToOString(aPath, osl_getThreadTextEncoding()); - pDosDir = opendir( aBypass.getStr() ); -#endif - - // Determine parents for new DirEntries - pParent = pDir->GetFlag() == FSYS_FLAG_NORMAL || - pDir->GetFlag() == FSYS_FLAG_ABSROOT - ? pDir - : pDir->GetParent(); - - } - - ~DirReader_Impl() - { if( pDosDir ) closedir( pDosDir ); } - - // Init and Read are system-independent - sal_uInt16 Init(); ///< Initializes (and if necessary) reads devices - sal_uInt16 Read(); ///< Reads one entry and appends it if ok -}; - - -#if defined WNT -sal_Bool IsRedirectable_Impl( const rtl::OString &rPath ); -#else -#define IsRedirectable_Impl( rPath ) sal_True -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx deleted file mode 100644 index 4c42f478fb17..000000000000 --- a/tools/source/fsys/dirent.cxx +++ /dev/null @@ -1,1627 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#if !defined UNX -#ifdef WNT -#include -#undef GetObject -#endif -#include -#include -#endif - -#if defined(UNX) -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include "comdep.hxx" -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace osl; -using ::rtl::OUString; - -static rtl::OUString GetSystemTempDirPath_Impl() -{ - rtl::OUString aTmpURL, aPath; - osl::FileBase::getTempDirURL( aTmpURL ); - osl::FileBase::getSystemPathFromFileURL( aTmpURL, aPath ); - return aPath; -} - -int Sys2SolarError_Impl( int nSysErr ) -{ - switch ( nSysErr ) - { -#ifdef WNT - case NO_ERROR: return ERRCODE_NONE; - case ERROR_INVALID_FUNCTION: return ERRCODE_IO_GENERAL; - case ERROR_FILE_NOT_FOUND: return ERRCODE_IO_NOTEXISTS; - case ERROR_PATH_NOT_FOUND: return ERRCODE_IO_NOTEXISTSPATH; - case ERROR_TOO_MANY_OPEN_FILES: return ERRCODE_IO_TOOMANYOPENFILES; - case ERROR_ACCESS_DENIED: return ERRCODE_IO_ACCESSDENIED; - case ERROR_INVALID_HANDLE: return ERRCODE_IO_GENERAL; - case ERROR_NOT_ENOUGH_MEMORY: return ERRCODE_IO_OUTOFMEMORY; - case ERROR_INVALID_BLOCK: return ERRCODE_IO_GENERAL; - case ERROR_BAD_FORMAT: return ERRCODE_IO_WRONGFORMAT; - case ERROR_INVALID_ACCESS: return ERRCODE_IO_ACCESSDENIED; - case ERROR_INVALID_DRIVE: return ERRCODE_IO_INVALIDDEVICE; - case ERROR_CURRENT_DIRECTORY: return ERRCODE_IO_CURRENTDIR; - case ERROR_NOT_SAME_DEVICE: return ERRCODE_IO_NOTSAMEDEVICE; - case ERROR_WRITE_PROTECT: return ERRCODE_IO_CANTWRITE; - case ERROR_BAD_UNIT: return ERRCODE_IO_INVALIDDEVICE; - case ERROR_NOT_READY: return ERRCODE_IO_DEVICENOTREADY; - case ERROR_BAD_COMMAND: return ERRCODE_IO_GENERAL; - case ERROR_CRC: return ERRCODE_IO_BADCRC; - case ERROR_BAD_LENGTH: return ERRCODE_IO_INVALIDLENGTH; - case ERROR_SEEK: return ERRCODE_IO_CANTSEEK; - case ERROR_NOT_DOS_DISK: return ERRCODE_IO_WRONGFORMAT; - case ERROR_SECTOR_NOT_FOUND: return ERRCODE_IO_GENERAL; - case ERROR_WRITE_FAULT: return ERRCODE_IO_CANTWRITE; - case ERROR_READ_FAULT: return ERRCODE_IO_CANTREAD; - case ERROR_GEN_FAILURE: return ERRCODE_IO_GENERAL; - case ERROR_SHARING_VIOLATION: return ERRCODE_IO_LOCKVIOLATION; - case ERROR_LOCK_VIOLATION: return ERRCODE_IO_LOCKVIOLATION; - case ERROR_WRONG_DISK: return ERRCODE_IO_INVALIDDEVICE; - case ERROR_NOT_SUPPORTED: return ERRCODE_IO_NOTSUPPORTED; -#else - case 0: return ERRCODE_NONE; - case ENOENT: return ERRCODE_IO_NOTEXISTS; - case EACCES: return ERRCODE_IO_ACCESSDENIED; - case EEXIST: return ERRCODE_IO_ALREADYEXISTS; - case EINVAL: return ERRCODE_IO_INVALIDPARAMETER; - case EMFILE: return ERRCODE_IO_TOOMANYOPENFILES; - case ENOMEM: return ERRCODE_IO_OUTOFMEMORY; - case ENOSPC: return ERRCODE_IO_OUTOFSPACE; -#endif - } - - OSL_TRACE( "FSys: unknown system error %d occurred", nSysErr ); - return FSYS_ERR_UNKNOWN; -} - -class DirEntryStack -{ -private: - ::std::vector< DirEntry* > maStack; - -public: - DirEntryStack() {}; - ~DirEntryStack(); - - inline void Push( DirEntry *pEntry ); - inline DirEntry* Pop(); - inline DirEntry* Top(); - inline DirEntry* Bottom(); - inline bool Empty(); - inline void Clear(); -}; - -inline void DirEntryStack::Push( DirEntry *pEntry ) -{ - maStack.push_back( pEntry ); -} - -inline DirEntry* DirEntryStack::Pop() -{ - DirEntry* pEntry = NULL; - if ( !maStack.empty() ) { - pEntry = maStack.back(); - maStack.pop_back(); - } - return pEntry; -} - -inline DirEntry* DirEntryStack::Top() -{ - return maStack.empty() ? NULL : maStack.back(); -} - -inline DirEntry* DirEntryStack::Bottom() -{ - return maStack.empty() ? NULL : maStack.front(); -} - -inline bool DirEntryStack::Empty() -{ - return maStack.empty(); -} - -inline void DirEntryStack::Clear() -{ - maStack.clear(); -} - -DBG_NAME( DirEntry ); - -DirEntryStack::~DirEntryStack() -{ - maStack.clear(); -} - -#ifdef DBG_UTIL -/** Check DirEntry for DBG_UTIL - - @param p Pointer to DirEntry - @return char* Error-TExtension or NULL -*/ -const char* ImpCheckDirEntry( const void* p ) -{ - DirEntry* p0 = (DirEntry*)p; - - if ( p0->pParent ) - DBG_CHKOBJ( p0->pParent, DirEntry, ImpCheckDirEntry ); - - return NULL; -} -#endif - -/** Insert "..." for max length of nMaxChars */ -rtl::OString ImplCutPath( const rtl::OString& rStr, sal_Int32 nMax, char cAccDel ) -{ - sal_Int32 nMaxPathLen = nMax; - sal_Bool bInsertPrefix = sal_False; - sal_Int32 nBegin = rStr.indexOf(cAccDel); - rtl::OStringBuffer aCutPath(rStr); - - if( nBegin == -1 ) - nBegin = 0; - else - nMaxPathLen += 2; // Prefix : - - while( aCutPath.getLength() > nMaxPathLen ) - { - sal_Int32 nEnd = aCutPath.toString().indexOf(cAccDel, nBegin + 1); - sal_Int32 nCount; - - if ( nEnd != -1 ) - { - nCount = nEnd - nBegin; - aCutPath.remove(nBegin, nCount); - bInsertPrefix = sal_True; - } - else - break; - } - - if ( aCutPath.getLength() > nMaxPathLen ) - { - for ( sal_Int32 n = nMaxPathLen; n > nMaxPathLen/2; --n ) - { - if (!comphelper::string::isalnumAscii(aCutPath[n])) - { - comphelper::string::truncateToLength(aCutPath, n); - aCutPath.append("..."); - break; - } - } - } - - if ( bInsertPrefix ) - { - rtl::OStringBuffer aIns; - aIns.append(cAccDel).append("..."); - aCutPath.insert(nBegin, aIns.makeStringAndClear()); - } - - return aCutPath.makeStringAndClear(); -} - -FSysError DirEntry::ImpParseName( const rtl::OString& rPfad ) -{ -#if defined(WNT) - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - // put single names onto stack - String aPfad(rtl::OStringToOUString(rPfad, osl_getThreadTextEncoding())); - DirEntryStack aStack; - - do - { - // split name before first "\\", - // if '\\' is at beginning of string, name is set to '\\'. - // ":" also splits the string and belongs to the name. - - // search first occurance of '\\', '/' or ':' - sal_uInt16 nPos; - for ( nPos = 0; - nPos < aPfad.Len() && //?O - aPfad.GetChar(nPos) != '\\' && aPfad.GetChar(nPos) != '/' && //?O - aPfad.GetChar(nPos) != ':'; //?O - nPos++ ) - /* do nothing */; - - // is the name a UNC pathname? - if ( nPos == 0 && aPfad.Len() > 1 && - ( ( aPfad.GetChar(0) == '\\' && aPfad.GetChar(1) == '\\' ) || - ( aPfad.GetChar(0) == '/' && aPfad.GetChar(1) == '/' ) ) ) - { - for ( nPos = 2; aPfad.Len() > nPos; ++nPos ) - if ( aPfad.GetChar(nPos) == '\\' || aPfad.GetChar(nPos) == '/' ) - break; - aName = rtl::OUStringToOString(aPfad.Copy( 2, nPos-2 ), osl_getThreadTextEncoding()); - aStack.Push( new DirEntry( aName, FSYS_FLAG_ABSROOT ) ); - } - // Is the name the root of the current drive? - else if ( nPos == 0 && aPfad.Len() > 0 && - ( aPfad.GetChar(0) == '\\' || aPfad.GetChar(0) == '/' ) ) - { - // Push root directory of current drive - aStack.Push( new DirEntry( FSYS_FLAG_ABSROOT ) ); - } - else - { - // Is the name itself a drive? - if ( nPos < aPfad.Len() && aPfad.GetChar(nPos) == ':' ) - { - aName = rtl::OUStringToOString(aPfad.Copy( 0, nPos + 1 ), osl_getThreadTextEncoding()); - - // Is the name the root of a drive? - if ( (nPos + 1) < aPfad.Len() && - ( aPfad.GetChar(nPos+1) == '\\' || aPfad.GetChar(nPos+1) == '/' ) ) - { - // unsupported if stack not empty or is a Novell format (URL) - if ( !aStack.Empty() || aName.getLength() > 2 ) - { - aName = rPfad; - return FSYS_ERR_MISPLACEDCHAR; - } - // Push as root directory of drive - aStack.Push( new DirEntry( aName, FSYS_FLAG_ABSROOT ) ); - } - else - { - // clear stack if another drive is currently on it - if ( !aStack.Empty() ) - { - rtl::OString aThis(aStack.Bottom()->aName); - aThis = aThis.toAsciiLowerCase(); - rtl::OString aOther(aName); - aOther = aOther.toAsciiLowerCase(); - if (aThis.compareTo(aOther) != 0) - aStack.Clear(); - } - - if ( aStack.Empty() ) - aStack.Push( new DirEntry( aName, FSYS_FLAG_RELROOT ) ); - } - } - // Name is not a drive - else - { - // split the name without seperator - aName = rtl::OUStringToOString(aPfad.Copy( 0, nPos ), osl_getThreadTextEncoding()); - - // Is the name the current directory? - if ( aName == "." ) - /* do nothing */; - - // Is the name the parent directory? - else if ( aName == ".." ) - { - // Is the stack empty, or a parent (or relative root) on it? - if ( ( aStack.Empty() ) || - ( aStack.Top()->eFlag == FSYS_FLAG_PARENT ) || - ( aStack.Top()->eFlag == FSYS_FLAG_RELROOT ) ) - // add leading parent to stack - aStack.Push( new DirEntry( FSYS_FLAG_PARENT ) ); - - // It's an absolute root path - else if ( aStack.Top()->eFlag == FSYS_FLAG_ABSROOT ) - { - // Then there is no parent directory - aName = rPfad; - return FSYS_ERR_NOTEXISTS; - } - else - // Otherwise removee parent TOS - delete aStack.Pop(); - } - - else - { - // add ordinary entries to the stack - DirEntry *pNew = new DirEntry( aName, FSYS_FLAG_NORMAL ); - if ( !pNew->IsValid() ) - { - aName = rPfad; - ErrCode eErr = pNew->GetError(); - delete pNew; - return eErr; - } - aStack.Push( pNew ); - } - } - } - - // determine remainder of path - aPfad.Erase( 0, nPos + 1 ); - while ( aPfad.Len() && ( aPfad.GetChar(0) == '\\' || aPfad.GetChar(0) == '/' ) ) - aPfad.Erase( 0, 1 ); - } - while ( aPfad.Len() ); - - sal_uIntPtr nErr = ERRCODE_NONE; - // Set the main entry itself - if ( aStack.Empty() ) - { - eFlag = FSYS_FLAG_CURRENT; - aName = rtl::OString(); - } - else - { - eFlag = aStack.Top()->eFlag; - aName = aStack.Top()->aName; - nErr = aStack.Top()->nError; - delete aStack.Pop(); - } - - // pop parent entry from stack - DirEntry** pTemp = &pParent; - while ( !aStack.Empty() ) - { - *pTemp = aStack.Pop(); - - // set member pointer to the pParent of the member's own parent - pTemp = &( (*pTemp)->pParent ); - } - - // Does this describe a volume? - if ( !pParent && eFlag == FSYS_FLAG_RELROOT && !aName.isEmpty() ) - eFlag = FSYS_FLAG_VOLUME; - - // use full aName if error code was set - if ( nErr ) - aName = rPfad; - return nErr; -#else - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - // Add single names to the stack - DirEntryStack aStack; - rtl::OString aPfad(rPfad); - do - { - // split names on the first occurance of "/", - // if '/' starts the string, it itself becomes the name - - // search first occurance of "/" - sal_uInt16 nPos; - for ( nPos = 0; - nPos < aPfad.getLength() && aPfad[nPos] != '/'; - nPos++ ) - /* do nothing */; - - // is the name the root of the current drive? - if ( nPos == 0 && !aPfad.isEmpty() && ( aPfad[0] == '/' ) ) - { - // push root directory of current drive to stack - aStack.Push( new DirEntry( FSYS_FLAG_ABSROOT ) ); - } - else - { - // split name without seperator - aName = aPfad.copy(0, nPos); - - // Is the name the current directory? - if ( aName == "." ) - /* do nothing */; - -#ifdef UNX - // Is the name the user's home directory? - else if ( aName == "~" ) - { - DirEntry aHome( String( (const char *) getenv( "HOME" ), osl_getThreadTextEncoding()) ); - for ( sal_uInt16 n = aHome.Level(); n; --n ) - aStack.Push( new DirEntry( aHome[ (sal_uInt16) n-1 ] ) ); - } -#endif - // Is the name the current parent directory? - else if ( aName == ".." ) - { - // Is the stack empty, or a parent (or relative root) is on top? - if ( ( aStack.Empty() ) || ( aStack.Top()->eFlag == FSYS_FLAG_PARENT ) ) - { - // push leading parents to stack - aStack.Push( new DirEntry(rtl::OString(), FSYS_FLAG_PARENT) ); - } - // Is the name an absolute root? - else if ( aStack.Top()->eFlag == FSYS_FLAG_ABSROOT ) - { - // they do not have parent directories - return FSYS_ERR_NOTEXISTS; - } - else - // otherwise remove parent TOS from stack - delete aStack.Pop(); - } - else - { - DirEntry *pNew = NULL; - // push ordinary entries on the stack - pNew = new DirEntry( aName, FSYS_FLAG_NORMAL ); - if ( !pNew->IsValid() ) - { - aName = rPfad; - ErrCode eErr = pNew->GetError(); - delete pNew; - return eErr; - } - aStack.Push( pNew ); - } - } - - // get remainder of path - aPfad = nPos < aPfad.getLength() - ? aPfad.copy(nPos + 1) : rtl::OString(); - while ( !aPfad.isEmpty() && ( aPfad[0] == '/' ) ) - aPfad = aPfad.copy(1); - } - while (!aPfad.isEmpty()); - - // insert main entry itself - if ( aStack.Empty() ) - { - eFlag = FSYS_FLAG_CURRENT; - aName = rtl::OString(); - } - else - { - eFlag = aStack.Top()->eFlag; - aName = aStack.Top()->aName; - delete aStack.Pop(); - } - - // Get parent entries from stack - DirEntry** pTemp = &pParent; - while ( !aStack.Empty() ) - { - *pTemp = aStack.Pop(); - pTemp = &( (*pTemp)->pParent ); - } - - return FSYS_ERR_OK; -#endif -} - -static FSysPathStyle GetStyle( FSysPathStyle eStyle ) -{ - if ( eStyle == FSYS_STYLE_HOST || eStyle == FSYS_STYLE_DETECT ) - return DEFSTYLE; - else - return eStyle; -} - -/** Convert name to match OS norm. */ -void DirEntry::ImpTrim() -{ - // Do not trim wildcard characters - if ( ( aName.indexOf( '*' ) != -1 ) || - ( aName.indexOf( '?' ) != -1 ) || - ( aName.indexOf( ';' ) != -1 ) ) - return; - -#if defined(WNT) - if ( aName.getLength() > 254 ) - { - nError = ERRCODE_IO_MISPLACEDCHAR|ERRCODE_WARNING_MASK; - aName = aName.copy(254); - } -#else - if ( aName.getLength() > 250 ) - { - nError = ERRCODE_IO_MISPLACEDCHAR|ERRCODE_WARNING_MASK; - aName = aName.copy(250); - } -#endif -} - -DirEntry::DirEntry( const rtl::OString& rName, DirEntryFlag eDirFlag ) : - pStat( 0 ), - aName( rName ) -{ - DBG_CTOR( DirEntry, ImpCheckDirEntry ); - - pParent = NULL; - eFlag = eDirFlag; - nError = FSYS_ERR_OK; - - ImpTrim(); -} - -DirEntry::DirEntry( const DirEntry& rOrig ) : - pStat( rOrig.pStat ? new FileStat(*rOrig.pStat) : 0 ), - aName( rOrig.aName ) -{ - DBG_CTOR( DirEntry, ImpCheckDirEntry ); - - eFlag = rOrig.eFlag; - nError = rOrig.nError; - - if ( rOrig.pParent ) - { - pParent = new DirEntry( *rOrig.pParent ); - } - else - { - pParent = NULL; - } -} - -DirEntry::DirEntry( const String& rInitName, FSysPathStyle eStyle ) : - pStat( 0 ) -{ - DBG_CTOR( DirEntry, ImpCheckDirEntry ); - - (void) eStyle; // only used for DBG_UTIL - - pParent = NULL; - - // faster check for empty string - if ( !rInitName.Len()) - { - eFlag = FSYS_FLAG_CURRENT; - nError = FSYS_ERR_OK; - return; - } - - rtl::OString aTmpName(rtl::OUStringToOString(rInitName, osl_getThreadTextEncoding())); - if (aTmpName.matchIgnoreAsciiCase(rtl::OString("file:"))) - { - DBG_WARNING( "File URLs are not permitted but accepted" ); - aTmpName = rtl::OUStringToOString(INetURLObject( rInitName ).PathToFileName(), osl_getThreadTextEncoding()); -#ifdef DBG_UTIL - eStyle = FSYS_STYLE_HOST; -#endif - } - else - { - ::rtl::OUString aTmp; - ::rtl::OUString aOInitName; - if ( FileBase::getFileURLFromSystemPath( OUString( rInitName ), aTmp ) == FileBase::E_None ) - { - aOInitName = OUString( rInitName ); - aTmpName = rtl::OUStringToOString(aOInitName, osl_getThreadTextEncoding()); - } - -#ifdef DBG_UTIL - if (eStyle == FSYS_STYLE_HOST && aTmpName.indexOf( "://" ) != -1) - { - rtl::OStringBuffer aErr("DirEntries akzeptieren nur File URLS: "); - aErr.append(aTmpName); - DBG_WARNING(aErr.getStr()); - } -#endif - } - - nError = ImpParseName( aTmpName ); - - if ( nError != FSYS_ERR_OK ) - eFlag = FSYS_FLAG_INVALID; -} - -DirEntry::DirEntry( const rtl::OString& rInitName, FSysPathStyle eStyle ) : - pStat( 0 ) -{ - DBG_CTOR( DirEntry, ImpCheckDirEntry ); - - (void) eStyle; // only used for DBG_UTIL - - pParent = NULL; - - // faster check for empty string - if ( rInitName.isEmpty() ) - { - eFlag = FSYS_FLAG_CURRENT; - nError = FSYS_ERR_OK; - return; - } - - rtl::OString aTmpName( rInitName ); - if (aTmpName.matchIgnoreAsciiCase(rtl::OString("file:"))) - { - DBG_WARNING( "File URLs are not permitted but accepted" ); - aTmpName = rtl::OUStringToOString(INetURLObject( rInitName ).PathToFileName(), osl_getThreadTextEncoding()); -#ifdef DBG_UTIL - eStyle = FSYS_STYLE_HOST; -#endif - } -#ifdef DBG_UTIL - else - { - if( eStyle == FSYS_STYLE_HOST && rInitName.indexOf("://") != -1 ) - { - rtl::OStringBuffer aErr("DirEntries akzeptieren nur File URLS: "); - aErr.append(rInitName); - DBG_WARNING(aErr.getStr()); - } - } -#endif - - nError = ImpParseName( aTmpName ); - - if ( nError != FSYS_ERR_OK ) - eFlag = FSYS_FLAG_INVALID; -} - -DirEntry::DirEntry( DirEntryFlag eDirFlag ) : - pStat( 0 ) -{ - DBG_CTOR( DirEntry, ImpCheckDirEntry ); - - eFlag = eDirFlag; - nError = ( eFlag == FSYS_FLAG_INVALID ) ? FSYS_ERR_UNKNOWN : FSYS_ERR_OK; - pParent = NULL; -} - -DirEntry::~DirEntry() -{ - DBG_DTOR( DirEntry, ImpCheckDirEntry ); - - delete pParent; - - delete pStat; -} - -const DirEntry* DirEntry::ImpGetTopPtr() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - const DirEntry *pTemp = this; - while ( pTemp->pParent ) - pTemp = pTemp->pParent; - - return pTemp; -} - -DirEntry* DirEntry::ImpGetTopPtr() -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - DirEntry *pTemp = this; - while ( pTemp->pParent ) - pTemp = pTemp->pParent; - - return pTemp; -} - -DirEntry* DirEntry::ImpChangeParent( DirEntry* pNewParent, sal_Bool bNormalize ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - DirEntry *pTemp = pParent; - if ( bNormalize && pNewParent && - pNewParent->eFlag == FSYS_FLAG_RELROOT && pNewParent->aName.isEmpty() ) - { - pParent = 0; - delete pNewParent; - } - else - pParent = pNewParent; - - return pTemp; -} - -sal_Bool DirEntry::Exists( FSysAccess nAccess ) const -{ - static osl::Mutex aLocalMutex; - osl::MutexGuard aGuard( aLocalMutex ); - if ( !IsValid() ) - return sal_False; - -#if defined WNT - // get special file names from system - if ( aName.equalsIgnoreAsciiCase("CLOCK$") || - aName.equalsIgnoreAsciiCase("CON") || - aName.equalsIgnoreAsciiCase("AUX") || - aName.equalsIgnoreAsciiCase("COM1") || - aName.equalsIgnoreAsciiCase("COM2") || - aName.equalsIgnoreAsciiCase("COM3") || - aName.equalsIgnoreAsciiCase("COM4") || - aName.equalsIgnoreAsciiCase("LPT1") || - aName.equalsIgnoreAsciiCase("LPT2") || - aName.equalsIgnoreAsciiCase("LPT3") || - aName.equalsIgnoreAsciiCase("NUL") || - aName.equalsIgnoreAsciiCase("PRN") ) - return sal_True; -#endif - - DirEntryKind eKind = FileStat( *this, nAccess ).GetKind(); - if ( eKind & ( FSYS_KIND_FILE | FSYS_KIND_DIR ) ) - { - return sal_True; - } - -#if defined WNT - if ( 0 != ( eKind & FSYS_KIND_DEV ) ) - { - return DRIVE_EXISTS( ImpGetTopPtr()->aName[0] ); - } -#endif - - return 0 != ( eKind & ( FSYS_KIND_FILE | FSYS_KIND_DIR ) ); -} - -sal_Bool DirEntry::First() -{ - String aUniPathName( GetPath().GetFull() ); - rtl::OString aPathName(rtl::OUStringToOString(aUniPathName, osl_getThreadTextEncoding())); - - DIR *pDir = opendir(aPathName.getStr()); - if ( pDir ) - { - WildCard aWildeKarte(rtl::OStringToOUString(CMP_LOWER(aName), osl_getThreadTextEncoding())); - for ( dirent* pEntry = readdir( pDir ); - pEntry; - pEntry = readdir( pDir ) ) - { - rtl::OString aFound(pEntry->d_name); - if (aWildeKarte.Matches(rtl::OStringToOUString(CMP_LOWER(aFound), osl_getThreadTextEncoding()))) - { - aName = aFound; - closedir( pDir ); - return sal_True; - } - } - closedir( pDir ); - } - return sal_False; -} - -String DirEntry::GetFull( FSysPathStyle eStyle, sal_Bool bWithDelimiter, - sal_uInt16 nMaxChars ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - rtl::OStringBuffer aBuf; - eStyle = GetStyle( eStyle ); - if ( pParent ) - { - if ( ( pParent->eFlag == FSYS_FLAG_ABSROOT || - pParent->eFlag == FSYS_FLAG_RELROOT || - pParent->eFlag == FSYS_FLAG_VOLUME ) ) - { - aBuf.append(rtl::OUStringToOString(pParent->GetName( eStyle ), osl_getThreadTextEncoding())); - aBuf.append(rtl::OUStringToOString(GetName( eStyle ), osl_getThreadTextEncoding())); - } - else - { - aBuf.append(rtl::OUStringToOString(pParent->GetFull( eStyle ), osl_getThreadTextEncoding())); - aBuf.append(ACCESSDELIM_C(eStyle)); - aBuf.append(rtl::OUStringToOString(GetName( eStyle ), osl_getThreadTextEncoding())); - } - } - else - { - aBuf.append(rtl::OUStringToOString(GetName(eStyle), osl_getThreadTextEncoding())); - } - - //! Hack - if ( bWithDelimiter ) - if ( aBuf[aBuf.getLength()-1] != ACCESSDELIM_C(eStyle) ) - aBuf.append(ACCESSDELIM_C(eStyle)); - - rtl::OString aRet = aBuf.makeStringAndClear(); - - // HACK - if ( nMaxChars < STRING_MAXLEN ) - aRet = ImplCutPath( aRet, nMaxChars, ACCESSDELIM_C(eStyle) ); - - return rtl::OStringToOUString(aRet, osl_getThreadTextEncoding()); -} - -DirEntry DirEntry::GetPath() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( pParent ) - return DirEntry( *pParent ); - - return DirEntry(); -} - -String DirEntry::GetExtension( char cSep ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - const char *p0 = aName.getStr(); - const char *p1 = p0 + aName.getLength() - 1; - while ( p1 >= p0 && *p1 != cSep ) - p1--; - - if ( p1 >= p0 ) - { - // found a cSep at position p1 - return rtl::OStringToOUString(aName.copy(p1 - p0 + 1), - osl_getThreadTextEncoding()); - } - - return String(); -} - -String DirEntry::GetBase( char cSep ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - const char *p0 = aName.getStr(); - const char *p1 = p0 + aName.getLength() - 1; - while ( p1 >= p0 && *p1 != cSep ) - p1--; - - if ( p1 >= p0 ) - { - // found a cSep at position p1 - return rtl::OStringToOUString(aName.copy(0, p1 - p0), - osl_getThreadTextEncoding()); - - } - // did not find a cSep - return rtl::OStringToOUString(aName, osl_getThreadTextEncoding()); -} - -String DirEntry::GetName( FSysPathStyle eStyle ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - rtl::OStringBuffer aRet; - eStyle = GetStyle( eStyle ); - - switch( eFlag ) - { - case FSYS_FLAG_PARENT: - aRet.append(ACTPARENT(eStyle)); - break; - - case FSYS_FLAG_ABSROOT: - { - aRet.append(aName); - aRet.append(ACCESSDELIM_C(eStyle)); - break; - } - - case FSYS_FLAG_INVALID: - case FSYS_FLAG_VOLUME: - { - aRet.append(aName); - break; - } - - case FSYS_FLAG_RELROOT: - if ( aName.isEmpty() ) - { - aRet.append(ACTCURRENT(eStyle)); - break; - } - - default: - aRet.append(aName); - break; - } - - return rtl::OStringToOUString(aRet.makeStringAndClear(), - osl_getThreadTextEncoding()); -} - -bool DirEntry::IsAbs() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - -#ifdef UNX - return ( pParent ? pParent->IsAbs() : eFlag == FSYS_FLAG_ABSROOT ); -#else - return ( pParent ? pParent->IsAbs() : eFlag == FSYS_FLAG_ABSROOT && !aName.isEmpty() ); -#endif -} - -String DirEntry::CutName( FSysPathStyle eStyle ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - eStyle = GetStyle( eStyle ); - - String aOldName( GetName( eStyle ) ); - - if ( pParent ) - { - DirEntry *pOldParent = pParent; - if ( pOldParent ) - { - pParent = pOldParent->pParent; - eFlag = pOldParent->eFlag; - aName = pOldParent->aName; - pOldParent->pParent = NULL; - delete pOldParent; - } - else - { - eFlag = FSYS_FLAG_CURRENT; - aName = rtl::OString(); - } - } - else - { - eFlag = FSYS_FLAG_CURRENT; - aName = rtl::OString(); - delete pParent; - pParent = NULL; - } - - return aOldName; -} - -sal_Bool DirEntry::operator==( const DirEntry& rEntry ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - // test whether the contents are textual the same - - if ( nError && ( nError == rEntry.nError ) ) - return sal_True; - if ( nError || rEntry.nError || - ( eFlag == FSYS_FLAG_INVALID ) || - ( rEntry.eFlag == FSYS_FLAG_INVALID ) ) - return sal_False; - - const DirEntry *pThis = (DirEntry *)this; - const DirEntry *pWith = (DirEntry *)&rEntry; - while( pThis && pWith && (pThis->eFlag == pWith->eFlag) ) - { - if ( CMP_LOWER(pThis->aName) != CMP_LOWER(pWith->aName) ) - break; - pThis = pThis->pParent; - pWith = pWith->pParent; - } - - return ( !pThis && !pWith ); -} - -DirEntry& DirEntry::operator=( const DirEntry& rEntry ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( this == &rEntry ) - return *this; - if ( rEntry.nError != FSYS_ERR_OK ) { - OSL_FAIL("Zuweisung mit invalidem DirEntry"); - nError = rEntry.nError; - return *this; - } - - // set name and type, but keep refs - aName = rEntry.aName; - eFlag = rEntry.eFlag; - nError = FSYS_ERR_OK; - - DirEntry *pOldParent = pParent; - if ( rEntry.pParent ) - pParent = new DirEntry( *rEntry.pParent ); - else - pParent = NULL; - - if ( pOldParent ) - delete pOldParent; - return *this; -} - -DirEntry DirEntry::operator+( const DirEntry& rEntry ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); -#ifdef DBG_UTIL - static sal_Bool bTested = sal_False; - if ( !bTested ) - { - bTested = sal_True; - FSysTest(); - } -#endif - - const DirEntry *pEntryTop = rEntry.ImpGetTopPtr(); - const DirEntry *pThisTop = ImpGetTopPtr(); - - if ( - (eFlag == FSYS_FLAG_RELROOT && aName.isEmpty()) || - ( - (!pEntryTop->aName.isEmpty() || - ((rEntry.Level()>1)?(rEntry[rEntry.Level()-2].aName.equalsIgnoreAsciiCase(RFS_IDENTIFIER)):sal_False)) - && - (pEntryTop->eFlag == FSYS_FLAG_ABSROOT || - pEntryTop->eFlag == FSYS_FLAG_RELROOT || - pEntryTop->eFlag == FSYS_FLAG_VOLUME) - ) - ) - { - return rEntry; - } - - // something + "." (=> pEntryTop == &rEntry) - if (pEntryTop->eFlag == FSYS_FLAG_RELROOT && pEntryTop->aName.isEmpty()) - { - DBG_ASSERT( pEntryTop == &rEntry, "DirEntry::op+ buggy" ); - return *this; - } - - // root += ".." (=> impossible) - if ( pEntryTop->eFlag == FSYS_FLAG_PARENT && pThisTop == this && - ( eFlag == FSYS_FLAG_ABSROOT ) ) - return DirEntry( FSYS_FLAG_INVALID ); - - // something += abs (=> only append device if existant) - if ( pEntryTop->eFlag == FSYS_FLAG_ABSROOT ) - { - rtl::OString aDevice; - if ( pThisTop->eFlag == FSYS_FLAG_ABSROOT ) - aDevice = pThisTop->aName; - DirEntry aRet = rEntry; - if ( !aDevice.isEmpty() ) - aRet.ImpGetTopPtr()->aName = aDevice; - return aRet; - } - - // something += ".." (=> break apart) - if ( eFlag == FSYS_FLAG_NORMAL && pEntryTop->eFlag == FSYS_FLAG_PARENT ) - { - String aConcated( GetFull() ); - aConcated += ACCESSDELIM_C(FSYS_STYLE_HOST); - aConcated += rEntry.GetFull(); - return DirEntry( aConcated ); - } - - // otherwise append consecutively - DirEntry aRet( rEntry ); - DirEntry *pTop = aRet.ImpGetTopPtr(); - pTop->pParent = new DirEntry( *this ); - - return aRet; -} - -DirEntry &DirEntry::operator+=( const DirEntry& rEntry ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - return *this = *this + rEntry; -} - -String DirEntry::GetAccessDelimiter( FSysPathStyle eFormatter ) -{ - return rtl::OUString( ACCESSDELIM_C( GetStyle( eFormatter ) ) ); -} - -void DirEntry::SetExtension( const String& rExtension, char cSep ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - // do not set extensions for drives - if(eFlag == FSYS_FLAG_ABSROOT) - { - nError = FSYS_ERR_NOTSUPPORTED; - return; - } - - rtl::OStringBuffer aBuf(aName); - - // search cSep within aName - const sal_Char *p0 = aBuf.getStr(); - const sal_Char *p1 = p0 + aBuf.getLength() - 1; - while ( p1 >= p0 && *p1 != cSep ) - p1--; - if ( p1 >= p0 ) - { - // found a cSep on position p1 - - sal_Int32 n = static_cast( - p1 - p0 + 1 - ( rExtension.Len() ? 0 : 1 )); - - aBuf.remove(n, aBuf.getLength()-n); - } - else if ( rExtension.Len() ) - { - // no cSep was found - aBuf.append(cSep); - } - - aBuf.append(rtl::OUStringToOString(rExtension, - osl_getThreadTextEncoding())); - - aName = aBuf.makeStringAndClear(); -} - -void DirEntry::SetName( const String& rName, FSysPathStyle eFormatter ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( eFormatter == FSYS_STYLE_HOST || eFormatter == FSYS_STYLE_DETECT ) - eFormatter = DEFSTYLE; - sal_Char cAccDelim(ACCESSDELIM_C(eFormatter)); - - if ( (eFlag != FSYS_FLAG_NORMAL) || - (aName.indexOf(':') != -1) || - (aName.indexOf(cAccDelim) != -1) ) - { - eFlag = FSYS_FLAG_INVALID; - } - else - { - aName = rtl::OUStringToOString(rName, osl_getThreadTextEncoding()); - } -} - -sal_Bool DirEntry::Find( const String& rPfad, char cDelim ) -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( ImpGetTopPtr()->eFlag == FSYS_FLAG_ABSROOT ) - return sal_True; - - sal_Bool bWild = aName.indexOf( '*' ) != -1 || - aName.indexOf( '?' ) != -1; - - if ( !cDelim ) - cDelim = SEARCHDELIM(DEFSTYLE)[0]; - - rtl::OString aThis = rtl::OStringBuffer() - .append(ACCESSDELIM_C(DEFSTYLE)) - .append(rtl::OUStringToOString(GetFull(), - osl_getThreadTextEncoding())) - .makeStringAndClear(); - sal_Int32 nIndex = 0; - do - { - rtl::OStringBuffer aPath(rtl::OUStringToOString(rPfad, - osl_getThreadTextEncoding()).getToken( 0, cDelim, nIndex )); - - if ( aPath.getLength() ) - { - if (aPath[aPath.getLength()-1] == ACCESSDELIM_C(DEFSTYLE)) - aPath.remove(aPath.getLength()-1, 1); - aPath.append(aThis); - DirEntry aEntry(rtl::OStringToOUString( - aPath.makeStringAndClear(), osl_getThreadTextEncoding())); - if ( aEntry.ToAbs() && - ( ( !bWild && aEntry.Exists() ) || ( bWild && aEntry.First() ) ) ) - { - (*this) = aEntry; - return sal_True; - } - } - } - while ( nIndex >= 0 ); - return sal_False; -} - -#ifndef UNX -DirEntry DirEntry::GetDevice() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - const DirEntry *pTop = ImpGetTopPtr(); - - if ( ( pTop->eFlag == FSYS_FLAG_ABSROOT || pTop->eFlag == FSYS_FLAG_RELROOT ) && - !pTop->aName.isEmpty() ) - return DirEntry( pTop->aName, FSYS_FLAG_VOLUME ); - else - return DirEntry( rtl::OString(), FSYS_FLAG_INVALID ); -} -#endif - -String DirEntry::GetSearchDelimiter( FSysPathStyle eFormatter ) -{ - return rtl::OStringToOUString(rtl::OString(SEARCHDELIM(GetStyle(eFormatter))), osl_getThreadTextEncoding()); -} - -namespace -{ - struct TempNameBase_Impl : public rtl::Static< DirEntry, TempNameBase_Impl > {}; -} - -DirEntry DirEntry::TempName( DirEntryKind eKind ) const -{ - // use base-temp-dir if necessary - const DirEntry &rEntry = TempNameBase_Impl::get(); - if ( !pParent && FSYS_FLAG_CURRENT != rEntry.eFlag && FSYS_FLAG_ABSROOT != eFlag ) - { - DirEntry aFactory( rEntry ); - aFactory += GetName(); - return aFactory.TempName(); - } - - rtl::OString aDirName; - char *ret_val; - size_t i; - - // determine Directory, Prefix and Extension - char pfx[6]; - char ext[5]; - const char *dir; - const char *pWild = strchr( aName.getStr(), '*' ); - if ( !pWild ) - pWild = strchr( aName.getStr(), '?' ); - - if ( pWild ) - { - if ( pParent ) - aDirName = rtl::OUStringToOString(pParent->GetFull(), osl_getThreadTextEncoding()); - strncpy( pfx, aName.getStr(), Min( (int)5, (int)(pWild-aName.getStr()) ) ); - pfx[ pWild-aName.getStr() ] = 0; - const char *pExt = strchr( pWild, '.' ); - if ( pExt ) - { - strncpy( ext, pExt, 4 ); - ext[4] = 0; - } - else - strcpy( ext, ".tmp" ); - } - else - { - aDirName = rtl::OUStringToOString(GetFull(), osl_getThreadTextEncoding()); - strcpy( pfx, "lo" ); - strcpy( ext, ".tmp" ); - } - dir = aDirName.getStr(); - - OString sTempRoot; - if ( eFlag == FSYS_FLAG_CURRENT || ( !pParent && pWild ) ) - { - rtl::OUString aPath = GetSystemTempDirPath_Impl(); - sTempRoot = OUStringToOString( aPath, osl_getThreadTextEncoding() ); - dir = sTempRoot.getStr(); - } - - DirEntry aRet(FSYS_FLAG_INVALID); - i = strlen(dir); - // need to add ?\\? + prefix + number + pid + .ext + '\0' -# define TMPNAME_SIZE ( 1 + 5 + 5 + 10 + 4 + 1 ) - ret_val = new char[i + TMPNAME_SIZE ]; - if (ret_val) - { - strcpy(ret_val,dir); - - /* Make sure directory ends with a separator */ -#if defined(WNT) - if ( i>0 && ret_val[i-1] != '\\' && ret_val[i-1] != '/' && - ret_val[i-1] != ':') - ret_val[i++] = '\\'; -#elif defined UNX - if (i>0 && ret_val[i-1] != '/') - ret_val[i++] = '/'; -#else -#error unknown operating system -#endif - - strncpy(ret_val + i, pfx, 5); - ret_val[i + 5] = '\0'; /* strncpy doesn't put a 0 if more */ - i = strlen(ret_val); /* than 'n' chars. */ - - /* Prefix can have 5 chars, leaving 3 for numbers. 26 ** 3 == 17576 - * Welcome to the 21st century, we can have longer filenames now ;) - * New format: pfx + "5 char milli/micro second res" + "current pid" + ".tmp" - */ -#ifdef _WIN32 - /* Milliseconds !! */ - static unsigned long u = GetTickCount(); - unsigned long mypid = static_cast(_getpid()); -#else - /* Microseconds !! */ - static unsigned long u = clock(); - unsigned long mypid = static_cast(getpid()); -#endif - for ( unsigned long nOld = u; ++u != nOld; ) /* Hae??? */ - { - u %= 100000; /* on *NIX repeats every 100ms, maybe less if CLOCKS_PER_SEC > 10^6 */ - snprintf(ret_val+i, TMPNAME_SIZE, "%05lu%lu", u, mypid); - - strcat(ret_val,ext); - - if ( FSYS_KIND_FILE == eKind ) - { - SvFileStream aStream( String( ret_val, osl_getThreadTextEncoding()), - STREAM_WRITE|STREAM_SHARE_DENYALL ); - if ( aStream.IsOpen() ) - { - aStream.Seek( STREAM_SEEK_TO_END ); - if ( 0 == aStream.Tell() ) - { - aRet = DirEntry( String( ret_val, osl_getThreadTextEncoding())); - break; - } - aStream.Close(); - } - } - else - { - // Redirect - String aRetVal(ret_val, osl_getThreadTextEncoding()); - String aRedirected (aRetVal); - if ( FSYS_KIND_DIR == eKind ) - { - if (0 == _mkdir(rtl::OUStringToOString(aRedirected, osl_getThreadTextEncoding()).getStr())) - { - aRet = DirEntry( aRetVal ); - break; - } - } - else - { -#if defined(UNX) - if (access(rtl::OUStringToOString(aRedirected, osl_getThreadTextEncoding()).getStr(), F_OK)) - { - aRet = DirEntry( aRetVal ); - break; - } -#else - struct stat aStat; - if (stat(rtl::OUStringToOString(aRedirected, osl_getThreadTextEncoding()).getStr(), &aStat)) - { - aRet = DirEntry( aRetVal ); - break; - } -#endif - } - } - } - - delete[] ret_val; - ret_val = 0; - } - - return aRet; -} - -const DirEntry &DirEntry::operator[]( sal_uInt16 nParentLevel ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - //TPF: maybe to be implemented (FastFSys) - - const DirEntry *pRes = this; - while ( pRes && nParentLevel-- ) - pRes = pRes->pParent; - - return *pRes; -} - -sal_Bool DirEntry::MakeDir( sal_Bool bSloppy ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - // fast check if exists - if ( FileStat( *this ).IsKind( FSYS_KIND_DIR ) ) - return sal_True; - if ( bSloppy && pParent ) - if ( FileStat( *pParent ).IsKind( FSYS_KIND_DIR ) ) - return sal_True; - - const DirEntry *pNewDir = bSloppy ? pParent : this; - if ( pNewDir ) - { - // Create path to dir - if ( pNewDir->pParent && !pNewDir->pParent->MakeDir(sal_False) ) - return sal_False; - - // create dir ourselves - if ( pNewDir->eFlag == FSYS_FLAG_ABSROOT || - pNewDir->eFlag == FSYS_FLAG_VOLUME ) - return sal_True; - else - { - //? nError = ??? - if ( FileStat( *pNewDir ).IsKind( FSYS_KIND_DIR ) ) - return sal_True; - else - { - String aDirName(pNewDir->GetFull()); - rtl::OString bDirName(rtl::OUStringToOString(aDirName, osl_getThreadTextEncoding())); - -#ifdef WIN32 - SetLastError(0); -#endif - sal_Bool bResult = (0 == _mkdir(bDirName.getStr())); - if ( !bResult ) - { -#ifdef WIN32 - ((DirEntry *)this)->SetError( Sys2SolarError_Impl( GetLastError() ) ); -#else - ((DirEntry *)this)->SetError( Sys2SolarError_Impl( errno ) ); -#endif - } - - return bResult; - } - } - } - return sal_True; -} - -FSysError DirEntry::Kill( FSysAction nActions ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - FSysError eError = FSYS_ERR_OK; - - // Terminate name string with two '0' - String aTmpName( GetFull() ); - rtl::OString bTmpName(rtl::OUStringToOString(aTmpName, osl_getThreadTextEncoding())); - - char *pName = new char[bTmpName.getLength()+2]; - strcpy( pName, bTmpName.getStr() ); - pName[bTmpName.getLength()+1] = (char) 0; - - // delete read-only files as well - sal_Bool isReadOnly = FileStat::GetReadOnlyFlag(*this); - if (isReadOnly) - { - FileStat::SetReadOnlyFlag(*this, sal_False); - } - - // directory? - if ( FileStat( *this ).IsKind(FSYS_KIND_DIR) ) - { - // Delete recursively? - if ( FSYS_ACTION_RECURSIVE == (nActions & FSYS_ACTION_RECURSIVE) ) - { - Dir aDir( *this, FSYS_KIND_DIR|FSYS_KIND_FILE ); - for ( sal_uInt16 n = 0; eError == FSYS_ERR_OK && n < aDir.Count(); ++n ) - { - const DirEntry &rSubDir = aDir[n]; - DirEntryFlag flag = rSubDir.GetFlag(); - if ( flag != FSYS_FLAG_CURRENT && flag != FSYS_FLAG_PARENT ) - eError = rSubDir.Kill(nActions); - } - } - - // remove Dir myself -#ifdef WIN32 - SetLastError(0); -#endif - if ( eError == FSYS_ERR_OK && 0 != _rmdir( (char*) pName ) ) - { - // Change CWD if deletion failed -#ifdef WIN32 - eError = Sys2SolarError_Impl( GetLastError() ); -#else - eError = Sys2SolarError_Impl( errno ); -#endif - if ( eError ) - { - GetPath().SetCWD(); -#ifdef WIN32 - SetLastError(0); -#endif - if (_rmdir( (char*) pName) != 0) - { -#ifdef WIN32 - eError = Sys2SolarError_Impl( GetLastError() ); -#else - eError = Sys2SolarError_Impl( errno ); -#endif - } - else - { - eError = FSYS_ERR_OK; - } - } - } - } - else - { - if ( FSYS_ACTION_USERECYCLEBIN == (nActions & FSYS_ACTION_USERECYCLEBIN) ) - { -#if defined(WNT) - SHFILEOPSTRUCT aOp; - aOp.hwnd = 0; - aOp.wFunc = FO_DELETE; - aOp.pFrom = pName; - aOp.pTo = 0; - aOp.fFlags = FOF_ALLOWUNDO|FOF_SILENT|FOF_NOCONFIRMATION; - aOp.hNameMappings = 0; - aOp.lpszProgressTitle = 0; - eError = Sys2SolarError_Impl( SHFileOperation( &aOp ) ); -#else - eError = ERRCODE_IO_NOTSUPPORTED; -#endif - } - else - { -#ifdef WIN32 - SetLastError(0); -#endif - if ( 0 != _unlink( (char*) pName ) ) - { -#ifdef WIN32 - eError = Sys2SolarError_Impl( GetLastError() ); -#else - eError = Sys2SolarError_Impl( errno ); -#endif - } - else - { - eError = ERRCODE_NONE; - } - } - } - - // restore original read-only flag upon error - if ( isReadOnly && (eError!=ERRCODE_NONE) ) - { - FileStat::SetReadOnlyFlag(*this, isReadOnly); - } - - delete[] pName; - return eError; -} - -/** Check if rSubEntry is (in)directly beneath *this */ -sal_Bool DirEntry::Contains( const DirEntry &rSubEntry ) const -{ - DBG_ASSERT( IsAbs() && rSubEntry.IsAbs(), "must be absolute entries" ); - - sal_uInt16 nThisLevel = Level(); - sal_uInt16 nSubLevel = rSubEntry.Level(); - if ( nThisLevel < nSubLevel ) - { - for ( ; nThisLevel; --nThisLevel, --nSubLevel ) - if ( (*this)[nThisLevel-1] != rSubEntry[nSubLevel-1] ) - return sal_False; - return sal_True; - } - return sal_False; -} - -sal_uInt16 DirEntry::Level() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - sal_uInt16 nLevel = 0; - const DirEntry *pRes = this; - while ( pRes ) - { - pRes = pRes->pParent; - nLevel++; - } - - return nLevel; -} - -sal_Bool DirEntry::IsValid() const -{ - return (nError == FSYS_ERR_OK); -} - -#if defined(DBG_UTIL) -void FSysTest() -{ -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/fstat.cxx b/tools/source/fsys/fstat.cxx deleted file mode 100644 index a0bbae1159d7..000000000000 --- a/tools/source/fsys/fstat.cxx +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifdef UNX -#include -#endif - -#include -#include - -#include "comdep.hxx" -#include - -FileStat::FileStat( const DirEntry& rDirEntry, FSysAccess nAccess ) -: // don't use Default-Ctors! - aDateCreated( sal_uIntPtr(0) ), - aTimeCreated( sal_uIntPtr(0) ), - aDateModified( sal_uIntPtr(0) ), - aTimeModified( sal_uIntPtr(0) ), - aDateAccessed( sal_uIntPtr(0) ), - aTimeAccessed( sal_uIntPtr(0) ) -{ - sal_Bool bCached = FSYS_ACCESS_CACHED == (nAccess & FSYS_ACCESS_CACHED); - sal_Bool bFloppy = FSYS_ACCESS_FLOPPY == (nAccess & FSYS_ACCESS_FLOPPY); - - const FileStat *pStatFromDir = bCached ? rDirEntry.ImpGetStat() : 0; - if ( pStatFromDir ) - { - nError = pStatFromDir->nError; - nKindFlags = pStatFromDir->nKindFlags; - nSize = pStatFromDir->nSize; - aCreator = pStatFromDir->aCreator; - aType = pStatFromDir->aType; - aDateCreated = pStatFromDir->aDateCreated; - aTimeCreated = pStatFromDir->aTimeCreated; - aDateModified = pStatFromDir->aDateModified; - aTimeModified = pStatFromDir->aTimeModified; - aDateAccessed = pStatFromDir->aDateAccessed; - aTimeAccessed = pStatFromDir->aTimeAccessed; - } - else - - Update( rDirEntry, bFloppy ); -} - -sal_Bool FileStat::IsKind( DirEntryKind nKind ) const -{ - sal_Bool bRet = ( ( nKind == FSYS_KIND_UNKNOWN ) && - ( nKindFlags == FSYS_KIND_UNKNOWN ) ) || - ( ( nKindFlags & nKind ) == nKind ); - return bRet; -} - -sal_Bool FileStat::GetReadOnlyFlag( const DirEntry &rEntry ) -{ - rtl::OString aFPath(rtl::OUStringToOString(rEntry.GetFull(), osl_getThreadTextEncoding())); -#if defined WNT - DWORD nRes = GetFileAttributes( (LPCTSTR) aFPath.getStr() ); - return ULONG_MAX != nRes && - ( FILE_ATTRIBUTE_READONLY & nRes ) == FILE_ATTRIBUTE_READONLY; -#elif defined UNX - /* could we stat the object? */ - struct stat aBuf; - if (stat(aFPath.getStr(), &aBuf)) - return sal_False; - /* jupp, is writable for user? */ - return((aBuf.st_mode & S_IWUSR) != S_IWUSR); -#else - return sal_False; -#endif -} - -sal_uIntPtr FileStat::SetReadOnlyFlag( const DirEntry &rEntry, sal_Bool bRO ) -{ - - rtl::OString aFPath(rtl::OUStringToOString(rEntry.GetFull(), osl_getThreadTextEncoding())); - -#if defined WNT - DWORD nRes = GetFileAttributes( (LPCTSTR) aFPath.getStr() ); - if ( ULONG_MAX != nRes ) - nRes = SetFileAttributes( (LPCTSTR) aFPath.getStr(), - ( nRes & ~FILE_ATTRIBUTE_READONLY ) | - ( bRO ? FILE_ATTRIBUTE_READONLY : 0 ) ); - return ( ULONG_MAX == nRes ) ? ERRCODE_IO_UNKNOWN : 0; -#elif defined UNX - /* first, stat the object to get permissions */ - struct stat aBuf; - if (stat(aFPath.getStr(), &aBuf)) - return ERRCODE_IO_NOTEXISTS; - /* set or clear write bit for user */ - mode_t nMode; - if (bRO) - { - nMode = aBuf.st_mode & ~(S_IWUSR | S_IWGRP | S_IWOTH); - } - else - nMode = aBuf.st_mode | S_IWUSR; - /* change it on fs */ - if (chmod(aFPath.getStr(), nMode)) - { - switch (errno) - { - case EPERM : - case EROFS : - return ERRCODE_IO_ACCESSDENIED; - default : - return ERRCODE_IO_NOTEXISTS; - } - } - else - return ERRCODE_NONE; -#else - return ERRCODE_IO_NOTSUPPORTED; -#endif -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/tdir.cxx b/tools/source/fsys/tdir.cxx deleted file mode 100644 index 5e6ed052f819..000000000000 --- a/tools/source/fsys/tdir.cxx +++ /dev/null @@ -1,416 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#define _DIR_CXX - -#include -#include -#include -#include - -#include "comdep.hxx" -#include - -DBG_NAME( Dir ) - -/// determines whether insertion is required -sal_Bool Dir::ImpInsertPointReached( const DirEntry& rNewEntry, - const FileStat& rNewStat, - size_t nCurPos, size_t nSortIndex ) const -{ -#define VALUE( nKindFlags ) \ - ( ( FSYS_KIND_FILE | FSYS_KIND_DIR | FSYS_KIND_DEV | \ - FSYS_KIND_CHAR | FSYS_KIND_BLOCK ) & nKindFlags ) - - if ( pLst->empty() ) - return sal_True; - - FSysSort nSort = (*pSortLst)[ nSortIndex ]; - FileStat *pOldStat = NULL; - DirEntry *pCurLstObj = (*pLst)[ nCurPos ]; - if ( pStatLst ) - pOldStat = (*pStatLst)[ nCurPos ]; - - switch( nSort ) - { - case FSYS_SORT_NAME: - case (FSYS_SORT_NAME | FSYS_SORT_ASCENDING): - if ( pCurLstObj->aName > rNewEntry.aName ) - return sal_True; - if ( !(pCurLstObj->aName == rNewEntry.aName) ) - return sal_False; - break; - case (FSYS_SORT_NAME | FSYS_SORT_DESCENDING): - if ( pCurLstObj->aName < rNewEntry.aName ) - return sal_True; - if ( !(pCurLstObj->aName == rNewEntry.aName) ) - return sal_False; - break; - - case FSYS_SORT_EXT: - case (FSYS_SORT_EXT | FSYS_SORT_ASCENDING): - { - if ( pCurLstObj->GetExtension() > rNewEntry.GetExtension() ) - return sal_True; - if ( !(pCurLstObj->GetExtension() == rNewEntry.GetExtension()) ) - return sal_False; - break; - } - case (FSYS_SORT_EXT | FSYS_SORT_DESCENDING): - { - if ( pCurLstObj->GetExtension() < rNewEntry.GetExtension() ) - return sal_True; - if ( !(pCurLstObj->GetExtension() == rNewEntry.GetExtension()) ) - return sal_False; - break; - } - - case FSYS_SORT_KIND: - case (FSYS_SORT_KIND | FSYS_SORT_ASCENDING ): - if ( VALUE(pOldStat->nKindFlags) > VALUE(rNewStat.nKindFlags) ) - return sal_True; - if ( !(VALUE(pOldStat->nKindFlags) == VALUE(rNewStat.nKindFlags)) ) - return sal_False; - break; - case (FSYS_SORT_KIND | FSYS_SORT_DESCENDING): - if ( VALUE(pOldStat->nKindFlags) < VALUE(rNewStat.nKindFlags) ) - return sal_True; - if ( !(VALUE(pOldStat->nKindFlags) == VALUE(rNewStat.nKindFlags)) ) - return sal_False; - break; - - case FSYS_SORT_SIZE: - case (FSYS_SORT_SIZE | FSYS_SORT_ASCENDING): - if ( pOldStat->nSize > rNewStat.nSize ) - return sal_True; - if ( !(pOldStat->nSize == rNewStat.nSize) ) - return sal_False; - break; - case (FSYS_SORT_SIZE | FSYS_SORT_DESCENDING): - if ( pOldStat->nSize < rNewStat.nSize ) - return sal_True; - if ( !(pOldStat->nSize == rNewStat.nSize) ) - return sal_False; - break; - - case FSYS_SORT_MODIFYED: - case (FSYS_SORT_MODIFYED | FSYS_SORT_ASCENDING): - if ( (pOldStat->aDateModified >= rNewStat.aDateModified) && - (pOldStat->aTimeModified > rNewStat.aTimeModified) ) - return sal_True; - if ( !((pOldStat->aDateModified == rNewStat.aDateModified) && - (pOldStat->aTimeModified == rNewStat.aTimeModified)) ) - return sal_False; - break; - case (FSYS_SORT_MODIFYED | FSYS_SORT_DESCENDING): - if ( (pOldStat->aDateModified <= rNewStat.aDateModified) && - (pOldStat->aTimeModified < rNewStat.aTimeModified) ) - return sal_True; - if ( !((pOldStat->aDateModified == rNewStat.aDateModified) && - (pOldStat->aTimeModified == rNewStat.aTimeModified)) ) - return sal_False; - break; - - case FSYS_SORT_CREATED: - case (FSYS_SORT_CREATED | FSYS_SORT_ASCENDING): - if ( (pOldStat->aDateCreated >= rNewStat.aDateCreated) && - (pOldStat->aTimeCreated > rNewStat.aTimeCreated) ) - return sal_True; - if ( !((pOldStat->aDateCreated == rNewStat.aDateCreated) && - (pOldStat->aTimeCreated == rNewStat.aTimeCreated)) ) - return sal_False; - break; - case (FSYS_SORT_CREATED | FSYS_SORT_DESCENDING): - if ( (pOldStat->aDateCreated <= rNewStat.aDateCreated) && - (pOldStat->aTimeCreated < rNewStat.aTimeCreated) ) - return sal_True; - if ( !((pOldStat->aDateCreated == rNewStat.aDateCreated) && - (pOldStat->aTimeCreated == rNewStat.aTimeCreated)) ) - return sal_False; - break; - - case FSYS_SORT_ACCESSED: - case (FSYS_SORT_ACCESSED | FSYS_SORT_ASCENDING): - if ( (pOldStat->aDateAccessed >= rNewStat.aDateAccessed) && - (pOldStat->aTimeAccessed > rNewStat.aTimeAccessed) ) - return sal_True; - if ( !((pOldStat->aDateAccessed == rNewStat.aDateAccessed) && - (pOldStat->aTimeAccessed == rNewStat.aTimeAccessed)) ) - return sal_False; - break; - case (FSYS_SORT_ACCESSED | FSYS_SORT_DESCENDING): - if ( (pOldStat->aDateAccessed <= rNewStat.aDateAccessed) && - (pOldStat->aTimeAccessed < rNewStat.aTimeAccessed) ) - return sal_True; - if ( !((pOldStat->aDateAccessed == rNewStat.aDateAccessed) && - (pOldStat->aTimeAccessed == rNewStat.aTimeAccessed)) ) - return sal_False; - break; - default: /* Kann nicht sein */; - } - - if ( nSortIndex == ( pSortLst->size() - 1 ) ) - return sal_True; - else - return ImpInsertPointReached( rNewEntry, rNewStat, - nCurPos, nSortIndex + 1 ); -#undef VALUE -} - -/// Insert as sorted -void Dir::ImpSortedInsert( const DirEntry *pNewEntry, const FileStat *pNewStat ) -{ - // special case: no sorting required - if ( !pSortLst ) { - pLst->push_back( (DirEntry*)pNewEntry ); - return; - } - - for ( size_t i = 0, n = pLst->size(); i < n; ++i ) - { - if ( ImpInsertPointReached( *pNewEntry, *pNewStat, i, 0 ) ) - { - if ( pStatLst ) { - FileStatList::iterator it = pStatLst->begin(); - ::std::advance( it, i ); - pStatLst->insert( it, (FileStat*)pNewStat ); - } - DirEntryList::iterator it = pLst->begin(); - ::std::advance( it, i ); - pLst->insert( it, (DirEntry*)pNewEntry ); - return; - } - } - - if ( pStatLst ) - pStatLst->push_back( (FileStat*)pNewStat ); - pLst->push_back( (DirEntry*)pNewEntry ); -} - -/// shared implementation of CTORs -void Dir::Construct( DirEntryKind nKindFlags ) -{ - pLst = NULL; - pSortLst = NULL; - pStatLst = NULL; - eAttrMask = nKindFlags; - rtl::OString aTempName(rtl::OUStringToOString(GetName(), osl_getThreadTextEncoding())); - if (aTempName.indexOf('*') != -1 || aTempName.indexOf('?') != -1) - { -#if defined( WNT ) - rtl::OString aTStr(rtl::OUStringToOString(CutName(), osl_getThreadTextEncoding())); - char* pBuffer = new char[aTStr.getLength()+1]; - strcpy( pBuffer, aTStr.getStr() ); - CharLowerBuff( pBuffer, aTStr.getLength() ); - aNameMask = WildCard( String(pBuffer, osl_getThreadTextEncoding()), ';' ); - delete [] pBuffer; -#else - aNameMask = WildCard( CutName(), ';' ); -#endif - } - else - aNameMask.setGlob(rtl::OUString(static_cast('*'))); -} - -void Dir::Reset() -{ - // remove old Reader if necessary - if ( pReader && pReader->bInUse ) - DELETEZ(pReader); - - // Remove all DirEntries from List and free memory - if ( pLst ) - { - for ( size_t i = 0, n = pLst->size(); i < n; ++i ) { - delete (*pLst)[ i ]; - } - pLst->clear(); - } - else - pLst = new DirEntryList(); - - // Remove old File-Stats - if ( pStatLst ) - { - for ( size_t i = 0, n = pStatLst->size(); i < n; ++i ) { - delete (*pStatLst)[ i ]; - } - pStatLst->clear(); - delete pStatLst; - pStatLst = NULL; - } - - // Does sorting require FileStats? - if ( pSortLst ) - { - for ( size_t i = 0, n = pSortLst->size(); i < n; ++i ) { - if ( (*pSortLst)[ i ] - & ( FSYS_SORT_KIND | FSYS_SORT_SIZE | FSYS_SORT_CREATED - | FSYS_SORT_MODIFYED | FSYS_SORT_ACCESSED - ) - ) { - pStatLst = new FileStatList(); - break; - } - } - } - - // Create new reader if necessary - if ( !pReader ) - pReader = new DirReader_Impl( *this ); - - // Does the directory exist at all? -#if !defined(UNX) //explanation: see DirReader_Impl::Read() in unx.cxx - if( !pReader->pDosDir ) - { - nError = FSYS_ERR_NOTADIRECTORY; - DELETEZ( pReader ); - return; - } -#endif -} - -sal_uInt16 Dir::Scan( sal_uInt16 nCount ) -{ - - sal_uInt16 nRead = 0; // Number of read entries in this round - - // did not complete - if ( pReader ) - { - // is this a new reader? - if ( pLst->empty() ) - { - // Scan directories - pReader->bInUse = sal_True; - nRead = pReader->Init(); - } - - // continue reading - while ( nRead <= nCount && !pReader->bReady ) - nRead = nRead + pReader->Read(); - - // done? - if ( pReader && pReader->bReady ) - DELETEZ( pReader ); - } - - // Return read entry count - return nRead; -} - -Dir::Dir( const DirEntry& rDirEntry, DirEntryKind nKindFlags ): - DirEntry( rDirEntry ), - pReader( 0 ) -{ - DBG_CTOR( Dir, NULL ); - - Construct( nKindFlags ); - Reset(); -} - -Dir::~Dir() -{ - DBG_DTOR( Dir, NULL ); - - // Remove all DirEntries and free memory - if ( pLst ) - { - for ( size_t i = 0, n = pLst->size(); i < n; ++i ) { - delete (*pLst)[ i ]; - } - pLst->clear(); - delete pLst; - } - - // Remove all Sorts from list and free memory - if ( pSortLst ) - { - pSortLst->clear(); - delete pSortLst; - } - - // Remove all FileStats from list and free memory - if ( pStatLst ) - { - for ( size_t i = 0, n = pStatLst->size(); i < n; ++i ) { - delete (*pStatLst)[ i ]; - } - pStatLst->clear(); - delete pStatLst; - } - - delete pReader; -} - -DirEntry& Dir::operator[] ( size_t nIndex ) const -{ - DBG_ASSERT( nIndex < Count(), "Dir::operator[] : nIndex > Count()" ); - - DirEntry *pEntry = (*pLst)[ nIndex ]; - return *pEntry; -} - -Dir& Dir::operator+=( const Dir& rDir ) -{ - // Read the rest of the directory - if ( pReader ) - Scan( USHRT_MAX ); - DBG_ASSERT( !rDir.pReader, "Dir::+= with incomplete Dir" ); - - if ( !pLst ) - pLst = new DirEntryList(); - - // FileStats required by sorting criteria? - sal_Bool bStat = sal_False; - if ( pSortLst ) { - for ( size_t i = 0, n = pSortLst->size(); i < n && !bStat; ++i ) { - if ( (*pSortLst)[ i ] - & ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE - | FSYS_SORT_ACCESSED | FSYS_SORT_KIND - ) - ) { - bStat = sal_True; - } - } - } - FileStat* stat = NULL; - for ( size_t nNr = 0; nNr < rDir.Count(); nNr++ ) - { - if ( bStat ) - { - if ( rDir.pStatLst ) - stat = new FileStat( *(*rDir.pStatLst)[ nNr ] ); - else - stat = new FileStat( rDir[nNr] ); - } - ImpSortedInsert( new DirEntry( rDir[nNr] ), stat ); - } - return *this; -} - -size_t Dir::Count( sal_Bool bUpdated ) const -{ - // Read the rest of the directory - if ( bUpdated && pReader ) - ((Dir*)this)->Scan( USHRT_MAX ); - - return pLst == NULL ? 0 : pLst->size(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx index 24557f5e4366..46f1bedd53bf 100644 --- a/tools/source/fsys/tempfile.cxx +++ b/tools/source/fsys/tempfile.cxx @@ -18,7 +18,6 @@ */ #include -#include "comdep.hxx" #include #include diff --git a/tools/source/fsys/unx.cxx b/tools/source/fsys/unx.cxx deleted file mode 100644 index f26882cd0d5e..000000000000 --- a/tools/source/fsys/unx.cxx +++ /dev/null @@ -1,366 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include -#include -#include -#include -#include - -#if defined LINUX || defined ANDROID -#include -#define mnttab mntent -#elif defined AIX -#include -#include -extern "C" int mntctl( int cmd, size_t size, char* buf ); -#elif defined(NETBSD) -#include -#elif defined(FREEBSD) || defined(MACOSX) || defined(OPENBSD) || \ - defined(DRAGONFLY) || defined(IOS) -struct mnttab -{ - char *mnt_dir; - char *mnt_fsname; -}; -#else -#include -#endif - -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - -#include -#include -#include "comdep.hxx" -#include - -#if defined SOLARIS -#define MOUNTSPECIAL mnt_special -#define MOUNTPOINT mnt_mountp -#define MOUNTOPTS mnt_mntopts -#define MOUNTFS mnt_fstype -#else -#define MOUNTSPECIAL mnt_fsname -#define MOUNTPOINT mnt_dir -#define MOUNTFS mnt_type -#endif - -struct mymnttab -{ - dev_t mountdevice; - rtl::OString mountspecial; - rtl::OString mountpoint; - rtl::OString mymnttab_filesystem; - mymnttab() { mountdevice = (dev_t) -1; } -}; - -#if defined(NETBSD) || defined(FREEBSD) || defined(MACOSX) || \ - defined(OPENBSD) || defined(DRAGONFLY) || defined(IOS) -sal_Bool GetMountEntry(dev_t /* dev */, struct mymnttab * /* mytab */ ) -{ - DBG_WARNING( "Sorry, not implemented: GetMountEntry" ); - return sal_False; -} -#elif defined AIX -sal_Bool GetMountEntry(dev_t dev, struct mymnttab *mytab) -{ - int bufsize; - if (mntctl (MCTL_QUERY, sizeof bufsize, (char*) &bufsize)) - return sal_False; - - char* buffer = (char *)malloc( bufsize * sizeof(char) ); - if (mntctl (MCTL_QUERY, bufsize, buffer) != -1) - for ( char* vmt = buffer; - vmt < buffer + bufsize; - vmt += ((struct vmount*)vmt)->vmt_length) - { - struct stat buf; - char *mountp = vmt2dataptr((struct vmount*)vmt, VMT_STUB); - if ((stat (mountp, &buf) != -1) && (buf.st_dev == dev)) - { - mytab->mountpoint = mountp; - mytab->mountspecial - = vmt2dataptr((struct vmount*)vmt, VMT_HOSTNAME); - if (mytab->mountspecial.Len()) - mytab->mountspecial += ':'; - mytab->mountspecial - += vmt2dataptr((struct vmount*)vmt, VMT_OBJECT); - mytab->mountdevice = dev; - free( buffer ); - return sal_True; - } - } - free( buffer ); - return sal_False; -} -#else -static sal_Bool GetMountEntry(dev_t dev, struct mymnttab *mytab) -{ -#if defined SOLARIS - FILE *fp = fopen (MNTTAB, "r"); - if (! fp) - return sal_False; - struct mnttab mnt[1]; - while (getmntent (fp, mnt) != -1) -#elif defined AIX || defined ANDROID - FILE *fp = NULL; - if (! fp) - return sal_False; - struct mnttab mnt[1]; - while ( 0 ) -#else - FILE *fp = setmntent (MOUNTED, "r"); - if (! fp) - return sal_False; - struct mnttab *mnt; - while ((mnt = getmntent (fp)) != NULL) -#endif - { -#ifdef SOLARIS - char *devopt = NULL; - if ( mnt->MOUNTOPTS != NULL ) - devopt = strstr (mnt->MOUNTOPTS, "dev="); - if (devopt) - { - if (dev != (dev_t) strtoul (devopt+4, NULL, 16)) - continue; - } - else -#endif - { - struct stat buf; - if ((stat (mnt->MOUNTPOINT, &buf) == -1) || (buf.st_dev != dev)) - continue; - } -# ifdef LINUX - // #61624# Opening file with setmntent and closing with fclose fails for glibc-2.1 - endmntent( fp ); -# else - fclose (fp); -# endif - mytab->mountspecial = mnt->MOUNTSPECIAL; - mytab->mountpoint = mnt->MOUNTPOINT; - mytab->mountdevice = dev; - mytab->mymnttab_filesystem = mnt->MOUNTFS; - - return sal_True; - } -# ifdef LINUX - /* #61624# see above */ - endmntent( fp ); -# else - fclose (fp); -# endif - return sal_False; -} -#endif - -sal_Bool DirEntry::ToAbs() -{ - if ( FSYS_FLAG_VOLUME == eFlag ) - { - eFlag = FSYS_FLAG_ABSROOT; - return sal_True; - } - - if ( IsAbs() ) - return sal_True; - - char sBuf[MAXPATHLEN + 1]; - *this = DirEntry( String( getcwd( sBuf, MAXPATHLEN ), osl_getThreadTextEncoding() ) ) + *this; - return IsAbs(); -} - -namespace { struct mymnt : public rtl::Static< mymnttab, mymnt > {}; } - -String DirEntry::GetVolume() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - DirEntry aPath( *this ); - aPath.ToAbs(); - - struct stat buf; - while (stat(rtl::OUStringToOString(aPath.GetFull(), osl_getThreadTextEncoding()).getStr(), &buf)) - { - if (aPath.Level() <= 1) - return String(); - aPath = aPath [1]; - } - mymnttab &rMnt = mymnt::get(); - return ((buf.st_dev == rMnt.mountdevice || GetMountEntry(buf.st_dev, &rMnt)) ? - rtl::OStringToOUString(rMnt.mountspecial, osl_getThreadTextEncoding()) : - rtl::OUString()); -} - -sal_Bool DirEntry::SetCWD( sal_Bool bSloppy ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - rtl::OString aPath(rtl::OUStringToOString(GetFull(), osl_getThreadTextEncoding())); - if (!chdir(aPath.getStr())) - { - return sal_True; - } - else - { - if (bSloppy && !chdir(aPath.getStr())) - { - return sal_True; - } - else - { - return sal_False; - } - } -} - -sal_uInt16 DirReader_Impl::Init() -{ - return 0; -} - -sal_uInt16 DirReader_Impl::Read() -{ - if (!pDosDir) - { - pDosDir = opendir(rtl::OUStringToOString(aPath, osl_getThreadTextEncoding()).getStr()); - } - - if (!pDosDir) - { - bReady = sal_True; - return 0; - } - - // List directories and dirs - if ( ( pDir->eAttrMask & FSYS_KIND_DIR || pDir->eAttrMask & FSYS_KIND_FILE ) && - ( ( pDosEntry = readdir( pDosDir ) ) != NULL ) ) - { - String aD_Name(pDosEntry->d_name, osl_getThreadTextEncoding()); - if ( pDir->aNameMask.Matches( aD_Name ) ) - { - DirEntryFlag eFlag = - 0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT - : 0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT - : FSYS_FLAG_NORMAL; - DirEntry *pTemp = new DirEntry(rtl::OString(pDosEntry->d_name), eFlag); - if ( pParent ) - pTemp->ImpChangeParent( new DirEntry( *pParent ), sal_False); - FileStat aStat( *pTemp ); - if ( ( ( ( pDir->eAttrMask & FSYS_KIND_DIR ) && - ( aStat.IsKind( FSYS_KIND_DIR ) ) ) || - ( ( pDir->eAttrMask & FSYS_KIND_FILE ) && - !( aStat.IsKind( FSYS_KIND_DIR ) ) ) ) && - !( pDir->eAttrMask & FSYS_KIND_VISIBLE && - pDosEntry->d_name[0] == '.' ) ) - { - if ( pDir->pStatLst ) // Does sorting criteria require status? - pDir->ImpSortedInsert( pTemp, new FileStat( aStat ) ); - else - pDir->ImpSortedInsert( pTemp, NULL ); - return 1; - } - else - delete pTemp; - } - } - else - bReady = sal_True; - return 0; -} - -sal_Bool FileStat::Update( const DirEntry& rDirEntry, SAL_UNUSED_PARAMETER sal_Bool ) -{ - - nSize = 0; - nKindFlags = 0; - aCreator.Erase(); - aType.Erase(); - aDateCreated = Date(0); - aTimeCreated = Time(0); - aDateModified = Date(0); - aTimeModified = Time(0); - aDateAccessed = Date(0); - aTimeAccessed = Time(0); - - if ( !rDirEntry.IsValid() ) - { - nError = FSYS_ERR_NOTEXISTS; - return sal_False; - } - - // Special case if DirEntry is root - if ( rDirEntry.eFlag == FSYS_FLAG_ABSROOT ) - { - nKindFlags = FSYS_KIND_DIR; - nError = FSYS_ERR_OK; - return sal_True; - } - - struct stat aStat; - rtl::OString aPath(rtl::OUStringToOString(rDirEntry.GetFull(), osl_getThreadTextEncoding())); - if (stat(aPath.getStr(), &aStat)) - { - // pl: #67851# - // do this here, because an existing filename containing "wildcards" - // should be handled as a file, not a wildcard - // note that this is not a solution, since filenames containing special characters - // are handled badly across the whole Office - - // special treatment if name contains wildcards - rtl::OString aTempName(rtl::OUStringToOString(rDirEntry.GetName(), osl_getThreadTextEncoding())); - if ( aTempName.indexOf('?') != -1 || - aTempName.indexOf('*') != -1 || - aTempName.indexOf(';') != -1 ) - { - nKindFlags = FSYS_KIND_WILD; - nError = FSYS_ERR_OK; - return sal_True; - } - - nError = FSYS_ERR_NOTEXISTS; - return sal_False; - } - - nError = FSYS_ERR_OK; - nSize = aStat.st_size; - - nKindFlags = FSYS_KIND_UNKNOWN; - if ( ( aStat.st_mode & S_IFDIR ) == S_IFDIR ) - nKindFlags = nKindFlags | FSYS_KIND_DIR; - if ( ( aStat.st_mode & S_IFREG ) == S_IFREG ) - nKindFlags = nKindFlags | FSYS_KIND_FILE; - if ( ( aStat.st_mode & S_IFCHR ) == S_IFCHR ) - nKindFlags = nKindFlags | FSYS_KIND_DEV | FSYS_KIND_CHAR; - if ( ( aStat.st_mode & S_IFBLK ) == S_IFBLK ) - nKindFlags = nKindFlags | FSYS_KIND_DEV | FSYS_KIND_BLOCK; - if ( nKindFlags == FSYS_KIND_UNKNOWN ) - nKindFlags = nKindFlags | FSYS_KIND_FILE; - - Unx2DateAndTime( aStat.st_ctime, aTimeCreated, aDateCreated ); - Unx2DateAndTime( aStat.st_mtime, aTimeModified, aDateModified ); - Unx2DateAndTime( aStat.st_atime, aTimeAccessed, aDateAccessed ); - - return sal_True; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/unx.hxx b/tools/source/fsys/unx.hxx deleted file mode 100644 index bcc86ec16238..000000000000 --- a/tools/source/fsys/unx.hxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef _unx_hxx -#define _unx_hxx - -#include -#include -#include -#include -#include -#include - -#define _mkdir(p) mkdir(p, 0777) -#define _rmdir rmdir -#define _chdir chdir -#define _unlink unlink -#define _getcwd getcwd -#define _access access - -#define DEFSTYLE FSYS_STYLE_BSD - -#define CMP_LOWER(s) (s) -#define LOWER(aString) (aString.Lower()) - -#include - -inline Time Unx2Time( time_t nTime ) -{ - tm atm; - tm *pTime; - pTime = localtime_r( &nTime, &atm ); - return Time( pTime->tm_hour, - pTime->tm_min, - pTime->tm_sec ); -} - -inline Date Unx2Date( time_t nDate ) -{ - tm atm; - tm *pTime; - pTime = localtime_r( &nDate, &atm ); - return Date( pTime->tm_mday, - pTime->tm_mon + 1, - pTime->tm_year + 1900 ); -} - -inline void Unx2DateAndTime( time_t nDate, Time& rTime, Date& rDate ) -{ - tm atm; - tm *pTime; - pTime = localtime_r( &nDate, &atm ); - rTime = Time( pTime->tm_hour, pTime->tm_min, pTime->tm_sec ); - rDate = Date( pTime->tm_mday, pTime->tm_mon + 1, pTime->tm_year + 1900 ); -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/wntmsc.cxx b/tools/source/fsys/wntmsc.cxx deleted file mode 100644 index c6cf063abdfa..000000000000 --- a/tools/source/fsys/wntmsc.cxx +++ /dev/null @@ -1,770 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifdef _MSC_VER -#pragma warning (push,1) -#endif - -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning (pop) -#endif - -#include "wntmsc.hxx" -#include -#include -#include -#include - -#define INIT_WIN32_FIND_DATAA { 0, { 0, 0 }, { 0, 0 }, { 0, 0 }, 0, 0, 0, 0, { 0 }, { 0 } } - -int Sys2SolarError_Impl( int nSysErr ); - -rtl::OString Upper_Impl(const rtl::OString &rStr) -{ - std::vector aBuffer(rStr.getLength()); - memcpy(&aBuffer[0], rStr.getStr(), rStr.getLength()); - CharUpperBuff(&aBuffer[0], rStr.getLength()); - return rtl::OString(&aBuffer[0], rStr.getLength()); -} - -DIR *opendir( const char* pPfad ) -{ - DIR *pDir = new DIR; - if ( pDir ) - pDir->p = (char*) pPfad; - return pDir; -} - -struct dirent *readdir( DIR *pDir ) -{ - bool bOk = false; - if ( pDir->p ) - { - char *pBuf = new char[ strlen( pDir->p ) + 5 ]; - if ( pBuf ) - { - // if string ends with *.*, seperate with "\\" (unless it exists) - strcpy( pBuf, pDir->p ); - strcat( pBuf, "\\*.*" + ( *(pBuf + strlen( pBuf ) - 1 ) == '\\' ) ); - CharUpperBuff( pBuf, strlen(pBuf) ); - pDir->h = FindFirstFile( pBuf, &pDir->aDirEnt ); - bOk = pDir->h != INVALID_HANDLE_VALUE; - pDir->p = NULL; - delete [] pBuf; - } - else - pDir->h = INVALID_HANDLE_VALUE; - } - else - { - bOk = FindNextFile( pDir->h, &pDir->aDirEnt ); - } - - return bOk ? &pDir->aDirEnt : NULL; -} - -int closedir( DIR *pDir ) -{ - sal_Bool bOk = sal_False; - if ( pDir ) - { - bOk = 0 != pDir->p || FindClose( pDir->h ); - delete pDir; - } - return bOk; -} - -sal_Bool DirEntry::ToAbs() -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( FSYS_FLAG_VOLUME == eFlag ) - { - eFlag = FSYS_FLAG_ABSROOT; - return sal_True; - } - - if ( IsAbs() ) - { - return sal_True; - } - - - char sBuf[256]; - char *pOld; - rtl::OString aFullName(rtl::OUStringToOString(GetFull(), - osl_getThreadTextEncoding())); - if ( GetFullPathName(aFullName.getStr(), 256, sBuf, &pOld) > 511 ) - return sal_False; - - *this = DirEntry( String(sBuf, osl_getThreadTextEncoding() )); - return sal_True; -} - -String DirEntry::GetVolume() const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - String aRet; - const DirEntry *pTop = ImpGetTopPtr(); - rtl::OString aTopName = rtl::OString(pTop->aName).toAsciiLowerCase(); - - if ( ( pTop->eFlag == FSYS_FLAG_ABSROOT || - pTop->eFlag == FSYS_FLAG_RELROOT || - pTop->eFlag == FSYS_FLAG_VOLUME ) - && aTopName != "a:" - && aTopName != "b:" && Exists() ) - { - char sFileSysName[256]; - char sVolumeName[256]; - DWORD nVolumeNameLen = 256; - DWORD nSerial[2]; - DWORD nMaxCompLen[2]; - DWORD nFlags[2]; - rtl::OString aRootDir = pTop->aName; - - // Try network device first due to slow samba drives - if ( !WNetGetConnection( aRootDir.getStr(), - sVolumeName, &nVolumeNameLen ) ) - aRet = String( sVolumeName, osl_getThreadTextEncoding()); - - // Append volume name for local drives - if ( aRet.Len() == 0 ) - { - aRootDir += "\\"; - if ( GetVolumeInformation( aRootDir.getStr(), - sVolumeName, 256, - (LPDWORD) &nSerial, (LPDWORD) &nMaxCompLen, - (LPDWORD) &nFlags, sFileSysName, 256 ) ) - aRet = String( sVolumeName, osl_getThreadTextEncoding()); - } - } - - return aRet; -} - -sal_Bool DirEntry::SetCWD( sal_Bool bSloppy ) const -{ - DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); - - if ( eFlag == FSYS_FLAG_CURRENT && !aName.getLength() ) - return sal_True; - - if ( SetCurrentDirectory(rtl::OUStringToOString(GetFull(), osl_getThreadTextEncoding()).getStr()) ) - { - return sal_True; - } - - if ( bSloppy && pParent && - SetCurrentDirectory(rtl::OUStringToOString(pParent->GetFull(), osl_getThreadTextEncoding()).getStr()) ) - { - return sal_True; - } - - return sal_False; -} - -USHORT DirReader_Impl::Init() -{ - // List Block-devices? - if ( pDir->eAttrMask & FSYS_KIND_BLOCK ) - { - // remember CWD - DirEntry aCurrentDir; - aCurrentDir.ToAbs(); - - // Check for existence and conformity to flags - USHORT nRead = 0; - char sDrive[3] = { '?', ':', 0 }; - char sRoot[4] = { '?', ':', '\\', 0 }; - for ( char c = 'a'; c <= 'z'; c++ ) - { - sDrive[0] = c; - sRoot[0] = c; - DirEntry* pDrive = new DirEntry( sDrive, FSYS_FLAG_VOLUME ); - if ( pDir->aNameMask.Matches( String(rtl::OStringToOUString(sDrive, osl_getThreadTextEncoding())) ) && GetDriveType( sRoot ) != 1 ) - { - if ( pDir->pStatLst ) // Status required by sorting criteria? - { - FileStat *pNewStat = new FileStat( *pDrive ); - pDir->ImpSortedInsert( pDrive, pNewStat ); - } - else - pDir->ImpSortedInsert( pDrive, NULL ); - ++nRead; - } - else - delete pDrive; - } - - // restore CWD - aCurrentDir.SetCWD(); - return nRead; - } - - return 0; -} - -USHORT DirReader_Impl::Read() -{ - // List directories and Files? - if ( ( pDir->eAttrMask & FSYS_KIND_DIR || - pDir->eAttrMask & FSYS_KIND_FILE ) && - ( ( pDosEntry = readdir( pDosDir ) ) != NULL ) ) - { - // Do not distinguish between lower-/upper-case letters - size_t nLen = strlen(pDosEntry->d_name); - std::vector aBuffer(nLen); - memcpy(&aBuffer[0], pDosEntry->d_name, nLen); - CharLowerBuff(&aBuffer[0], nLen); - rtl::OString aLowerName(&aBuffer[0], nLen); - - // check Flags - sal_Bool bIsDirAndWantsDir = - ( ( pDir->eAttrMask & FSYS_KIND_DIR ) && -#ifdef ICC - ( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") || - strcmp(pDosEntry->d_name,"..")) ) ); -#else - ( pDosEntry->d_type & DOS_DIRECT ) ); -#endif - sal_Bool bIsFileAndWantsFile = - ( ( pDir->eAttrMask & FSYS_KIND_FILE ) && -#ifdef ICC - !( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") || - strcmp(pDosEntry->d_name,"..")) ) && -#else - !( pDosEntry->d_type & DOS_DIRECT ) && -#endif - !( pDosEntry->d_type & DOS_VOLUMEID ) ); - sal_Bool bIsHidden = (pDosEntry->d_type & _A_HIDDEN) != 0; - sal_Bool bWantsHidden = 0 == ( pDir->eAttrMask & FSYS_KIND_VISIBLE ); - if ( ( bIsDirAndWantsDir || bIsFileAndWantsFile ) && - ( bWantsHidden || !bIsHidden ) && - pDir->aNameMask.Matches( rtl::OStringToOUString(aLowerName, osl_getThreadTextEncoding()) ) ) - { -#ifdef DBG_UTIL - DbgOutf( "%s %s flags:%x found", - pDosEntry->d_name, - bIsFileAndWantsFile ? "file" : "dir", - pDosEntry->d_type ); -#endif - DirEntryFlag eFlag = - 0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT - : 0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT - : FSYS_FLAG_NORMAL; - DirEntry *pTemp = new DirEntry( rtl::OString(pDosEntry->d_name), - eFlag ); - - pTemp->ImpSetStat( new FileStat( (void*) pDosDir ) ); - - if ( pParent ) - pTemp->ImpChangeParent( new DirEntry( *pParent ), sal_False ); - if ( pDir->pStatLst ) // Status required by sorting criteria? - { - FileStat *pNewStat = new FileStat( (void*) pDosDir ); - pDir->ImpSortedInsert( pTemp, pNewStat ); - } - else - pDir->ImpSortedInsert( pTemp, NULL ); - return 1; - } -#ifdef DBG_UTIL - else - DbgOutf( "%s flags:%x skipped", - pDosEntry->d_name, - pDosEntry->d_type ); -#endif - - } - else - bReady = sal_True; - return 0; -} - -/// shared part of CTors for FileStat -void FileStat::ImpInit( void* p ) -{ - _WIN32_FIND_DATAA *pDirEnt = (_WIN32_FIND_DATAA*) p; - - nError = FSYS_ERR_OK; - nSize = pDirEnt->nFileSizeLow; - - SYSTEMTIME aSysTime; - FILETIME aLocTime; - - // use the last write date / time when the creation date / time isn't set - if ( ( pDirEnt->ftCreationTime.dwLowDateTime == 0 ) && - ( pDirEnt->ftCreationTime.dwHighDateTime == 0 ) ) - { - pDirEnt->ftCreationTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime; - pDirEnt->ftCreationTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime; - } - - // use the last write date / time when the last accessed date / time isn't set - if ( ( pDirEnt->ftLastAccessTime.dwLowDateTime == 0 ) && - ( pDirEnt->ftLastAccessTime.dwHighDateTime == 0 ) ) - { - pDirEnt->ftLastAccessTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime; - pDirEnt->ftLastAccessTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime; - } - - FileTimeToLocalFileTime( &pDirEnt->ftCreationTime, &aLocTime ); - FileTimeToSystemTime( &aLocTime, &aSysTime ); - aDateCreated = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); - aTimeCreated = Time( aSysTime.wHour, aSysTime.wMinute, - aSysTime.wSecond, 0 ); - - FileTimeToLocalFileTime( &pDirEnt->ftLastWriteTime, &aLocTime ); - FileTimeToSystemTime( &aLocTime, &aSysTime ); - aDateModified = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); - aTimeModified = Time( aSysTime.wHour, aSysTime.wMinute, - aSysTime.wSecond, 0 ); - - FileTimeToLocalFileTime( &pDirEnt->ftLastAccessTime, &aLocTime ); - FileTimeToSystemTime( &aLocTime, &aSysTime ); - aDateAccessed = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear ); - aTimeAccessed = Time( aSysTime.wHour, aSysTime.wMinute, - aSysTime.wSecond, 0 ); - - nKindFlags = FSYS_KIND_FILE; - if ( pDirEnt->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - nKindFlags = FSYS_KIND_DIR; -} - -FileStat::FileStat( const void *pInfo ): // struct dirent - aDateCreated(0), - aTimeCreated(0), - aDateModified(0), - aTimeModified(0), - aDateAccessed(0), - aTimeAccessed(0) -{ - ImpInit( ( (dirent*) pInfo ) ); -} - -#ifdef _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable: 4917) -#endif - -#include - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#ifdef UNICODE -#define lstrchr wcschr -#define lstrncmp wcsncmp -#else -#define lstrchr strchr -#define lstrncmp strncmp -#endif - -void SHFreeMem( void *p ) -{ - LPMALLOC pMalloc = NULL; - - if ( SUCCEEDED(SHGetMalloc(&pMalloc)) ) - { - pMalloc->Free( p ); - pMalloc->Release(); - } -} - -HRESULT SHGetIDListFromPath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl ) -{ - if ( IsBadWritePtr(ppidl, sizeof(LPITEMIDLIST)) ) - return E_INVALIDARG; - - LPSHELLFOLDER pDesktopFolder = NULL; - - HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder ); - if ( FAILED(hResult) ) - return hResult; - - ULONG chEaten = lstrlen( pszPath ); - DWORD dwAttributes = FILE_ATTRIBUTE_DIRECTORY; - -#ifdef UNICODE - LPOLESTR wszPath = pszPath; -#else - WCHAR wszPath[MAX_PATH]; - MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszPath, -1, wszPath, MAX_PATH ); -#endif - - hResult = pDesktopFolder->ParseDisplayName( hwndOwner, (LPBC)NULL, wszPath, &chEaten, ppidl, &dwAttributes ); - pDesktopFolder->Release(); - - return hResult; -} - -HRESULT SHGetFolderFromIDList( LPCITEMIDLIST pidl, LPSHELLFOLDER *ppFolder ) -{ - if ( IsBadWritePtr(ppFolder, sizeof(LPSHELLFOLDER)) ) - return E_INVALIDARG; - - *ppFolder = NULL; - - LPSHELLFOLDER pDesktopFolder = NULL; - - HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder ); - if ( FAILED(hResult) ) - return hResult; - - hResult = pDesktopFolder->BindToObject( pidl, (LPBC)NULL, IID_IShellFolder, (LPVOID *)ppFolder ); - pDesktopFolder->Release(); - - return hResult; -} - -HRESULT SHResolvePath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl ) -{ - // If hwndOwner is NULL, use the desktop window, because dialogs need a parent - -#ifdef BOOTSTRAP - return NO_ERROR; -#else - if ( !hwndOwner ) - hwndOwner = GetDesktopWindow(); - - HRESULT hResult = NOERROR; - LPTSTR pszPathCopy; - LPTSTR pszTrailingPath; - TCHAR cBackup = 0; - - // First make a copy of the path - - pszPathCopy = new TCHAR[lstrlen(pszPath) + 1]; - lstrcpy( pszPathCopy, pszPath ); - - // Determine the first token - - if ( !lstrncmp( pszPathCopy, "\\\\", 2 ) ) - pszTrailingPath = lstrchr( pszPathCopy + 2, '\\' ); - else - pszTrailingPath = lstrchr( pszPathCopy, '\\' ); - - // Now scan the path tokens - - while ( SUCCEEDED(hResult) ) - { - if ( pszTrailingPath ) - { - cBackup = *(++pszTrailingPath); - *pszTrailingPath = 0; - } - - LPITEMIDLIST pidl = NULL; - - // Make item ID list from leading path - - hResult = SHGetIDListFromPath( hwndOwner, pszPathCopy, &pidl ); - - // if path exists try to open it as folder - - if ( SUCCEEDED(hResult) ) - { - // Only open the folder if it was not the last token - - if ( pszTrailingPath ) - { - LPSHELLFOLDER pFolder; - - // Create a folder instance - hResult = SHGetFolderFromIDList( pidl, &pFolder); - - // Is it a folder ? - if ( SUCCEEDED(hResult) ) - { - // No try to instantiate an enumerator. - // This should popup a login dialog if any - - LPENUMIDLIST pEnum = NULL; - - hResult = pFolder->EnumObjects( hwndOwner, - SHCONTF_NONFOLDERS | SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, - &pEnum ); - - // Release the enumerator interface - if ( SUCCEEDED(hResult) ) - pEnum->Release(); - - // Release the folder interface - pFolder->Release(); - } - - SHFreeMem( pidl ); - } - else // It was the last token - { - if ( ppidl ) - *ppidl = pidl; - else - SHFreeMem( pidl ); - } - } - - - // Forward to next token - - if ( pszTrailingPath ) - { - *pszTrailingPath = cBackup; - pszTrailingPath = lstrchr( pszTrailingPath, '\\' ); - } - else - break; - } - - // Free the working copy of the path - delete pszPathCopy; - - // NOERROR or OLE error code - return hResult; -#endif -} - -// The Wrapper - -sal_Bool Exists_Impl(const rtl::OString& crPath) -{ - // We do not know if OLE was initialized for this thread - - CoInitialize( NULL ); - - sal_Bool bSuccess = SUCCEEDED( SHResolvePath(NULL, crPath.getStr(), NULL) ); - - CoUninitialize(); - - return bSuccess; -} - -sal_Bool FileStat::Update( const DirEntry& rDirEntry, sal_Bool bForceAccess ) -{ - nSize = 0; - nKindFlags = 0; - aCreator.Erase(); - aType.Erase(); - aDateCreated = Date(0); - aTimeCreated = Time(0); - aDateModified = Date(0); - aTimeModified = Time(0); - aDateAccessed = Date(0); - aTimeAccessed = Time(0); - - if ( !rDirEntry.IsValid() ) - { - nError = FSYS_ERR_UNKNOWN; - nKindFlags = 0; - return sal_False; - } - - // Special treatment if it's a root without device - - if ( !rDirEntry.aName.getLength() && rDirEntry.eFlag == FSYS_FLAG_ABSROOT ) - { - nKindFlags = FSYS_KIND_DIR; - nError = FSYS_ERR_OK; - return sal_True; - } - - // Redirect - String aPath( rDirEntry.GetFull() ); - DirEntry aDirEntry( aPath ); - - // Is a medium in this device? - // How? - sal_Bool bAccess = sal_True; - const DirEntry *pTop = aDirEntry.ImpGetTopPtr(); - rtl::OString aName = rtl::OString(pTop->aName).toAsciiLowerCase(); - if ( !bForceAccess && - ( pTop->eFlag == FSYS_FLAG_ABSROOT || - pTop->eFlag == FSYS_FLAG_RELROOT || - pTop->eFlag == FSYS_FLAG_VOLUME ) ) - { - if ( aName == "a:" || aName == "b:" ) - bAccess = sal_False; - else - OSL_TRACE( "FSys: will access removable device!" ); - } - if ( bAccess && ( aName == "a:" || aName == "b:" ) ) - { - DBG_WARNING( "floppy will clatter" ); - } - - // Special treatment if it's a volume - if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME || - aDirEntry.eFlag == FSYS_FLAG_ABSROOT ) - { - if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) - nKindFlags = FSYS_KIND_DEV | ( aDirEntry.aName.getLength() == 2 - ? FSYS_KIND_BLOCK - : FSYS_KIND_CHAR ); - else - nKindFlags = FSYS_KIND_DIR; - - if ( !bAccess ) - { - if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) - nKindFlags |= FSYS_KIND_REMOVEABLE; - nError = FSYS_ERR_NOTEXISTS; - nKindFlags = 0; - return sal_False; - } - - rtl::OString aRootDir = aDirEntry.aName; - aRootDir += "\\"; - UINT nType = GetDriveType( aRootDir.getStr() ); //TPF: 2i - if ( nType == 1 || nType == 0 ) - { - nError = FSYS_ERR_NOTEXISTS; - nKindFlags = 0; - return sal_False; - } - - if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ) - nKindFlags = nKindFlags | - ( ( nType == DRIVE_REMOVABLE ) ? FSYS_KIND_REMOVEABLE : 0 ) | - ( ( nType == DRIVE_FIXED ) ? FSYS_KIND_FIXED : 0 ) | - ( ( nType == DRIVE_REMOTE ) ? FSYS_KIND_REMOTE : 0 ) | - ( ( nType == DRIVE_RAMDISK ) ? FSYS_KIND_RAM : 0 ) | - ( ( nType == DRIVE_CDROM ) ? FSYS_KIND_CDROM : 0 ) | - ( ( nType == 0 ) ? FSYS_KIND_UNKNOWN : 0 ); - - nError = ERRCODE_NONE; - - return sal_True; - } - - // Get status data from OS - HANDLE h; //() - _WIN32_FIND_DATAA aEntry = INIT_WIN32_FIND_DATAA; - DirEntry aAbsEntry( aDirEntry ); - if ( bAccess && aAbsEntry.ToAbs() ) - { - // names can contain ';*?' as normal characters - rtl::OString aFilePath(rtl::OUStringToOString(aAbsEntry.GetFull(), osl_getThreadTextEncoding())); - - OSL_TRACE( "FileStat: %s", aFilePath.getStr() ); - h = aFilePath.getLength() < 230 - ? FindFirstFile( aFilePath.getStr(), &aEntry )//TPF: 2i - : INVALID_HANDLE_VALUE; - - if ( INVALID_HANDLE_VALUE != h ) - { - if ( !( aEntry.dwFileAttributes & 0x40 ) ) // com1: etc. e.g. not encrypted (means normal) - { - rtl::OString aUpperName = Upper_Impl(rtl::OUStringToOString(aAbsEntry.GetName(), osl_getThreadTextEncoding())); - - // HRO: #74051# Compare also with short alternate filename - if ( aUpperName != Upper_Impl( aEntry.cFileName ) && aUpperName != Upper_Impl( aEntry.cAlternateFileName ) ) - h = INVALID_HANDLE_VALUE; - } - } - - if ( INVALID_HANDLE_VALUE == h ) - { - DWORD dwError = GetLastError(); - - if ( ERROR_BAD_NET_NAME == dwError ) - { - nKindFlags = FSYS_KIND_UNKNOWN; - nError = FSYS_ERR_NOTEXISTS; - return sal_False; - } - - // UNC-Volume? - DirEntry *pTop2 = aAbsEntry.ImpGetTopPtr(); - if ( pTop2->GetFlag() == FSYS_FLAG_ABSROOT && - ( pTop2->aName.getLength() > 1 && (pTop2->aName[1] != ':' )) ) - { - if ( bForceAccess ) - { - if ( Exists_Impl( aFilePath ) ) - { - nKindFlags = FSYS_KIND_DIR|FSYS_KIND_REMOTE; - nError = FSYS_ERR_OK; - return sal_True; - } - else - { - nKindFlags = FSYS_KIND_UNKNOWN; - nError = FSYS_ERR_NOTEXISTS; - return sal_False; - } - } - } - } - } - else - h = INVALID_HANDLE_VALUE; - - if ( h == INVALID_HANDLE_VALUE ) - { - // Special treatment if name contains wildcard - rtl::OString aTempName(rtl::OUStringToOString(aDirEntry.GetName(), osl_getThreadTextEncoding())); - if ( strchr( aTempName.getStr(), '?' ) || - strchr( aTempName.getStr(), '*' ) || - strchr( aTempName.getStr(), ';' ) ) - { - nKindFlags = FSYS_KIND_WILD; - nError = FSYS_ERR_OK; - return sal_True; - } - - if ( bAccess ) - { - nError = FSYS_ERR_NOTEXISTS; - nKindFlags = FSYS_KIND_UNKNOWN; - } - else - nKindFlags = FSYS_KIND_REMOVEABLE; - } - else - { - ImpInit( &aEntry ); - FindClose( h ); - } - - if ( 0 != nError ) - nKindFlags = 0; - - return 0 == nError; - -} - -sal_Bool IsRedirectable_Impl( const rtl::OString& rPath ) -{ - if ( rPath.getLength() >= 3 && ':' == rPath[1] ) - { - rtl::OString aVolume = rPath.copy( 0, 3 ); - UINT nType = GetDriveType( aVolume.getStr() ); - SetLastError( ERROR_SUCCESS ); - return DRIVE_FIXED != nType; - } - return sal_False; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/wntmsc.hxx b/tools/source/fsys/wntmsc.hxx deleted file mode 100644 index 734a68f0f2f1..000000000000 --- a/tools/source/fsys/wntmsc.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef _dosmsc_hxx -#define _dosmsc_hxx - -#include - -#ifndef ICC -#include -#endif - -#include -#include -#include -#include -#include -#include - -#define DOS_DIRECT _A_SUBDIR -#define DOS_VOLUMEID 0x08 - -#ifndef S_IFBLK -#define S_IFBLK 0x6000 -#endif - -#define dirent _WIN32_FIND_DATAA -#define d_name cFileName -#define d_type dwFileAttributes - -typedef struct -{ - _WIN32_FIND_DATAA aDirEnt; - HANDLE h; - const char *p; -} DIR; - -#define DEFSTYLE FSYS_STYLE_NTFS -#define MKDIR( p ) mkdir( p ) -#define CMP_LOWER(s) ( s.toAsciiLowerCase() ) - -inline sal_Bool DRIVE_EXISTS(char c) -{ - rtl::OStringBuffer aDriveRoot; - aDriveRoot.append(c); - aDriveRoot.append(":\\"); - return GetDriveType( aDriveRoot.getStr() ) > 1; -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit