sys: Added a bunch of logging
This commit is contained in:
parent
54785b29dd
commit
3f936b57f5
@ -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) {
|
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 });
|
ContentRegistry::Settings::getEntries()[unlocalizedCategory.c_str()].emplace_back(Entry{ unlocalizedName.c_str(), callback });
|
||||||
|
|
||||||
auto &json = getSettingsData();
|
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) {
|
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 });
|
ContentRegistry::Settings::getEntries()[unlocalizedCategory].emplace_back(Entry{ unlocalizedName, callback });
|
||||||
|
|
||||||
auto &json = getSettingsData();
|
auto &json = getSettingsData();
|
||||||
@ -157,6 +161,8 @@ namespace hex {
|
|||||||
/* Command Palette Commands */
|
/* 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) {
|
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 });
|
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) {
|
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 };
|
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) {
|
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 };
|
getFunctions()[getFunctionName(ns, name)] = Function { parameterCount, func, true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +204,8 @@ namespace hex {
|
|||||||
/* Views */
|
/* Views */
|
||||||
|
|
||||||
void ContentRegistry::Views::impl::add(View *view) {
|
void ContentRegistry::Views::impl::add(View *view) {
|
||||||
|
log::info("Registered new view: {}", view->getUnlocalizedName());
|
||||||
|
|
||||||
getEntries().emplace_back(view);
|
getEntries().emplace_back(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +217,8 @@ namespace hex {
|
|||||||
/* Tools */
|
/* Tools */
|
||||||
|
|
||||||
void ContentRegistry::Tools:: add(const std::string &unlocalizedName, const std::function<void()> &function) {
|
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 });
|
getEntries().emplace_back(impl::Entry{ unlocalizedName, function });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +230,8 @@ namespace hex {
|
|||||||
/* Data Inspector */
|
/* Data Inspector */
|
||||||
|
|
||||||
void ContentRegistry::DataInspector::add(const std::string &unlocalizedName, size_t requiredSize, ContentRegistry::DataInspector::impl::GeneratorFunction function) {
|
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) });
|
getEntries().push_back({ unlocalizedName, requiredSize, std::move(function) });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,6 +242,8 @@ namespace hex {
|
|||||||
/* Data Processor Nodes */
|
/* Data Processor Nodes */
|
||||||
|
|
||||||
void ContentRegistry::DataProcessorNode::impl::add(const impl::Entry &entry) {
|
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);
|
getEntries().push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,10 +258,14 @@ namespace hex {
|
|||||||
/* Languages */
|
/* Languages */
|
||||||
|
|
||||||
void ContentRegistry::Language::registerLanguage(const std::string &name, const std::string &languageCode) {
|
void ContentRegistry::Language::registerLanguage(const std::string &name, const std::string &languageCode) {
|
||||||
|
log::info("Registered new language: {} ({})", name, languageCode);
|
||||||
|
|
||||||
getLanguages().insert({ languageCode, name });
|
getLanguages().insert({ languageCode, name });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentRegistry::Language::addLocalizations(const std::string &languageCode, const LanguageDefinition &definition) {
|
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);
|
getLanguageDefinitions()[languageCode].push_back(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +278,9 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Interface */
|
||||||
|
|
||||||
void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) {
|
void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) {
|
||||||
getWelcomeScreenEntries().push_back(function);
|
getWelcomeScreenEntries().push_back(function);
|
||||||
}
|
}
|
||||||
@ -283,6 +308,8 @@ namespace hex {
|
|||||||
/* Providers */
|
/* Providers */
|
||||||
|
|
||||||
void ContentRegistry::Provider::impl::addProviderName(const std::string &unlocalizedName) {
|
void ContentRegistry::Provider::impl::addProviderName(const std::string &unlocalizedName) {
|
||||||
|
log::info("Registered new provider: {}", unlocalizedName);
|
||||||
|
|
||||||
SharedData::providerNames.push_back(unlocalizedName);
|
SharedData::providerNames.push_back(unlocalizedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ namespace hex::init {
|
|||||||
try {
|
try {
|
||||||
fs::create_directories(folder);
|
fs::create_directories(folder);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
log::error("Failed to create folder {}!", folder.string());
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +97,8 @@ namespace hex::init {
|
|||||||
for (const auto &dir : hex::getPath(ImHexPath::Resources)) {
|
for (const auto &dir : hex::getPath(ImHexPath::Resources)) {
|
||||||
auto path = dir / "font.ttf";
|
auto path = dir / "font.ttf";
|
||||||
if (fs::exists(path)) {
|
if (fs::exists(path)) {
|
||||||
|
log::info("Loading custom front from {}", path.string());
|
||||||
|
|
||||||
fontFile = path;
|
fontFile = path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -215,6 +218,8 @@ namespace hex::init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (PluginManager::getPlugins().empty()) {
|
if (PluginManager::getPlugins().empty()) {
|
||||||
|
log::error("No plugins found!");
|
||||||
|
|
||||||
getInitArguments().push_back({ "no-plugins", { } });
|
getInitArguments().push_back({ "no-plugins", { } });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -235,7 +240,8 @@ namespace hex::init {
|
|||||||
bool loadSettings() {
|
bool loadSettings() {
|
||||||
try {
|
try {
|
||||||
ContentRegistry::Settings::load();
|
ContentRegistry::Settings::load();
|
||||||
} catch (...) {
|
} catch (std::exception &e) {
|
||||||
|
log::error("Failed to load configuration! {}", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +270,8 @@ namespace hex::init {
|
|||||||
bool storeSettings() {
|
bool storeSettings() {
|
||||||
try {
|
try {
|
||||||
ContentRegistry::Settings::store();
|
ContentRegistry::Settings::store();
|
||||||
} catch (...) {
|
} catch (std::exception &e) {
|
||||||
|
log::error("Failed to store configuration! {}", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,6 +22,8 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
{
|
{
|
||||||
Window::initNative();
|
Window::initNative();
|
||||||
|
|
||||||
|
hex::log::info("Welcome to ImHex!");
|
||||||
|
|
||||||
init::WindowSplash splashWindow;
|
init::WindowSplash splashWindow;
|
||||||
|
|
||||||
for (const auto &[name, task] : init::getInitTasks())
|
for (const auto &[name, task] : init::getInitTasks())
|
||||||
@ -46,12 +48,10 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
else if (argc == 2)
|
else if (argc == 2)
|
||||||
EventManager::post<RequestOpenFile>(argv[1]);
|
EventManager::post<RequestOpenFile>(argv[1]);
|
||||||
else {
|
else {
|
||||||
hex::log::fatal("Usage: imhex [file_name]");
|
hex::log::fatal("Usage: {} [<file_name>]", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hex::log::info("Welcome to ImHex!");
|
|
||||||
|
|
||||||
window.loop();
|
window.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,8 +762,10 @@ namespace hex {
|
|||||||
log::error("GLFW Error [{}] : {}", error, desc);
|
log::error("GLFW Error [{}] : {}", error, desc);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit()) {
|
||||||
throw std::runtime_error("Failed to initialize GLFW!");
|
log::fatal("Failed to initialize GLFW!");
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(OS_WINDOWS)
|
#if defined(OS_WINDOWS)
|
||||||
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
||||||
@ -782,8 +784,10 @@ namespace hex {
|
|||||||
|
|
||||||
glfwSetWindowUserPointer(this->m_window, this);
|
glfwSetWindowUserPointer(this->m_window, this);
|
||||||
|
|
||||||
if (this->m_window == nullptr)
|
if (this->m_window == nullptr) {
|
||||||
throw std::runtime_error("Failed to create window!");
|
log::fatal("Failed to create window!");
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(this->m_window);
|
glfwMakeContextCurrent(this->m_window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
@ -870,32 +874,21 @@ namespace hex {
|
|||||||
for (u32 i = 0; i < count; i++) {
|
for (u32 i = 0; i < count; i++) {
|
||||||
auto path = std::filesystem::path(paths[i]);
|
auto path = std::filesystem::path(paths[i]);
|
||||||
|
|
||||||
if (path.extension() == ".hexpat" || path.extension() == ".pat") {
|
bool handled = false;
|
||||||
File file(path.string(), File::Mode::Read);
|
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())
|
handled = true;
|
||||||
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);
|
|
||||||
break;
|
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 {
|
|
||||||
EventManager::post<RequestOpenFile>(path.string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!handled)
|
||||||
|
EventManager::post<RequestOpenFile>(path.string());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user