| 152 | } |
| 153 | |
| 154 | void File::Open(const wchar* filePath, FileOpenMode openMode_) |
| 155 | { |
| 156 | Assert_(fileHandle == INVALID_HANDLE_VALUE); |
| 157 | openMode = openMode_; |
| 158 | |
| 159 | if(openMode == FileOpenMode::Read) |
| 160 | { |
| 161 | Assert_(FileExists(filePath)); |
| 162 | |
| 163 | // Open the file |
| 164 | fileHandle = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 165 | if(fileHandle == INVALID_HANDLE_VALUE) |
| 166 | { |
| 167 | std::wstring errPrefix = std::wstring(L"Failed to open file ") + filePath + L":\n"; |
| 168 | Assert_(false); |
| 169 | throw Win32Exception(GetLastError(), errPrefix.c_str()); |
| 170 | } |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | // If the exists, delete it |
| 175 | if(FileExists(filePath)) |
| 176 | Win32Call(DeleteFile(filePath)); |
| 177 | |
| 178 | // Create the file |
| 179 | fileHandle = CreateFile(filePath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); |
| 180 | if(fileHandle == INVALID_HANDLE_VALUE) |
| 181 | { |
| 182 | std::wstring errPrefix = std::wstring(L"Failed to open file ") + filePath + L":\n"; |
| 183 | Assert_(false); |
| 184 | throw Win32Exception(GetLastError(), errPrefix.c_str()); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void File::Close() |
| 190 | { |
no test coverage detected