| 137 | |
| 138 | #ifdef _WIN32 |
| 139 | static bool |
| 140 | read_dir_iv(const TCHAR *path, unsigned char *diriv, FILETIME& LastWriteTime) |
| 141 | { |
| 142 | |
| 143 | HANDLE hfile = INVALID_HANDLE_VALUE; |
| 144 | DWORD nRead = 0; |
| 145 | |
| 146 | bool caught_wstring = false; |
| 147 | |
| 148 | try { |
| 149 | wstring path_str; |
| 150 | |
| 151 | path_str.append(path); |
| 152 | |
| 153 | if (path_str[path_str.size() - 1] != '\\') { |
| 154 | path_str.push_back('\\'); |
| 155 | } |
| 156 | |
| 157 | path_str.append(DIR_IV_NAME); |
| 158 | |
| 159 | hfile = ::CreateFile(&path_str[0], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
| 160 | |
| 161 | if (hfile == INVALID_HANDLE_VALUE) { |
| 162 | auto lasterr =::GetLastError(); |
| 163 | throw(L"\terror opening diriv file " + path_str + L" lasterr = " + to_wstring(lasterr)); |
| 164 | } |
| 165 | |
| 166 | if (!::ReadFile(hfile, diriv, DIR_IV_LEN, &nRead, NULL)) { |
| 167 | auto lasterr = ::GetLastError(); |
| 168 | throw(L"\terror reading diriv file " + path_str + L" lasterr = " + to_wstring(lasterr)); |
| 169 | } |
| 170 | |
| 171 | if (!::GetFileTime(hfile, NULL, NULL, &LastWriteTime)) { |
| 172 | auto lasterr = ::GetLastError(); |
| 173 | throw(L"\terror getting filetime of diriv file " + path_str + L" lasterr = " + to_wstring(lasterr)); |
| 174 | } |
| 175 | } catch (const wstring& mes) { |
| 176 | DbgPrint(L"\tget_diriv: %s\n", mes.c_str()); |
| 177 | nRead = 0; |
| 178 | caught_wstring = true; |
| 179 | } catch (...) { |
| 180 | nRead = 0; |
| 181 | } |
| 182 | |
| 183 | if (hfile != INVALID_HANDLE_VALUE) |
| 184 | ::CloseHandle(hfile); |
| 185 | |
| 186 | if (!caught_wstring && nRead != DIR_IV_LEN) { |
| 187 | DbgPrint(L"\tget_diriv read incorrect number of bytes from %s, read %u bytes instead of %u\n", path, nRead, DIR_IV_LEN); |
| 188 | } |
| 189 | |
| 190 | return nRead == DIR_IV_LEN; |
| 191 | } |
| 192 | |
| 193 | #endif // _WIN32 |
| 194 |
no test coverage detected