1
0
mirror of synced 2024-11-24 15:50:16 +01:00

build: Remove all static variables from headers to hopefully fix plugins

This commit is contained in:
WerWolv 2023-07-26 13:50:51 +02:00
parent 866c87b2bf
commit 27c8e19c14
31 changed files with 236 additions and 225 deletions

View File

@ -82,7 +82,8 @@ namespace hex {
*/
template<typename E>
static EventList::iterator subscribe(typename E::Callback function) {
return s_events.insert(s_events.end(), std::make_pair(E::Id, std::make_unique<E>(function)));
auto &events = getEvents();
return events.insert(events.end(), std::make_pair(E::Id, std::make_unique<E>(function)));
}
/**
@ -93,7 +94,7 @@ namespace hex {
*/
template<typename E>
static void subscribe(void *token, typename E::Callback function) {
s_tokenStore.insert(std::make_pair(token, subscribe<E>(function)));
getTokenStore().insert(std::make_pair(token, subscribe<E>(function)));
}
/**
@ -101,7 +102,7 @@ namespace hex {
* @param token Token returned by subscribe
*/
static void unsubscribe(const EventList::iterator &token) noexcept {
s_events.erase(token);
getEvents().erase(token);
}
/**
@ -111,13 +112,14 @@ namespace hex {
*/
template<typename E>
static void unsubscribe(void *token) noexcept {
auto iter = std::find_if(s_tokenStore.begin(), s_tokenStore.end(), [&](auto &item) {
auto &tokenStore = getTokenStore();
auto iter = std::find_if(tokenStore.begin(), tokenStore.end(), [&](auto &item) {
return item.first == token && item.second->first == E::Id;
});
if (iter != s_tokenStore.end()) {
s_events.remove(*iter->second);
s_tokenStore.erase(iter);
if (iter != tokenStore.end()) {
getEvents().remove(*iter->second);
tokenStore.erase(iter);
}
}
@ -129,7 +131,7 @@ namespace hex {
*/
template<typename E>
static void post(auto &&...args) noexcept {
for (const auto &[id, event] : s_events) {
for (const auto &[id, event] : getEvents()) {
if (id == E::Id) {
(*static_cast<E *const>(event.get()))(std::forward<decltype(args)>(args)...);
}
@ -145,13 +147,13 @@ namespace hex {
* @brief Unsubscribe all subscribers from all events
*/
static void clear() noexcept {
s_events.clear();
s_tokenStore.clear();
getEvents().clear();
getTokenStore().clear();
}
private:
static std::map<void *, EventList::iterator> s_tokenStore;
static EventList s_events;
static std::map<void *, EventList::iterator>& getTokenStore();
static EventList& getEvents();
};
/* Default Events */

View File

@ -413,9 +413,6 @@ namespace hex {
* @brief Clear all shortcuts
*/
static void clearShortcuts();
private:
static std::map<Shortcut, std::function<void()>> s_globalShortcuts;
};
}

View File

@ -30,10 +30,6 @@ namespace hex {
private:
LayoutManager() = default;
static std::optional<std::fs::path> s_layoutPathToLoad;
static std::optional<std::string> s_layoutStringToLoad;
static std::vector<Layout> s_layouts;
};
}

View File

@ -43,10 +43,6 @@ namespace hex {
private:
std::string m_unlocalizedString;
static std::string s_fallbackLanguage;
static std::string s_selectedLanguage;
static std::map<std::string, std::string> s_currStrings;
};
std::string operator+(const std::string &&left, const LangEntry &&right);

View File

@ -90,13 +90,7 @@ namespace hex {
static void unload();
static void reload();
static const auto &getPlugins() {
return PluginManager::s_plugins;
}
private:
static std::fs::path s_pluginFolder;
static std::vector<Plugin> s_plugins;
static const std::vector<Plugin> &getPlugins();
};
}

View File

@ -116,27 +116,16 @@ namespace hex {
* @brief Get the list of registered handlers
* @return List of registered handlers
*/
static std::vector<Handler>& getHandlers() {
return s_handlers;
}
static std::vector<Handler>& getHandlers();
/**
* @brief Get the list of registered per-provider handlers
* @return List of registered per-provider handlers
*/
static std::vector<ProviderHandler>& getProviderHandlers() {
return s_providerHandlers;
}
static std::vector<ProviderHandler>& getProviderHandlers();
private:
ProjectFile() = default;
static std::function<bool(const std::fs::path&)> s_loadProjectFunction;
static std::function<bool(std::optional<std::fs::path>, bool)> s_storeProjectFunction;
static std::fs::path s_currProjectPath;
static std::vector<Handler> s_handlers;
static std::vector<ProviderHandler> s_providerHandlers;
};
}

View File

@ -167,17 +167,6 @@ namespace hex {
static void runDeferredCalls();
private:
static std::mutex s_deferredCallsMutex, s_tasksFinishedMutex;
static std::list<std::shared_ptr<Task>> s_tasks;
static std::list<std::shared_ptr<Task>> s_taskQueue;
static std::list<std::function<void()>> s_deferredCalls;
static std::list<std::function<void()>> s_tasksFinishedCallbacks;
static std::mutex s_queueMutex;
static std::condition_variable s_jobCondVar;
static std::vector<std::jthread> s_workers;
static void runner(const std::stop_token &stopToken);
};

View File

@ -78,18 +78,11 @@ namespace hex {
StyleMap styleMap;
};
static std::map<std::string, ThemeHandler>& getThemeHandlers() { return s_themeHandlers; }
static std::map<std::string, StyleHandler>& getStyleHandlers() { return s_styleHandlers; }
static std::map<std::string, ThemeHandler>& getThemeHandlers();
static std::map<std::string, StyleHandler>& getStyleHandlers();
private:
ThemeManager() = default;
static std::map<std::string, nlohmann::json> s_themes;
static std::map<std::string, ThemeHandler> s_themeHandlers;
static std::map<std::string, StyleHandler> s_styleHandlers;
static std::string s_imageTheme;
static std::string s_currTheme;
};
}

View File

@ -51,10 +51,7 @@ namespace hex::dp {
[[nodiscard]] std::vector<u8>& getDefaultData() { return this->m_defaultData; }
static void setIdCounter(int id) {
if (id > Attribute::s_idCounter)
Attribute::s_idCounter = id;
}
static void setIdCounter(int id);
private:
int m_id;
@ -69,8 +66,6 @@ namespace hex::dp {
friend class Node;
void setParentNode(Node *node) { this->m_parentNode = node; }
static int s_idCounter;
};
}

View File

@ -14,16 +14,11 @@ namespace hex::dp {
[[nodiscard]] int getFromId() const { return this->m_from; }
[[nodiscard]] int getToId() const { return this->m_to; }
static void setIdCounter(int id) {
if (id > Link::s_idCounter)
Link::s_idCounter = id;
}
static void setIdCounter(int id);
private:
int m_id;
int m_from, m_to;
static int s_idCounter;
};
}

View File

@ -69,10 +69,7 @@ namespace hex::dp {
return this->m_position;
}
static void setIdCounter(int id) {
if (id > Node::s_idCounter)
Node::s_idCounter = id;
}
static void setIdCounter(int id);
const std::vector<u8>& getBufferOnInput(u32 index);
const i128& getIntegerOnInput(u32 index);
@ -90,8 +87,6 @@ namespace hex::dp {
prv::Overlay *m_overlay = nullptr;
ImVec2 m_position;
static int s_idCounter;
Attribute& getAttribute(u32 index) {
if (index >= this->getAttributes().size())
throw std::runtime_error("Attribute index out of bounds!");

View File

@ -93,13 +93,7 @@ namespace hex {
return *this;
}
static void setCACert(std::string data) {
HttpRequest::s_caCertData = std::move(data);
}
static void setProxy(std::string proxy) {
HttpRequest::s_proxyUrl = std::move(proxy);
}
static void setProxy(std::string proxy);
void setMethod(std::string method) {
this->m_method = std::move(method);
@ -286,9 +280,7 @@ namespace hex {
char *url = nullptr;
curl_easy_getinfo(this->m_curl, CURLINFO_EFFECTIVE_URL, &url);
log::error("Http request '{0} {1}' failed with error {2}: '{3}'", this->m_method, url, u32(result), curl_easy_strerror(result));
if (!HttpRequest::s_proxyUrl.empty()){
log::info("A custom proxy '{0}' is in use. Is it working correctly?", HttpRequest::s_proxyUrl);
}
checkProxyErrors();
return { };
}
@ -300,11 +292,13 @@ namespace hex {
return Result<T>(statusCode, { data.begin(), data.end() });
}
[[maybe_unused]] static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userData);
static size_t writeToVector(void *contents, size_t size, size_t nmemb, void *userdata);
static size_t writeToFile(void *contents, size_t size, size_t nmemb, void *userdata);
static int progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow);
private:
static void checkProxyErrors();
private:
CURL *m_curl;
@ -320,7 +314,6 @@ namespace hex {
std::atomic<bool> m_canceled = false;
[[maybe_unused]] std::unique_ptr<mbedtls_x509_crt> m_caCert;
static std::string s_caCertData, s_proxyUrl;
};
}

View File

@ -206,9 +206,6 @@ namespace hex::prv {
std::string m_errorMessage;
size_t m_pageSize = MaxPageSize;
private:
static u32 s_idCounter;
};
}

