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