2024-09-07 18:00:09 +06:00
|
|
|
#pragma once
|
2024-12-13 18:31:55 +03:00
|
|
|
|
2024-12-15 11:37:36 -03:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
2024-09-07 18:00:09 +06:00
|
|
|
#include <vector>
|
|
|
|
|
2024-12-15 11:37:36 -03:00
|
|
|
inline std::vector<uint8_t> LoadFile(const std::filesystem::path& path)
|
2024-09-07 18:00:09 +06:00
|
|
|
{
|
2024-12-15 11:37:36 -03:00
|
|
|
std::ifstream stream(path, std::ios::binary);
|
|
|
|
if (!stream.is_open())
|
2024-09-07 18:21:08 +06:00
|
|
|
{
|
2024-12-13 18:31:55 +03:00
|
|
|
return {};
|
2024-09-07 18:21:08 +06:00
|
|
|
}
|
2024-09-07 18:00:09 +06:00
|
|
|
|
2024-12-15 11:37:36 -03:00
|
|
|
stream.seekg(0, std::ios::end);
|
|
|
|
std::streampos size = stream.tellg();
|
|
|
|
stream.seekg(0, std::ios::beg);
|
2024-09-07 18:00:09 +06:00
|
|
|
|
2024-12-15 11:37:36 -03:00
|
|
|
std::vector<uint8_t> data;
|
2024-09-07 18:21:08 +06:00
|
|
|
data.resize(size);
|
2024-12-15 11:37:36 -03:00
|
|
|
stream.read((char *)(data.data()), size);
|
|
|
|
if (stream.bad())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
2024-09-07 18:00:09 +06:00
|
|
|
|
2024-09-07 18:21:08 +06:00
|
|
|
return data;
|
2024-09-09 23:23:04 +06:00
|
|
|
}
|