xref: /aoo42x/main/tools/source/fsys/os2.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #define INCL_DOSEXCEPTIONS
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <stdlib.h>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #ifdef __BORLANDC__
33*cdf0e10cSrcweir #include <alloc.h>
34*cdf0e10cSrcweir #else
35*cdf0e10cSrcweir #include <malloc.h>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include <tools/debug.hxx>
38*cdf0e10cSrcweir #include <tools/list.hxx>
39*cdf0e10cSrcweir #include <tools/bigint.hxx>
40*cdf0e10cSrcweir #include <tools/fsys.hxx>
41*cdf0e10cSrcweir #include "comdep.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #ifdef OS2
44*cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX //autogen
45*cdf0e10cSrcweir #include <vos/mutex.hxx>
46*cdf0e10cSrcweir #endif
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir int Sys2SolarError_Impl( int nSysErr );
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir DECLARE_LIST( DirEntryList, DirEntry* );
52*cdf0e10cSrcweir DECLARE_LIST( FSysSortList, FSysSort* );
53*cdf0e10cSrcweir DECLARE_LIST( FileStatList, FileStat* );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir static char sCaseMap[256];
56*cdf0e10cSrcweir static BOOL bCaseMap = FALSE;
57*cdf0e10cSrcweir static BOOL bDriveMap = FALSE;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir struct DriveMapItem
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     DirEntryKind    nKind;
62*cdf0e10cSrcweir     char            cName;
63*cdf0e10cSrcweir     FSysPathStyle   nStyle;
64*cdf0e10cSrcweir };
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void CreateCaseMapImpl();
67*cdf0e10cSrcweir void CreateDriveMapImpl();
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir static DriveMapItem aDriveMap[26];
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir static BOOL   bLastCaseSensitive    = FALSE;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir //====================================================================
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir int ApiRet2ToSolarError_Impl( int nApiRet )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     switch ( nApiRet )
78*cdf0e10cSrcweir     {
79*cdf0e10cSrcweir         case NO_ERROR:                      return ERRCODE_NONE;
80*cdf0e10cSrcweir         case ERROR_FILE_NOT_FOUND:          return ERRCODE_IO_NOTEXISTS;
81*cdf0e10cSrcweir         case ERROR_PATH_NOT_FOUND:          return ERRCODE_IO_NOTEXISTSPATH;
82*cdf0e10cSrcweir         case ERROR_TOO_MANY_OPEN_FILES:     return ERRCODE_IO_TOOMANYOPENFILES;
83*cdf0e10cSrcweir         case ERROR_ACCESS_DENIED:           return ERRCODE_IO_ACCESSDENIED;
84*cdf0e10cSrcweir         case ERROR_NOT_ENOUGH_MEMORY:       return ERRCODE_IO_OUTOFMEMORY;
85*cdf0e10cSrcweir         case ERROR_BAD_FORMAT:              return ERRCODE_IO_WRONGFORMAT;
86*cdf0e10cSrcweir         case ERROR_NOT_SAME_DEVICE:         return ERRCODE_IO_INVALIDDEVICE;
87*cdf0e10cSrcweir         case ERROR_WRITE_PROTECT:           return ERRCODE_IO_INVALIDDEVICE;
88*cdf0e10cSrcweir         case ERROR_BAD_UNIT:                return ERRCODE_IO_INVALIDDEVICE;
89*cdf0e10cSrcweir         case ERROR_CRC:                     return ERRCODE_IO_INVALIDDEVICE;
90*cdf0e10cSrcweir         case ERROR_NOT_DOS_DISK:            return ERRCODE_IO_INVALIDDEVICE;
91*cdf0e10cSrcweir         case ERROR_WRITE_FAULT:             return ERRCODE_IO_CANTWRITE;
92*cdf0e10cSrcweir         case ERROR_READ_FAULT:              return ERRCODE_IO_CANTREAD;
93*cdf0e10cSrcweir         case ERROR_SHARING_VIOLATION:       return ERRCODE_IO_LOCKVIOLATION;
94*cdf0e10cSrcweir         case ERROR_LOCK_VIOLATION:          return ERRCODE_IO_LOCKVIOLATION;
95*cdf0e10cSrcweir         case ERROR_WRONG_DISK:              return ERRCODE_IO_LOCKVIOLATION;
96*cdf0e10cSrcweir         case ERROR_HANDLE_DISK_FULL:        return ERRCODE_IO_OUTOFSPACE;
97*cdf0e10cSrcweir         case ERROR_NOT_SUPPORTED:           return ERRCODE_IO_NOTSUPPORTED;
98*cdf0e10cSrcweir         case ERROR_DUP_NAME:                return ERRCODE_IO_ALREADYEXISTS;
99*cdf0e10cSrcweir         case ERROR_BAD_NETPATH:             return ERRCODE_IO_NOTEXISTSPATH;
100*cdf0e10cSrcweir         case ERROR_DEV_NOT_EXIST:           return ERRCODE_IO_NOTEXISTS;
101*cdf0e10cSrcweir         case ERROR_NETWORK_ACCESS_DENIED:   return ERRCODE_IO_ACCESSDENIED;
102*cdf0e10cSrcweir         case ERROR_INVALID_PARAMETER:       return ERRCODE_IO_INVALIDPARAMETER;
103*cdf0e10cSrcweir         case ERROR_NET_WRITE_FAULT:         return ERRCODE_IO_CANTWRITE;
104*cdf0e10cSrcweir         case ERROR_DEVICE_IN_USE:           return ERRCODE_IO_INVALIDPARAMETER;
105*cdf0e10cSrcweir         case ERROR_DISK_FULL:               return ERRCODE_IO_OUTOFSPACE;
106*cdf0e10cSrcweir         case ERROR_BAD_ARGUMENTS:           return ERRCODE_IO_INVALIDPARAMETER;
107*cdf0e10cSrcweir         case ERROR_BAD_PATHNAME:            return ERRCODE_IO_NOTEXISTSPATH;
108*cdf0e10cSrcweir         case ERROR_LOCK_FAILED:             return ERRCODE_IO_LOCKVIOLATION;
109*cdf0e10cSrcweir         case ERROR_LOCKED:                  return ERRCODE_IO_LOCKVIOLATION;
110*cdf0e10cSrcweir         case ERROR_DUPLICATE_NAME:          return ERRCODE_IO_ALREADYEXISTS;
111*cdf0e10cSrcweir         case ERROR_DIRECTORY_IN_CDS:        return ERRCODE_IO_LOCKVIOLATION;
112*cdf0e10cSrcweir         case ERROR_CURRENT_DIRECTORY:       return ERRCODE_IO_LOCKVIOLATION;
113*cdf0e10cSrcweir         case ERROR_FILENAME_EXCED_RANGE:    return ERRCODE_IO_NAMETOOLONG;
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     DBG_TRACE1( "FSys: unknown apiret error %d occured", nApiRet );
117*cdf0e10cSrcweir     return FSYS_ERR_UNKNOWN;
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //--------------------------------------------------------------------
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir char* volumeid( const char* pPfad )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     static FSINFO   aFSInfoBuf;
125*cdf0e10cSrcweir     ULONG           ulFSInfoLevel = FSIL_VOLSER;
126*cdf0e10cSrcweir     ULONG           nDriveNumber;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     nDriveNumber = toupper(*pPfad) - 'A' + 1;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     if ( nDriveNumber >= 3 )
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         APIRET rc = DosQueryFSInfo(
133*cdf0e10cSrcweir             nDriveNumber, ulFSInfoLevel, &aFSInfoBuf, sizeof(FSINFO) );
134*cdf0e10cSrcweir         if ( rc )
135*cdf0e10cSrcweir             return 0;
136*cdf0e10cSrcweir         return (char*) aFSInfoBuf.vol.szVolLabel;
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir     return 0;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir //--------------------------------------------------------------------
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir /*************************************************************************
144*cdf0e10cSrcweir |*
145*cdf0e10cSrcweir |*    DirEntry::ToAbs()
146*cdf0e10cSrcweir |*
147*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
148*cdf0e10cSrcweir |*    Ersterstellung    MI 26.04.91
149*cdf0e10cSrcweir |*    Letzte Aenderung  MA 02.12.91 13:30
150*cdf0e10cSrcweir |*
151*cdf0e10cSrcweir *************************************************************************/
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir BOOL DirEntry::ToAbs()
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     if ( FSYS_FLAG_VOLUME == eFlag )
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir         eFlag = FSYS_FLAG_ABSROOT;
160*cdf0e10cSrcweir         return TRUE;
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     if ( IsAbs() )
164*cdf0e10cSrcweir         return TRUE;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	char sBuf[_MAX_PATH + 1];
167*cdf0e10cSrcweir 	*this = DirEntry( String( getcwd( sBuf, _MAX_PATH ), osl_getThreadTextEncoding() ) ) + *this;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     return IsAbs();
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir /*************************************************************************
173*cdf0e10cSrcweir |*
174*cdf0e10cSrcweir |*    DirEntry::GetVolume()
175*cdf0e10cSrcweir |*
176*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
177*cdf0e10cSrcweir |*    Ersterstellung    MI 04.03.92
178*cdf0e10cSrcweir |*    Letzte Aenderung  MI 04.03.92
179*cdf0e10cSrcweir |*
180*cdf0e10cSrcweir *************************************************************************/
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir String DirEntry::GetVolume() const
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     String aRet;
187*cdf0e10cSrcweir     const DirEntry *pTop = ImpGetTopPtr();
188*cdf0e10cSrcweir     ByteString aName = ByteString( pTop->aName ).ToLowerAscii();
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     if ( ( pTop->eFlag == FSYS_FLAG_ABSROOT ||
191*cdf0e10cSrcweir            pTop->eFlag == FSYS_FLAG_RELROOT ||
192*cdf0e10cSrcweir            pTop->eFlag == FSYS_FLAG_VOLUME )
193*cdf0e10cSrcweir          && aName != "a:" && aName != "b:" && Exists() )
194*cdf0e10cSrcweir     {
195*cdf0e10cSrcweir         const char *pVol;
196*cdf0e10cSrcweir         pVol = volumeid( (char*) pTop->aName.GetBuffer() );
197*cdf0e10cSrcweir 		if (pVol)
198*cdf0e10cSrcweir 			aRet = String( pVol, osl_getThreadTextEncoding());
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     return aRet;
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir /*************************************************************************
205*cdf0e10cSrcweir |*
206*cdf0e10cSrcweir |*    DirEntry::SetCWD()
207*cdf0e10cSrcweir |*
208*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
209*cdf0e10cSrcweir |*    Ersterstellung    MI 26.04.91
210*cdf0e10cSrcweir |*    Letzte Aenderung  MI 21.05.92
211*cdf0e10cSrcweir |*
212*cdf0e10cSrcweir *************************************************************************/
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir BOOL DirEntry::SetCWD( BOOL bSloppy ) const
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     if ( eFlag == FSYS_FLAG_CURRENT && !aName.Len() )
219*cdf0e10cSrcweir         return TRUE;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     if ( !chdir(ByteString(GetFull(), osl_getThreadTextEncoding()).GetBuffer()) )
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir         //nError = FSYS_ERR_OK;
224*cdf0e10cSrcweir         return TRUE;
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     if ( bSloppy && pParent &&
228*cdf0e10cSrcweir          !chdir(ByteString(pParent->GetFull(), osl_getThreadTextEncoding()).GetBuffer()) )
229*cdf0e10cSrcweir     {
230*cdf0e10cSrcweir         //nError = FSYS_ERR_OK;
231*cdf0e10cSrcweir         return TRUE;
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     //nError = FSYS_ERR_NOTADIRECTORY;
235*cdf0e10cSrcweir     return FALSE;
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir /*************************************************************************
239*cdf0e10cSrcweir |*
240*cdf0e10cSrcweir |*    DirEntry::MoveTo()
241*cdf0e10cSrcweir |*
242*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
243*cdf0e10cSrcweir |*    Ersterstellung    MI 26.04.91
244*cdf0e10cSrcweir |*    Letzte Aenderung  MA 02.12.91 14:07
245*cdf0e10cSrcweir |*
246*cdf0e10cSrcweir *************************************************************************/
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir #if 0 // YD see dirent.cxx
249*cdf0e10cSrcweir BOOL createLongNameEA( const PCSZ pszPath, ULONG ulAttributes, const String& aLongName );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir FSysError DirEntry::MoveTo( const DirEntry& rDest ) const
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     DirEntry aTmpDest(rDest);
256*cdf0e10cSrcweir     FileStat aTmpStat(aTmpDest);
257*cdf0e10cSrcweir     if ( aTmpStat.IsKind(FSYS_KIND_DIR) )
258*cdf0e10cSrcweir         aTmpDest += DirEntry( GetName() );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     String aSource( GetFull() );
261*cdf0e10cSrcweir     String aDest( aTmpDest.GetFull() );
262*cdf0e10cSrcweir     String aShortSource("");
263*cdf0e10cSrcweir     String aShortDest("");
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     if (Folder::IsAvailable())
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         if  (IsLongNameOnFAT())
268*cdf0e10cSrcweir         {
269*cdf0e10cSrcweir             // in kurzen Pfad wandeln
270*cdf0e10cSrcweir             ItemIDPath      aItemIDPath(aSource);
271*cdf0e10cSrcweir             aShortSource = aItemIDPath.GetHostNotationPath();
272*cdf0e10cSrcweir         }
273*cdf0e10cSrcweir         if  (rDest.IsLongNameOnFAT())
274*cdf0e10cSrcweir         {
275*cdf0e10cSrcweir             // in kurzen Pfad wandeln
276*cdf0e10cSrcweir             ItemIDPath      aItemIDPath(aDest);
277*cdf0e10cSrcweir             aShortDest = aItemIDPath.GetHostNotationPath();
278*cdf0e10cSrcweir         }
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     APIRET nRet = DosMove( aShortSource.Len()>0?(PSZ)aShortSource.GetStr():(PSZ)aSource.GetStr(),
282*cdf0e10cSrcweir                            aShortDest.Len()>0?(PSZ)aShortDest.GetStr():(PSZ)aDest.GetStr());
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     if ( nRet == ERROR_DIRECTORY_IN_CDS ||
285*cdf0e10cSrcweir          nRet == ERROR_CURRENT_DIRECTORY )
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         // 2nd chance with modified CWD
288*cdf0e10cSrcweir         DosSetCurrentDir( (PSZ) "\\" );
289*cdf0e10cSrcweir         nRet = DosMove( aShortSource.Len()>0?(PSZ)aShortSource.GetStr():(PSZ)aSource.GetStr(),
290*cdf0e10cSrcweir                         aShortDest.Len()>0?(PSZ)aShortDest.GetStr():(PSZ)aDest.GetStr());
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir     else if ( nRet == ERROR_NOT_SAME_DEVICE )
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         // other volume => copy+delete
295*cdf0e10cSrcweir         FileCopier aMover( *this, rDest );
296*cdf0e10cSrcweir         nRet = aMover.Execute( FSYS_ACTION_MOVE|FSYS_ACTION_RECURSIVE );
297*cdf0e10cSrcweir         return nRet;
298*cdf0e10cSrcweir     }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     if ( (nRet==NO_ERROR) && aShortDest.Len()>0)
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir 	createLongNameEA((const char*)aShortDest,  FILE_NORMAL, rDest.GetName());
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     return ApiRet2ToSolarError_Impl( nRet );
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir #endif // 0
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir //-------------------------------------------------------------------------
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir USHORT DirReader_Impl::Init()
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir     // Block-Devices auflisten?
314*cdf0e10cSrcweir     if ( pDir->eAttrMask & FSYS_KIND_BLOCK )
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         CreateDriveMapImpl();
317*cdf0e10cSrcweir         // CWD merken
318*cdf0e10cSrcweir         DirEntry aCurrentDir;
319*cdf0e10cSrcweir         aCurrentDir.ToAbs();
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir         // einzeln auf Existenz und Masken-konformit"at pr"ufen
322*cdf0e10cSrcweir         USHORT nRead = 0;
323*cdf0e10cSrcweir         char sDrive[3] = { '?', ':', 0 };
324*cdf0e10cSrcweir         char sRoot[4] = { '?', ':', '\\', 0 };
325*cdf0e10cSrcweir         for ( char c = 'a'; c <= 'z'; c++ )
326*cdf0e10cSrcweir         {
327*cdf0e10cSrcweir             sDrive[0] = c;
328*cdf0e10cSrcweir             sRoot[0] = c;
329*cdf0e10cSrcweir             DirEntry* pDrive = new DirEntry( sDrive, FSYS_FLAG_VOLUME, FSYS_STYLE_HOST );
330*cdf0e10cSrcweir             if ( pDir->aNameMask.Matches( String( ByteString(sDrive), osl_getThreadTextEncoding()))
331*cdf0e10cSrcweir 				&& aDriveMap[c-'a'].nKind != FSYS_KIND_UNKNOWN )
332*cdf0e10cSrcweir             {
333*cdf0e10cSrcweir                 if ( pDir->pStatLst ) //Status fuer Sort gewuenscht?
334*cdf0e10cSrcweir                 {
335*cdf0e10cSrcweir                     FileStat *pNewStat = new FileStat( *pDrive );
336*cdf0e10cSrcweir                     pDir->ImpSortedInsert( pDrive, pNewStat );
337*cdf0e10cSrcweir                 }
338*cdf0e10cSrcweir                 else
339*cdf0e10cSrcweir                     pDir->ImpSortedInsert( pDrive, NULL );
340*cdf0e10cSrcweir                 ++nRead;
341*cdf0e10cSrcweir             }
342*cdf0e10cSrcweir             else
343*cdf0e10cSrcweir                 delete pDrive;
344*cdf0e10cSrcweir         }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir         // CWD restaurieren
347*cdf0e10cSrcweir         aCurrentDir.SetCWD();
348*cdf0e10cSrcweir         return nRead;
349*cdf0e10cSrcweir     }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     return 0;
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir //-------------------------------------------------------------------------
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir USHORT DirReader_Impl::Read()
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir 	if (!pDosDir)
359*cdf0e10cSrcweir 	{
360*cdf0e10cSrcweir 		pDosDir = opendir( (char*) ByteString(aPath, osl_getThreadTextEncoding()).GetBuffer() );
361*cdf0e10cSrcweir 	}
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	if (!pDosDir)
364*cdf0e10cSrcweir 	{
365*cdf0e10cSrcweir 		bReady = TRUE;
366*cdf0e10cSrcweir 		return 0;
367*cdf0e10cSrcweir 	}
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     // Directories und Files auflisten?
370*cdf0e10cSrcweir 	if ( ( pDir->eAttrMask & FSYS_KIND_DIR || pDir->eAttrMask & FSYS_KIND_FILE ) &&
371*cdf0e10cSrcweir 		 ( ( pDosEntry = readdir( pDosDir ) ) != NULL ) )
372*cdf0e10cSrcweir 	{
373*cdf0e10cSrcweir 		String aD_Name(pDosEntry->d_name, osl_getThreadTextEncoding());
374*cdf0e10cSrcweir         if ( pDir->aNameMask.Matches( aD_Name  ) )
375*cdf0e10cSrcweir         {
376*cdf0e10cSrcweir 			DirEntryFlag eFlag =
377*cdf0e10cSrcweir 					0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT
378*cdf0e10cSrcweir 				:	0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT
379*cdf0e10cSrcweir 				:	FSYS_FLAG_NORMAL;
380*cdf0e10cSrcweir             DirEntry *pTemp = new DirEntry( ByteString(pDosEntry->d_name), eFlag, FSYS_STYLE_UNX );
381*cdf0e10cSrcweir             if ( pParent )
382*cdf0e10cSrcweir                 pTemp->ImpChangeParent( new DirEntry( *pParent ), FALSE);
383*cdf0e10cSrcweir             FileStat aStat( *pTemp );
384*cdf0e10cSrcweir             if ( ( ( ( pDir->eAttrMask & FSYS_KIND_DIR ) &&
385*cdf0e10cSrcweir 					 ( aStat.IsKind( FSYS_KIND_DIR ) ) ) ||
386*cdf0e10cSrcweir 				   ( ( pDir->eAttrMask & FSYS_KIND_FILE ) &&
387*cdf0e10cSrcweir 					 !( aStat.IsKind( FSYS_KIND_DIR ) ) ) ) &&
388*cdf0e10cSrcweir 				 !( pDir->eAttrMask & FSYS_KIND_VISIBLE &&
389*cdf0e10cSrcweir 					pDosEntry->d_name[0] == '.' ) )
390*cdf0e10cSrcweir             {
391*cdf0e10cSrcweir                 if ( pDir->pStatLst ) //Status fuer Sort gewuenscht?
392*cdf0e10cSrcweir                     pDir->ImpSortedInsert( pTemp, new FileStat( aStat ) );
393*cdf0e10cSrcweir                 else
394*cdf0e10cSrcweir                     pDir->ImpSortedInsert( pTemp, NULL );;
395*cdf0e10cSrcweir 				return 1;
396*cdf0e10cSrcweir             }
397*cdf0e10cSrcweir             else
398*cdf0e10cSrcweir                 delete pTemp;
399*cdf0e10cSrcweir         }
400*cdf0e10cSrcweir 	}
401*cdf0e10cSrcweir 	else
402*cdf0e10cSrcweir 		bReady = TRUE;
403*cdf0e10cSrcweir 	return 0;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir /*************************************************************************
407*cdf0e10cSrcweir |*
408*cdf0e10cSrcweir |*    FileStat::FileStat()
409*cdf0e10cSrcweir |*
410*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
411*cdf0e10cSrcweir |*    Ersterstellung    MA 05.11.91
412*cdf0e10cSrcweir |*    Letzte Aenderung  MA 07.11.91
413*cdf0e10cSrcweir |*
414*cdf0e10cSrcweir *************************************************************************/
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir FileStat::FileStat( const void *pInfo,      // struct dirent
417*cdf0e10cSrcweir                     const void * ):         // dummy
418*cdf0e10cSrcweir         aDateCreated(0),
419*cdf0e10cSrcweir         aTimeCreated(0),
420*cdf0e10cSrcweir         aDateModified(0),
421*cdf0e10cSrcweir         aTimeModified(0),
422*cdf0e10cSrcweir         aDateAccessed(0),
423*cdf0e10cSrcweir         aTimeAccessed(0)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     struct dirent *pDirent = (struct dirent*) pInfo;
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir     nSize = pDirent->d_size;
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir     aDateCreated  = MsDos2Date( (FDATE*) &pDirent->d_date );
430*cdf0e10cSrcweir     aTimeCreated  = MsDos2Time( (FTIME*) &pDirent->d_time );
431*cdf0e10cSrcweir     aDateModified = aDateModified;
432*cdf0e10cSrcweir     aTimeModified = aTimeModified;
433*cdf0e10cSrcweir     aDateAccessed = aDateModified;
434*cdf0e10cSrcweir     aTimeAccessed = aTimeModified;
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     nKindFlags = FSYS_KIND_FILE;
437*cdf0e10cSrcweir     if ( pDirent->d_type & DOS_DIRECT )
438*cdf0e10cSrcweir         nKindFlags = FSYS_KIND_DIR;
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir /*************************************************************************
442*cdf0e10cSrcweir |*
443*cdf0e10cSrcweir |*    FileStat::Update()
444*cdf0e10cSrcweir |*
445*cdf0e10cSrcweir |*    Beschreibung      FSYS.SDW
446*cdf0e10cSrcweir |*    Ersterstellung    MI 11.06.91
447*cdf0e10cSrcweir |*    Letzte Aenderung  MA 07.11.91
448*cdf0e10cSrcweir |*
449*cdf0e10cSrcweir *************************************************************************/
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir struct _FSYS_FSQBUFFER
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     FSQBUFFER2  aBuf;
454*cdf0e10cSrcweir     UCHAR       sBuf[256];
455*cdf0e10cSrcweir };
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir BOOL FileStat::Update( const DirEntry& rDirEntry, BOOL bAccessRemovableDevice )
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     nSize = 0;
460*cdf0e10cSrcweir     FSysPathStyle eStyle = FSYS_STYLE_UNKNOWN;
461*cdf0e10cSrcweir     aCreator.Erase();
462*cdf0e10cSrcweir     aType.Erase();
463*cdf0e10cSrcweir     aDateCreated = Date(0);
464*cdf0e10cSrcweir     aTimeCreated = Time(0);
465*cdf0e10cSrcweir     aDateModified = Date(0);
466*cdf0e10cSrcweir     aTimeModified = Time(0);
467*cdf0e10cSrcweir     aDateAccessed = Date(0);
468*cdf0e10cSrcweir     aTimeAccessed = Time(0);
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 	if ( !rDirEntry.IsValid() )
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		nError = FSYS_ERR_NOTEXISTS;
473*cdf0e10cSrcweir 		return FALSE;
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 	// Sonderbehandlung falls es sich um eine Root ohne Laufwerk handelt
477*cdf0e10cSrcweir 	if ( !rDirEntry.aName.Len() && rDirEntry.eFlag == FSYS_FLAG_ABSROOT )
478*cdf0e10cSrcweir 	{
479*cdf0e10cSrcweir 		nKindFlags = FSYS_KIND_DIR;
480*cdf0e10cSrcweir 		nError = FSYS_ERR_OK;
481*cdf0e10cSrcweir 		return TRUE;
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir     // Sonderbehandlung falls es sich um eine Wildcard handelt
485*cdf0e10cSrcweir     ByteString aTempName( rDirEntry.GetName(), osl_getThreadTextEncoding() );
486*cdf0e10cSrcweir     if ( strchr( aTempName.GetBuffer(), '?' ) ||
487*cdf0e10cSrcweir          strchr( aTempName.GetBuffer(), '*' ) ||
488*cdf0e10cSrcweir          strchr( aTempName.GetBuffer(), ';' ) )
489*cdf0e10cSrcweir     {
490*cdf0e10cSrcweir         nKindFlags = FSYS_KIND_WILD;
491*cdf0e10cSrcweir         nError = FSYS_ERR_OK;
492*cdf0e10cSrcweir         return TRUE;
493*cdf0e10cSrcweir     }
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir     // Sonderbehandlung falls es sich um eine Root handelt
496*cdf0e10cSrcweir     if ( rDirEntry.eFlag == FSYS_FLAG_VOLUME ||
497*cdf0e10cSrcweir          rDirEntry.eFlag == FSYS_FLAG_ABSROOT )
498*cdf0e10cSrcweir     {
499*cdf0e10cSrcweir         if ( rDirEntry.eFlag == FSYS_FLAG_VOLUME )
500*cdf0e10cSrcweir             nKindFlags = FSYS_KIND_DEV;
501*cdf0e10cSrcweir         else
502*cdf0e10cSrcweir             nKindFlags = FSYS_KIND_DIR;
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir         if ( rDirEntry.aName.Len() == 2 )
505*cdf0e10cSrcweir         {
506*cdf0e10cSrcweir             if ( !bDriveMap )
507*cdf0e10cSrcweir                 CreateDriveMapImpl();
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 			ByteString rDirEntryUpperCase = ByteString( rDirEntry.aName ).ToUpperAscii();
510*cdf0e10cSrcweir             DriveMapItem &rItem = aDriveMap[rDirEntryUpperCase.GetChar(0) - 'A'];
511*cdf0e10cSrcweir             if ( !rItem.nKind )
512*cdf0e10cSrcweir             {
513*cdf0e10cSrcweir                 nError = ERRCODE_IO_INVALIDDEVICE;
514*cdf0e10cSrcweir                                 nKindFlags = FSYS_KIND_UNKNOWN;
515*cdf0e10cSrcweir                 return FALSE;
516*cdf0e10cSrcweir             }
517*cdf0e10cSrcweir             else
518*cdf0e10cSrcweir             {
519*cdf0e10cSrcweir                 if ( rDirEntry.eFlag == FSYS_FLAG_VOLUME )
520*cdf0e10cSrcweir                     nKindFlags |= FSYS_KIND_BLOCK | rItem.nKind;
521*cdf0e10cSrcweir                 eStyle = rItem.nStyle;
522*cdf0e10cSrcweir             }
523*cdf0e10cSrcweir         }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir         nError = FSYS_ERR_OK;
526*cdf0e10cSrcweir         return TRUE;
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir     // disable error-boxes for hard-errors
530*cdf0e10cSrcweir     DosError(FERR_DISABLEHARDERR);
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     // Statusinformation vom Betriebssystem holen
533*cdf0e10cSrcweir     DirEntry    aTempDirEntry( rDirEntry );
534*cdf0e10cSrcweir     char*       p;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     aTempDirEntry.ToAbs();
537*cdf0e10cSrcweir     ByteString aFullName( aTempDirEntry.GetFull(), osl_getThreadTextEncoding() );
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir #if 0 // YD
540*cdf0e10cSrcweir 	if (Folder::IsAvailable() && aTempDirEntry.IsLongNameOnFAT())
541*cdf0e10cSrcweir 	{
542*cdf0e10cSrcweir 		// in String mit kurzem Pfad wandeln
543*cdf0e10cSrcweir 		ItemIDPath aItemIDPath(aTempDirEntry.GetFull());
544*cdf0e10cSrcweir 		aFullName = ByteString( aItemIDPath.GetHostNotationPath(), osl_getThreadTextEncoding() );
545*cdf0e10cSrcweir 	}
546*cdf0e10cSrcweir #endif
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     p = (char *) aFullName.GetBuffer();
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     FILESTATUS3 filestat;
551*cdf0e10cSrcweir     memset( &filestat, 0, sizeof( filestat ) );
552*cdf0e10cSrcweir     if( DosQueryPathInfo( (PSZ)p, 1, &filestat, sizeof( filestat ) ) )
553*cdf0e10cSrcweir     {
554*cdf0e10cSrcweir         nError = FSYS_ERR_NOTEXISTS;
555*cdf0e10cSrcweir         nKindFlags = FSYS_KIND_UNKNOWN;
556*cdf0e10cSrcweir         return FALSE;
557*cdf0e10cSrcweir     }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir     nError = FSYS_ERR_OK;
560*cdf0e10cSrcweir     nSize = filestat.cbFile;
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     nKindFlags = FSYS_KIND_UNKNOWN;
563*cdf0e10cSrcweir     if( filestat.attrFile & FILE_DIRECTORY )
564*cdf0e10cSrcweir         nKindFlags |= FSYS_KIND_DIR;
565*cdf0e10cSrcweir     if ( nKindFlags == FSYS_KIND_UNKNOWN )
566*cdf0e10cSrcweir         nKindFlags = nKindFlags | FSYS_KIND_FILE;
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     aDateModified = Date( filestat.fdateLastWrite.day,
569*cdf0e10cSrcweir                           filestat.fdateLastWrite.month,
570*cdf0e10cSrcweir                           filestat.fdateLastWrite.year + 1980 );
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir     aTimeModified = Time( filestat.ftimeLastWrite.hours,
573*cdf0e10cSrcweir                           filestat.ftimeLastWrite.minutes,
574*cdf0e10cSrcweir                           filestat.ftimeLastWrite.twosecs*2 );
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir     if ( filestat.fdateCreation.day )
577*cdf0e10cSrcweir     {
578*cdf0e10cSrcweir         aDateCreated  = Date( filestat.fdateCreation.day,
579*cdf0e10cSrcweir                               filestat.fdateCreation.month,
580*cdf0e10cSrcweir                               filestat.fdateCreation.year + 1980 );
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir         aTimeCreated  = Time( filestat.ftimeCreation.hours,
583*cdf0e10cSrcweir                               filestat.ftimeCreation.minutes,
584*cdf0e10cSrcweir                               filestat.ftimeCreation.twosecs*2 );
585*cdf0e10cSrcweir     }
586*cdf0e10cSrcweir     else
587*cdf0e10cSrcweir     {
588*cdf0e10cSrcweir         aDateCreated = aDateModified;
589*cdf0e10cSrcweir         aTimeCreated = aTimeModified;
590*cdf0e10cSrcweir     }
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir     if ( filestat.fdateLastAccess.day > 0 )
593*cdf0e10cSrcweir     {
594*cdf0e10cSrcweir         aDateAccessed = Date( filestat.fdateLastAccess.day,
595*cdf0e10cSrcweir                               filestat.fdateLastAccess.month,
596*cdf0e10cSrcweir                               filestat.fdateLastAccess.year + 1980 );
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir         aTimeAccessed = Time( filestat.ftimeLastAccess.hours,
599*cdf0e10cSrcweir                                 filestat.ftimeLastAccess.minutes,
600*cdf0e10cSrcweir                                 filestat.ftimeLastAccess.twosecs*2 );
601*cdf0e10cSrcweir     }
602*cdf0e10cSrcweir     else
603*cdf0e10cSrcweir     {
604*cdf0e10cSrcweir         aDateAccessed = aDateModified;
605*cdf0e10cSrcweir         aTimeAccessed = aTimeModified;
606*cdf0e10cSrcweir     }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir     return TRUE;
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir BOOL IsRedirectable_Impl( const ByteString &rPath )
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     if ( rPath.Len() >= 3 && ':' == rPath.GetBuffer()[1] )
614*cdf0e10cSrcweir     {
615*cdf0e10cSrcweir         ByteString aVolume = rPath.Copy( 0, 3 );
616*cdf0e10cSrcweir         DriveMapItem &rItem = aDriveMap[toupper(aVolume.GetChar(0)) - 'A'];
617*cdf0e10cSrcweir         return FSYS_KIND_FIXED != rItem.nKind;
618*cdf0e10cSrcweir     }
619*cdf0e10cSrcweir     return FALSE;
620*cdf0e10cSrcweir }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir #if 0
623*cdf0e10cSrcweir BOOL IsRedirectable_Impl( const String &rPath )
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir     if ( rPath.Len() >= 3 && ':' == rPath.GetStr()[1] )
626*cdf0e10cSrcweir     {
627*cdf0e10cSrcweir         DriveMapItem &rItem = aDriveMap[toupper(rPath[0]) - 'A'];
628*cdf0e10cSrcweir         return FSYS_KIND_FIXED != rItem.nKind;
629*cdf0e10cSrcweir     }
630*cdf0e10cSrcweir     return FALSE;
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir #endif
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir /*************************************************************************
636*cdf0e10cSrcweir |*
637*cdf0e10cSrcweir |*    TempDirImpl()
638*cdf0e10cSrcweir |*
639*cdf0e10cSrcweir |*    Beschreibung      liefert den Namens des Directories fuer temporaere
640*cdf0e10cSrcweir |*                      Dateien
641*cdf0e10cSrcweir |*    Ersterstellung    MI 16.03.94
642*cdf0e10cSrcweir |*    Letzte Aenderung  MI 16.03.94
643*cdf0e10cSrcweir |*
644*cdf0e10cSrcweir *************************************************************************/
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir const char* TempDirImpl( char *pBuf )
647*cdf0e10cSrcweir {
648*cdf0e10cSrcweir     PSZ         pVar;
649*cdf0e10cSrcweir     USHORT      nRet;
650*cdf0e10cSrcweir     BOOL        bAppendTemp = FALSE; // mu\s noch \\temp angeh"angt werden
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir     // Erstmal sehen, ob TEMP oder TMP gesetzt sind
653*cdf0e10cSrcweir     nRet = DosScanEnv( (PSZ)"TEMP", &pVar );
654*cdf0e10cSrcweir     if( nRet )
655*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"temp", &pVar );
656*cdf0e10cSrcweir     if( nRet )
657*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"TMP", &pVar );
658*cdf0e10cSrcweir     if( nRet )
659*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"tmp", &pVar );
660*cdf0e10cSrcweir     if( nRet )
661*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"TMPDIR", &pVar );
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     // falls das geklappt hat, und ein Backslash dranhaengt,
664*cdf0e10cSrcweir     // oder falls es bisher nicht geklappt hat,
665*cdf0e10cSrcweir     // muessen wir nachher einen Backslash entfernen
666*cdf0e10cSrcweir     BOOL bRemoveBS = nRet || *(pVar+strlen(pVar)-1) == '\\';
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     // Keine temp-Variable gefunden, dann gehen wir mal auf die Suche
669*cdf0e10cSrcweir     // nach dem System-Laufwerk
670*cdf0e10cSrcweir     if( nRet )
671*cdf0e10cSrcweir     {
672*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"USER_INI",&pVar );
673*cdf0e10cSrcweir         bAppendTemp = (0 == nRet);
674*cdf0e10cSrcweir     }
675*cdf0e10cSrcweir     if( nRet )
676*cdf0e10cSrcweir     {
677*cdf0e10cSrcweir         nRet = DosScanEnv( (PSZ)"SYSTEM_INI", &pVar );
678*cdf0e10cSrcweir         bAppendTemp = (0 == nRet);
679*cdf0e10cSrcweir     }
680*cdf0e10cSrcweir     if( nRet )
681*cdf0e10cSrcweir         // Wenn das immer noch nicht reicht nehmen wir eben die Root von C:
682*cdf0e10cSrcweir #ifdef __BORLANDC__
683*cdf0e10cSrcweir         pVar = (PSZ)"c:\\temp\\";
684*cdf0e10cSrcweir #else
685*cdf0e10cSrcweir         pVar = (PCSZ)"c:\\temp\\";
686*cdf0e10cSrcweir #endif
687*cdf0e10cSrcweir     strcpy( pBuf, (const char*)pVar );
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     // jetzt haengt ggf. ein Backlash dran, den wir abschneiden,
690*cdf0e10cSrcweir     // ggf. inklusive dahinter haengendem Dateinamen
691*cdf0e10cSrcweir     if ( bRemoveBS )
692*cdf0e10cSrcweir     {
693*cdf0e10cSrcweir         char *pTail = pBuf + strlen(pBuf) - 1;
694*cdf0e10cSrcweir         for ( char cLast = *pTail; cLast != '\\'; cLast = *(--pTail) )
695*cdf0e10cSrcweir             *pTail = 0;
696*cdf0e10cSrcweir     }
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     if ( bAppendTemp )
699*cdf0e10cSrcweir         strcat( pBuf, "\\temp" );
700*cdf0e10cSrcweir     DirEntry( pBuf ).MakeDir();
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     return pBuf;
703*cdf0e10cSrcweir }
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir #define CURRENT_COUNTRY 0
706*cdf0e10cSrcweir #define NLS_CODEPAGE 850
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir /*====================================================================
709*cdf0e10cSrcweir  * CreateCaseMapImpl()
710*cdf0e10cSrcweir  * creates a map of each character to convert to lower
711*cdf0e10cSrcweir  *--------------------------------------------------------------------*/
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir #if 0
714*cdf0e10cSrcweir void CreateCaseMapImpl()
715*cdf0e10cSrcweir {
716*cdf0e10cSrcweir     // build a string starting with code 0 as first character upto 255
717*cdf0e10cSrcweir     char sTemp[256];
718*cdf0e10cSrcweir 	USHORT n;
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir     for ( n = 0; n < 256; ++n )
721*cdf0e10cSrcweir         sTemp[n] = (char) n;
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir     // convert string to upper case
724*cdf0e10cSrcweir     COUNTRYCODE aCountry;
725*cdf0e10cSrcweir     aCountry.country = CURRENT_COUNTRY;   /* Country code */
726*cdf0e10cSrcweir     aCountry.codepage = NLS_CODEPAGE;     /* Code page */
727*cdf0e10cSrcweir     DosMapCase( 255, &aCountry, sTemp+1 );
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir     // fill a global buffer starting with code 0 as first character upto 255
730*cdf0e10cSrcweir     for ( n = 0; n < 256; ++n )
731*cdf0e10cSrcweir         sCaseMap[n] = (char) n;
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     // reorder by upper-code and store in a global buffer
734*cdf0e10cSrcweir     for ( n = 255; n > 0; --n )
735*cdf0e10cSrcweir         // was this character converted?
736*cdf0e10cSrcweir         if ( sTemp[n] != (char) n )
737*cdf0e10cSrcweir             // we found a convertion from upper to lower
738*cdf0e10cSrcweir             sCaseMap[ (unsigned char) sTemp[n] ] = (char) n;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir     bCaseMap = TRUE;
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir String ToLowerImpl( const String& rSource )
744*cdf0e10cSrcweir {
745*cdf0e10cSrcweir     if ( !bCaseMap )
746*cdf0e10cSrcweir         CreateCaseMapImpl();
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir     // TH sagt: International ist zu langsam, also mit einer eigenen Map
749*cdf0e10cSrcweir     ByteString aLower( rSource );
750*cdf0e10cSrcweir     for ( USHORT n = 0; n < aLower.Len(); ++n )
751*cdf0e10cSrcweir         aLower[n] = sCaseMap[ (unsigned char) aLower[n] ];
752*cdf0e10cSrcweir     return aLower;
753*cdf0e10cSrcweir }
754*cdf0e10cSrcweir #endif // 0
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir /*====================================================================
757*cdf0e10cSrcweir  * CreateDriveMapImpl()
758*cdf0e10cSrcweir  * creates a map of drive-infos like FileSystem (style) and Kind (remote)
759*cdf0e10cSrcweir  *--------------------------------------------------------------------*/
760*cdf0e10cSrcweir typedef struct _FSQBUFFER_
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir     FSQBUFFER2  aBuf;
763*cdf0e10cSrcweir     UCHAR       sBuf[64];
764*cdf0e10cSrcweir } FSQBUFFER_;
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir void CreateDriveMapImpl()
767*cdf0e10cSrcweir {
768*cdf0e10cSrcweir #ifdef POWERPC
769*cdf0e10cSrcweir     // !!!!! Hack, da der untere Teil mit Beta 2 noch abstuertzt !!!!!
770*cdf0e10cSrcweir     BYTE nFloppies = 1;
771*cdf0e10cSrcweir     for ( USHORT nDrive = 0; nDrive < 26; ++nDrive )
772*cdf0e10cSrcweir     {
773*cdf0e10cSrcweir         if ( nDrive < nFloppies )
774*cdf0e10cSrcweir         {
775*cdf0e10cSrcweir             aDriveMap[nDrive].nKind = FSYS_KIND_REMOVEABLE;
776*cdf0e10cSrcweir             aDriveMap[nDrive].nStyle = FSYS_STYLE_FAT;
777*cdf0e10cSrcweir         }
778*cdf0e10cSrcweir         else
779*cdf0e10cSrcweir         {
780*cdf0e10cSrcweir             aDriveMap[nDrive].nKind = FSYS_KIND_UNKNOWN;
781*cdf0e10cSrcweir             aDriveMap[nDrive].nStyle = FSYS_STYLE_UNKNOWN;
782*cdf0e10cSrcweir         }
783*cdf0e10cSrcweir     }
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir     aDriveMap[2].nKind = FSYS_KIND_FIXED;
786*cdf0e10cSrcweir     aDriveMap[2].nStyle = FSYS_STYLE_FAT;
787*cdf0e10cSrcweir #else
788*cdf0e10cSrcweir     FSQBUFFER_	aBuf;
789*cdf0e10cSrcweir     ULONG       nBufLen;
790*cdf0e10cSrcweir     APIRET      nRet;
791*cdf0e10cSrcweir 	USHORT 		nDrive;
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir     // disable error-boxes for hard-errors
794*cdf0e10cSrcweir     DosError(FERR_DISABLEHARDERR);
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir     // determine number of floppy-drives
797*cdf0e10cSrcweir     BYTE nFloppies;
798*cdf0e10cSrcweir     nRet = DosDevConfig( (void*) &nFloppies, DEVINFO_FLOPPY );
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir     // reset the map
801*cdf0e10cSrcweir     for ( nDrive = 0; nDrive < 26; ++nDrive )
802*cdf0e10cSrcweir     {
803*cdf0e10cSrcweir         if ( nDrive < nFloppies )
804*cdf0e10cSrcweir         {
805*cdf0e10cSrcweir             aDriveMap[nDrive].nKind = FSYS_KIND_REMOVEABLE;
806*cdf0e10cSrcweir             aDriveMap[nDrive].nStyle = FSYS_STYLE_FAT;
807*cdf0e10cSrcweir         }
808*cdf0e10cSrcweir         else
809*cdf0e10cSrcweir         {
810*cdf0e10cSrcweir             aDriveMap[nDrive].nKind = FSYS_KIND_UNKNOWN;
811*cdf0e10cSrcweir             aDriveMap[nDrive].nStyle = FSYS_STYLE_UNKNOWN;
812*cdf0e10cSrcweir         }
813*cdf0e10cSrcweir     }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir     // determine file-system via DosOpen/DocDevIOCtrl
816*cdf0e10cSrcweir     for ( nDrive = 2; nDrive < 26; ++nDrive )
817*cdf0e10cSrcweir     {
818*cdf0e10cSrcweir         // open drive
819*cdf0e10cSrcweir         BOOL bFixed;
820*cdf0e10cSrcweir         HFILE nDevHandle;
821*cdf0e10cSrcweir         char pDriveName[3] = "#:";
822*cdf0e10cSrcweir         pDriveName[0] = nDrive+'a';
823*cdf0e10cSrcweir         ULONG nAction;
824*cdf0e10cSrcweir         nRet = DosOpen( (PSZ) pDriveName, &nDevHandle,
825*cdf0e10cSrcweir             &nAction, 0, 0, OPEN_ACTION_OPEN_IF_EXISTS,
826*cdf0e10cSrcweir             OPEN_FLAGS_DASD|OPEN_SHARE_DENYNONE|OPEN_ACCESS_READONLY,
827*cdf0e10cSrcweir             0 );
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir         // exists?
830*cdf0e10cSrcweir         if ( !nRet )
831*cdf0e10cSrcweir         {
832*cdf0e10cSrcweir             // removeable?
833*cdf0e10cSrcweir             BYTE nDriveId = nDrive;
834*cdf0e10cSrcweir             ULONG nParaOutLen, nDataOutLen;
835*cdf0e10cSrcweir             nRet = DosDevIOCtl(nDevHandle, 8, 0x20,
836*cdf0e10cSrcweir                 &nDriveId, sizeof(nDriveId), &nParaOutLen,
837*cdf0e10cSrcweir                 &bFixed, sizeof(bFixed), &nDataOutLen );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir             // prepare the drive-map
840*cdf0e10cSrcweir             if ( !nRet && !bFixed )
841*cdf0e10cSrcweir                 aDriveMap[nDrive].nKind = FSYS_KIND_REMOVEABLE;
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir             // close drive
844*cdf0e10cSrcweir             DosClose(nDevHandle);
845*cdf0e10cSrcweir         }
846*cdf0e10cSrcweir         else if ( nRet == ERROR_NOT_READY )
847*cdf0e10cSrcweir             aDriveMap[nDrive].nKind = FSYS_KIND_REMOVEABLE | FSYS_KIND_CDROM;
848*cdf0e10cSrcweir     }
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     // determine file-system via FSAttach
851*cdf0e10cSrcweir     nRet = 0;
852*cdf0e10cSrcweir     for ( USHORT n = 3; nRet != ERROR_NO_MORE_ITEMS; ++n )
853*cdf0e10cSrcweir     {
854*cdf0e10cSrcweir         nBufLen = sizeof( aBuf );
855*cdf0e10cSrcweir         nRet = DosQueryFSAttach( 0, n, FSAIL_DRVNUMBER,
856*cdf0e10cSrcweir             (_FSQBUFFER2*) &aBuf, &nBufLen );
857*cdf0e10cSrcweir         if ( !nRet )
858*cdf0e10cSrcweir         {
859*cdf0e10cSrcweir             nDrive = toupper(aBuf.aBuf.szName[0]) - 'A';
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir             if ( aDriveMap[nDrive].nKind == FSYS_KIND_UNKNOWN )
862*cdf0e10cSrcweir                 aDriveMap[nDrive].nKind =
863*cdf0e10cSrcweir                     aBuf.aBuf.iType == 3 ? FSYS_KIND_FIXED :
864*cdf0e10cSrcweir                     aBuf.aBuf.iType == 4 ? FSYS_KIND_REMOTE :
865*cdf0e10cSrcweir                     FSYS_KIND_UNKNOWN;
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir             char *pType = (char*)(aBuf.aBuf.szName + aBuf.aBuf.cbName + 1);
868*cdf0e10cSrcweir             aDriveMap[nDrive].nStyle =
869*cdf0e10cSrcweir                 strcmp( pType, "FAT" ) == 0 ? FSYS_STYLE_FAT :
870*cdf0e10cSrcweir                 strcmp( pType, "FAT32" ) == 0 ? FSYS_STYLE_VFAT :
871*cdf0e10cSrcweir                 strcmp( pType, "NTFS" ) == 0 ? FSYS_STYLE_NTFS :
872*cdf0e10cSrcweir                 strcmp( pType, "HPFS" ) == 0 ? FSYS_STYLE_HPFS :
873*cdf0e10cSrcweir                 strcmp( pType, "JFS" ) == 0 ? FSYS_STYLE_HPFS :
874*cdf0e10cSrcweir                 strcmp( pType, "RAMFS" ) == 0 ? FSYS_STYLE_HPFS :
875*cdf0e10cSrcweir                 strcmp( pType, "NDFS32" ) == 0 ? FSYS_STYLE_HPFS :
876*cdf0e10cSrcweir                 strcmp( pType, "NWFS" ) == 0 ? FSYS_STYLE_NWFS :
877*cdf0e10cSrcweir 				strcmp( pType, "EXT2" ) == 0 ? FSYS_STYLE_UNX :
878*cdf0e10cSrcweir 				strcmp( pType, "NFS" ) == 0 ? FSYS_STYLE_UNX :
879*cdf0e10cSrcweir                 FSYS_STYLE_UNKNOWN;
880*cdf0e10cSrcweir             if ( strcmp( pType, "CDFS" ) == 0 )
881*cdf0e10cSrcweir                 aDriveMap[nDrive].nKind = FSYS_KIND_CDROM|FSYS_KIND_REMOVEABLE;
882*cdf0e10cSrcweir         }
883*cdf0e10cSrcweir     }
884*cdf0e10cSrcweir #endif
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir     bDriveMap = TRUE;
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir Time MsDos2Time( const time_t *pTimeT )
890*cdf0e10cSrcweir {
891*cdf0e10cSrcweir     tm *pTm = localtime( pTimeT );
892*cdf0e10cSrcweir     if ( pTm )
893*cdf0e10cSrcweir         return Time( pTm->tm_hour, pTm->tm_min, pTm->tm_sec );
894*cdf0e10cSrcweir     else
895*cdf0e10cSrcweir         return Time(0);
896*cdf0e10cSrcweir }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir Date MsDos2Date( const time_t *pTimeT )
899*cdf0e10cSrcweir {
900*cdf0e10cSrcweir     tm *pTm = localtime( pTimeT );
901*cdf0e10cSrcweir     if ( pTm )
902*cdf0e10cSrcweir         return Date( pTm->tm_mday, pTm->tm_mon + 1, pTm->tm_year );
903*cdf0e10cSrcweir     else
904*cdf0e10cSrcweir         return Date(0);
905*cdf0e10cSrcweir }
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir /*************************************************************************
908*cdf0e10cSrcweir |*
909*cdf0e10cSrcweir |*    DirEntry::GetPathStyle() const
910*cdf0e10cSrcweir |*
911*cdf0e10cSrcweir |*    Beschreibung
912*cdf0e10cSrcweir |*    Ersterstellung    MI 11.05.95
913*cdf0e10cSrcweir |*    Letzte Aenderung  MI 11.05.95
914*cdf0e10cSrcweir |*
915*cdf0e10cSrcweir *************************************************************************/
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir FSysPathStyle DirEntry::GetPathStyle( const String &rDevice )
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir     ByteString aRootDir(rDevice, osl_getThreadTextEncoding());
920*cdf0e10cSrcweir     // UNC-Pathname?
921*cdf0e10cSrcweir     if ( aRootDir.Len()==0 || ( aRootDir.Len() > 1 && aRootDir.GetChar(1) != ':' ) )
922*cdf0e10cSrcweir         return FSYS_STYLE_UNKNOWN;
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir     if ( !bDriveMap )
925*cdf0e10cSrcweir         CreateDriveMapImpl();
926*cdf0e10cSrcweir     return aDriveMap[toupper(aRootDir.GetChar(0)) - 'A'].nStyle;
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir /*************************************************************************
930*cdf0e10cSrcweir |*
931*cdf0e10cSrcweir |*    DirEntry::IsCaseSensitive() const
932*cdf0e10cSrcweir |*
933*cdf0e10cSrcweir |*    Beschreibung
934*cdf0e10cSrcweir |*    Ersterstellung    TPF 26.02.1999
935*cdf0e10cSrcweir |*    Letzte Aenderung
936*cdf0e10cSrcweir |*
937*cdf0e10cSrcweir *************************************************************************/
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir BOOL DirEntry::IsCaseSensitive( FSysPathStyle eFormatter ) const
940*cdf0e10cSrcweir {
941*cdf0e10cSrcweir 	if (eFormatter==FSYS_STYLE_HOST)
942*cdf0e10cSrcweir 	{
943*cdf0e10cSrcweir 		if 	(GetPathStyle(GetDevice().GetName()) == FSYS_STYLE_UNX)
944*cdf0e10cSrcweir 		{
945*cdf0e10cSrcweir 			return TRUE;
946*cdf0e10cSrcweir 		}
947*cdf0e10cSrcweir 		else
948*cdf0e10cSrcweir 		{
949*cdf0e10cSrcweir 			return FALSE;
950*cdf0e10cSrcweir 		}
951*cdf0e10cSrcweir 	}
952*cdf0e10cSrcweir 	else
953*cdf0e10cSrcweir 	{
954*cdf0e10cSrcweir 		BOOL isCaseSensitive = FALSE;			// ich bin unter OS2, also ist der default im Zweifelsfall case insensitiv
955*cdf0e10cSrcweir 		switch ( eFormatter )
956*cdf0e10cSrcweir 		{
957*cdf0e10cSrcweir 			case FSYS_STYLE_MAC:
958*cdf0e10cSrcweir 			case FSYS_STYLE_FAT:
959*cdf0e10cSrcweir 			case FSYS_STYLE_VFAT:
960*cdf0e10cSrcweir 			case FSYS_STYLE_NTFS:
961*cdf0e10cSrcweir 			case FSYS_STYLE_NWFS:
962*cdf0e10cSrcweir 			case FSYS_STYLE_HPFS:
963*cdf0e10cSrcweir 			case FSYS_STYLE_DETECT:
964*cdf0e10cSrcweir 				{
965*cdf0e10cSrcweir 					isCaseSensitive = FALSE;
966*cdf0e10cSrcweir 					break;
967*cdf0e10cSrcweir 				}
968*cdf0e10cSrcweir 			case FSYS_STYLE_SYSV:
969*cdf0e10cSrcweir 			case FSYS_STYLE_BSD:
970*cdf0e10cSrcweir 				{
971*cdf0e10cSrcweir 					isCaseSensitive = TRUE;
972*cdf0e10cSrcweir 					break;
973*cdf0e10cSrcweir 				}
974*cdf0e10cSrcweir 			default:
975*cdf0e10cSrcweir 				{
976*cdf0e10cSrcweir 					isCaseSensitive = FALSE;	// ich bin unter OS2, also ist der default im Zweifelsfall case insensitiv
977*cdf0e10cSrcweir 					break;
978*cdf0e10cSrcweir 				}
979*cdf0e10cSrcweir 		}
980*cdf0e10cSrcweir 		return isCaseSensitive;
981*cdf0e10cSrcweir 	}
982*cdf0e10cSrcweir }
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir //=========================================================================
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir ErrCode FileStat::QueryDiskSpace( const String &rPath,
990*cdf0e10cSrcweir                                   BigInt &rFreeBytes, BigInt &rTotalBytes )
991*cdf0e10cSrcweir {
992*cdf0e10cSrcweir     FSALLOCATE aFSInfoBuf;
993*cdf0e10cSrcweir     ByteString aVol( DirEntry(rPath).ImpGetTopPtr()->GetName(), osl_getThreadTextEncoding());
994*cdf0e10cSrcweir     ULONG nDriveNumber = toupper( aVol.GetChar(0) ) - 'A' + 1;
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir     APIRET rc = DosQueryFSInfo( nDriveNumber, FSIL_ALLOC,
997*cdf0e10cSrcweir                                 &aFSInfoBuf, sizeof(aFSInfoBuf) );
998*cdf0e10cSrcweir     if ( rc )
999*cdf0e10cSrcweir         return Sys2SolarError_Impl( rc );
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     BigInt aBytesPerCluster( BigInt(aFSInfoBuf.cbSector) *
1002*cdf0e10cSrcweir                              BigInt(aFSInfoBuf.cSectorUnit) );
1003*cdf0e10cSrcweir     rFreeBytes = aBytesPerCluster * BigInt(aFSInfoBuf.cUnitAvail);
1004*cdf0e10cSrcweir     rTotalBytes = aBytesPerCluster * BigInt(aFSInfoBuf.cUnit);
1005*cdf0e10cSrcweir     return 0;
1006*cdf0e10cSrcweir }
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir //=========================================================================
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir void FSysEnableSysErrorBox( BOOL bEnable )
1011*cdf0e10cSrcweir {
1012*cdf0e10cSrcweir     DosError( bEnable ? 0 : FERR_DISABLEHARDERR );
1013*cdf0e10cSrcweir }
1014*cdf0e10cSrcweir 
1015