-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (55 loc) · 1.36 KB
/
main.cpp
File metadata and controls
65 lines (55 loc) · 1.36 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
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <ios>
int main(int argc, const char* argv[])
{
std::filesystem::path current_dir{ std::filesystem::current_path() };
for (const std::filesystem::directory_entry& file : std::filesystem::directory_iterator(current_dir))
{
if (file.is_directory()
|| file.path().extension() == ".hpp"
|| file.path().filename().string().ends_with(argv[0])
|| file.path().filename().string().starts_with("ignore_"))
{
continue;
}
std::ifstream bin(file.path(), std::ios::binary | std::ios::ate);
if (!bin)
continue;
size_t bin_size = bin.tellg();
bin.seekg(0, std::ios::beg);
std::ofstream hex(file.path().string() + ".hpp");
if (!hex)
continue;
std::string var_name = file.path().filename().string();
for (char& c : var_name)
{
if (c == '.')
c = '_';
}
hex << "#pragma once\n"
"#include <array>\n"
"#include <cstdint>\n"
"\n"
"inline constexpr std::array<uint8_t, " << bin_size << "> "
<< var_name
<< " =\n"
"{";
hex << std::hex;
int i = 0;
for (int c = bin.get(); c != std::char_traits<char>::eof(); c = bin.get())
{
if (i % 20 == 0)
hex << "\n ";
hex << "0x" << c;
if (i != bin_size - 1)
hex << ", ";
i++;
}
hex << "\n};";
std::cout << "Converted: " << file.path().string() << '\n';
}
return 0;
}