-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathmain.cpp
More file actions
132 lines (109 loc) · 3.13 KB
/
main.cpp
File metadata and controls
132 lines (109 loc) · 3.13 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "pch.h"
struct writer : cppwinrt::writer_base<writer>
{
};
int main(int const argc, char** argv)
{
if (argc < 3)
{
puts("Usage: prebuild.exe input output");
return 0;
}
writer strings_h;
writer strings_cpp;
strings_h.write(R"(
#pragma once
namespace cppwinrt::strings {
extern "C++" {
)");
strings_cpp.write(R"(
#include "strings.h"
namespace cppwinrt::strings {
)");
for (auto&& file : std::filesystem::directory_iterator(argv[1]))
{
if (!std::filesystem::is_regular_file(file))
{
continue;
}
auto path = file.path();
auto name = path.filename();
name.replace_extension();
auto view = cppwinrt::file_to_string(path.string());
strings_h.write(R"(extern char const %[%];
)",
name.string(),
static_cast<uint64_t>(view.size() + 1));
strings_cpp.write(R"(extern char const %[] = R"xyz()xyz"
)",
name.string());
std::string_view remainder = view;
while (!remainder.empty())
{
auto const size = std::min(size_t{ 16'000 }, remainder.size());
auto const chunk = remainder.substr(0, size);
strings_cpp.write(R"(R"xyz(%)xyz"
)",
chunk);
remainder = remainder.substr(size);
}
strings_cpp.write(";\n");
}
strings_h.write(R"(
}
}
)");
strings_cpp.write(R"(
}
)");
writer version_rc;
// Extract major.minor substrings from CPPWINRT_VERSION_STRING (e.g. "3.0.250316.1")
std::string_view const full_version{ CPPWINRT_VERSION_STRING };
auto const first_dot = full_version.find('.');
auto const second_dot = full_version.find('.', first_dot + 1);
auto const ver_major = full_version.substr(0, first_dot);
auto const ver_minor = full_version.substr(first_dot + 1, second_dot - first_dot - 1);
version_rc.write(R"(
#include "winres.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION %,%,0,0
PRODUCTVERSION %,%,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x0L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Microsoft Corporation"
VALUE "FileDescription", "C++/WinRT"
VALUE "FileVersion", "%.%.0.0"
VALUE "LegalCopyright", "Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "cppwinrt.exe"
VALUE "ProductName", "C++/WinRT"
VALUE "ProductVersion", "%"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
)",
ver_major, ver_minor, // FILEVERSION
ver_major, ver_minor, // PRODUCTVERSION
ver_major, ver_minor, // FileVersion string
CPPWINRT_VERSION_STRING); // ProductVersion string
std::filesystem::create_directories(argv[2]);
auto const output = std::filesystem::canonical(argv[2]);
strings_h.flush_to_file(output / "strings.h");
strings_cpp.flush_to_file(output / "strings.cpp");
version_rc.flush_to_file(output / "version.rc");
}