Skip to content

Commit 3db6c32

Browse files
committed
Start working on extensions.
- Update translations task to put translations under extensions. - Put translations in the right place. - Remove INI bakery plugin. - Use mo2- prefixed extensions for translations. - Generate metadata for the translations extension.
1 parent eba5bf4 commit 3db6c32

File tree

11 files changed

+193
-142
lines changed

11 files changed

+193
-142
lines changed

mob.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ host =
2121
super = cmake_common modorganizer* githubpp
2222
plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_*
2323

24+
[translations]
25+
mo2-translations = organizer
26+
mo2-game-bethesda = game_creation game_enderal game_enderalse game_fallout3 game_fallout4 game_fallout4vr game_falloutNV game_gamebryo game_morrowind game_nehrim game_oblivion game_skyrim game_skyrimse game_skyrimvr game_ttw
27+
2428
[task]
2529
enabled = true
2630
mo_org = ModOrganizer2
@@ -150,10 +154,10 @@ install_pdbs =
150154
install_dlls =
151155
install_loot =
152156
install_plugins =
157+
install_extensions =
153158
install_stylesheets =
154159
install_licenses =
155160
install_pythoncore =
156-
install_translations =
157161
vs =
158162
qt_install =
159163
qt_bin =

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ file(GLOB_RECURSE source_files *.cpp)
44
file(GLOB_RECURSE header_files *.h)
55

66
add_executable(mob ${source_files} ${header_files})
7-
set_target_properties(mob PROPERTIES CXX_STANDARD 20)
7+
set_target_properties(mob PROPERTIES CXX_STANDARD 23)
88

99
target_compile_definitions(mob PUBLIC NOMINMAX)
1010
target_compile_options(mob PUBLIC "/MT")

