| 742 | } |
| 743 | |
| 744 | void NFileOperations::DeleteFileSecurely( |
| 745 | const std::wstring &strFilename, OverwriteMethod_t uOverwriteMethod) |
| 746 | { |
| 747 | HANDLE hFile; |
| 748 | WIN32_FIND_DATA wfd; |
| 749 | HANDLE hFindFile; |
| 750 | HCRYPTPROV hProv; |
| 751 | LARGE_INTEGER lRealFileSize; |
| 752 | BYTE pass1Data; |
| 753 | BYTE pass2Data; |
| 754 | BYTE pass3Data; |
| 755 | DWORD nBytesWritten; |
| 756 | BOOL bFolder; |
| 757 | int i = 0; |
| 758 | |
| 759 | hFindFile = FindFirstFile(strFilename.c_str(), &wfd); |
| 760 | |
| 761 | if (hFindFile == INVALID_HANDLE_VALUE) |
| 762 | { |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | bFolder = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; |
| 767 | |
| 768 | FindClose(hFindFile); |
| 769 | |
| 770 | if (bFolder) |
| 771 | { |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | /* Determine the actual size of the file on disk |
| 776 | (i.e. how many clusters it is allocated). */ |
| 777 | GetFileClusterSize(strFilename, &lRealFileSize); |
| 778 | |
| 779 | /* Open the file, block any sharing mode, to stop the file |
| 780 | been opened while it is overwritten. */ |
| 781 | hFile = CreateFile(strFilename.c_str(), FILE_WRITE_DATA, 0, NULL, OPEN_EXISTING, NULL, NULL); |
| 782 | |
| 783 | if (hFile == INVALID_HANDLE_VALUE) |
| 784 | { |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | /* Extend the file out to the end of its last sector. */ |
| 789 | SetFilePointerEx(hFile, lRealFileSize, NULL, FILE_BEGIN); |
| 790 | SetEndOfFile(hFile); |
| 791 | |
| 792 | /* Start at the beginning of the file, and |
| 793 | write in the first-pass data, 0x00 over |
| 794 | the length of the whole file. */ |
| 795 | SetFilePointer(hFile, 0, NULL, FILE_BEGIN); |
| 796 | pass1Data = 0x00; |
| 797 | |
| 798 | for (i = 0; i < lRealFileSize.QuadPart; i++) |
| 799 | { |
| 800 | WriteFile(hFile, (LPVOID) &pass1Data, 1, &nBytesWritten, NULL); |
| 801 | } |
nothing calls this directly
no test coverage detected