MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / OpenFile

Method OpenFile

src/WraithXCOD/WraithXCOD/WinFileSystem.cpp:31–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31HANDLE WinFileSystem::OpenFile(const std::string& fileName, const std::string& mode)
32{
33 HANDLE result = NULL;
34 char buffer[MAX_PATH]{};
35
36 if (PathIsRelativeA(fileName.c_str()))
37 {
38 if (sprintf_s(buffer, "%s%s%s", Directory.c_str(), (Directory.size() > 0 ? "\\" : ""), fileName.c_str()) <= 0)
39 {
40 LastErrorCode = 0x505000;
41 return NULL;
42 }
43 }
44 else
45 {
46 std::memcpy(buffer, fileName.c_str(), std::min(sizeof(buffer), fileName.size()));
47 }
48
49 if (mode == "r")
50 {
51 result = CreateFileA(
52 buffer,
53 FILE_READ_DATA | FILE_READ_ATTRIBUTES,
54 FILE_SHARE_READ | FILE_SHARE_WRITE,
55 NULL,
56 OPEN_EXISTING,
57 0,
58 NULL);
59 }
60 else if (mode == "w")
61 {
62 result = CreateFileA(
63 buffer,
64 GENERIC_WRITE,
65 0,
66 NULL,
67 CREATE_NEW | OPEN_EXISTING,
68 0,
69 NULL);
70 }
71 else
72 {
73 LastErrorCode = 0x505001;
74 return NULL;
75 }
76
77 if (result == INVALID_HANDLE_VALUE || result == NULL)
78 {
79 LastErrorCode = 0x505002;
80 return NULL;
81 }
82
83 LastErrorCode = 0;
84 return result;
85}
86
87void WinFileSystem::CloseHandle(HANDLE handle)
88{

Callers 12

LoadPackageMethod · 0.45
ExtractPackageObjectMethod · 0.45
ExtractPackageObjectMethod · 0.45
LoadCDNXPAKMethod · 0.45
LoadPackageMethod · 0.45
ExtractPackageObjectMethod · 0.45
LoadCDNXPAKMethod · 0.45
LoadPackageMethod · 0.45
ExtractPackageObjectMethod · 0.45
LoadPackageMethod · 0.45
ExtractPackageObjectMethod · 0.45

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected