xref: /trunk/main/tools/source/fsys/tdir.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26 
27 #define _DIR_CXX
28 
29 #include <stdlib.h>
30 #include <cstdarg>
31 #include <limits.h>
32 #include <tools/debug.hxx>
33 #include <tools/list.hxx>
34 
35 #ifndef _COMPED_HXX
36 #include "comdep.hxx"
37 #endif
38 #include <tools/fsys.hxx>
39 
40 
41 DBG_NAME( Dir )
42 
DECLARE_LIST(DirEntryList,DirEntry *)43 DECLARE_LIST( DirEntryList, DirEntry* )
44 DECLARE_LIST( FSysSortList, FSysSort* )
45 DECLARE_LIST( FileStatList, FileStat* )
46 
47 #define APPEND (sal_uInt16) 65535
48 
49 /*************************************************************************
50 |*
51 |*    Dir::InsertPointReached()
52 |*
53 |*    Beschreibung      stellt fest, ob eingefuegt werden musz
54 |*    Ersterstellung    MA 05.11.91
55 |*    Letzte Aenderung  MI 05.02.92
56 |*
57 *************************************************************************/
58 
59 sal_Bool Dir::ImpInsertPointReached( const DirEntry& rNewEntry,
60                                  const FileStat& rNewStat,
61                                  sal_uIntPtr nCurPos, sal_uIntPtr nSortIndex ) const
62 {
63 #define VALUE( nKindFlags ) \
64     ( ( FSYS_KIND_FILE | FSYS_KIND_DIR | FSYS_KIND_DEV | \
65         FSYS_KIND_CHAR | FSYS_KIND_BLOCK ) & nKindFlags )
66 
67     // einfache Dinge erfordern einfache Loesungen
68     if ( !pLst->Count() )
69         return sal_True;
70 
71     FSysSort  nSort      = *( pSortLst->GetObject( nSortIndex ) );
72     FileStat *pOldStat   = NULL;
73     DirEntry *pCurLstObj = pLst->GetObject( nCurPos );
74     if ( pStatLst )
75         pOldStat = pStatLst->GetObject( nCurPos );
76 
77     switch( nSort )
78     {
79         case  FSYS_SORT_NAME:
80         case (FSYS_SORT_NAME | FSYS_SORT_ASCENDING):
81             if ( pCurLstObj->aName > rNewEntry.aName )
82                 return sal_True;
83             if ( !(pCurLstObj->aName == rNewEntry.aName) )
84                 return sal_False;
85             break;
86         case (FSYS_SORT_NAME | FSYS_SORT_DESCENDING):
87             if ( pCurLstObj->aName < rNewEntry.aName )
88                 return sal_True;
89             if ( !(pCurLstObj->aName == rNewEntry.aName) )
90                 return sal_False;
91             break;
92 
93         case  FSYS_SORT_EXT:
94         case (FSYS_SORT_EXT | FSYS_SORT_ASCENDING):
95         {
96             if ( pCurLstObj->GetExtension() > rNewEntry.GetExtension() )
97                 return sal_True;
98             if ( !(pCurLstObj->GetExtension() == rNewEntry.GetExtension()) )
99                 return sal_False;
100             break;
101         }
102         case (FSYS_SORT_EXT | FSYS_SORT_DESCENDING):
103         {
104             if ( pCurLstObj->GetExtension() < rNewEntry.GetExtension() )
105                 return sal_True;
106             if ( !(pCurLstObj->GetExtension() == rNewEntry.GetExtension()) )
107                 return sal_False;
108             break;
109         }
110 
111         case  FSYS_SORT_KIND:
112         case (FSYS_SORT_KIND | FSYS_SORT_ASCENDING ):
113             if ( VALUE(pOldStat->nKindFlags) > VALUE(rNewStat.nKindFlags) )
114                 return sal_True;
115             if ( !(VALUE(pOldStat->nKindFlags) == VALUE(rNewStat.nKindFlags)) )
116                 return sal_False;
117             break;
118         case (FSYS_SORT_KIND | FSYS_SORT_DESCENDING):
119             if ( VALUE(pOldStat->nKindFlags) < VALUE(rNewStat.nKindFlags) )
120                 return sal_True;
121             if ( !(VALUE(pOldStat->nKindFlags) == VALUE(rNewStat.nKindFlags)) )
122                 return sal_False;
123             break;
124 
125         case  FSYS_SORT_SIZE:
126         case (FSYS_SORT_SIZE | FSYS_SORT_ASCENDING):
127             if ( pOldStat->nSize > rNewStat.nSize )
128                 return sal_True;
129             if ( !(pOldStat->nSize == rNewStat.nSize) )
130                 return sal_False;
131             break;
132         case (FSYS_SORT_SIZE | FSYS_SORT_DESCENDING):
133             if ( pOldStat->nSize < rNewStat.nSize )
134                 return sal_True;
135             if ( !(pOldStat->nSize == rNewStat.nSize) )
136                 return sal_False;
137             break;
138 
139         case  FSYS_SORT_MODIFYED:
140         case (FSYS_SORT_MODIFYED | FSYS_SORT_ASCENDING):
141             if ( (pOldStat->aDateModified >= rNewStat.aDateModified) &&
142                  (pOldStat->aTimeModified >  rNewStat.aTimeModified) )
143                  return sal_True;
144             if ( !((pOldStat->aDateModified == rNewStat.aDateModified) &&
145                    (pOldStat->aTimeModified == rNewStat.aTimeModified)) )
146                 return sal_False;
147             break;
148         case (FSYS_SORT_MODIFYED | FSYS_SORT_DESCENDING):
149             if ( (pOldStat->aDateModified <= rNewStat.aDateModified) &&
150                  (pOldStat->aTimeModified <  rNewStat.aTimeModified) )
151                  return sal_True;
152             if ( !((pOldStat->aDateModified == rNewStat.aDateModified) &&
153                    (pOldStat->aTimeModified == rNewStat.aTimeModified)) )
154                 return sal_False;
155             break;
156 
157         case  FSYS_SORT_CREATED:
158         case (FSYS_SORT_CREATED | FSYS_SORT_ASCENDING):
159             if ( (pOldStat->aDateCreated >= rNewStat.aDateCreated) &&
160                  (pOldStat->aTimeCreated >  rNewStat.aTimeCreated) )
161                  return sal_True;
162             if ( !((pOldStat->aDateCreated == rNewStat.aDateCreated) &&
163                    (pOldStat->aTimeCreated == rNewStat.aTimeCreated)) )
164                 return sal_False;
165             break;
166         case (FSYS_SORT_CREATED | FSYS_SORT_DESCENDING):
167             if ( (pOldStat->aDateCreated <= rNewStat.aDateCreated) &&
168                  (pOldStat->aTimeCreated <  rNewStat.aTimeCreated) )
169                  return sal_True;
170             if ( !((pOldStat->aDateCreated == rNewStat.aDateCreated) &&
171                    (pOldStat->aTimeCreated == rNewStat.aTimeCreated)) )
172                 return sal_False;
173             break;
174 
175         case  FSYS_SORT_ACCESSED:
176         case (FSYS_SORT_ACCESSED | FSYS_SORT_ASCENDING):
177             if ( (pOldStat->aDateAccessed >= rNewStat.aDateAccessed) &&
178                  (pOldStat->aTimeAccessed >  rNewStat.aTimeAccessed) )
179                  return sal_True;
180             if ( !((pOldStat->aDateAccessed == rNewStat.aDateAccessed) &&
181                    (pOldStat->aTimeAccessed == rNewStat.aTimeAccessed)) )
182                 return sal_False;
183             break;
184         case (FSYS_SORT_ACCESSED | FSYS_SORT_DESCENDING):
185             if ( (pOldStat->aDateAccessed <= rNewStat.aDateAccessed) &&
186                  (pOldStat->aTimeAccessed <  rNewStat.aTimeAccessed) )
187                  return sal_True;
188             if ( !((pOldStat->aDateAccessed == rNewStat.aDateAccessed) &&
189                    (pOldStat->aTimeAccessed == rNewStat.aTimeAccessed)) )
190                 return sal_False;
191             break;
192         default: /* Kann nicht sein */;
193     }
194 
195     if ( nSortIndex == ( pSortLst->Count() - 1 ) )
196         return sal_True;
197     else
198         //Rekursion
199         return ImpInsertPointReached( rNewEntry, rNewStat,
200                                       nCurPos, nSortIndex + 1 );
201 #undef VALUE
202 }
203 
204 /*************************************************************************
205 |*
206 |*    Dir::ImpSortedInsert()
207 |*
208 |*    Beschreibung      fuegt sortiert ein
209 |*    Ersterstellung    MA 05.11.91
210 |*    Letzte Aenderung  MA 03.12.91
211 |*
212 *************************************************************************/
213 
ImpSortedInsert(const DirEntry * pNewEntry,const FileStat * pNewStat)214 void Dir::ImpSortedInsert( const DirEntry *pNewEntry, const FileStat *pNewStat )
215 {
216     //Sonderfall, keine Sortierung gewuenscht.
217     if ( !pSortLst ) {
218         pLst->Insert( (DirEntry*)pNewEntry, APPEND );
219         return;
220     }
221 
222     pLst->First();
223     do {
224         if ( ImpInsertPointReached( *pNewEntry, *pNewStat, pLst->GetCurPos(),
225                                     (sal_uIntPtr)0  ) )
226         {
227             if ( pStatLst )
228                 pStatLst->Insert( (FileStat*)pNewStat, pLst->GetCurPos() );
229             pLst->Insert( (DirEntry*)pNewEntry );
230             return;
231         }
232     } while( pLst->Next() );
233 
234     if ( pStatLst )
235         pStatLst->Insert( (FileStat*)pNewStat, APPEND );
236     pLst->Insert( (DirEntry*)pNewEntry, APPEND );
237 }
238 
239 /*************************************************************************
240 |*
241 |*    Dir::Construct()
242 |*
243 |*    Beschreibung      gemeinsame Implementation der Ctoren
244 |*    Ersterstellung    MI 02.06.93
245 |*    Letzte Aenderung  MI 02.06.93
246 |*
247 *************************************************************************/
248 
Construct(DirEntryKind nKindFlags)249 void Dir::Construct( DirEntryKind nKindFlags )
250 {
251     pLst     = NULL;
252     pSortLst = NULL;
253     pStatLst = NULL;
254     eAttrMask = nKindFlags;
255     ByteString aTempName( GetName(), osl_getThreadTextEncoding() );
256     if ( aTempName.Search( "*" ) != STRING_NOTFOUND ||
257          aTempName.Search( "?" ) != STRING_NOTFOUND )
258 #if defined( WNT ) && !defined( WTC )
259     {
260         ByteString aTStr(CutName(), osl_getThreadTextEncoding());
261         char* pBuffer = new char[aTStr.Len()+1];
262         strcpy( pBuffer, aTStr.GetBuffer() );
263         CharLowerBuff( pBuffer, aTStr.Len() );
264         aNameMask = WildCard( String(pBuffer, osl_getThreadTextEncoding()), ';' );
265         delete [] pBuffer;
266     }
267 #else
268     aNameMask = WildCard( CutName(), ';' );
269 #endif
270     else
271         aNameMask = String("*", osl_getThreadTextEncoding());
272 }
273 
274 /*************************************************************************
275 |*
276 |*    Dir::Update()
277 |*
278 |*    Beschreibung      FSYS.SDW
279 |*    Ersterstellung    MI 16.05.91
280 |*    Letzte Aenderung  MI 19.09.96
281 |*
282 *************************************************************************/
283 
Update()284 sal_Bool Dir::Update()
285 {
286 	Reset();
287 	return Scan( USHRT_MAX ) > 0;
288 }
289 
290 /*************************************************************************
291 |*
292 |*    Dir::Reset()
293 |*
294 |*    Beschreibung
295 |*    Ersterstellung    MI 22.10.96
296 |*    Letzte Aenderung  MI 22.10.96
297 |*
298 *************************************************************************/
299 
Reset()300 void Dir::Reset()
301 {
302 	// ggf. alten Reader l"oschen
303 	if ( pReader && pReader->bInUse )
304 		DELETEZ(pReader);
305 
306 	// alle DirEntries aus der Liste entfernen und deren Speicher freigeben
307 	if ( pLst )
308 	{
309 		DirEntry* pEntry = pLst->First();
310 		while (pEntry)
311 		{
312 			DirEntry* pNext = pLst->Next();
313 			delete pEntry;
314 			pEntry = pNext;
315 		}
316 		pLst->Clear();
317 	}
318 	else
319 		pLst = new DirEntryList();
320 
321 	//	Alte File-Stat's Loeschen
322 	if ( pStatLst )
323 	{
324 		//Erstmal die alten Loeschen
325 		FileStat* pEntry = pStatLst->First();
326 		while (pEntry)
327 		{
328 			FileStat*  pNext = pStatLst->Next();
329 			delete pEntry;
330 			pEntry = pNext;
331 		}
332 		pStatLst->Clear();
333 		delete pStatLst;
334 	}
335 
336 	// Verlangen die Sortierkriterien FileStat's?
337 	if ( pSortLst )
338 	{
339 		pSortLst->First();
340 		do
341 		{
342 			if ( *( pSortLst->GetCurObject() ) &
343 					( FSYS_SORT_KIND | FSYS_SORT_SIZE |
344 					FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_ACCESSED ) )
345 				pStatLst = new FileStatList();
346 		} while ( !pStatLst && pSortLst->Next() );
347 	}
348 
349 #ifndef BOOTSTRAP
350 	// ggf. einen neuen Reader aufsetzen
351 	if ( !pReader )
352 		pReader = new DirReader_Impl( *this );
353 #endif
354 
355 	// gibt es das zu oeffnende Verzeichnis ueberhaupt?
356 #if !defined(UNX) && !defined(OS2) //explanation: see DirReader_Impl::Read() in unx.cxx
357 	if( !pReader->pDosDir )
358 	{
359 		nError = FSYS_ERR_NOTADIRECTORY;
360 		DELETEZ( pReader );
361 		return;
362 	}
363 #endif
364 }
365 
366 /*************************************************************************
367 |*
368 |*    Dir::Scan()
369 |*
370 |*    Beschreibung      FSYS.SDW
371 |*    Ersterstellung    MI 18.09.96
372 |*    Letzte Aenderung  MI 19.09.96
373 |*
374 *************************************************************************/
375 
Scan(sal_uInt16 nCount)376 sal_uInt16 Dir::Scan( sal_uInt16 nCount )
377 {
378 
379 	sal_uInt16 nRead = 0; // Anzahl in dieser Runde gelesener Eintr"age
380 	FSysFailOnErrorImpl();
381 
382 	// noch nicht fertig gewesen
383 	if ( pReader )
384 	{
385 		// frischer Reader?
386 		if ( !pLst->Count() )
387 		{
388 			// dann ggf. Laufwerke scannen
389 			pReader->bInUse = sal_True;
390 			nRead = pReader->Init();
391 		}
392 
393 		// weiterlesen...
394 		while ( nRead <= nCount && !pReader->bReady )
395 			nRead = nRead + pReader->Read();
396 
397 		// fertig?
398 		if ( pReader && pReader->bReady )
399 			DELETEZ( pReader );
400 	}
401 
402 	// Anzahl der gelesenen zur"uckgeben
403 	return nRead;
404 }
405 
406 /*************************************************************************
407 |*
408 |*    Dir::Dir()
409 |*
410 |*    Beschreibung      FSYS.SDW
411 |*    Ersterstellung    MI 16.05.91
412 |*    Letzte Aenderung  MI 04.03.92
413 |*
414 *************************************************************************/
415 
Dir(const DirEntry & rDirEntry,DirEntryKind nKindFlags,FSysSort nSort,...)416 Dir::Dir( const DirEntry& rDirEntry, DirEntryKind nKindFlags, FSysSort nSort, ... ):
417     DirEntry( rDirEntry ),
418 	pReader( 0 )
419 {
420     DBG_CTOR( Dir, NULL );
421 
422     Construct( nKindFlags );
423 
424     std::va_list pArgs;
425     va_start( pArgs, nSort );
426     ImpSetSort( pArgs, nSort );
427 
428 	Reset();
429 }
430 
431 /*************************************************************************
432 |*
433 |*    Dir::Dir()
434 |*
435 |*    Beschreibung      FSYS.SDW
436 |*    Ersterstellung    MI 02.06.93
437 |*    Letzte Aenderung  MI 02.06.93
438 |*
439 *************************************************************************/
440 
Dir(const DirEntry & rDirEntry,DirEntryKind nKindFlags)441 Dir::Dir( const DirEntry& rDirEntry, DirEntryKind nKindFlags ):
442     DirEntry( rDirEntry ),
443 	pReader( 0 )
444 {
445     DBG_CTOR( Dir, NULL );
446 
447     Construct( nKindFlags );
448     Reset();
449 }
450 
451 /*************************************************************************
452 |*
453 |*    Dir::Dir()
454 |*
455 |*    Beschreibung      FSYS.SDW
456 |*    Ersterstellung    MI 16.05.91
457 |*    Letzte Aenderung  MA 04.11.91
458 |*
459 *************************************************************************/
460 
Dir()461 Dir::Dir():
462 	pReader( 0 )
463 {
464     DBG_CTOR( Dir, NULL );
465 
466     pLst     = NULL;
467     pSortLst = NULL;
468     pStatLst = NULL;
469     eAttrMask = FSYS_KIND_ALL;
470     aNameMask = String("*", osl_getThreadTextEncoding());
471 }
472 
473 /*************************************************************************
474 |*
475 |*    Dir::~Dir()
476 |*
477 |*    Beschreibung      FSYS.SDW
478 |*    Ersterstellung    MI 16.05.91
479 |*    Letzte Aenderung  MA 04.11.91
480 |*
481 *************************************************************************/
482 
~Dir()483 Dir::~Dir()
484 {
485     DBG_DTOR( Dir, NULL );
486 
487     // alle DirEntries aus der Liste entfernen und deren Speicher freigeben
488     if ( pLst )
489     {
490 		DirEntry* pEntry = pLst->First();
491 		while (pEntry)
492 		{
493 			DirEntry* pNext = pLst->Next();
494 			delete pEntry;
495 			pEntry = pNext;
496 		}
497 		pLst->Clear();
498 
499         delete pLst;
500     }
501 
502     // alle Sorts aus der Liste entfernen und deren Speicher freigeben
503     if ( pSortLst )
504     {
505 		FSysSort* pEntry = pSortLst->First();
506 		while (pEntry)
507 		{
508 			FSysSort*  pNext = pSortLst->Next();
509 			delete pEntry;
510 			pEntry = pNext;
511 		}
512 		pSortLst->Clear();
513 
514         delete pSortLst;
515     }
516 
517     // alle FileStat's aus der Liste entfernen und deren Speicher freigeben
518     if ( pStatLst )
519     {
520 		FileStat* pEntry = pStatLst->First();
521 		while (pEntry)
522 		{
523 			FileStat*  pNext = pStatLst->Next();
524 			delete pEntry;
525 			pEntry = pNext;
526 		}
527 		pStatLst->Clear();
528         delete pStatLst;
529     }
530 
531 	// ggf. laufenden Reader freigeben
532 	delete pReader;
533 }
534 
535 /*************************************************************************
536 |*
537 |*    Dir::ImpSetSort()
538 |*
539 |*    Beschreibung      FSYS.SDW
540 |*    Ersterstellung    MA 04.11.91
541 |*    Letzte Aenderung  MI 05.02.92
542 |*
543 *************************************************************************/
544 
ImpSetSort(std::va_list pArgs,int nFirstSort)545 FSysError Dir::ImpSetSort( std::va_list pArgs, int nFirstSort )
546 {
547     sal_Bool             bLast;
548     FSysSort        *pSort;
549     FSysSortList    *pNewSortLst = new FSysSortList;
550 
551 	*( pSort = new FSysSort ) = nFirstSort;
552     do
553     {
554 		// letztes Kriterium?
555         bLast = FSYS_SORT_END == (*pSort & FSYS_SORT_END);
556         *pSort &= ~FSYS_SORT_END;
557 
558 		FSysSort nSort = *pSort & ~(sal_uInt16)FSYS_SORT_ASCENDING
559 							  &  ~(sal_uInt16)FSYS_SORT_DESCENDING;
560 
561 		// g"utliges Sortierkriterium?
562         if ( ( nSort ==  FSYS_SORT_NAME ) ||
563              ( nSort ==  FSYS_SORT_SIZE ) ||
564              ( nSort ==  FSYS_SORT_EXT )  ||
565              ( nSort ==  FSYS_SORT_CREATED ) ||
566              ( nSort ==  FSYS_SORT_MODIFYED ) ||
567              ( nSort ==  FSYS_SORT_ACCESSED ) ||
568 			 ( nSort ==  FSYS_SORT_KIND ) )
569         {
570             pNewSortLst->Insert( pSort, APPEND );
571             *(pSort = new FSysSort) = va_arg( pArgs, FSysSort );
572         }
573         else
574         {   // ungueltiger Sort oder FSYS_SORT_NONE
575 			FSysSort* pEntry = pNewSortLst->First();
576 			while (pEntry)
577 			{
578 				FSysSort* pNext = pNewSortLst->Next();
579 				delete pEntry;
580 				pEntry = pNext;
581 			}
582 			pNewSortLst->Clear();
583             delete pNewSortLst;
584             if ( *pSort ==  FSYS_SORT_NONE )
585 			{
586                 delete pSort;
587                 if ( pSortLst )
588                     delete pSortLst;
589                 return FSYS_ERR_OK;
590             }
591             else
592 			{
593                 delete pSort;
594                 return FSYS_ERR_NOTSUPPORTED;
595             }
596         }
597     } while ( !bLast );
598 
599     va_end( pArgs );
600 	delete pSort;			// JP:6.3.00 - delete the initial pointer
601 
602     //Enfernen der alten Sort-Elemente
603     if ( pSortLst )
604 	{
605 		FSysSort* pEntry = pSortLst->First();
606 		while (pEntry)
607 		{
608 			FSysSort* pNext = pSortLst->Next();
609 			delete pEntry;
610 			pEntry = pNext;
611 		}
612 		pSortLst->Clear();
613 		delete pSortLst;
614 	}
615     pSortLst = pNewSortLst;
616 
617     //Jetzt noch neu Sortieren...
618 
619     //Wenn keine FileStats da sind, aber nun welche gebraucht werden,
620     //ist der Aufruf von Update() die einfachste Moeglichkeit
621     if ( !pStatLst && pSortLst )
622     {
623         pSortLst->First();
624         do
625         {
626             if ( *(pSortLst->GetCurObject()) &
627                   ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE |
628                     FSYS_SORT_ACCESSED | FSYS_SORT_KIND ) )
629             {
630                 Update();
631                 return FSYS_ERR_OK;
632             }
633         } while ( !pStatLst && pSortLst->Next() );
634     }
635 
636     if ( pLst ) { //Keine DirEntry's, kein Sort.
637         DirEntryList    *pOldLst = pLst; //alte Liste merken
638         pLst = new DirEntryList();       //neue Liste (zu Sortieren)
639 
640         FileStatList *pOldStatLst = NULL; //alte StatListe merken
641         if ( pStatLst ) {
642             pOldStatLst = pStatLst;
643             pStatLst = new FileStatList(); //neue StatListe (zu Sortieren)
644         }
645         pOldLst->First();
646         do
647         {
648             //Sortiertes Einfuegen der Elemente aus den gemerkten Listen
649             //in die 'richtigen' Listen
650             if ( pOldStatLst )
651                 ImpSortedInsert( pOldLst->GetCurObject(),
652                                  pOldStatLst->GetObject( pOldLst->GetCurPos() ) );
653             else
654                 ImpSortedInsert( pOldLst->GetCurObject(), NULL );
655         } while( pOldLst->Next() );
656 
657         delete pOldLst;
658         if ( pOldStatLst )
659             delete pOldStatLst;
660     }
661     return FSYS_ERR_OK;
662 }
663 
664 /*************************************************************************
665 |*
666 |*    Dir::SetSort()
667 |*
668 |*    Beschreibung      FSYS.SDW
669 |*    Ersterstellung    MA 04.11.91
670 |*    Letzte Aenderung  MI 05.02.92
671 |*
672 *************************************************************************/
673 
SetSort(FSysSort nSort,...)674 FSysError Dir::SetSort( FSysSort nSort, ... )
675 {
676     std::va_list pArgs;
677     va_start( pArgs, nSort );
678     return ImpSetSort( pArgs, nSort );
679 }
680 
681 /*************************************************************************
682 |*
683 |*    Dir::operator[]()
684 |*
685 |*    Beschreibung      FSYS.SDW
686 |*    Ersterstellung    MI 16.05.91
687 |*    Letzte Aenderung  MI 16.05.91
688 |*
689 *************************************************************************/
690 
operator [](sal_uInt16 nIndex) const691 DirEntry& Dir::operator[] ( sal_uInt16 nIndex ) const
692 {
693     DBG_ASSERT( nIndex < Count(), "Dir::operator[] : nIndex > Count()" );
694 
695     DirEntry *pEntry = pLst->GetObject( nIndex );
696 	return *pEntry;
697 }
698 
699 /*************************************************************************
700 |*
701 |*    Dir::operator+= ()
702 |*
703 |*    Beschreibung      FSYS.SDW
704 |*    Ersterstellung    MI 16.05.91
705 |*    Letzte Aenderung  MI 16.05.91
706 |*
707 *************************************************************************/
708 
operator +=(const Dir & rDir)709 Dir& Dir::operator+=( const Dir& rDir )
710 {
711 	// ggf. erst den Rest lesen
712 	if ( pReader )
713 		Scan( USHRT_MAX );
714 	DBG_ASSERT( !rDir.pReader, "Dir::+= with incomplete Dir" );
715 
716 	// ggf. initiale Liste erzeugen
717     if ( !pLst )
718         pLst = new DirEntryList();
719 
720     //Verlangen die Sortierkriterien FileStat's?
721     sal_Bool bStat = sal_False;
722     if ( pSortLst ) {
723         pSortLst->First();
724         do {
725             if ( *(pSortLst->GetCurObject()) &
726                   ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE |
727                     FSYS_SORT_ACCESSED | FSYS_SORT_KIND ) )
728                 bStat = sal_True;
729         } while ( !bStat && pSortLst->Next() );
730     }
731     FileStat * stat = NULL;
732     for ( sal_uInt16 nNr = 0; nNr < rDir.Count(); nNr++ )
733     {
734         if ( bStat )
735         {
736             if ( rDir.pStatLst )
737                 stat = new FileStat( *rDir.pStatLst->GetObject(nNr) );
738             else
739                 stat = new FileStat( rDir[nNr] );
740         }
741         ImpSortedInsert( new DirEntry( rDir[nNr] ), stat );
742     }
743     return *this;
744 }
745 
746 /*************************************************************************
747 |*
748 |*    Dir::Count()
749 |*
750 |*    Beschreibung      FSYS.SDW
751 |*    Ersterstellung    MI 16.05.91
752 |*    Letzte Aenderung  MI 18.09.96
753 |*
754 *************************************************************************/
755 
756 
Count(sal_Bool bUpdated) const757 sal_uInt16 Dir::Count( sal_Bool bUpdated ) const
758 {
759 	// ggf. erst den Rest lesen
760 	if ( bUpdated && pReader )
761 		((Dir*)this)->Scan( USHRT_MAX );
762 
763 	return pLst == NULL ? 0 : (sal_uInt16) pLst->Count();
764 }
765