-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
70 lines (55 loc) · 1.34 KB
/
Utils.cpp
File metadata and controls
70 lines (55 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "stdafx.h"
#include "Utils.h"
bool Utils::directoryExists(wstring path) {
DWORD fileAttributes = GetFileAttributesW(path.c_str());
if(fileAttributes == INVALID_FILE_ATTRIBUTES) {
return false;
}
if(fileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
return true;
}
return false;
}
bool Utils::fileExists(wstring path) {
DWORD fileAttributes = GetFileAttributesW(path.c_str());
if(fileAttributes == INVALID_FILE_ATTRIBUTES) {
return false;
}
if(fileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
return false;
}
return true;
}
void* Utils::loadFile(wstring path, size_t * pSize) {
size_t read;
void* result;
FILE* fp;
errno_t err;
err = _wfopen_s(&fp, path.c_str(), _T("rb"));
if(err) {
Console::Log(L"Can't open DLL file == NULL");
return nullptr;
}
//if(fp == NULL) {
// Console::Log(L"Can't open DLL file == NULL");
// return NULL;
//}
fseek(fp, 0, SEEK_END);
*pSize = static_cast<size_t>(ftell(fp));
if(*pSize == 0) {
fclose(fp);
return nullptr;
}
result = (unsigned char *)malloc(*pSize);
if(result == nullptr) {
return nullptr;
}
fseek(fp, 0, SEEK_SET);
read = fread(result, 1, *pSize, fp);
fclose(fp);
if(read != *pSize) {
free(result);
return nullptr;
}
return result;
}