Skip to content

Commit 75db75e

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 a835d16 commit 75db75e

File tree

11 files changed

+191
-142
lines changed

11 files changed

+191
-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
@@ -145,10 +149,10 @@ install_pdbs =
145149
install_dlls =
146150
install_loot =
147151
install_plugins =
152+
install_extensions =
148153
install_stylesheets =
149154
install_licenses =
150155
install_pythoncore =
151-
install_translations =
152156
vs =
153157
qt_install =
154158
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
@@ -34,24 +34,32 @@ namespace mob::details {
3434

3535
// returns a string from conf, bails out if it doesn't exist
3636
//
37-
std::string get_string(std::string_view section, std::string_view key)
37+
std::string get_string(std::string_view section, std::string_view key,
38+
std::optional<std::string> default_)
3839
{
3940
auto sitor = g_conf.find(section);
4041
if (sitor == g_conf.end())
4142
gcx().bail_out(context::conf, "[{}] doesn't exist", section);
4243

4344
auto kitor = sitor->second.find(key);
44-
if (kitor == sitor->second.end())
45-
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
45+
if (kitor == sitor->second.end()) {
46+
if (!default_.has_value()) {
47+
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
48+
}
49+
return *default_;
50+
}
4651

4752
return kitor->second;
4853
}
4954

5055
// calls get_string(), converts to int
5156
//
52-
int get_int(std::string_view section, std::string_view key)
57+
int get_int(std::string_view section, std::string_view key,
58+
std::optional<int> default_)
5359
{
54-
const auto s = get_string(section, key);
60+
const auto s = get_string(section, key, default_.transform([](auto v) {
61+
return std::to_string(v);
62+
}));
5563

5664
try {
5765
return std::stoi(s);
@@ -63,9 +71,12 @@ namespace mob::details {
6371

6472
// calls get_string(), converts to bool
6573
//
66-
bool get_bool(std::string_view section, std::string_view key)
74+
bool get_bool(std::string_view section, std::string_view key,
75+
std::optional<bool> default_)
6776
{
68-
const auto s = get_string(section, key);
77+
const auto s = get_string(section, key, default_.transform([](auto v) {
78+
return v ? "true" : "false";
79+
}));
6980
return bool_from_string(s);
7081
}
7182

@@ -378,13 +389,8 @@ namespace mob {
378389

379390
MOB_ASSERT(!tasks.empty());
380391

381-
for (auto& t : tasks) {
382-
if (t->name() != task &&
383-
details::find_string_for_task(t->name(), key)) {
384-
continue;
385-
}
392+
for (auto& t : tasks)
386393
details::set_string_for_task(t->name(), key, value);
387-
}
388394
}
389395
else {
390396
// global task option
@@ -488,7 +494,7 @@ namespace mob {
488494
resolve_path("install_licenses", p.install_bin(), "licenses");
489495
resolve_path("install_pythoncore", p.install_bin(), "pythoncore");
490496
resolve_path("install_stylesheets", p.install_bin(), "stylesheets");
491-
resolve_path("install_translations", p.install_bin(), "translations");
497+
resolve_path("install_extensions", p.install_bin(), "extensions");
492498

493499
// finally, resolve the tools that are unlikely to be in PATH; all the
494500
// other tools (7z, jom, patch, etc.) are assumed to be in PATH (which
@@ -634,6 +640,11 @@ namespace mob {
634640
return {};
635641
}
636642

643+
conf_translations conf::translation()
644+
{
645+
return {};
646+
}
647+
637648
conf_prebuilt conf::prebuilt()
638649
{
639650
return {};
@@ -725,6 +736,8 @@ namespace mob {
725736

726737
conf_versions::conf_versions() : conf_section("versions") {}
727738

739+
conf_translations::conf_translations() : conf_section("translations") {}
740+
728741
conf_prebuilt::conf_prebuilt() : conf_section("prebuilt") {}
729742

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

src/core/conf.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ namespace mob::details {
77

88
// returns an option named `key` from the given `section`
99
//
10-
std::string get_string(std::string_view section, std::string_view key);
10+
std::string get_string(std::string_view section, std::string_view key,
11+
std::optional<std::string> default_ = {});
1112

1213
// calls get_string(), converts to bool
1314
//
14-
bool get_bool(std::string_view section, std::string_view key);
15+
bool get_bool(std::string_view section, std::string_view key,
16+
std::optional<bool> default_ = {});
1517

1618
// calls get_string(), converts to in
1719
//
18-
int get_int(std::string_view section, std::string_view key);
20+
int get_int(std::string_view section, std::string_view key,
21+
std::optional<int> default_ = {});
1922

2023
// sets the given option, bails out if the option doesn't exist
2124
//
@@ -46,25 +49,31 @@ namespace mob {
4649
template <class DefaultType>
4750
class conf_section {
4851
public:
49-
DefaultType get(std::string_view key) const
52+
DefaultType get(std::string_view key,
53+
std::optional<DefaultType> default_ = {}) const
5054
{
51-
return details::get_string(name_, key);
55+
if constexpr (std::is_same_v<DefaultType, std::string>) {
56+
return details::get_string(name_, key, default_);
57+
}
58+
else {
59+
return details::get_string(name_, key);
60+
}
5261
}
5362

5463
// undefined
5564
template <class T>
56-
T get(std::string_view key) const;
65+
T get(std::string_view key, std::optional<T> default_ = {}) const;
5766

5867
template <>
59-
bool get<bool>(std::string_view key) const
68+
bool get<bool>(std::string_view key, std::optional<bool> default_) const
6069
{
61-
return details::get_bool(name_, key);
70+
return details::get_bool(name_, key, default_);
6271
}
6372

6473
template <>
65-
int get<int>(std::string_view key) const
74+
int get<int>(std::string_view key, std::optional<int> default_) const
6675
{
67-
return details::get_int(name_, key);
76+
return details::get_int(name_, key, default_);
6877
}
6978

7079
void set(std::string_view key, std::string_view value)
@@ -220,6 +229,13 @@ namespace mob {
220229
conf_versions();
221230
};
222231

232+
// options in [translations]
233+
//
234+
class conf_translations : public conf_section<std::string> {
235+
public:
236+
conf_translations();
237+
};
238+
223239
// options in [prebuilt]
224240
//
225241
class conf_prebuilt : public conf_section<std::string> {
@@ -254,11 +270,10 @@ namespace mob {
254270

255271
VALUE(install_dlls);
256272
VALUE(install_loot);
257-
VALUE(install_plugins);
273+
VALUE(install_extensions);
258274
VALUE(install_stylesheets);
259275
VALUE(install_licenses);
260276
VALUE(install_pythoncore);
261-
VALUE(install_translations);
262277

263278
VALUE(vs);
264279
VALUE(qt_install);
@@ -282,6 +297,7 @@ namespace mob {
282297
conf_cmake cmake();
283298
conf_tools tool();
284299
conf_transifex transifex();
300+
conf_translations translation();
285301
conf_prebuilt prebuilt();
286302
conf_versions version();
287303
conf_paths path();

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
@@ -74,33 +74,13 @@ namespace mob {
7474
.add_task<mo>("modorganizer-nxmhandler")
7575
.add_task<mo>("modorganizer-helper")
7676
.add_task<mo>("githubpp")
77-
.add_task<mo>("modorganizer-game_gamebryo")
7877
.add_task<mo>({"modorganizer-bsapacker", "bsa_packer"})
7978
.add_task<mo>("modorganizer-preview_bsa");
8079

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

10182
add_task<parallel_tasks>()
10283
.add_task<mo>({"modorganizer-tool_inieditor", "inieditor"})
103-
.add_task<mo>({"modorganizer-tool_inibakery", "inibakery"})
10484
.add_task<mo>("modorganizer-preview_base")
10585
.add_task<mo>("modorganizer-diagnose_basic")
10686
.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
@@ -235,13 +235,9 @@ namespace mob::tasks {
235235
enum flags {
236236
noflags = 0x00,
237237

238-
// gamebryo project, used by the translations task because these
239-
// projects have multiple .ts files that have to be merged
240-
gamebryo = 0x01,
241-
242238
// project that uses nuget, cmake doesn't support those right now, so
243239
// `msbuild -t:restore` has to be run manually
244-
nuget = 0x02,
240+
nuget = 0x01,
245241
};
246242

247243
// some mo tasks have more than one name, mostly because the transifex slugs
@@ -252,10 +248,6 @@ namespace mob::tasks {
252248
modorganizer(std::vector<std::string> names, flags f = noflags);
253249
modorganizer(std::vector<const char*> names, flags f = noflags);
254250

255-
// whether this project has the gamebryo flag on
256-
//
257-
bool is_gamebryo_plugin() const;
258-
259251
// whether this project has the nuget flag on
260252
//
261253
bool is_nuget_plugin() const;
@@ -632,11 +624,6 @@ namespace mob::tasks {
632624
// duplicate warnings
633625
std::set<fs::path> warned_;
634626

635-
// whether the given project name is a gamebryo task, `dir` is just for
636-
// logging
637-
//
638-
bool is_gamebryo_plugin(const std::string& dir, const std::string& project);
639-
640627
// parses the directory name, walks all the .ts files, returns a project
641628
// object for them
642629
//
@@ -645,7 +632,7 @@ namespace mob::tasks {
645632
// returns a lang object that contains at least the given main_ts_file,
646633
// but might contain more if it's a gamebryo plugin
647634
//
648-
lang create_lang(bool gamebryo, const std::string& project_name,
635+
lang create_lang(const std::string& project_name,
649636
const fs::path& main_ts_file);
650637
};
651638

0 commit comments

Comments
 (0)