MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / Open

Method Open

SampleFramework11/v1.02/FileIO.cpp:154–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154void 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
189void File::Close()
190{

Callers 2

FileReadSerializerMethod · 0.45
FileWriteSerializerMethod · 0.45

Calls 3

FileExistsFunction · 0.85
Win32ExceptionClass · 0.85
Win32CallFunction · 0.85

Tested by

no test coverage detected