1
0
mirror of synced 2025-01-18 09:04:52 +01:00

sys: Added a bunch of logging

This commit is contained in:
WerWolv 2022-01-13 14:34:27 +01:00
parent 54785b29dd
commit 3f936b57f5
4 changed files with 57 additions and 30 deletions

View File

@ -41,6 +41,8 @@ namespace hex {
}
void ContentRegistry::Settings::add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 defaultValue, const ContentRegistry::Settings::Callback &callback) {
log::info("Registered new integer setting: [{}]: {}", unlocalizedCategory, unlocalizedName);
ContentRegistry::Settings::getEntries()[unlocalizedCategory.c_str()].emplace_back(Entry{ unlocalizedName.c_str(), callback });
auto &json = getSettingsData();
@ -52,6 +54,8 @@ namespace hex {
}
void ContentRegistry::Settings::add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const ContentRegistry::Settings::Callback &callback) {
log::info("Registered new string setting: [{}]: {}", unlocalizedCategory, unlocalizedName);
ContentRegistry::Settings::getEntries()[unlocalizedCategory].emplace_back(Entry{ unlocalizedName, callback });
auto &json = getSettingsData();
@ -157,6 +161,8 @@ namespace hex {
/* Command Palette Commands */
void ContentRegistry::CommandPaletteCommands::add(ContentRegistry::CommandPaletteCommands::Type type, const std::string &command, const std::string &unlocalizedDescription, const std::function<std::string(std::string)> &displayCallback, const std::function<void(std::string)> &executeCallback) {
log::info("Registered new command palette command: {}", command);
getEntries().push_back(ContentRegistry::CommandPaletteCommands::Entry{ type, command, unlocalizedDescription, displayCallback, executeCallback });
}
@ -179,10 +185,14 @@ namespace hex {
}
void ContentRegistry::PatternLanguage::addFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const ContentRegistry::PatternLanguage::Callback &func) {
log::info("Registered new pattern language function: {}", getFunctionName(ns, name));
getFunctions()[getFunctionName(ns, name)] = Function { parameterCount, func, false };
}
void ContentRegistry::PatternLanguage::addDangerousFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const ContentRegistry::PatternLanguage::Callback &func) {
log::info("Registered new dangerous pattern language function: {}", getFunctionName(ns, name));
getFunctions()[getFunctionName(ns, name)] = Function { parameterCount, func, true };
}
@ -194,6 +204,8 @@ namespace hex {
/* Views */
void ContentRegistry::Views::impl::add(View *view) {
log::info("Registered new view: {}", view->getUnlocalizedName());
getEntries().emplace_back(view);
}
@ -205,6 +217,8 @@ namespace hex {
/* Tools */
void ContentRegistry::Tools:: add(const std::string &unlocalizedName, const std::function<void()> &function) {
log::info("Registered new tool: {}", unlocalizedName);
getEntries().emplace_back(impl::Entry{ unlocalizedName, function });
}
@ -216,6 +230,8 @@ namespace hex {
/* Data Inspector */
void ContentRegistry::DataInspector::add(const std::string &unlocalizedName, size_t requiredSize, ContentRegistry::DataInspector::impl::GeneratorFunction function) {
log::info("Registered new data inspector format: {}", unlocalizedName);
getEntries().push_back({ unlocalizedName, requiredSize, std::move(function) });
}
@ -226,6 +242,8 @@ namespace hex {
/* Data Processor Nodes */
void ContentRegistry::DataProcessorNode::impl::add(const impl::Entry &entry) {
log::info("Registered new data processor node type: [{}]: ", entry.category, entry.name);
getEntries().push_back(entry);
}
@ -240,10 +258,14 @@ namespace hex {
/* Languages */
void ContentRegistry::Language::registerLanguage(const std::string &name, const std::string &languageCode) {
log::info("Registered new language: {} ({})", name, languageCode);
getLanguages().insert({ languageCode, name });
}
void ContentRegistry::Language::addLocalizations(const std::string &languageCode, const LanguageDefinition &definition) {
log::info("Registered new localization for language {} with {} entries", languageCode, definition.getEntries().size());
getLanguageDefinitions()[languageCode].push_back(definition);
}
@ -256,6 +278,9 @@ namespace hex {
}
/* Interface */
void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) {
getWelcomeScreenEntries().push_back(function);
}
@ -283,6 +308,8 @@ namespace hex {
/* Providers */
void ContentRegistry::Provider::impl::addProviderName(const std::string &unlocalizedName) {
log::info("Registered new provider: {}", unlocalizedName);
SharedData::providerNames.push_back(unlocalizedName);
}

View File

@ -74,6 +74,7 @@ namespace hex::init {
try {
fs::create_directories(folder);
} catch (...) {
log::error("Failed to create folder {}!", folder.string());
result = false;
}
}
@ -96,6 +97,8 @@ namespace hex::init {
for (const auto &dir : hex::getPath(ImHexPath::Resources)) {
auto path = dir / "font.ttf";
if (fs::exists(path)) {
log::info("Loading custom front from {}", path.string());
fontFile = path;
break;
}
@ -215,6 +218,8 @@ namespace hex::init {
}
if (PluginManager::getPlugins().empty()) {
log::error("No plugins found!");
getInitArguments().push_back({ "no-plugins", { } });
return false;
}
@ -235,7 +240,8 @@ namespace hex::init {
bool loadSettings() {
try {
ContentRegistry::Settings::load();
} catch (...) {
} catch (std::exception &e) {
log::error("Failed to load configuration! {}", e.what());
return false;
}
@ -264,7 +270,8 @@ namespace hex::init {
bool storeSettings() {
try {
ContentRegistry::Settings::store();
} catch (...) {
} catch (std::exception &e) {
log::error("Failed to store configuration! {}", e.what());
return false;
}
return true;

View File

@ -22,6 +22,8 @@ int main(int argc, char **argv, char **envp) {
{
Window::initNative();
hex::log::info("Welcome to ImHex!");
init::WindowSplash splashWindow;
for (const auto &[name, task] : init::getInitTasks())
@ -46,12 +48,10 @@ int main(int argc, char **argv, char **envp) {
else if (argc == 2)
EventManager::post<RequestOpenFile>(argv[1]);
else {
hex::log::fatal("Usage: imhex [file_name]");
hex::log::fatal("Usage: {} [<file_name>]", argv[0]);
return EXIT_FAILURE;
}
hex::log::info("Welcome to ImHex!");
window.loop();
}

View File

@ -762,8 +762,10 @@ namespace hex {
log::error("GLFW Error [{}] : {}", error, desc);
});
if (!glfwInit())
throw std::runtime_error("Failed to initialize GLFW!");
if (!glfwInit()) {
log::fatal("Failed to initialize GLFW!");
std::abort();
}
#if defined(OS_WINDOWS)
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
@ -782,8 +784,10 @@ namespace hex {
glfwSetWindowUserPointer(this->m_window, this);
if (this->m_window == nullptr)
throw std::runtime_error("Failed to create window!");
if (this->m_window == nullptr) {
log::fatal("Failed to create window!");
std::abort();
}
glfwMakeContextCurrent(this->m_window);
glfwSwapInterval(1);
@ -870,33 +874,22 @@ namespace hex {
for (u32 i = 0; i < count; i++) {
auto path = std::filesystem::path(paths[i]);
if (path.extension() == ".hexpat" || path.extension() == ".pat") {
File file(path.string(), File::Mode::Read);
bool handled = false;
for (const auto &[extensions, handler] : ContentRegistry::FileHandler::getEntries()) {
for (const auto &extension : extensions) {
if (path.extension() == extension) {
if (!handler(path))
View::showMessagePopup("hex.message.file_handler_failed"_lang);
if (file.isValid())
EventManager::post<RequestSetPatternLanguageCode>(file.readString());
} else if (path.extension() == ".hexproj") {
ProjectFile::load(path.string());
} else if (path.extension() == ".yar") {
for (auto &destPath : hex::getPath(ImHexPath::Yara)) {
std::error_code error;
if (std::filesystem::copy_file(path, destPath / path.filename(), std::filesystem::copy_options::overwrite_existing, error)) {
View::showMessagePopup("hex.message.yara_rule_added"_lang);
handled = true;
break;
}
}
} else if (path.extension() == ".mgc") {
for (auto &destPath : hex::getPath(ImHexPath::Magic)) {
std::error_code error;
if (std::filesystem::copy_file(path, destPath / path.filename(), std::filesystem::copy_options::overwrite_existing, error)) {
View::showMessagePopup("hex.message.magic_db_added"_lang);
break;
}
}
} else {
if (!handled)
EventManager::post<RequestOpenFile>(path.string());
}
}
});
glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) {