View File

@ -34,9 +34,7 @@ namespace hex {
return { 0, 0 };
}
[[nodiscard]] static std::vector<std::unique_ptr<PopupBase>> &getOpenPopups() {
return s_openPopups;
}
[[nodiscard]] static std::vector<std::unique_ptr<PopupBase>> &getOpenPopups();
[[nodiscard]] const std::string &getUnlocalizedName() const {
return this->m_unlocalizedName;
@ -58,9 +56,6 @@ namespace hex {
return this->m_close;
}
protected:
static std::vector<std::unique_ptr<PopupBase>> s_openPopups;
private:
std::string m_unlocalizedName;
@ -84,7 +79,7 @@ namespace hex {
auto popup = std::make_unique<T>(std::forward<Args>(args)...);
s_openPopups.emplace_back(std::move(popup));
getOpenPopups().emplace_back(std::move(popup));
}
};

View File

@ -51,20 +51,17 @@ namespace hex {
return LangEntry(unlocalizedName) + "###" + unlocalizedName;
}
static ImFontAtlas *getFontAtlas() { return View::s_fontAtlas; }
static void setFontAtlas(ImFontAtlas *atlas) { View::s_fontAtlas = atlas; }
static ImFontAtlas *getFontAtlas();
static void setFontAtlas(ImFontAtlas *atlas);
static ImFontConfig getFontConfig() { return View::s_fontConfig; }
static void setFontConfig(ImFontConfig config) { View::s_fontConfig = config; }
static ImFontConfig getFontConfig();
static void setFontConfig(ImFontConfig config);
private:
std::string m_unlocalizedViewName;
bool m_windowOpen = false;
std::map<Shortcut, std::function<void()>> m_shortcuts;
static ImFontAtlas *s_fontAtlas;
static ImFontConfig s_fontConfig;
friend class ShortcutManager;
};

