forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileLoader.cpp
More file actions
50 lines (43 loc) · 1 KB
/
Copy pathFileLoader.cpp
File metadata and controls
50 lines (43 loc) · 1 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
#include "PCH.h"
#include "FileLoader.h"
#include <array>
#include <algorithm>
#include <stdio.h>
#include <string>
namespace sh::core
{
auto FileLoader::LoadBinary(std::string_view dir) -> std::optional<std::vector<unsigned char>>
{
std::vector<unsigned char> data;
FILE* file;
file = fopen(dir.data(), "rb");
if (!file)
return {};
std::array<unsigned char, 100> buffer{};
size_t size = 0;
while ((size = fread(buffer.data(), sizeof(unsigned char), 100, file)) > 0)
{
for (int i = 0; i < size; ++i)
data.push_back(buffer[i]);
}
fclose(file);
return data;
}
auto FileLoader::LoadText(std::string_view dir) ->std::optional<std::string>
{
std::string strData;
FILE* file;
file = fopen(dir.data(), "r");
if (!file)
return {};
std::array<char, 100> buffer{};
size_t size = 0;
while ((size = fread(buffer.data(), sizeof(unsigned char), 100, file)) > 0)
{
for (int i = 0; i < size; ++i)
strData.push_back(buffer[i]);
}
fclose(file);
return strData;
}
}