-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.cpp
More file actions
81 lines (62 loc) · 1.85 KB
/
utility.cpp
File metadata and controls
81 lines (62 loc) · 1.85 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
71
72
73
74
75
76
77
78
79
80
81
#include "header.hpp"
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
void getPathInfo(const std::wstring& path, std::wstring& dir, std::wstring& fileName){
dir = L"./";
fileName = path;
for (int n = path.size(); n --> 0;) {
if (path[n] == L'/' || path[n] == L'\\') {
dir = path.substr(0, n + 1);
fileName = &path[n + 1];
break;
}
}
}
std::wstring getExtension(const std::wstring& path){
const wchar_t* result = &path[path.size() - 1];
while(*result != L'.' && result != &path[0]){
--result;
}
return result;
}
std::vector<std::wstring> getFileNamesInDir(std::wstring path){
std::vector<std::wstring> fileNames;
wchar_t lastChar = path.back();
if(lastChar != L'/' || lastChar != L'\\'){
path += L"/";
}
path += L"*";
WIN32_FIND_DATAW findData;
HANDLE hFind = FindFirstFileW(
path.c_str() ,
&findData
);
if(hFind == INVALID_HANDLE_VALUE){
return fileNames;
}
if(!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){
fileNames.push_back(findData.cFileName);
}
while(FindNextFileW(hFind , &findData)){
if(!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){
fileNames.push_back(std::move(findData.cFileName));
}
}
FindClose(hFind);
return std::move(fileNames);
}
std::vector<byte> getFileBytes(const std::wstring& filePath){
std::vector<byte> bytes;
FILE* file = _wfopen(filePath.c_str(), L"rb");
if(file == NULL) {
ffxReadError(filePath, L"Cannot open file");
}else{
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
bytes.resize(fileSize);
fread(bytes.data(), 1, bytes.size(), file);
fclose(file);
}
return std::move(bytes);
}