View File

@ -2,7 +2,17 @@
namespace hex {
EventManager::EventList EventManager::s_events;
std::map<void *, EventManager::EventList::iterator> EventManager::s_tokenStore;
std::map<void *, EventManager::EventList::iterator>& EventManager::getTokenStore() {
static std::map<void *, EventManager::EventList::iterator> tokenStore;
return tokenStore;
}
EventManager::EventList& EventManager::getEvents() {
static EventManager::EventList events;
return events;
}
}

View File

@ -5,10 +5,15 @@
namespace hex {
std::map<Shortcut, std::function<void()>> ShortcutManager::s_globalShortcuts;
namespace {
std::map<Shortcut, std::function<void()>> s_globalShortcuts;
}
void ShortcutManager::addGlobalShortcut(const Shortcut &shortcut, const std::function<void()> &callback) {
ShortcutManager::s_globalShortcuts.insert({ shortcut, callback });
s_globalShortcuts.insert({ shortcut, callback });
}
void ShortcutManager::addShortcut(View *view, const Shortcut &shortcut, const std::function<void()> &callback) {
@ -48,16 +53,16 @@ namespace hex {
void ShortcutManager::processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, false, keyCode);
if (ShortcutManager::s_globalShortcuts.contains(pressedShortcut + AllowWhileTyping)) {
ShortcutManager::s_globalShortcuts[pressedShortcut + AllowWhileTyping]();
} else if (ShortcutManager::s_globalShortcuts.contains(pressedShortcut)) {
if (s_globalShortcuts.contains(pressedShortcut + AllowWhileTyping)) {
s_globalShortcuts[pressedShortcut + AllowWhileTyping]();
} else if (s_globalShortcuts.contains(pressedShortcut)) {
if (!ImGui::GetIO().WantTextInput)
ShortcutManager::s_globalShortcuts[pressedShortcut]();
s_globalShortcuts[pressedShortcut]();
}
}
void ShortcutManager::clearShortcuts() {
ShortcutManager::s_globalShortcuts.clear();
s_globalShortcuts.clear();
}
}

View File

@ -9,9 +9,14 @@
namespace hex {
std::optional<std::fs::path> LayoutManager::s_layoutPathToLoad;
std::optional<std::string> LayoutManager::s_layoutStringToLoad;
std::vector<LayoutManager::Layout> LayoutManager::s_layouts;
namespace {
std::optional<std::fs::path> s_layoutPathToLoad;
std::optional<std::string> s_layoutStringToLoad;
std::vector<LayoutManager::Layout> s_layouts;
}
void LayoutManager::load(const std::fs::path &path) {
s_layoutPathToLoad = path;

View File

@ -4,9 +4,14 @@
namespace hex {
std::string LangEntry::s_fallbackLanguage;
std::string LangEntry::s_selectedLanguage;
std::map<std::string, std::string> LangEntry::s_currStrings;
namespace {
std::string s_fallbackLanguage;
std::string s_selectedLanguage;
std::map<std::string, std::string> s_currStrings;
}
LanguageDefinition::LanguageDefinition(std::map<std::string, std::string> &&entries) {
for (const auto &[key, value] : entries) {
@ -67,7 +72,7 @@ namespace hex {
}
const std::string &LangEntry::get() const {
auto &lang = LangEntry::s_currStrings;
auto &lang = s_currStrings;
if (lang.contains(this->m_unlocalizedString))
return lang[this->m_unlocalizedString];
else
@ -75,7 +80,7 @@ namespace hex {
}
void LangEntry::loadLanguage(const std::string &language) {
LangEntry::s_currStrings.clear();
s_currStrings.clear();
auto &definitions = ContentRegistry::Language::impl::getLanguageDefinitions();
@ -83,15 +88,15 @@ namespace hex {
return;
for (auto &definition : definitions[language])
LangEntry::s_currStrings.insert(definition.getEntries().begin(), definition.getEntries().end());
s_currStrings.insert(definition.getEntries().begin(), definition.getEntries().end());
const auto fallbackLanguage = LangEntry::getFallbackLanguage();
if (language != fallbackLanguage) {
for (auto &definition : definitions[fallbackLanguage])
LangEntry::s_currStrings.insert(definition.getEntries().begin(), definition.getEntries().end());
s_currStrings.insert(definition.getEntries().begin(), definition.getEntries().end());
}
LangEntry::s_selectedLanguage = language;
s_selectedLanguage = language;
}
const std::map<std::string, std::string> &LangEntry::getSupportedLanguages() {
@ -99,20 +104,20 @@ namespace hex {
}
void LangEntry::setFallbackLanguage(const std::string &language) {
LangEntry::s_fallbackLanguage = language;
s_fallbackLanguage = language;
}
const std::string &LangEntry::getFallbackLanguage() {
return LangEntry::s_fallbackLanguage;
return s_fallbackLanguage;
}
void LangEntry::resetLanguageStrings() {
LangEntry::s_currStrings.clear();
LangEntry::s_selectedLanguage.clear();
s_currStrings.clear();
s_selectedLanguage.clear();
}
const std::string &LangEntry::getSelectedLanguage() {
return LangEntry::s_selectedLanguage;
return s_selectedLanguage;
}
}

View File

@ -170,34 +170,42 @@ namespace hex {
}
std::fs::path PluginManager::s_pluginFolder;
std::vector<Plugin> PluginManager::s_plugins;
namespace {
std::fs::path s_pluginFolder;
std::vector<Plugin> s_plugins;
}
bool PluginManager::load(const std::fs::path &pluginFolder) {
if (!wolv::io::fs::exists(pluginFolder))
return false;
PluginManager::s_pluginFolder = pluginFolder;
s_pluginFolder = pluginFolder;
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug")
PluginManager::s_plugins.emplace_back(pluginPath.path());
s_plugins.emplace_back(pluginPath.path());
}
if (PluginManager::s_plugins.empty())
if (s_plugins.empty())
return false;
return true;
}
void PluginManager::unload() {
PluginManager::s_plugins.clear();
PluginManager::s_pluginFolder.clear();
s_plugins.clear();
s_pluginFolder.clear();
}
void PluginManager::reload() {
PluginManager::unload();
PluginManager::load(PluginManager::s_pluginFolder);
PluginManager::load(s_pluginFolder);
}
const std::vector<Plugin> &PluginManager::getPlugins() {
return s_plugins;
}
}

View File

@ -11,20 +11,25 @@
namespace hex {
std::vector<ProjectFile::Handler> ProjectFile::s_handlers;
std::vector<ProjectFile::ProviderHandler> ProjectFile::s_providerHandlers;
namespace {
std::fs::path ProjectFile::s_currProjectPath;
std::vector<ProjectFile::Handler> s_handlers;
std::vector<ProjectFile::ProviderHandler> s_providerHandlers;
std::fs::path s_currProjectPath;
std::function<bool(const std::fs::path&)> s_loadProjectFunction;
std::function<bool(std::optional<std::fs::path>, bool)> s_storeProjectFunction;
}
std::function<bool(const std::fs::path&)> ProjectFile::s_loadProjectFunction;
std::function<bool(std::optional<std::fs::path>, bool)> ProjectFile::s_storeProjectFunction;
void ProjectFile::setProjectFunctions(
const std::function<bool(const std::fs::path&)> &loadFun,
const std::function<bool(std::optional<std::fs::path>, bool)> &storeFun
) {
ProjectFile::s_loadProjectFunction = loadFun;
ProjectFile::s_storeProjectFunction = storeFun;
s_loadProjectFunction = loadFun;
s_storeProjectFunction = storeFun;
}
bool ProjectFile::load(const std::fs::path &filePath) {
@ -36,19 +41,27 @@ namespace hex {
}
bool ProjectFile::hasPath() {
return !ProjectFile::s_currProjectPath.empty();
return !s_currProjectPath.empty();
}
void ProjectFile::clearPath() {
ProjectFile::s_currProjectPath.clear();
s_currProjectPath.clear();
}
std::fs::path ProjectFile::getPath() {
return ProjectFile::s_currProjectPath;
return s_currProjectPath;
}
void ProjectFile::setPath(const std::fs::path &path) {
ProjectFile::s_currProjectPath = path;
s_currProjectPath = path;
}
std::vector<ProjectFile::Handler> &ProjectFile::getHandlers() {
return s_handlers;
}
std::vector<ProjectFile::ProviderHandler> &ProjectFile::getProviderHandlers() {
return s_providerHandlers;
}
}

View File

@ -14,15 +14,20 @@
namespace hex {
std::mutex TaskManager::s_deferredCallsMutex, TaskManager::s_tasksFinishedMutex;
namespace {
std::list<std::shared_ptr<Task>> TaskManager::s_tasks, TaskManager::s_taskQueue;
std::list<std::function<void()>> TaskManager::s_deferredCalls;
std::list<std::function<void()>> TaskManager::s_tasksFinishedCallbacks;
std::mutex s_deferredCallsMutex, s_tasksFinishedMutex;
std::list<std::shared_ptr<Task>> s_tasks, s_taskQueue;
std::list<std::function<void()>> s_deferredCalls;
std::list<std::function<void()>> s_tasksFinishedCallbacks;
std::mutex s_queueMutex;
std::condition_variable s_jobCondVar;
std::vector<std::jthread> s_workers;
}
std::mutex TaskManager::s_queueMutex;
std::condition_variable TaskManager::s_jobCondVar;
std::vector<std::jthread> TaskManager::s_workers;
static void setThreadName(const std::string &name) {
#if defined(OS_WINDOWS)
@ -210,19 +215,19 @@ namespace hex {
log::debug("Initializing task manager thread pool with {} workers.", threadCount);
for (u32 i = 0; i < threadCount; i++)
TaskManager::s_workers.emplace_back(TaskManager::runner);
s_workers.emplace_back(TaskManager::runner);
}
void TaskManager::exit() {
for (auto &task : TaskManager::s_tasks)
for (auto &task : s_tasks)
task->interrupt();
for (auto &thread : TaskManager::s_workers)
for (auto &thread : s_workers)
thread.request_stop();
s_jobCondVar.notify_all();
TaskManager::s_workers.clear();
s_workers.clear();
}
void TaskManager::runner(const std::stop_token &stopToken) {

View File

@ -9,11 +9,16 @@
namespace hex {
std::map<std::string, nlohmann::json> ThemeManager::s_themes;
std::map<std::string, ThemeManager::ThemeHandler> ThemeManager::s_themeHandlers;
std::map<std::string, ThemeManager::StyleHandler> ThemeManager::s_styleHandlers;
std::string ThemeManager::s_imageTheme;
std::string ThemeManager::s_currTheme;
namespace {
std::map<std::string, nlohmann::json> s_themes;
std::map<std::string, ThemeManager::ThemeHandler> s_themeHandlers;
std::map<std::string, ThemeManager::StyleHandler> s_styleHandlers;
std::string s_imageTheme;
std::string s_currTheme;
}
void ThemeManager::addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function<ImColor(u32)> &getFunction, const std::function<void(u32, ImColor)> &setFunction) {
s_themeHandlers[name] = { colorMap, getFunction, setFunction };
@ -201,11 +206,20 @@ namespace hex {
}
void ThemeManager::reset() {
ThemeManager::s_themes.clear();
ThemeManager::s_styleHandlers.clear();
ThemeManager::s_themeHandlers.clear();
ThemeManager::s_imageTheme.clear();
ThemeManager::s_currTheme.clear();
s_themes.clear();
s_styleHandlers.clear();
s_themeHandlers.clear();
s_imageTheme.clear();
s_currTheme.clear();
}
std::map<std::string, ThemeManager::ThemeHandler> &ThemeManager::getThemeHandlers() {
return s_themeHandlers;
}
std::map<std::string, ThemeManager::StyleHandler> &ThemeManager::getStyleHandlers() {
return s_styleHandlers;
}
}

View File

@ -3,9 +3,14 @@
namespace hex::dp {
int Attribute::s_idCounter = 1;
namespace {
Attribute::Attribute(IOType ioType, Type type, std::string unlocalizedName) : m_id(Attribute::s_idCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(std::move(unlocalizedName)) {
int s_idCounter = 1;
}
Attribute::Attribute(IOType ioType, Type type, std::string unlocalizedName) : m_id(s_idCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(std::move(unlocalizedName)) {
}
Attribute::~Attribute() {
@ -13,4 +18,9 @@ namespace hex::dp {
attr->removeConnectedAttribute(linkId);
}
void Attribute::setIdCounter(int id) {
if (id > s_idCounter)
s_idCounter = id;
}
}

View File

@ -3,9 +3,16 @@
namespace hex::dp {
int Link::s_idCounter = 1;
namespace {
Link::Link(int from, int to) : m_id(Link::s_idCounter++), m_from(from), m_to(to) { }
int s_idCounter = 1;
}
Link::Link(int from, int to) : m_id(s_idCounter++), m_from(from), m_to(to) { }
void Link::setIdCounter(int id) {
if (id > s_idCounter)
s_idCounter = id;
}
}

View File

@ -7,9 +7,13 @@
namespace hex::dp {
int Node::s_idCounter = 1;
namespace {
Node::Node(std::string unlocalizedTitle, std::vector<Attribute> attributes) : m_id(Node::s_idCounter++), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_attributes(std::move(attributes)) {
int s_idCounter = 1;
}
Node::Node(std::string unlocalizedTitle, std::vector<Attribute> attributes) : m_id(s_idCounter++), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_attributes(std::move(attributes)) {
for (auto &attr : this->m_attributes)
attr.setParentNode(this);
}
@ -136,4 +140,9 @@ namespace hex::dp {
this->m_overlay->getData() = data;
}
void Node::setIdCounter(int id) {
if (id > s_idCounter)
s_idCounter = id;
}
}

View File

@ -2,8 +2,12 @@
namespace hex {
std::string HttpRequest::s_caCertData;
std::string HttpRequest::s_proxyUrl;
namespace {
std::string s_proxyUrl;
}
HttpRequest::HttpRequest(std::string method, std::string url) : m_method(std::move(method)), m_url(std::move(url)) {
AT_FIRST_TIME {
@ -38,21 +42,6 @@ namespace hex {
curl_easy_setopt(this->m_curl, CURLOPT_PROXY, s_proxyUrl.c_str());
}
CURLcode HttpRequest::sslCtxFunction(CURL *ctx, void *sslctx, void *userData) {
hex::unused(ctx, userData);
auto *cfg = static_cast<mbedtls_ssl_config *>(sslctx);
auto crt = static_cast<mbedtls_x509_crt*>(userData);
mbedtls_x509_crt_init(crt);
mbedtls_x509_crt_parse(crt, reinterpret_cast<const u8 *>(HttpRequest::s_caCertData.data()), HttpRequest::s_caCertData.size());
mbedtls_ssl_conf_ca_chain(cfg, crt, nullptr);
return CURLE_OK;
}
size_t HttpRequest::writeToVector(void *contents, size_t size, size_t nmemb, void *userdata) {
auto &response = *reinterpret_cast<std::vector<u8>*>(userdata);
auto startSize = response.size();
@ -84,4 +73,14 @@ namespace hex {
return request.m_canceled ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
}
void HttpRequest::setProxy(std::string proxy) {
s_proxyUrl = std::move(proxy);
}
void HttpRequest::checkProxyErrors() {
if (!s_proxyUrl.empty()){
log::info("A custom proxy '{0}' is in use. Is it working correctly?", s_proxyUrl);
}
}
}

View File

@ -13,7 +13,12 @@
namespace hex::prv {
u32 Provider::s_idCounter = 0;
namespace {
u32 s_idCounter = 0;
}
Provider::Provider() : m_id(s_idCounter++) {
this->m_patches.emplace_back();

View File

@ -2,6 +2,12 @@
namespace hex::impl {
std::vector<std::unique_ptr<PopupBase>> PopupBase::s_openPopups;
[[nodiscard]] std::vector<std::unique_ptr<PopupBase>> &PopupBase::getOpenPopups() {
static std::vector<std::unique_ptr<PopupBase>> openPopups;
return openPopups;
}
}

View File

@ -8,8 +8,12 @@
namespace hex {
ImFontAtlas *View::s_fontAtlas;
ImFontConfig View::s_fontConfig;
namespace {
ImFontAtlas *s_fontAtlas;
ImFontConfig s_fontConfig;
}
View::View(std::string unlocalizedName) : m_unlocalizedViewName(std::move(unlocalizedName)) { }
@ -62,4 +66,10 @@ namespace hex {
rightButtonFn();
}
ImFontAtlas *View::getFontAtlas() { return s_fontAtlas; }
void View::setFontAtlas(ImFontAtlas *atlas) { s_fontAtlas = atlas; }
ImFontConfig View::getFontConfig() { return s_fontConfig; }
void View::setFontConfig(ImFontConfig config) { s_fontConfig = config; }
}

View File

@ -108,29 +108,6 @@ namespace hex::init {
bool setupEnvironment() {
hex::log::debug("Using romfs: '{}'", romfs::name());
// Load the SSL certificate
constexpr static auto CaCertFileName = "cacert.pem";
// Look for a custom certificate in the config folder
std::fs::path caCertPath;
for (const auto &folder : fs::getDefaultPaths(fs::ImHexPath::Config)) {
for (const auto &file : std::fs::directory_iterator(folder)) {
if (file.path().filename() == CaCertFileName) {
caCertPath = file.path();
break;
}
}
}
// If a custom certificate was found, use it, otherwise use the one from the romfs
std::string caCertData;
if (!caCertPath.empty())
caCertData = wolv::io::File(caCertPath, wolv::io::File::Mode::Read).readString();
else
caCertData = std::string(romfs::get(CaCertFileName).string());
HttpRequest::setCACert(caCertData);
return true;
}