Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Extensions #127

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added icons/translations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions mob.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ install_message = never
host =

[aliases]
super = cmake_common modorganizer* githubpp
super = cmake_common modorganizer*
plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_*

[translations]
mo2-translations = organizer uibase plugin_python
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 @@ -139,6 +143,7 @@ python = release
third_party =
prefix =
cache =
icons =
patches =
licenses =
build =
Expand All @@ -150,11 +155,12 @@ install_pdbs =
install_dlls =
install_loot =
install_plugins =
install_extensions =
install_stylesheets =
install_licenses =
install_pythoncore =
install_translations =
vs =
vcpkg =
qt_install =
qt_bin =
qt_translations =
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
70 changes: 0 additions & 70 deletions src/cmd/cmake.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions src/cmd/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,27 +367,6 @@ namespace mob {
std::vector<fs::path> get_repos() const;
};

// runs cmake in a directory with the same parameters as `build` would
//
class cmake_command : public command {
public:
cmake_command();
meta_t meta() const override;

protected:
clipp::group do_group() override;
int do_run() override;
std::string do_doc() override;

private:
std::string gen_;
std::string cmd_;
bool x64_ = true;
bool debug_ = false;
std::string prefix_;
std::string path_;
};

// lists the inis found by mob
//
class inis_command : public command {
Expand Down
45 changes: 30 additions & 15 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 @@ -509,8 +515,10 @@ namespace mob {
set_path_if_empty("pf_x86", find_program_files_x86);
set_path_if_empty("pf_x64", find_program_files_x64);
set_path_if_empty("vs", find_vs);
set_path_if_empty("vcpkg", find_vcpkg); // set after vs as it will use the VS
set_path_if_empty("qt_install", find_qt);
set_path_if_empty("temp_dir", find_temp_dir);
set_path_if_empty("icons", find_in_root("icons"));
set_path_if_empty("patches", find_in_root("patches"));
set_path_if_empty("licenses", find_in_root("licenses"));
set_path_if_empty("qt_bin", qt::installation_path() / "bin");
Expand All @@ -530,15 +538,15 @@ namespace mob {
resolve_path("install", p.prefix(), "install");
resolve_path("install_installer", p.install(), "installer");
resolve_path("install_bin", p.install(), "bin");
resolve_path("install_libs", p.install(), "libs");
resolve_path("install_libs", p.install(), "lib");
resolve_path("install_pdbs", p.install(), "pdb");
resolve_path("install_dlls", p.install_bin(), "dlls");
resolve_path("install_loot", p.install_bin(), "loot");
resolve_path("install_plugins", p.install_bin(), "plugins");
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 +692,11 @@ namespace mob {
return {};
}

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

conf_prebuilt conf::prebuilt()
{
return {};
Expand Down Expand Up @@ -777,6 +790,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
44 changes: 32 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 All @@ -245,6 +263,7 @@ namespace mob {
VALUE(third_party);
VALUE(prefix);
VALUE(cache);
VALUE(icons);
VALUE(patches);
VALUE(licenses);
VALUE(build);
Expand All @@ -257,13 +276,13 @@ 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(vcpkg);
VALUE(qt_install);
VALUE(qt_bin);
VALUE(qt_translations);
Expand All @@ -285,6 +304,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
Loading
Loading