#include "pch.h" #include "conf.h" #include "utility.h" #include "context.h" namespace mob { fs::path find_root_impl() { gcx().trace(context::generic, "looking for root directory"); fs::path p = fs::absolute("third-party"); gcx().trace(context::generic, "checking " + p.string()); if (fs::exists(p)) return p; p = fs::absolute("../third-party"); gcx().trace(context::generic, "checking " + p.string()); if (fs::exists(p)) return p; p = fs::absolute("../../third-party"); gcx().trace(context::generic, "checking " + p.string()); if (fs::exists(p)) return p; p = fs::absolute("../../../third-party"); gcx().trace(context::generic, "checking " + p.string()); if (fs::exists(p)) return p; gcx().bail_out(context::generic, "root directory not found"); } fs::path find_root() { const auto p = find_root_impl().parent_path(); gcx().trace(context::generic, "found root directory at " + p.string()); return p; } fs::path find_in_root(const fs::path& file) { static fs::path root = find_root(); fs::path p = root / file; if (!fs::exists(p)) gcx().bail_out(context::generic, p.string() + " not found"); gcx().trace(context::generic, "found " + p.string()); return p; } fs::path find_third_party_directory() { static fs::path path = find_in_root("third-party"); return path; } static std::map g_conf = { {"qt_install", ""}, {"vs", "16"}, {"vs_year", "2019"}, {"vs_toolset", "14.2"}, {"sdk", "10.0.18362.0"}, {"sevenzip", "19.00"}, {"zlib", "1.2.11"}, {"boost", "1.72.0-b1-rc1"}, {"boost_vs", "14.2"}, {"python", "v3.8.1"}, {"fmt", "6.1.2"}, {"gtest", "master"}, {"libbsarch", "0.0.8"}, {"libloot", "0.15.1"}, {"libloot_hash", "gf725dd7"}, {"openssl", "1.1.1d"}, {"bzip2", "1.0.6"}, {"lz4", "v1.9.2"}, {"nmm", "0.70.11"}, {"spdlog", "v1.4.2"}, {"usvfs", "master"}, {"qt", "5.14.2"}, {"qt_vs", "2017"}, {"pyqt", "5.14.2"}, {"pyqt_builder", "1.3.0"}, {"sip", "5.1.2"}, {"pyqt_sip", "12.7.2"}, {"prefix", R"(C:\dev\projects\mobuild-out)"}, }; const std::string& get_conf(const std::string& name) { auto itor = g_conf.find(name); if (itor == g_conf.end()) gcx().bail_out(context::generic, "conf '" + name + "' doesn't exist"); return itor->second; } bool g_dry = false; int g_log = 5; bool g_redownload = false; bool g_reextract = false; bool g_rebuild = false; bool conf::log_dump() { return g_log > 5; } bool conf::log_trace() { return g_log > 4; } bool conf::log_debug() { return g_log > 3; } bool conf::log_info() { return g_log > 2; } bool conf::log_warning() { return g_log > 1; } bool conf::log_error() { return g_log > 0; } bool conf::dry() { return g_dry; } bool conf::redownload() { return g_redownload; } bool conf::reextract() { return g_reextract; } bool conf::rebuild() { return g_rebuild; } std::string conf::mo_org() { return "ModOrganizer2"; } std::string conf::mo_branch() { return "master"; } void conf::set(int argc, char** argv) { for (int i=1; i& parts) { for (std::size_t i=0; i locations = { program_files_x64(), "C:", "D:" }; // look for qmake, which is in %qt%/version/msvc.../bin fs::path qmake = find_in_path("qmake.exe"); if (!qmake.empty()) locations.insert(locations.begin(), qmake.parent_path() / "../../"); // look for qtcreator.exe, which is in %qt%/Tools/QtCreator/bin fs::path qtcreator = find_in_path("qtcreator.exe"); if (!qtcreator.empty()) locations.insert(locations.begin(), qtcreator.parent_path() / "../../../"); for (fs::path loc : locations) { loc = fs::absolute(loc); if (find_qt(loc)) return loc; } gcx().bail_out(context::generic, "can't find qt install"); }(); return path; } fs::path paths::qt_bin() { static fs::path path = qt() / "bin"; return path; } fs::path get_known_folder(const GUID& id) { wchar_t* buffer = nullptr; const auto r = ::SHGetKnownFolderPath(id, 0, 0, &buffer); if (r != S_OK) return {}; fs::path p = buffer; ::CoTaskMemFree(buffer); return p; } fs::path paths::program_files_x86() { static fs::path path = [] { fs::path p = get_known_folder(FOLDERID_ProgramFilesX86); if (p.empty()) { const auto e = GetLastError(); p = fs::path(R"(C:\Program Files (x86))"); gcx().warning(context::generic, "failed to get x86 program files folder, defaulting to " + p.string(), e); } else { gcx().trace(context::generic, "x86 program files is " + p.string()); } return p; }(); return path; } fs::path paths::program_files_x64() { static fs::path path = [] { fs::path p = get_known_folder(FOLDERID_ProgramFilesX64); if (p.empty()) { const auto e = GetLastError(); p = fs::path(R"(C:\Program Files)"); gcx().warning(context::generic, "failed to get x64 program files folder, defaulting to " + p.string(), e); } else { gcx().trace(context::generic, "x64 program files is " + p.string()); } return p; }(); return path; } fs::path paths::temp_dir() { static fs::path temp_dir = [] { const std::size_t buffer_size = MAX_PATH + 2; wchar_t buffer[buffer_size] = {}; if (GetTempPathW(static_cast(buffer_size), buffer) == 0) { const auto e = GetLastError(); gcx().bail_out(context::generic, "can't get temp path", e); } fs::path p(buffer); gcx().trace(context::generic, "temp dir is " + p.string()); return p; }(); return temp_dir; } fs::path paths::temp_file() { static fs::path dir = temp_dir(); wchar_t name[MAX_PATH + 1] = {}; if (GetTempFileNameW(dir.native().c_str(), L"mob", 0, name) == 0) { const auto e = GetLastError(); gcx().bail_out(context::generic, "can't create temp file in " + dir.string(), e); } return dir / name; } } // namespace