forked from cyrilcode/embed-resource
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathembedresource.cpp
More file actions
54 lines (39 loc) · 1.15 KB
/
embedresource.cpp
File metadata and controls
54 lines (39 loc) · 1.15 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
#include <experimental/filesystem>
#include <fstream>
using namespace std;
using namespace experimental::filesystem;
int main(int argc, char** argv)
{
if (argc < 3) {
fprintf(stderr, "USAGE: %s {sym} {rsrc}\n\n"
" Creates {sym}.c from the contents of {rsrc}\n",
argv[0]);
return EXIT_FAILURE;
}
path dst{argv[1]};
path src{argv[2]};
string sym = src.filename().string();
replace(sym.begin(), sym.end(), '.', '_');
replace(sym.begin(), sym.end(), '-', '_');
create_directories(dst.parent_path());
ofstream ofs{dst};
ifstream ifs{src};
ofs << "#include <stdlib.h>" << endl;
ofs << "extern const char _resource_" << sym << "[] = {" << endl;
size_t lineCount = 0;
while (true)
{
char c;
ifs.get(c);
if (ifs.eof())
break;
ofs << "0x" << hex << (unsigned int)c << ", ";
if (++lineCount == 10) {
ofs << endl;
lineCount = 0;
}
}
ofs << "};" << endl;
ofs << "extern const size_t _resource_" << sym << "_len = sizeof(_resource_" << sym << ");";
return EXIT_SUCCESS;
}