the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 708 lines 21 kB view raw
1#include "stdafx.h" 2#include "FileFilter.h" 3#include "McRegionLevelStorageSource.h" 4#include "File.h" 5 6#ifdef __PS3__ 7#include <cell/cell_fs.h> 8#endif 9#ifdef __PSVITA__ 10#include <fios2.h> 11#endif 12 13const wchar_t File::pathSeparator = L'\\'; 14#ifdef _XBOX 15const std::wstring File::pathRoot = L"GAME:"; // Path root after pathSeparator has been removed 16#else 17const std::wstring File::pathRoot = L""; // Path root after pathSeparator has been removed 18#endif 19 20//Creates a new File instance from a parent abstract pathname and a child pathname string. 21File::File( const File &parent, const std::wstring& child ) 22{ 23 m_abstractPathName = parent.getPath() + pathSeparator + child; 24} 25 26//Creates a new File instance by converting the given pathname string into an abstract pathname. 27File::File( const wstring& pathname ) //: parent( NULL ) 28{ 29 // #ifndef _CONTENT_PACKAGE 30 // char buf[256]; 31 // wcstombs(buf, pathname.c_str(), 256); 32 // printf("File::File - %s\n",buf); 33 // #endif 34 if( pathname.empty() ) 35 m_abstractPathName = wstring( L"" ); 36 else 37 m_abstractPathName = pathname; 38 39#ifdef _WINDOWS64 40 string path = wstringtochararray(m_abstractPathName); 41 string finalPath = StorageManager.GetMountedPath(path.c_str()); 42 if(finalPath.size() == 0) finalPath = path; 43 m_abstractPathName = convStringToWstring(finalPath); 44#elif defined(_DURANGO) 45 wstring finalPath = StorageManager.GetMountedPath(m_abstractPathName.c_str()); 46 if(finalPath.size() == 0) finalPath = m_abstractPathName; 47 m_abstractPathName = finalPath; 48#endif 49 /* 50 vector<wstring> path = stringSplit( pathname, pathSeparator ); 51 52 if( path.back().compare( pathRoot ) != 0 ) 53 m_abstractPathName = path.back(); 54 else 55 m_abstractPathName = L""; 56 57 path.pop_back(); 58 59 if( path.size() > 0 ) 60 { 61 // If the last member of the vector is the root then just stop 62 if( path.back().compare( pathRoot ) != 0 ) 63 this->parent = new File( &path ); 64 else 65 this->parent = NULL; 66 } 67 */ 68} 69 70File::File( const std::wstring& parent, const std::wstring& child ) //: m_abstractPathName( child ) 71{ 72 m_abstractPathName = pathRoot + pathSeparator + parent + pathSeparator + child; 73 //this->parent = new File( parent ); 74} 75 76//Creates a new File instance by converting the given path vector into an abstract pathname. 77/* 78File::File( vector<wstring> *path ) : parent( NULL ) 79{ 80m_abstractPathName = path->back(); 81path->pop_back(); 82 83if( path->size() > 0 ) 84{ 85// If the last member of the vector is the root then just stop 86if( path->back().compare( pathRoot ) != 0 ) 87this->parent = new File( path ); 88else 89this->parent = NULL; 90} 91} 92*/ 93 94//Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, 95//then the directory must be empty in order to be deleted. 96//Returns: 97//true if and only if the file or directory is successfully deleted; false otherwise 98bool File::_delete() 99{ 100#ifdef _UNICODE 101 BOOL result = DeleteFile( getPath().c_str() ); 102#else 103 BOOL result = DeleteFile( wstringtofilename(getPath()) ); 104#endif 105 if( result == 0 ) 106 { 107 DWORD error = GetLastError(); 108#ifndef _CONTENT_PACKAGE 109 printf( "File::_delete - Error code %d (%#0.8X)\n", error, error ); 110#endif 111 return false; 112 } 113 else 114 return true; 115} 116 117//Creates the directory named by this abstract pathname. 118//Returns: 119//true if and only if the directory was created; false otherwise 120bool File::mkdir() const 121{ 122#ifdef _UNICODE 123 return CreateDirectory( getPath().c_str(), NULL) != 0; 124 125#else 126 return CreateDirectory( wstringtofilename(getPath()), NULL) != 0; 127#endif 128} 129 130 131//Creates the directory named by this abstract pathname, including any 132//necessary but nonexistent parent directories. Note that if this 133//operation fails it may have succeeded in creating some of the necessary 134//parent directories. 135// 136//@return <code>true</code> if and only if the directory was created, 137// along with all necessary parent directories; <code>false</code> 138// otherwise 139// 140//@throws SecurityException 141// If a security manager exists and its <code>{@link 142// java.lang.SecurityManager#checkRead(java.lang.String)}</code> 143// method does not permit verification of the existence of the 144// named directory and all necessary parent directories; or if 145// the <code>{@link 146// java.lang.SecurityManager#checkWrite(java.lang.String)}</code> 147// method does not permit the named directory and all necessary 148// parent directories to be created 149// 150bool File::mkdirs() const 151{ 152 std::vector<std::wstring> path = stringSplit( m_abstractPathName, pathSeparator ); 153 154 std::wstring pathToHere = L""; 155 AUTO_VAR(itEnd, path.end()); 156 for( AUTO_VAR(it, path.begin()); it != itEnd; it++ ) 157 { 158 // If this member of the vector is the root then just skip to the next 159 if( pathRoot.compare( *it ) == 0 ) 160 { 161 pathToHere = *it; 162 continue; 163 } 164 165 pathToHere = pathToHere + pathSeparator + *it; 166 167 // if not exists 168#ifdef _UNICODE 169 if( GetFileAttributes( pathToHere.c_str() ) == -1 ) 170 { 171 DWORD result = CreateDirectory( pathToHere.c_str(), NULL); 172 if( result == 0 ) 173 { 174 // Failed to create 175 return false; 176 } 177 } 178#else 179 if( GetFileAttributes( wstringtofilename(pathToHere) ) == -1 ) 180 { 181 DWORD result = CreateDirectory( wstringtofilename(pathToHere), NULL); 182 if( result == 0 ) 183 { 184 // Failed to create 185 return false; 186 } 187 } 188#endif 189 } 190 191 // We should now exist 192 assert( exists() ); 193 194 return true; 195} 196 197/* 198File *File::getParent() const 199{ 200return (File *) parent; 201} 202*/ 203 204//Tests whether the file or directory denoted by this abstract pathname exists. 205//Returns: 206//true if and only if the file or directory denoted by this abstract pathname exists; false otherwise 207bool File::exists() const 208{ 209 // TODO 4J Stu - Possible we could get an error result from something other than the file not existing? 210#ifdef _UNICODE 211 return GetFileAttributes( getPath().c_str() ) != -1; 212 213#else 214 return GetFileAttributes( wstringtofilename(getPath()) ) != -1; 215#endif 216} 217 218//Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, 219//in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file. 220//Returns: 221//true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise 222bool File::isFile() const 223{ 224 return exists() && !isDirectory(); 225} 226 227//Renames the file denoted by this abstract pathname. 228//Whether or not this method can move a file from one filesystem to another is platform-dependent. 229//The return value should always be checked to make sure that the rename operation was successful. 230// 231//Parameters: 232//dest - The new abstract pathname for the named file 233//Returns: 234//true if and only if the renaming succeeded; false otherwise 235bool File::renameTo(File dest) 236{ 237 // 4J Stu - The wstringtofilename function returns a pointer to the same location in memory every time it is 238 // called, therefore we were getting sourcePath and destPath having the same value. The solution here is to 239 // make a copy of the sourcePath by storing it in a std::string 240 std::string sourcePath = wstringtofilename(getPath()); 241 const char *destPath = wstringtofilename(dest.getPath()); 242#ifdef _DURANGO 243 __debugbreak(); // TODO 244 BOOL result = false; 245#else 246 BOOL result = MoveFile(sourcePath.c_str(), destPath); 247#endif 248 249 if( result == 0 ) 250 { 251 DWORD error = GetLastError(); 252#ifndef _CONTENT_PACKAGE 253 printf( "File::renameTo - Error code %d (%#0.8X)\n", error, error ); 254#endif 255 return false; 256 } 257 else 258 return true; 259} 260 261//Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. 262//If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, 263//one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory 264//are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using 265//the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; 266//if this pathname is relative then each resulting pathname will be relative to the same directory. 267// 268//There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, 269//in particular, guaranteed to appear in alphabetical order. 270// 271//Returns: 272//An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. 273//The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, 274//or if an I/O error occurs. 275std::vector<File *> *File::listFiles() const 276{ 277 std::vector<File *> *vOutput = new vector<File *>(); 278 279 // TODO 4J Stu - Also need to check for I/O errors? 280 if( !isDirectory() ) 281 return vOutput; 282 283#ifdef __PS3__ 284 const char *lpFileName=wstringtofilename(getPath()); 285 char filePath[256]; 286 287 std::string mountedPath = StorageManager.GetMountedPath(lpFileName); 288 if(mountedPath.length() > 0) 289 { 290 strcpy(filePath, mountedPath.c_str()); 291 } 292 else if(lpFileName[0] == '/') // already fully qualified path 293 strcpy(filePath, lpFileName ); 294 else 295 sprintf(filePath,"%s/%s",getUsrDirPath(), lpFileName ); 296 int fd; 297 CellFsErrno err = cellFsOpendir(filePath , &fd); 298 299 CellFsDirectoryEntry de; 300 uint32_t count = 0; 301 err = cellFsGetDirectoryEntries(fd, &de, sizeof(CellFsDirectoryEntry), &count); 302 if(count != 0) 303 { 304 do 305 { 306 if(de.attribute.st_mode & CELL_FS_S_IFREG) vOutput->push_back( new File( *this, filenametowstring( de.entry_name.d_name ) ) ); 307 err = cellFsGetDirectoryEntries(fd, &de, sizeof(CellFsDirectoryEntry), &count); 308 } while( count ); 309 } 310 err = cellFsClose(fd); 311#elif defined __ORBIS__ || defined __PSVITA__ 312 const char *lpFileName=wstringtofilename(getPath()); 313 char filePath[256]; 314 315 std::string mountedPath = StorageManager.GetMountedPath(lpFileName); 316 if(mountedPath.length() > 0) 317 { 318 strcpy(filePath, mountedPath.c_str()); 319 } 320 else if(lpFileName[0] == '/') // already fully qualified path 321 strcpy(filePath, lpFileName ); 322 else 323 sprintf(filePath,"%s/%s",getUsrDirPath(), lpFileName ); 324 325 bool exists = sceFiosDirectoryExistsSync( NULL, filePath ); 326 if( !exists ) 327 { 328 app.DebugPrintf("\nsceFiosDirectoryExistsSync - Directory doesn't exist\n"); 329 } 330 331 //CD - Vita note: sceFiosDHOpenSync returns SCE_FIOS_ERROR_UNIMPLEMENTED 332 //CD - The Handle also returns as 0 [dh], sceFiosDHOpen could also be failing 333 //CD - Hence, this fails stating 0 files in directory 334 335 SceFiosDH dh = SCE_FIOS_DH_INVALID; 336 SceFiosBuffer buf; 337 buf.length = 0; 338 SceFiosOp op = sceFiosDHOpen(NULL, &dh, filePath, buf); 339 340 int err = sceFiosOpWait(op); 341 if( err != SCE_FIOS_OK ) 342 { 343 app.DebugPrintf("\nsceFiosOpWait = 0x%x\n",err); 344 } 345 SceFiosSize size = sceFiosOpGetActualCount(op); 346 char *pBuf = new char[size]; 347 buf.set(pBuf, (size_t)size); 348 349 sceFiosOpDelete( op ); 350 sceFiosDHClose(NULL, dh); 351 352 err = sceFiosDHOpenSync(NULL, &dh, filePath, buf); 353 if( err != SCE_FIOS_OK ) 354 { 355 app.DebugPrintf("\nsceFiosDHOpenSync = 0x%x\n",err); 356 } 357 SceFiosDirEntry entry; 358 ZeroMemory(&entry, sizeof(SceFiosDirEntry)); 359 err = sceFiosDHReadSync(NULL, dh, &entry); 360 while( err == SCE_FIOS_OK) 361 { 362 vOutput->push_back( new File( *this, filenametowstring( entry.fullPath + entry.offsetToName ) ) ); 363 ZeroMemory(&entry, sizeof(SceFiosDirEntry)); 364 err = sceFiosDHReadSync(NULL, dh, &entry); 365 }; 366 367 sceFiosDHClose(NULL, dh); 368 delete pBuf; 369#else 370 371 WIN32_FIND_DATA wfd; 372 373#ifdef _UNICODE 374 WCHAR path[MAX_PATH]; 375 swprintf( path, L"%ls\\*", getPath().c_str() ); 376 HANDLE hFind = FindFirstFile( path, &wfd); 377 if(hFind != INVALID_HANDLE_VALUE) 378 { 379 int count = 0; 380 do 381 { 382 //if( !(wfd.dwFileAttributes & dwAttr) ) 383 vOutput->push_back( new File( *this, wfd.cFileName ) ); 384 } 385 while( FindNextFile( hFind, &wfd) ); 386 FindClose( hFind); 387 } 388#else 389 char path[MAX_PATH] {}; 390 snprintf( path, MAX_PATH, "%s\\*", wstringtofilename( getPath() ) ); 391 HANDLE hFind = FindFirstFile( path, &wfd); 392 if(hFind != INVALID_HANDLE_VALUE) 393 { 394 //int count = 0; 395 do 396 { 397 //if( !(wfd.dwFileAttributes & dwAttr) ) 398 vOutput->push_back( new File( *this, filenametowstring( wfd.cFileName ) ) ); 399 } 400 while( FindNextFile( hFind, &wfd) ); 401 FindClose( hFind); 402 } 403#endif 404#endif 405 return vOutput; 406} 407 408//Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that 409//satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames 410//in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname 411//satisfies the filter if and only if the value true results when the FileFilter.accept(java.io.File) method of the filter is invoked 412//on the pathname. 413//Parameters: 414//filter - A file filter 415//Returns: 416//An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. 417//The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs. 418std::vector<File *> *File::listFiles(FileFilter *filter) const 419{ 420 // TODO 4J Stu - Also need to check for I/O errors? 421 if( !isDirectory() ) 422 return NULL; 423 424 std::vector<File *> *vOutput = new std::vector<File *>(); 425 426#ifdef __PS3__ 427 const char *lpFileName=wstringtofilename(getPath()); 428 char filePath[256]; 429 430 std::string mountedPath = StorageManager.GetMountedPath(lpFileName); 431 if(mountedPath.length() > 0) 432 { 433 strcpy(filePath, mountedPath.c_str()); 434 } 435 else if(lpFileName[0] == '/') // already fully qualified path 436 strcpy(filePath, lpFileName ); 437 else 438 sprintf(filePath,"%s/%s",getUsrDirPath(), lpFileName ); 439 int fd; 440 CellFsErrno err = cellFsOpendir(filePath, &fd); 441 442 CellFsDirectoryEntry de; 443 uint32_t count = 0; 444 err = cellFsGetDirectoryEntries(fd, &de, sizeof(CellFsDirectoryEntry), &count); 445 if(count != 0) 446 { 447 do 448 { 449 File thisFile = File( *this, filenametowstring( de.entry_name.d_name ) ); 450 if( filter->accept( &thisFile ) ) 451 { 452 File storageFile = thisFile; 453 if(de.attribute.st_mode & CELL_FS_S_IFREG) vOutput->push_back( &storageFile ); 454 } 455 err = cellFsGetDirectoryEntries(fd, &de, sizeof(CellFsDirectoryEntry), &count); 456 } while( count ); 457 } 458 err = cellFsClose(fd); 459#else 460 461#ifdef _UNICODE 462 463 WCHAR path[MAX_PATH]; 464 WIN32_FIND_DATA wfd; 465 DWORD dwAttr = FILE_ATTRIBUTE_DIRECTORY; 466 467 swprintf( path, L"%ls\\*", getPath().c_str() ); 468 HANDLE hFind = FindFirstFile( path, &wfd); 469 if(hFind != INVALID_HANDLE_VALUE) 470 { 471 int count = 0; 472 do 473 { 474 File thisFile = File( *this, wfd.cFileName ); 475 if( filter->accept( &thisFile ) ) 476 { 477 File storageFile = thisFile; 478 vOutput->push_back( &storageFile ); 479 } 480 } while( FindNextFile( hFind, &wfd) ); 481 FindClose( hFind); 482 } 483#else 484 char path[MAX_PATH]; 485 WIN32_FIND_DATA wfd; 486 //DWORD dwAttr = FILE_ATTRIBUTE_DIRECTORY; 487 488 sprintf( path, "%s\\*", wstringtofilename( getPath() ) ); 489 HANDLE hFind = FindFirstFile( path, &wfd); 490 if(hFind != INVALID_HANDLE_VALUE) 491 { 492 //int count = 0; 493 do 494 { 495 File thisFile = File( *this, filenametowstring( wfd.cFileName ) ); 496 if( filter->accept( &thisFile ) ) 497 { 498 File storageFile = thisFile; 499 vOutput->push_back( &storageFile ); 500 } 501 } while( FindNextFile( hFind, &wfd) ); 502 FindClose( hFind); 503 } 504#endif 505#endif 506 return vOutput; 507} 508 509//Tests whether the file denoted by this abstract pathname is a directory. 510//Returns: 511//true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise 512bool File::isDirectory() const 513{ 514#ifdef _UNICODE 515 return exists() && ( GetFileAttributes( getPath().c_str() ) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; 516#else 517 return exists() && ( GetFileAttributes( wstringtofilename(getPath()) ) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; 518#endif 519} 520 521//Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory. 522//Returns: 523//The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist 524int64_t File::length() 525{ 526#ifdef __PS3__ 527 //extern const char* getPS3HomePath(); 528 CellFsErrno err=0; 529 const char *lpFileName=wstringtofilename(getPath()); 530 char filePath[256]; 531 532 std::string mountedPath = StorageManager.GetMountedPath(lpFileName); 533 if(mountedPath.length() > 0) 534 { 535 strcpy(filePath, mountedPath.c_str()); 536 } 537 else if(lpFileName[0] == '/') // already fully qualified path 538 strcpy(filePath, lpFileName ); 539 else 540 sprintf(filePath,"%s/%s",getUsrDirPath(), lpFileName ); 541 542#ifndef _CONTENT_PACKAGE 543 //printf("+++File::length - %s\n",filePath); 544#endif 545 // check if the file exists first 546 CellFsStat statData; 547 err=cellFsStat(filePath, &statData); 548 549 if( err != CELL_FS_SUCCEEDED) 550 { 551 //printf("+++File::length FAILED with %d\n",err); 552 return 0; 553 } 554 if(statData.st_mode == CELL_FS_S_IFDIR) 555 { 556 //printf("+++File::length FAILED with %d\n",err); 557 return 0; 558 } 559 560 //printf("+++File::length - %ll\n",statData.st_size); 561 562 return statData.st_size; 563#elif defined __ORBIS__ || defined __PSVITA__ 564 565 char filePath[256]; 566 const char *lpFileName=wstringtofilename(getPath()); 567 568 std::string mountedPath = StorageManager.GetMountedPath(lpFileName); 569 if(mountedPath.length() > 0) 570 { 571 strcpy(filePath, mountedPath.c_str()); 572 } 573 else if(lpFileName[0] == '/') // already fully qualified path 574 strcpy(filePath, lpFileName ); 575 else 576 sprintf(filePath,"%s/%s",getUsrDirPath(), lpFileName ); 577 578 // check if the file exists first 579 SceFiosStat statData; 580 if(sceFiosStatSync(NULL, filePath, &statData) != SCE_FIOS_OK) 581 { 582 return 0; 583 } 584 if(statData.statFlags & SCE_FIOS_STATUS_DIRECTORY ) 585 { 586 return 0; 587 } 588 return statData.fileSize; 589#else 590 WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer; 591 592#ifdef _UNICODE 593 BOOL result = GetFileAttributesEx( 594 getPath().c_str(), // file or directory name 595 GetFileExInfoStandard, // attribute 596 &fileInfoBuffer // attribute information 597 ); 598#else 599 BOOL result = GetFileAttributesEx( 600 wstringtofilename(getPath()), // file or directory name 601 GetFileExInfoStandard, // attribute 602 &fileInfoBuffer // attribute information 603 ); 604#endif 605 606 if( result != 0 && !( (fileInfoBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ) 607 { 608 // Success 609 LARGE_INTEGER liFileSize; 610 liFileSize.HighPart = fileInfoBuffer.nFileSizeHigh; 611 liFileSize.LowPart = fileInfoBuffer.nFileSizeLow; 612 613 return liFileSize.QuadPart; 614 } 615 else 616 { 617 //Fail or a Directory 618 return 0l; 619 } 620#endif 621} 622 623//Returns the time that the file denoted by this abstract pathname was last modified. 624//Returns: 625//A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), 626//or 0L if the file does not exist or if an I/O error occurs 627int64_t File::lastModified() 628{ 629 WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer; 630#ifdef _UNICODE 631 BOOL result = GetFileAttributesEx( 632 getPath().c_str(), // file or directory name 633 GetFileExInfoStandard, // attribute 634 &fileInfoBuffer // attribute information 635 ); 636#else 637 BOOL result = GetFileAttributesEx( 638 wstringtofilename(getPath()), // file or directory name 639 GetFileExInfoStandard, // attribute 640 &fileInfoBuffer // attribute information 641 ); 642#endif 643 644 if( result != 0 && !( (fileInfoBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ) 645 { 646 // Success 647 LARGE_INTEGER liLastModified; 648 liLastModified.HighPart = fileInfoBuffer.ftLastWriteTime.dwHighDateTime; 649 liLastModified.LowPart = fileInfoBuffer.ftLastWriteTime.dwLowDateTime; 650 651 return liLastModified.QuadPart; 652 } 653 else 654 { 655 //Fail or a Directory 656 return 0l; 657 } 658} 659 660const std::wstring File::getPath() const 661{ 662 /* 663 wstring path; 664 if ( parent != NULL) 665 path = parent->getPath(); 666 else 667 path = wstring(pathRoot); 668 669 path.push_back( pathSeparator ); 670 path.append(m_abstractPathName); 671 */ 672 return m_abstractPathName; 673} 674 675std::wstring File::getName() const 676{ 677 unsigned int sep = (unsigned int )(m_abstractPathName.find_last_of( this->pathSeparator )); 678 return m_abstractPathName.substr( sep + 1, m_abstractPathName.length() ); 679} 680 681bool File::eq_test(const File &x, const File &y) 682{ 683 return x.getPath().compare( y.getPath() ) == 0; 684} 685 686// 4J TODO JEV, a better hash function may be nessesary. 687int File::hash_fnct(const File &k) 688{ 689 int hashCode = 0; 690 691 //if (k->parent != NULL) 692 // hashCode = hash_fnct(k->getParent()); 693 694 wchar_t *ref = (wchar_t *) k.m_abstractPathName.c_str(); 695 696 for (unsigned int i = 0; i < k.m_abstractPathName.length(); i++) 697 { 698 hashCode += ((hashCode * 33) + ref[i]) % 149; 699 } 700 701 return (int) hashCode; 702} 703 704int FileKeyHash::operator() (const File &k) const 705{ return File::hash_fnct(k); } 706 707bool FileKeyEq::operator() (const File &x, const File &y) const 708{ return File::eq_test(x,y); }