src/core/conf.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,32 @@ namespace mob::details {
5151

5252
// returns a string from conf, bails out if it doesn't exist
5353
//
54-
std::string get_string(std::string_view section, std::string_view key)
54+
std::string get_string(std::string_view section, std::string_view key,
55+
std::optional<std::string> default_)
5556
{
5657
auto sitor = g_conf.find(section);
5758
if (sitor == g_conf.end())
5859
gcx().bail_out(context::conf, "[{}] doesn't exist", section);
5960

6061
auto kitor = sitor->second.find(key);
61-
if (kitor == sitor->second.end())
62-
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
62+
if (kitor == sitor->second.end()) {
63+
if (!default_.has_value()) {
64+
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
65+
}
66+
return *default_;
67+
}
6368

6469
return kitor->second;
6570
}
6671

6772
// calls get_string(), converts to int
6873
//
69-
int get_int(std::string_view section, std::string_view key)
74+
int get_int(std::string_view section, std::string_view key,
75+
std::optional<int> default_)
7076
{
71-
const auto s = get_string(section, key);
77+
const auto s = get_string(section, key, default_.transform([](auto v) {
78+
return std::to_string(v);
79+
}));
7280

7381
try {
7482
return std::stoi(s);
@@ -80,9 +88,12 @@ namespace mob::details {
8088

8189
// calls get_string(), converts to bool
8290
//
83-
bool get_bool(std::string_view section, std::string_view key)
91+
bool get_bool(std::string_view section, std::string_view key,
92+
std::optional<bool> default_)
8493
{
85-
const auto s = get_string(section, key);
94+
const auto s = get_string(section, key, default_.transform([](auto v) {
95+
return v ? "true" : "false";
96+
}));
8697
return bool_from_string(s);
8798
}
8899

@@ -428,13 +439,8 @@ namespace mob {
428439

429440
MOB_ASSERT(!tasks.empty());
430441

431-
for (auto& t : tasks) {
432-
if (t->name() != task &&
433-
details::find_string_for_task(t->name(), key)) {
434-
continue;
435-
}
442+
for (auto& t : tasks)
436443
details::set_string_for_task(t->name(), key, value);
437-
}
438444
}
439445
else {
440446
// global task option
@@ -538,7 +544,7 @@ namespace mob {
538544
resolve_path("install_licenses", p.install_bin(), "licenses");
539545
resolve_path("install_pythoncore", p.install_bin(), "pythoncore");
540546
resolve_path("install_stylesheets", p.install_bin(), "stylesheets");
541-
resolve_path("install_translations", p.install_bin(), "translations");
547+
resolve_path("install_extensions", p.install_bin(), "extensions");
542548

543549
// finally, resolve the tools that are unlikely to be in PATH; all the
544550
// other tools (7z, jom, patch, etc.) are assumed to be in PATH (which
@@ -684,6 +690,11 @@ namespace mob {
684690
return {};
685691
}
686692

693+
conf_translations conf::translation()
694+
{
695+
return {};
696+
}
697+
687698
conf_prebuilt conf::prebuilt()
688699
{
689700
return {};
@@ -777,6 +788,8 @@ namespace mob {
777788

778789
conf_build_types::conf_build_types() : conf_section("build-types") {}
779790

791+
conf_translations::conf_translations() : conf_section("translations") {}
792+
780793
conf_prebuilt::conf_prebuilt() : conf_section("prebuilt") {}
781794

782795
conf_paths::conf_paths() : conf_section("paths") {}

src/core/conf.h

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace mob::details {
99

1010
// returns an option named `key` from the given `section`
1111
//
12-
std::string get_string(std::string_view section, std::string_view key);
12+
std::string get_string(std::string_view section, std::string_view key,
13+
std::optional<std::string> default_ = {});
1314

1415
// convert a string to the given type
1516
template <class T>
@@ -25,11 +26,13 @@ namespace mob::details {
2526

2627
// calls get_string(), converts to bool
2728
//
28-
bool get_bool(std::string_view section, std::string_view key);
29+
bool get_bool(std::string_view section, std::string_view key,
30+
std::optional<bool> default_ = {});
2931

3032
// calls get_string(), converts to in
3133
//
32-
int get_int(std::string_view section, std::string_view key);
34+
int get_int(std::string_view section, std::string_view key,
35+
std::optional<int> default_ = {});
3336

3437
// sets the given option, bails out if the option doesn't exist
3538
//
@@ -60,9 +63,17 @@ namespace mob {
6063
template <class DefaultType>
6164
class conf_section {
6265
public:
63-
DefaultType get(std::string_view key) const
66+
DefaultType get(std::string_view key,
67+
std::optional<DefaultType> default_ = {}) const
6468
{
65-
const auto value = details::get_string(name_, key);
69+
const auto value = [=] {
70+
if constexpr (std::is_same_v<DefaultType, std::string>) {
71+
return details::get_string(name_, key, default_);
72+
}
73+
else {
74+
return details::get_string(name_, key);
75+
}
76+
}();
6677

6778
if constexpr (std::is_convertible_v<std::string, DefaultType>) {
6879
return value;
@@ -74,18 +85,18 @@ namespace mob {
7485

7586
// undefined
7687
template <class T>
77-
T get(std::string_view key) const;
88+
T get(std::string_view key, std::optional<T> default_ = {}) const;
7889

7990
template <>
80-
bool get<bool>(std::string_view key) const
91+
bool get<bool>(std::string_view key, std::optional<bool> default_) const
8192
{
82-
return details::get_bool(name_, key);
93+
return details::get_bool(name_, key, default_);
8394
}
8495

8596
template <>
86-
int get<int>(std::string_view key) const
97+
int get<int>(std::string_view key, std::optional<int> default_) const
8798
{
88-
return details::get_int(name_, key);
99+
return details::get_int(name_, key, default_);
89100
}
90101

91102
void set(std::string_view key, std::string_view value)
@@ -223,6 +234,13 @@ namespace mob {
223234
conf_build_types();
224235
};
225236

237+
// options in [translations]
238+
//
239+
class conf_translations : public conf_section<std::string> {
240+
public:
241+
conf_translations();
242+
};
243+
226244
// options in [prebuilt]
227245
//
228246
class conf_prebuilt : public conf_section<std::string> {
@@ -257,11 +275,10 @@ namespace mob {
257275

258276
VALUE(install_dlls);
259277
VALUE(install_loot);
260-
VALUE(install_plugins);
278+
VALUE(install_extensions);
261279
VALUE(install_stylesheets);
262280
VALUE(install_licenses);
263281
VALUE(install_pythoncore);
264-
VALUE(install_translations);
265282

266283
VALUE(vs);
267284
VALUE(qt_install);
@@ -285,6 +302,7 @@ namespace mob {
285302
conf_cmake cmake();
286303
conf_tools tool();
287304
conf_transifex transifex();
305+
conf_translations translation();
288306
conf_prebuilt prebuilt();
289307
conf_versions version();
290308
conf_build_types build_types();

src/core/op.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ namespace mob::op {
116116
}
117117
}
118118

119+
void delete_file_glob_recurse(const context& cx, const fs::path& directory,
120+
const fs::path& glob, flags f)
121+
{
122+
cx.trace(context::fs, "deleting glob {}", glob);
123+
124+
const auto native = glob.native();
125+
126+
if (!fs::exists(directory))
127+
return;
128+
129+
for (auto&& e : fs::recursive_directory_iterator(directory)) {
130+
const auto p = e.path();
131+
const auto name = p.filename().native();
132+
133+
if (!PathMatchSpecW(name.c_str(), native.c_str())) {
134+
cx.trace(context::fs, "{} did not match {}; skipping", name, glob);
135+
136+
continue;
137+
}
138+
139+
delete_file(cx, p, f);
140+
}
141+
}
142+
119143
void remove_readonly(const context& cx, const fs::path& dir, flags f)
120144
{
121145
cx.trace(context::fs, "removing read-only from {}", dir);

src/core/op.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ namespace mob::op {
6565
//
6666
void delete_file_glob(const context& cx, const fs::path& glob, flags f = noflags);
6767

68+
// deletes all files matching the glob in the given directory and its subdirectories
69+
//
70+
void delete_file_glob_recurse(const context& cx, const fs::path& directory,
71+
const fs::path& glob, flags f = noflags);
72+
6873
// removes the readonly flag for all files in `dir`, recursive
6974
//
7075
void remove_readonly(const context& cx, const fs::path& dir, flags f = noflags);

src/main.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,13 @@ namespace mob {
7373
.add_task<mo>("modorganizer-nxmhandler")
7474
.add_task<mo>("modorganizer-helper")
7575
.add_task<mo>("githubpp")
76-
.add_task<mo>("modorganizer-game_gamebryo")
7776
.add_task<mo>({"modorganizer-bsapacker", "bsa_packer"})
7877
.add_task<mo>("modorganizer-preview_bsa");
7978

80-
// the gamebryo flag must be set for all game plugins that inherit from
81-
// the gamebryo classes; this will merge the .ts file from gamebryo with
82-
// the one from the specific plugin
83-
add_task<parallel_tasks>()
84-
.add_task<mo>("modorganizer-game_oblivion", mo::gamebryo)
85-
.add_task<mo>("modorganizer-game_nehrim", mo::gamebryo)
86-
.add_task<mo>("modorganizer-game_fallout3", mo::gamebryo)
87-
.add_task<mo>("modorganizer-game_fallout4", mo::gamebryo)
88-
.add_task<mo>("modorganizer-game_fallout4vr", mo::gamebryo)
89-
.add_task<mo>("modorganizer-game_fallout76", mo::gamebryo)
90-
.add_task<mo>("modorganizer-game_falloutnv", mo::gamebryo)
91-
.add_task<mo>("modorganizer-game_morrowind", mo::gamebryo)
92-
.add_task<mo>("modorganizer-game_skyrim", mo::gamebryo)
93-
.add_task<mo>("modorganizer-game_skyrimse", mo::gamebryo)
94-
.add_task<mo>("modorganizer-game_skyrimvr", mo::gamebryo)
95-
.add_task<mo>("modorganizer-game_starfield", mo::gamebryo)
96-
.add_task<mo>("modorganizer-game_ttw", mo::gamebryo)
97-
.add_task<mo>("modorganizer-game_enderal", mo::gamebryo)
98-
.add_task<mo>("modorganizer-game_enderalse", mo::gamebryo);
79+
add_task<parallel_tasks>().add_task<mo>("modorganizer-game_bethesda");
9980

10081
add_task<parallel_tasks>()
10182
.add_task<mo>({"modorganizer-tool_inieditor", "inieditor"})
102-
.add_task<mo>({"modorganizer-tool_inibakery", "inibakery"})
10383
.add_task<mo>("modorganizer-preview_base")
10484
.add_task<mo>("modorganizer-diagnose_basic")
10585
.add_task<mo>("modorganizer-check_fnis")

src/tasks/modorganizer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ namespace mob::tasks {
8080
}
8181
}
8282

83-
bool modorganizer::is_gamebryo_plugin() const
84-
{
85-
return is_set(flags_, gamebryo);
86-
}
87-
8883
bool modorganizer::is_nuget_plugin() const
8984
{
9085
return is_set(flags_, nuget);

src/tasks/sevenz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace mob::tasks {
7979

8080
void sevenz::build()
8181
{
82-
build_loop(cx(), [&](bool mp) {
82+
build_loop(cx(), [&]([[maybe_unused]] bool mp) {
8383
const int exit_code = run_tool(nmake()
8484
.path(module_to_build())
8585
.def("CPU=x64")

src/tasks/tasks.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,9 @@ namespace mob::tasks {
220220
enum flags {
221221
noflags = 0x00,
222222

223-
// gamebryo project, used by the translations task because these
224-
// projects have multiple .ts files that have to be merged
225-
gamebryo = 0x01,
226-
227223
// project that uses nuget, cmake doesn't support those right now, so
228224
// `msbuild -t:restore` has to be run manually
229-
nuget = 0x02,
225+
nuget = 0x01,
230226
};
231227

232228
// some mo tasks have more than one name, mostly because the transifex slugs
@@ -237,10 +233,6 @@ namespace mob::tasks {
237233
modorganizer(std::vector<std::string> names, flags f = noflags);
238234
modorganizer(std::vector<const char*> names, flags f = noflags);
239235

240-
// whether this project has the gamebryo flag on
241-
//
242-
bool is_gamebryo_plugin() const;
243-
244236
// whether this project has the nuget flag on
245237
//
246238
bool is_nuget_plugin() const;
@@ -623,11 +615,6 @@ namespace mob::tasks {
623615
// duplicate warnings
624616
std::set<fs::path> warned_;
625617

626-
// whether the given project name is a gamebryo task, `dir` is just for
627-
// logging
628-
//
629-
bool is_gamebryo_plugin(const std::string& dir, const std::string& project);
630-
631618
// parses the directory name, walks all the .ts files, returns a project
632619
// object for them
633620
//
@@ -636,7 +623,7 @@ namespace mob::tasks {
636623
// returns a lang object that contains at least the given main_ts_file,
637624
// but might contain more if it's a gamebryo plugin
638625
//
639-
lang create_lang(bool gamebryo, const std::string& project_name,
626+
lang create_lang(const std::string& project_name,
640627
const fs::path& main_ts_file);
641628
};
642629

0 commit comments

Comments
 (0)