Skip to content

Commit

Permalink
Start working on extensions.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Holt59 committed Jul 1, 2024
1 parent eba5bf4 commit 3db6c32
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 142 deletions.
6 changes: 5 additions & 1 deletion mob.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ host =
super = cmake_common modorganizer* githubpp
plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_*

[translations]
mo2-translations = organizer
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

[task]
enabled = true
mo_org = ModOrganizer2
Expand Down Expand Up @@ -150,10 +154,10 @@ install_pdbs =
install_dlls =
install_loot =
install_plugins =
install_extensions =
install_stylesheets =
install_licenses =
install_pythoncore =
install_translations =
vs =
qt_install =
qt_bin =
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ file(GLOB_RECURSE source_files *.cpp)
file(GLOB_RECURSE header_files *.h)

add_executable(mob ${source_files} ${header_files})
set_target_properties(mob PROPERTIES CXX_STANDARD 20)
set_target_properties(mob PROPERTIES CXX_STANDARD 23)

target_compile_definitions(mob PUBLIC NOMINMAX)
target_compile_options(mob PUBLIC "/MT")
Expand Down
41 changes: 27 additions & 14 deletions src/core/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,32 @@ namespace mob::details {

// returns a string from conf, bails out if it doesn't exist
//
std::string get_string(std::string_view section, std::string_view key)
std::string get_string(std::string_view section, std::string_view key,
std::optional<std::string> default_)
{
auto sitor = g_conf.find(section);
if (sitor == g_conf.end())
gcx().bail_out(context::conf, "[{}] doesn't exist", section);

auto kitor = sitor->second.find(key);
if (kitor == sitor->second.end())
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
if (kitor == sitor->second.end()) {
if (!default_.has_value()) {
gcx().bail_out(context::conf, "no key '{}' in [{}]", key, section);
}
return *default_;
}

return kitor->second;
}

// calls get_string(), converts to int
//
int get_int(std::string_view section, std::string_view key)
int get_int(std::string_view section, std::string_view key,
std::optional<int> default_)
{
const auto s = get_string(section, key);
const auto s = get_string(section, key, default_.transform([](auto v) {
return std::to_string(v);
}));

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

// calls get_string(), converts to bool
//
bool get_bool(std::string_view section, std::string_view key)
bool get_bool(std::string_view section, std::string_view key,
std::optional<bool> default_)
{
const auto s = get_string(section, key);
const auto s = get_string(section, key, default_.transform([](auto v) {
return v ? "true" : "false";
}));
return bool_from_string(s);
}

Expand Down Expand Up @@ -428,13 +439,8 @@ namespace mob {

MOB_ASSERT(!tasks.empty());

for (auto& t : tasks) {
if (t->name() != task &&
details::find_string_for_task(t->name(), key)) {
continue;
}
for (auto& t : tasks)
details::set_string_for_task(t->name(), key, value);
}
}
else {
// global task option
Expand Down Expand Up @@ -538,7 +544,7 @@ namespace mob {
resolve_path("install_licenses", p.install_bin(), "licenses");
resolve_path("install_pythoncore", p.install_bin(), "pythoncore");
resolve_path("install_stylesheets", p.install_bin(), "stylesheets");
resolve_path("install_translations", p.install_bin(), "translations");
resolve_path("install_extensions", p.install_bin(), "extensions");

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

conf_translations conf::translation()
{
return {};
}

conf_prebuilt conf::prebuilt()
{
return {};
Expand Down Expand Up @@ -777,6 +788,8 @@ namespace mob {

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

conf_translations::conf_translations() : conf_section("translations") {}

conf_prebuilt::conf_prebuilt() : conf_section("prebuilt") {}

conf_paths::conf_paths() : conf_section("paths") {}
Expand Down
42 changes: 30 additions & 12 deletions src/core/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace mob::details {

// returns an option named `key` from the given `section`
//
std::string get_string(std::string_view section, std::string_view key);
std::string get_string(std::string_view section, std::string_view key,
std::optional<std::string> default_ = {});

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

// calls get_string(), converts to bool
//
bool get_bool(std::string_view section, std::string_view key);
bool get_bool(std::string_view section, std::string_view key,
std::optional<bool> default_ = {});

// calls get_string(), converts to in
//
int get_int(std::string_view section, std::string_view key);
int get_int(std::string_view section, std::string_view key,
std::optional<int> default_ = {});

// sets the given option, bails out if the option doesn't exist
//
Expand Down Expand Up @@ -60,9 +63,17 @@ namespace mob {
template <class DefaultType>
class conf_section {
public:
DefaultType get(std::string_view key) const
DefaultType get(std::string_view key,
std::optional<DefaultType> default_ = {}) const
{
const auto value = details::get_string(name_, key);
const auto value = [=] {
if constexpr (std::is_same_v<DefaultType, std::string>) {
return details::get_string(name_, key, default_);
}
else {
return details::get_string(name_, key);
}
}();

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

// undefined
template <class T>
T get(std::string_view key) const;
T get(std::string_view key, std::optional<T> default_ = {}) const;

template <>
bool get<bool>(std::string_view key) const
bool get<bool>(std::string_view key, std::optional<bool> default_) const
{
return details::get_bool(name_, key);
return details::get_bool(name_, key, default_);
}

template <>
int get<int>(std::string_view key) const
int get<int>(std::string_view key, std::optional<int> default_) const
{
return details::get_int(name_, key);
return details::get_int(name_, key, default_);
}

void set(std::string_view key, std::string_view value)
Expand Down Expand Up @@ -223,6 +234,13 @@ namespace mob {
conf_build_types();
};

// options in [translations]
//
class conf_translations : public conf_section<std::string> {
public:
conf_translations();
};

// options in [prebuilt]
//
class conf_prebuilt : public conf_section<std::string> {
Expand Down Expand Up @@ -257,11 +275,10 @@ namespace mob {

VALUE(install_dlls);
VALUE(install_loot);
VALUE(install_plugins);
VALUE(install_extensions);
VALUE(install_stylesheets);
VALUE(install_licenses);
VALUE(install_pythoncore);
VALUE(install_translations);

VALUE(vs);
VALUE(qt_install);
Expand All @@ -285,6 +302,7 @@ namespace mob {
conf_cmake cmake();
conf_tools tool();
conf_transifex transifex();
conf_translations translation();
conf_prebuilt prebuilt();
conf_versions version();
conf_build_types build_types();
Expand Down
24 changes: 24 additions & 0 deletions src/core/op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ namespace mob::op {
}
}

void delete_file_glob_recurse(const context& cx, const fs::path& directory,
const fs::path& glob, flags f)
{
cx.trace(context::fs, "deleting glob {}", glob);

const auto native = glob.native();

if (!fs::exists(directory))
return;

for (auto&& e : fs::recursive_directory_iterator(directory)) {
const auto p = e.path();
const auto name = p.filename().native();

if (!PathMatchSpecW(name.c_str(), native.c_str())) {
cx.trace(context::fs, "{} did not match {}; skipping", name, glob);

continue;
}

delete_file(cx, p, f);
}
}

void remove_readonly(const context& cx, const fs::path& dir, flags f)
{
cx.trace(context::fs, "removing read-only from {}", dir);
Expand Down
5 changes: 5 additions & 0 deletions src/core/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace mob::op {
//
void delete_file_glob(const context& cx, const fs::path& glob, flags f = noflags);

// deletes all files matching the glob in the given directory and its subdirectories
//
void delete_file_glob_recurse(const context& cx, const fs::path& directory,
const fs::path& glob, flags f = noflags);

// removes the readonly flag for all files in `dir`, recursive
//
void remove_readonly(const context& cx, const fs::path& dir, flags f = noflags);
Expand Down
22 changes: 1 addition & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,13 @@ namespace mob {
.add_task<mo>("modorganizer-nxmhandler")
.add_task<mo>("modorganizer-helper")
.add_task<mo>("githubpp")
.add_task<mo>("modorganizer-game_gamebryo")
.add_task<mo>({"modorganizer-bsapacker", "bsa_packer"})
.add_task<mo>("modorganizer-preview_bsa");

// the gamebryo flag must be set for all game plugins that inherit from
// the gamebryo classes; this will merge the .ts file from gamebryo with
// the one from the specific plugin
add_task<parallel_tasks>()
.add_task<mo>("modorganizer-game_oblivion", mo::gamebryo)
.add_task<mo>("modorganizer-game_nehrim", mo::gamebryo)
.add_task<mo>("modorganizer-game_fallout3", mo::gamebryo)
.add_task<mo>("modorganizer-game_fallout4", mo::gamebryo)
.add_task<mo>("modorganizer-game_fallout4vr", mo::gamebryo)
.add_task<mo>("modorganizer-game_fallout76", mo::gamebryo)
.add_task<mo>("modorganizer-game_falloutnv", mo::gamebryo)
.add_task<mo>("modorganizer-game_morrowind", mo::gamebryo)
.add_task<mo>("modorganizer-game_skyrim", mo::gamebryo)
.add_task<mo>("modorganizer-game_skyrimse", mo::gamebryo)
.add_task<mo>("modorganizer-game_skyrimvr", mo::gamebryo)
.add_task<mo>("modorganizer-game_starfield", mo::gamebryo)
.add_task<mo>("modorganizer-game_ttw", mo::gamebryo)
.add_task<mo>("modorganizer-game_enderal", mo::gamebryo)
.add_task<mo>("modorganizer-game_enderalse", mo::gamebryo);
add_task<parallel_tasks>().add_task<mo>("modorganizer-game_bethesda");

add_task<parallel_tasks>()
.add_task<mo>({"modorganizer-tool_inieditor", "inieditor"})
.add_task<mo>({"modorganizer-tool_inibakery", "inibakery"})
.add_task<mo>("modorganizer-preview_base")
.add_task<mo>("modorganizer-diagnose_basic")
.add_task<mo>("modorganizer-check_fnis")
Expand Down
5 changes: 0 additions & 5 deletions src/tasks/modorganizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ namespace mob::tasks {
}
}

bool modorganizer::is_gamebryo_plugin() const
{
return is_set(flags_, gamebryo);
}

bool modorganizer::is_nuget_plugin() const
{
return is_set(flags_, nuget);
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sevenz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace mob::tasks {

void sevenz::build()
{
build_loop(cx(), [&](bool mp) {
build_loop(cx(), [&]([[maybe_unused]] bool mp) {
const int exit_code = run_tool(nmake()
.path(module_to_build())
.def("CPU=x64")
Expand Down
17 changes: 2 additions & 15 deletions src/tasks/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,9 @@ namespace mob::tasks {
enum flags {
noflags = 0x00,

// gamebryo project, used by the translations task because these
// projects have multiple .ts files that have to be merged
gamebryo = 0x01,

// project that uses nuget, cmake doesn't support those right now, so
// `msbuild -t:restore` has to be run manually
nuget = 0x02,
nuget = 0x01,
};

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

// whether this project has the gamebryo flag on
//
bool is_gamebryo_plugin() const;

// whether this project has the nuget flag on
//
bool is_nuget_plugin() const;
Expand Down Expand Up @@ -623,11 +615,6 @@ namespace mob::tasks {
// duplicate warnings
std::set<fs::path> warned_;

// whether the given project name is a gamebryo task, `dir` is just for
// logging
//
bool is_gamebryo_plugin(const std::string& dir, const std::string& project);

// parses the directory name, walks all the .ts files, returns a project
// object for them
//
Expand All @@ -636,7 +623,7 @@ namespace mob::tasks {
// returns a lang object that contains at least the given main_ts_file,
// but might contain more if it's a gamebryo plugin
//
lang create_lang(bool gamebryo, const std::string& project_name,
lang create_lang(const std::string& project_name,
const fs::path& main_ts_file);
};

Expand Down
Loading

0 comments on commit 3db6c32

Please sign in to comment.