1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifdef _MSC_VER
#pragma warning (push,1)
#endif
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#ifdef _MSC_VER
#pragma warning (pop)
#endif
#include "wntmsc.hxx"
#include <tools/errinf.hxx>
#include <tools/debug.hxx>
#include <tools/wldcrd.hxx>
#include <tools/fsys.hxx>
#include <tools/bigint.hxx>
#include <vector>
int Sys2SolarError_Impl( int nSysErr );
static sal_Bool bLastCaseSensitive = sal_False;
//--------------------------------------------------------------------
rtl::OString Upper_Impl(const rtl::OString &rStr)
{
std::vector<sal_Char> aBuffer(rStr.getLength());
memcpy(&aBuffer[0], rStr.getStr(), rStr.getLength());
CharUpperBuff(&aBuffer[0], rStr.getLength());
return rtl::OString(&aBuffer[0], rStr.getLength());
}
//--------------------------------------------------------------------
DIR *opendir( const char* pPfad )
{
DIR *pDir = new DIR;
if ( pDir )
pDir->p = (char*) pPfad;
return pDir;
}
struct dirent *readdir( DIR *pDir )
{
bool bOk = false;
if ( pDir->p )
{
char *pBuf = new char[ strlen( pDir->p ) + 5 ];
if ( pBuf )
{
// *.* dahinter, ggf mit "\\" abtrennen (falls nicht schon da)
strcpy( pBuf, pDir->p );
strcat( pBuf, "\\*.*" + ( *(pBuf + strlen( pBuf ) - 1 ) == '\\' ) );
CharUpperBuff( pBuf, strlen(pBuf) );
pDir->h = FindFirstFile( pBuf, &pDir->aDirEnt );
bOk = pDir->h != INVALID_HANDLE_VALUE;
pDir->p = NULL;
delete [] pBuf;
}
else
pDir->h = INVALID_HANDLE_VALUE;
}
else
{
bOk = FindNextFile( pDir->h, &pDir->aDirEnt );
}
return bOk ? &pDir->aDirEnt : NULL;
}
int closedir( DIR *pDir )
{
sal_Bool bOk = sal_False;
if ( pDir )
{
bOk = 0 != pDir->p || FindClose( pDir->h );
delete pDir;
}
return bOk;
}
/*************************************************************************
|*
|* DirEntry::ToAbs()
|*
*************************************************************************/
sal_Bool DirEntry::ToAbs()
{
DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
if ( FSYS_FLAG_VOLUME == eFlag )
{
eFlag = FSYS_FLAG_ABSROOT;
return sal_True;
}
if ( IsAbs() )
{
return sal_True;
}
char sBuf[256];
char *pOld;
rtl::OString aFullName(rtl::OUStringToOString(GetFull(),
osl_getThreadTextEncoding()));
FSysFailOnErrorImpl();
if ( GetFullPathName(aFullName.getStr(), 256, sBuf, &pOld) > 511 )
return sal_False;
*this = DirEntry( String(sBuf, osl_getThreadTextEncoding() ));
return sal_True;
}
/*************************************************************************
|*
|* DirEntry::GetVolume()
|*
*************************************************************************/
String DirEntry::GetVolume() const
{
DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
String aRet;
const DirEntry *pTop = ImpGetTopPtr();
rtl::OString aName = rtl::OString(pTop->aName).toAsciiLowerCase();
if ( ( pTop->eFlag == FSYS_FLAG_ABSROOT ||
pTop->eFlag == FSYS_FLAG_RELROOT ||
pTop->eFlag == FSYS_FLAG_VOLUME )
&& !aName.equalsL(RTL_CONSTASCII_STRINGPARAM("a:"))
&& !aName.equalsL(RTL_CONSTASCII_STRINGPARAM("b:")) && Exists() )
{
char sFileSysName[256];
char sVolumeName[256];
DWORD nVolumeNameLen = 256;
DWORD nSerial[2];
DWORD nMaxCompLen[2];
DWORD nFlags[2];
rtl::OString aRootDir = pTop->aName;
FSysFailOnErrorImpl();
// Network-Device zuerst probieren wegen langsamer Samba-Drives
if ( !WNetGetConnection( aRootDir.getStr(),
sVolumeName, &nVolumeNameLen ) )
aRet = String( sVolumeName, osl_getThreadTextEncoding());
// dann den VolumeNamen fuer lokale Drives
if ( aRet.Len() == 0 )
{
aRootDir += rtl::OString(RTL_CONSTASCII_STRINGPARAM("\\"));
if ( GetVolumeInformation( aRootDir.getStr(),
sVolumeName, 256,
(LPDWORD) &nSerial, (LPDWORD) &nMaxCompLen,
(LPDWORD) &nFlags, sFileSysName, 256 ) )
aRet = String( sVolumeName, osl_getThreadTextEncoding());
}
}
return aRet;
}
/*************************************************************************
|*
|* DirEntry::SetCWD()
|*
*************************************************************************/
sal_Bool DirEntry::SetCWD( sal_Bool bSloppy ) const
{
DBG_CHKTHIS( DirEntry, ImpCheckDirEntry );
FSysFailOnErrorImpl();
if ( eFlag == FSYS_FLAG_CURRENT && !aName.getLength() )
return sal_True;
if ( SetCurrentDirectory(rtl::OUStringToOString(GetFull(), osl_getThreadTextEncoding()).getStr()) )
{
return sal_True;
}
if ( bSloppy && pParent &&
SetCurrentDirectory(rtl::OUStringToOString(pParent->GetFull(), osl_getThreadTextEncoding()).getStr()) )
{
return sal_True;
}
return sal_False;
}
//-------------------------------------------------------------------------
USHORT DirReader_Impl::Init()
{
// Block-Devices auflisten?
if ( pDir->eAttrMask & FSYS_KIND_BLOCK )
{
// CWD merken
DirEntry aCurrentDir;
aCurrentDir.ToAbs();
// einzeln auf Existenz und Masken-konformit"at pr"ufen
USHORT nRead = 0;
char sDrive[3] = { '?', ':', 0 };
char sRoot[4] = { '?', ':', '\\', 0 };
for ( char c = 'a'; c <= 'z'; c++ )
{
sDrive[0] = c;
sRoot[0] = c;
DirEntry* pDrive = new DirEntry( sDrive, FSYS_FLAG_VOLUME, FSYS_STYLE_HOST );
if ( pDir->aNameMask.Matches( String(rtl::OStringToOUString(sDrive, osl_getThreadTextEncoding())) ) && GetDriveType( sRoot ) != 1 )
{
if ( pDir->pStatLst ) //Status fuer Sort gewuenscht?
{
FileStat *pNewStat = new FileStat( *pDrive );
pDir->ImpSortedInsert( pDrive, pNewStat );
}
else
pDir->ImpSortedInsert( pDrive, NULL );
++nRead;
}
else
delete pDrive;
}
// CWD restaurieren
aCurrentDir.SetCWD();
return nRead;
}
return 0;
}
//-------------------------------------------------------------------------
USHORT DirReader_Impl::Read()
{
// Directories und Files auflisten?
if ( ( pDir->eAttrMask & FSYS_KIND_DIR ||
pDir->eAttrMask & FSYS_KIND_FILE ) &&
( ( pDosEntry = readdir( pDosDir ) ) != NULL ) )
{
// Gross/Kleinschreibung nicht beruecksichtigen
size_t nLen = strlen(pDosEntry->d_name);
std::vector<char> aBuffer(nLen);
memcpy(&aBuffer[0], pDosEntry->d_name, nLen);
CharLowerBuff(&aBuffer[0], nLen);
rtl::OString aLowerName(&aBuffer[0], nLen);
// Flags pruefen
sal_Bool bIsDirAndWantsDir =
( ( pDir->eAttrMask & FSYS_KIND_DIR ) &&
#ifdef ICC
( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") ||
strcmp(pDosEntry->d_name,"..")) ) );
#else
( pDosEntry->d_type & DOS_DIRECT ) );
#endif
sal_Bool bIsFileAndWantsFile =
( ( pDir->eAttrMask & FSYS_KIND_FILE ) &&
#ifdef ICC
!( pDosEntry->d_type & ( strcmp(pDosEntry->d_name,".") ||
strcmp(pDosEntry->d_name,"..")) ) &&
#else
!( pDosEntry->d_type & DOS_DIRECT ) &&
#endif
!( pDosEntry->d_type & DOS_VOLUMEID ) );
sal_Bool bIsHidden = (pDosEntry->d_type & _A_HIDDEN) != 0;
sal_Bool bWantsHidden = 0 == ( pDir->eAttrMask & FSYS_KIND_VISIBLE );
if ( ( bIsDirAndWantsDir || bIsFileAndWantsFile ) &&
( bWantsHidden || !bIsHidden ) &&
pDir->aNameMask.Matches( rtl::OStringToOUString(aLowerName, osl_getThreadTextEncoding()) ) )
{
#ifdef DBG_UTIL
DbgOutf( "%s %s flags:%x found",
pDosEntry->d_name,
bIsFileAndWantsFile ? "file" : "dir",
pDosEntry->d_type );
#endif
DirEntryFlag eFlag =
0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT
: 0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT
: FSYS_FLAG_NORMAL;
DirEntry *pTemp = new DirEntry( rtl::OString(pDosEntry->d_name),
eFlag, FSYS_STYLE_NTFS );
#ifdef FEAT_FSYS_DOUBLESPEED
pTemp->ImpSetStat( new FileStat( (void*) pDosDir, (void*) 0 ) );
#endif
if ( pParent )
pTemp->ImpChangeParent( new DirEntry( *pParent ), sal_False );
if ( pDir->pStatLst ) //Status fuer Sort gewuenscht?
{
FileStat *pNewStat = new FileStat( (void*) pDosDir, (void*) 0 );
pDir->ImpSortedInsert( pTemp, pNewStat );
}
else
pDir->ImpSortedInsert( pTemp, NULL );
return 1;
}
#ifdef DBG_UTIL
else
DbgOutf( "%s flags:%x skipped",
pDosEntry->d_name,
pDosEntry->d_type );
#endif
}
else
bReady = sal_True;
return 0;
}
/*************************************************************************
|*
|* InitFileStat()
|*
|* Beschreibung gemeinsamer Teil der Ctoren fuer FileStat
|*
*************************************************************************/
void FileStat::ImpInit( void* p )
{
_WIN32_FIND_DATAA *pDirEnt = (_WIN32_FIND_DATAA*) p;
nError = FSYS_ERR_OK;
nSize = pDirEnt->nFileSizeLow;
SYSTEMTIME aSysTime;
FILETIME aLocTime;
// use the last write date / time when the creation date / time isn't set
if ( ( pDirEnt->ftCreationTime.dwLowDateTime == 0 ) &&
( pDirEnt->ftCreationTime.dwHighDateTime == 0 ) )
{
pDirEnt->ftCreationTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime;
pDirEnt->ftCreationTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime;
}
// use the last write date / time when the last accessed date / time isn't set
if ( ( pDirEnt->ftLastAccessTime.dwLowDateTime == 0 ) &&
( pDirEnt->ftLastAccessTime.dwHighDateTime == 0 ) )
{
pDirEnt->ftLastAccessTime.dwLowDateTime = pDirEnt->ftLastWriteTime.dwLowDateTime;
pDirEnt->ftLastAccessTime.dwHighDateTime = pDirEnt->ftLastWriteTime.dwHighDateTime;
}
FileTimeToLocalFileTime( &pDirEnt->ftCreationTime, &aLocTime );
FileTimeToSystemTime( &aLocTime, &aSysTime );
aDateCreated = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear );
aTimeCreated = Time( aSysTime.wHour, aSysTime.wMinute,
aSysTime.wSecond, 0 );
FileTimeToLocalFileTime( &pDirEnt->ftLastWriteTime, &aLocTime );
FileTimeToSystemTime( &aLocTime, &aSysTime );
aDateModified = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear );
aTimeModified = Time( aSysTime.wHour, aSysTime.wMinute,
aSysTime.wSecond, 0 );
FileTimeToLocalFileTime( &pDirEnt->ftLastAccessTime, &aLocTime );
FileTimeToSystemTime( &aLocTime, &aSysTime );
aDateAccessed = Date( aSysTime.wDay, aSysTime.wMonth, aSysTime.wYear );
aTimeAccessed = Time( aSysTime.wHour, aSysTime.wMinute,
aSysTime.wSecond, 0 );
nKindFlags = FSYS_KIND_FILE;
if ( pDirEnt->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
nKindFlags = FSYS_KIND_DIR;
}
/*************************************************************************
|*
|* FileStat::FileStat()
|*
*************************************************************************/
FileStat::FileStat( const void *pInfo, // struct dirent
const void * ): // dummy
aDateCreated(0),
aTimeCreated(0),
aDateModified(0),
aTimeModified(0),
aDateAccessed(0),
aTimeAccessed(0)
{
ImpInit( ( (dirent*) pInfo ) );
}
/*************************************************************************
|*
|* FileStat::Update()
|*
*************************************************************************/
#ifdef _MSC_VER
#pragma warning(push, 1)
#pragma warning(disable: 4917)
#endif
#include <shlobj.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef UNICODE
#define lstrchr wcschr
#define lstrncmp wcsncmp
#else
#define lstrchr strchr
#define lstrncmp strncmp
#endif
//---------------------------------------------------------------------------
void SHFreeMem( void *p )
{
LPMALLOC pMalloc = NULL;
if ( SUCCEEDED(SHGetMalloc(&pMalloc)) )
{
pMalloc->Free( p );
pMalloc->Release();
}
}
//---------------------------------------------------------------------------
HRESULT SHGetIDListFromPath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl )
{
if ( IsBadWritePtr(ppidl, sizeof(LPITEMIDLIST)) )
return E_INVALIDARG;
LPSHELLFOLDER pDesktopFolder = NULL;
HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder );
if ( FAILED(hResult) )
return hResult;
ULONG chEaten = lstrlen( pszPath );
DWORD dwAttributes = FILE_ATTRIBUTE_DIRECTORY;
#ifdef UNICODE
LPOLESTR wszPath = pszPath;
#else
WCHAR wszPath[MAX_PATH];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszPath, -1, wszPath, MAX_PATH );
#endif
hResult = pDesktopFolder->ParseDisplayName( hwndOwner, (LPBC)NULL, wszPath, &chEaten, ppidl, &dwAttributes );
pDesktopFolder->Release();
return hResult;
}
//---------------------------------------------------------------------------
HRESULT SHGetFolderFromIDList( LPCITEMIDLIST pidl, LPSHELLFOLDER *ppFolder )
{
if ( IsBadWritePtr(ppFolder, sizeof(LPSHELLFOLDER)) )
return E_INVALIDARG;
*ppFolder = NULL;
LPSHELLFOLDER pDesktopFolder = NULL;
HRESULT hResult = SHGetDesktopFolder( &pDesktopFolder );
if ( FAILED(hResult) )
return hResult;
hResult = pDesktopFolder->BindToObject( pidl, (LPBC)NULL, IID_IShellFolder, (LPVOID *)ppFolder );
pDesktopFolder->Release();
return hResult;
}
//---------------------------------------------------------------------------
HRESULT SHResolvePath( HWND hwndOwner, LPCTSTR pszPath, LPITEMIDLIST *ppidl )
{
// If hwndOwner is NULL, use the desktop window, because dialogs need a parent
#ifdef BOOTSTRAP
return NO_ERROR;
#else
if ( !hwndOwner )
hwndOwner = GetDesktopWindow();
HRESULT hResult = NOERROR;
LPTSTR pszPathCopy;
LPTSTR pszTrailingPath;
TCHAR cBackup = 0;
// First make a copy of the path
pszPathCopy = new TCHAR[lstrlen(pszPath) + 1];
if ( pszPathCopy )
lstrcpy( pszPathCopy, pszPath );
else
return E_OUTOFMEMORY;
// Determine the first token
if ( !lstrncmp( pszPathCopy, "\\\\", 2 ) )
pszTrailingPath = lstrchr( pszPathCopy + 2, '\\' );
else
pszTrailingPath = lstrchr( pszPathCopy, '\\' );
// Now scan the path tokens
while ( SUCCEEDED(hResult) )
{
if ( pszTrailingPath )
{
cBackup = *(++pszTrailingPath);
*pszTrailingPath = 0;
}
LPITEMIDLIST pidl = NULL;
// Make item ID list from leading path
hResult = SHGetIDListFromPath( hwndOwner, pszPathCopy, &pidl );
// if path exists try to open it as folder
if ( SUCCEEDED(hResult) )
{
// Only open the folder if it was not the last token
if ( pszTrailingPath )
{
LPSHELLFOLDER pFolder;
// Create a folder instance
hResult = SHGetFolderFromIDList( pidl, &pFolder);
// Is it a folder ?
if ( SUCCEEDED(hResult) )
{
// No try to instantiate an enumerator.
// This should popup a login dialog if any
LPENUMIDLIST pEnum = NULL;
hResult = pFolder->EnumObjects( hwndOwner,
SHCONTF_NONFOLDERS | SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN,
&pEnum );
// Release the enumerator interface
if ( SUCCEEDED(hResult) )
pEnum->Release();
// Release the folder interface
pFolder->Release();
}
SHFreeMem( pidl );
}
else // It was the last token
{
if ( ppidl )
*ppidl = pidl;
else
SHFreeMem( pidl );
}
}
// Forward to next token
if ( pszTrailingPath )
{
*pszTrailingPath = cBackup;
pszTrailingPath = lstrchr( pszTrailingPath, '\\' );
}
else
break;
}
// Free the working copy of the path
delete pszPathCopy;
// NOERROR or OLE error code
return hResult;
#endif
}
//---------------------------------------------------------------------------
// The Wrapper
//---------------------------------------------------------------------------
sal_Bool Exists_Impl(const rtl::OString& crPath)
{
// We do not know if OLE was initialized for this thread
CoInitialize( NULL );
sal_Bool bSuccess = SUCCEEDED( SHResolvePath(NULL, crPath.getStr(), NULL) );
CoUninitialize();
return bSuccess;
}
//---------------------------------------------------------------------------
sal_Bool FileStat::Update( const DirEntry& rDirEntry, sal_Bool bForceAccess )
{
nSize = 0;
nKindFlags = 0;
aCreator.Erase();
aType.Erase();
aDateCreated = Date(0);
aTimeCreated = Time(0);
aDateModified = Date(0);
aTimeModified = Time(0);
aDateAccessed = Date(0);
aTimeAccessed = Time(0);
if ( !rDirEntry.IsValid() )
{
nError = FSYS_ERR_UNKNOWN;
nKindFlags = 0;
return sal_False;
}
// Sonderbehandlung falls es sich um eine Root ohne Laufwerk handelt
if ( !rDirEntry.aName.getLength() && rDirEntry.eFlag == FSYS_FLAG_ABSROOT )
{
nKindFlags = FSYS_KIND_DIR;
nError = FSYS_ERR_OK;
return sal_True;
}
// keine Error-Boxen anzeigen
FSysFailOnErrorImpl();
// Redirect
String aPath( rDirEntry.GetFull() );
#ifndef BOOTSTRAP
FSysRedirector::DoRedirect( aPath );
#endif
DirEntry aDirEntry( aPath );
// ist ein Medium im Laufwerk?
HACK("wie?")
sal_Bool bAccess = sal_True;
const DirEntry *pTop = aDirEntry.ImpGetTopPtr();
rtl::OString aName = rtl::OString(pTop->aName).toAsciiLowerCase();
if ( !bForceAccess &&
( pTop->eFlag == FSYS_FLAG_ABSROOT ||
pTop->eFlag == FSYS_FLAG_RELROOT ||
pTop->eFlag == FSYS_FLAG_VOLUME ) )
if ( aName.equalsL(RTL_CONSTASCII_STRINGPARAM("a:")) ||
aName.equalsL(RTL_CONSTASCII_STRINGPARAM("b:")) )
bAccess = sal_False;
else
OSL_TRACE( "FSys: will access removable device!" );
if ( bAccess && ( aName.equalsL(RTL_CONSTASCII_STRINGPARAM("a:")) ||
aName.equalsL(RTL_CONSTASCII_STRINGPARAM("b:")) ) )
{
DBG_WARNING( "floppy will clatter" );
}
// Sonderbehandlung, falls es sich um ein Volume handelt
if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME ||
aDirEntry.eFlag == FSYS_FLAG_ABSROOT )
{
if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME )
nKindFlags = FSYS_KIND_DEV | ( aDirEntry.aName.getLength() == 2
? FSYS_KIND_BLOCK
: FSYS_KIND_CHAR );
else
nKindFlags = FSYS_KIND_DIR;
if ( !bAccess )
{
if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME )
nKindFlags |= FSYS_KIND_REMOVEABLE;
nError = FSYS_ERR_NOTEXISTS;
nKindFlags = 0;
return sal_False;
}
rtl::OString aRootDir = aDirEntry.aName;
aRootDir += rtl::OString(RTL_CONSTASCII_STRINGPARAM("\\"));
UINT nType = GetDriveType( aRootDir.getStr() ); //TPF: 2i
if ( nType == 1 || nType == 0 )
{
nError = FSYS_ERR_NOTEXISTS;
nKindFlags = 0;
return sal_False;
}
if ( aDirEntry.eFlag == FSYS_FLAG_VOLUME )
nKindFlags = nKindFlags |
( ( nType == DRIVE_REMOVABLE ) ? FSYS_KIND_REMOVEABLE : 0 ) |
( ( nType == DRIVE_FIXED ) ? FSYS_KIND_FIXED : 0 ) |
( ( nType == DRIVE_REMOTE ) ? FSYS_KIND_REMOTE : 0 ) |
( ( nType == DRIVE_RAMDISK ) ? FSYS_KIND_RAM : 0 ) |
( ( nType == DRIVE_CDROM ) ? FSYS_KIND_CDROM : 0 ) |
( ( nType == 0 ) ? FSYS_KIND_UNKNOWN : 0 );
nError = ERRCODE_NONE;
return sal_True;
}
// Statusinformation vom Betriebssystem holen
HANDLE h; //()
_WIN32_FIND_DATAA aEntry = {};
DirEntry aAbsEntry( aDirEntry );
if ( bAccess && aAbsEntry.ToAbs() )
{
// im Namen k"onnen auch ';*?' als normale Zeichen vorkommen
rtl::OString aFilePath(rtl::OUStringToOString(aAbsEntry.GetFull(), osl_getThreadTextEncoding()));
OSL_TRACE( "FileStat: %s", aFilePath.getStr() );
h = aFilePath.getLength() < 230
// die Win32-API ist hier sehr schwammig
? FindFirstFile( aFilePath.getStr(), &aEntry )//TPF: 2i
: INVALID_HANDLE_VALUE;
if ( INVALID_HANDLE_VALUE != h )
{
if ( !( aEntry.dwFileAttributes & 0x40 ) ) // com1: etc. e.g. not encrypted (means normal)
{
rtl::OString aUpperName = Upper_Impl(rtl::OUStringToOString(aAbsEntry.GetName(), osl_getThreadTextEncoding()));
// HRO: #74051# Compare also with short alternate filename
if ( aUpperName != Upper_Impl( aEntry.cFileName ) && aUpperName != Upper_Impl( aEntry.cAlternateFileName ) )
h = INVALID_HANDLE_VALUE;
}
}
if ( INVALID_HANDLE_VALUE == h )
{
DWORD dwError = GetLastError();
if ( ERROR_BAD_NET_NAME == dwError )
{
nKindFlags = FSYS_KIND_UNKNOWN;
nError = FSYS_ERR_NOTEXISTS;
return sal_False;
}
// UNC-Volume?
DirEntry *pTop = aAbsEntry.ImpGetTopPtr();
if ( pTop->GetFlag() == FSYS_FLAG_ABSROOT &&
( pTop->aName.getLength() > 1 && (pTop->aName[1] != ':' )) )
{
if ( bForceAccess )
{
if ( Exists_Impl( aFilePath ) )
{
nKindFlags = FSYS_KIND_DIR|FSYS_KIND_REMOTE;
nError = FSYS_ERR_OK;
return sal_True;
}
else
{
nKindFlags = FSYS_KIND_UNKNOWN;
nError = FSYS_ERR_NOTEXISTS;
return sal_False;
}
}
}
}
}
else
h = INVALID_HANDLE_VALUE;
if ( h == INVALID_HANDLE_VALUE )
{
// Sonderbehandlung falls es sich um eine Wildcard handelt
rtl::OString aTempName(rtl::OUStringToOString(aDirEntry.GetName(), osl_getThreadTextEncoding()));
if ( strchr( aTempName.getStr(), '?' ) ||
strchr( aTempName.getStr(), '*' ) ||
strchr( aTempName.getStr(), ';' ) )
{
nKindFlags = FSYS_KIND_WILD;
nError = FSYS_ERR_OK;
return sal_True;
}
if ( bAccess )
{
nError = FSYS_ERR_NOTEXISTS;
nKindFlags = FSYS_KIND_UNKNOWN;
}
else
nKindFlags = FSYS_KIND_REMOVEABLE;
}
else
{
ImpInit( &aEntry );
FindClose( h );
}
if ( 0 != nError )
nKindFlags = 0;
return 0 == nError;
}
sal_Bool IsRedirectable_Impl( const rtl::OString& rPath )
{
if ( rPath.getLength() >= 3 && ':' == rPath[1] )
{
rtl::OString aVolume = rPath.copy( 0, 3 );
UINT nType = GetDriveType( aVolume.getStr() );
SetLastError( ERROR_SUCCESS );
return DRIVE_FIXED != nType;
}
return sal_False;
}
/*************************************************************************
|*
|* TempDirImpl()
|*
|* Beschreibung liefert den Namens des Directories fuer temporaere
|* Dateien
|*
*************************************************************************/
const char* TempDirImpl( char *pBuf )
{
if ( !GetTempPath( MAX_PATH, pBuf ) &&
!GetWindowsDirectory( pBuf, MAX_PATH ) &&
!GetEnvironmentVariable( "HOMEPATH", pBuf, MAX_PATH ) )
return 0;
return pBuf;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|