| 661 | } // Namespace Win32 |
| 662 | |
| 663 | bool FS::VerifyWriteAccess(const Path &path) |
| 664 | { |
| 665 | // due to UAC's habit of creating "virtual stores" when permission isn't actually available |
| 666 | // actually create, write, read, verify, and delete a file to the folder being tested |
| 667 | |
| 668 | String temp = path.getFullPath(); |
| 669 | temp += "\\torque_writetest.tmp"; |
| 670 | |
| 671 | // first, (try and) delete the file if it exists |
| 672 | ::DeleteFileW(temp.utf16()); |
| 673 | |
| 674 | // now, create the file |
| 675 | |
| 676 | HANDLE hFile = ::CreateFileW(PathToOS(temp).utf16(), |
| 677 | GENERIC_WRITE, 0, |
| 678 | NULL, CREATE_ALWAYS, |
| 679 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, |
| 680 | NULL); |
| 681 | |
| 682 | if ( hFile == INVALID_HANDLE_VALUE || hFile == NULL ) |
| 683 | return false; |
| 684 | |
| 685 | U32 t = Platform::getTime(); |
| 686 | |
| 687 | DWORD bytesWritten; |
| 688 | if (!::WriteFile(hFile,&t,sizeof(t),&bytesWritten,0)) |
| 689 | { |
| 690 | ::CloseHandle(hFile); |
| 691 | ::DeleteFileW(temp.utf16()); |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | // close the file |
| 696 | ::CloseHandle(hFile); |
| 697 | |
| 698 | // open for read |
| 699 | |
| 700 | hFile = ::CreateFileW(PathToOS(temp).utf16(), |
| 701 | GENERIC_READ, FILE_SHARE_READ, |
| 702 | NULL, OPEN_EXISTING, |
| 703 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, |
| 704 | NULL); |
| 705 | |
| 706 | if ( hFile == INVALID_HANDLE_VALUE || hFile == NULL ) |
| 707 | return false; |
| 708 | |
| 709 | U32 t2 = 0; |
| 710 | |
| 711 | DWORD bytesRead; |
| 712 | if (!::ReadFile(hFile,&t2,sizeof(t2),&bytesRead,0)) |
| 713 | { |
| 714 | ::CloseHandle(hFile); |
| 715 | ::DeleteFileW(temp.utf16()); |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | ::CloseHandle(hFile); |
| 720 | ::DeleteFileW(temp.utf16()); |