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