fix: Replace old defaults path system with a new one

#1767
This commit is contained in:
WerWolv
2024-06-22 10:44:55 +02:00
parent beef0fff33
commit b60a262b58
41 changed files with 461 additions and 356 deletions

View File

@@ -3,16 +3,17 @@
#include <hex/api/event_manager.hpp>
#include <hex/api/project_file_manager.hpp>
#include <wolv/utils/guards.hpp>
#include <wolv/net/socket_server.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <hex/helpers/default_paths.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/providers/provider.hpp>
#include <nlohmann/json.hpp>
#include <wolv/utils/guards.hpp>
#include <wolv/utils/string.hpp>
#include <wolv/net/socket_server.hpp>
#include <fmt/chrono.h>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {
@@ -82,7 +83,7 @@ namespace hex::plugin::builtin {
}
}
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Backups)) {
for (const auto &path : paths::Backups.write()) {
const auto backupPath = path / hex::format("auto_backup.{:%y%m%d_%H%M%S}.hexproj", fmt::gmtime(std::chrono::system_clock::now()));
if (ProjectFile::store(backupPath, false)) {
log::info("Created auto-backup file '{}'", wolv::util::toUTF8String(backupPath));

View File

@@ -3,19 +3,19 @@
#include <content/providers/file_provider.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event_manager.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/magic.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/literals.hpp>
#include <hex/helpers/utils.hpp>
#include <romfs/romfs.hpp>
#include <hex/helpers/default_paths.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/subcommands/subcommands.hpp>
#include <romfs/romfs.hpp>
#include <wolv/utils/string.hpp>
#include <wolv/math_eval/math_evaluator.hpp>
@@ -308,7 +308,7 @@ namespace hex::plugin::builtin {
if (processedArgs.empty()) {
processedArgs.emplace_back("--help");
} else {
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::PatternsInclude))
for (const auto &path : paths::PatternsInclude.read())
processedArgs.emplace_back(hex::format("--includes={}", wolv::util::toUTF8String(path)));
}

View File

@@ -4,6 +4,7 @@
#include <romfs/romfs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>
namespace hex::plugin::builtin {
@@ -17,7 +18,7 @@ namespace hex::plugin::builtin {
for (const auto &[extractFolder, alwaysExtract] : Paths) {
for (const auto &romfsPath : romfs::list(extractFolder)) {
for (const auto &imhexPath : fs::getDataPaths()) {
for (const auto &imhexPath : paths::getDataPaths(false)) {
const auto path = imhexPath / std::fs::relative(romfsPath, extractFolder);
log::info("Extracting {} to {}", romfsPath.string(), path.string());
if (!alwaysExtract && wolv::io::fs::exists(path))

View File

@@ -1,6 +1,8 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/helpers/default_paths.hpp>
#include <toasts/toast_notification.hpp>
namespace hex::plugin::builtin {
@@ -12,7 +14,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::FileHandler::add({ ".hexlyt" }, [](const std::fs::path &path) {
for (const auto &folder : fs::getDefaultPaths(fs::ImHexPath::Layouts)) {
for (const auto &folder : paths::Layouts.write()) {
if (wolv::io::fs::copyFile(path, folder / path.filename()))
return true;
}
@@ -21,7 +23,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) {
for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Magic)) {
for (const auto &destPath : paths::Magic.write()) {
if (wolv::io::fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) {
ui::ToastInfo::open("hex.builtin.view.information.magic_db_added"_lang);
return true;

View File

@@ -8,6 +8,7 @@
#include <hex/api/project_file_manager.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/api/achievement_manager.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/event_manager.hpp>
#include <hex/providers/provider.hpp>
@@ -177,6 +178,10 @@ namespace hex::plugin::builtin {
}
void registerProjectHandlers() {
hex::ProjectFile::setProjectFunctions(load, store);
hex::ProjectFile::setProjectFunctions(load, store);
ContentRegistry::Interface::addSidebarItem(ICON_VS_PROJECT, [] {
ImGui::TextUnformatted("Test");
});
}
}

View File

@@ -1,4 +1,3 @@
#include <imgui.h>
#include <imgui_internal.h>
@@ -7,6 +6,7 @@
#include <hex/api/project_file_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/default_paths.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
@@ -41,7 +41,7 @@ namespace hex::plugin::builtin::recent {
};
public:
PopupAutoBackups() : Popup("hex.builtin.welcome.start.recent.auto_backups", true, true) {
for (const auto &backupPath : fs::getDefaultPaths(fs::ImHexPath::Backups)) {
for (const auto &backupPath : paths::Backups.read()) {
for (const auto &entry : std::fs::directory_iterator(backupPath)) {
if (entry.is_regular_file() && entry.path().extension() == ".hexproj") {
wolv::io::File backupFile(entry.path(), wolv::io::File::Mode::Read);
@@ -99,7 +99,7 @@ namespace hex::plugin::builtin::recent {
return;
// The recent provider is saved to every "recent" directory
for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) {
for (const auto &recentPath : paths::Recent.write()) {
wolv::io::File recentFile(recentPath / fileName, wolv::io::File::Mode::Create);
if (!recentFile.isValid())
continue;
@@ -129,7 +129,7 @@ namespace hex::plugin::builtin::recent {
return;
// The recent provider is saved to every "recent" directory
for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) {
for (const auto &recentPath : paths::Recent.write()) {
wolv::io::File recentFile(recentPath / fileName, wolv::io::File::Mode::Create);
if (!recentFile.isValid())
continue;
@@ -160,7 +160,7 @@ namespace hex::plugin::builtin::recent {
// Query all recent providers
std::vector<std::fs::path> recentFilePaths;
for (const auto &folder : fs::getDefaultPaths(fs::ImHexPath::Recent)) {
for (const auto &folder : paths::Recent.read()) {
for (const auto &entry : std::fs::directory_iterator(folder)) {
if (entry.is_regular_file())
recentFilePaths.push_back(entry.path());
@@ -203,7 +203,7 @@ namespace hex::plugin::builtin::recent {
std::copy(uniqueProviders.begin(), uniqueProviders.end(), std::front_inserter(s_recentEntries));
s_autoBackupsFound = false;
for (const auto &backupPath : fs::getDefaultPaths(fs::ImHexPath::Backups)) {
for (const auto &backupPath : paths::Backups.read()) {
for (const auto &entry : std::fs::directory_iterator(backupPath)) {
if (entry.is_regular_file() && entry.path().extension() == ".hexproj") {
s_autoBackupsFound = true;
@@ -347,7 +347,7 @@ namespace hex::plugin::builtin::recent {
s_recentEntries.clear();
// Remove all recent files
for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) {
for (const auto &recentPath : paths::Recent.write()) {
for (const auto &entry : std::fs::directory_iterator(recentPath))
std::fs::remove(entry.path());
}

View File

@@ -1,17 +1,16 @@
#include <hex/api/theme_manager.hpp>
#include <hex/api/event_manager.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <hex/helpers/default_paths.hpp>
#include <imgui.h>
#include <imgui_internal.h>
#include <implot.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <imnodes.h>
#include <TextEditor.h>
#include <romfs/romfs.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/api/event_manager.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin {
@@ -369,7 +368,7 @@ namespace hex::plugin::builtin {
}
// Load user themes
for (const auto &themeFolder : fs::getDefaultPaths(fs::ImHexPath::Themes)) {
for (const auto &themeFolder : paths::Themes.read()) {
for (const auto &theme : std::fs::directory_iterator(themeFolder)) {
if (theme.is_regular_file())
ThemeManager::addTheme(wolv::io::File(theme.path(), wolv::io::File::Mode::Read).readString());

View File

@@ -10,6 +10,7 @@
#include <hex/helpers/fs.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/default_paths.hpp>
#include <content/popups/popup_docs_question.hpp>
@@ -451,28 +452,28 @@ namespace hex::plugin::builtin {
void ViewAbout::drawPathsPage() {
constexpr static std::array<std::pair<const char *, fs::ImHexPath>, size_t(fs::ImHexPath::END)> PathTypes = {
constexpr static std::array<std::pair<const char *, const paths::impl::DefaultPath*>, paths::All.size()> PathTypes = {
{
{ "Patterns", fs::ImHexPath::Patterns },
{ "Patterns Includes", fs::ImHexPath::PatternsInclude },
{ "Magic", fs::ImHexPath::Magic },
{ "Plugins", fs::ImHexPath::Plugins },
{ "Yara Patterns", fs::ImHexPath::Yara },
{ "Yara Advaned Analysis", fs::ImHexPath::YaraAdvancedAnalysis },
{ "Config", fs::ImHexPath::Config },
{ "Backups", fs::ImHexPath::Backups },
{ "Resources", fs::ImHexPath::Resources },
{ "Constants lists", fs::ImHexPath::Constants },
{ "Custom encodings", fs::ImHexPath::Encodings },
{ "Logs", fs::ImHexPath::Logs },
{ "Recent files", fs::ImHexPath::Recent },
{ "Scripts", fs::ImHexPath::Scripts },
{ "Data inspector scripts", fs::ImHexPath::Inspectors },
{ "Themes", fs::ImHexPath::Themes },
{ "Native Libraries", fs::ImHexPath::Libraries },
{ "Custom data processor nodes", fs::ImHexPath::Nodes },
{ "Layouts", fs::ImHexPath::Layouts },
{ "Workspaces", fs::ImHexPath::Workspaces },
{ "Patterns", &paths::Patterns },
{ "Patterns Includes", &paths::PatternsInclude },
{ "Magic", &paths::Magic },
{ "Plugins", &paths::Plugins },
{ "Yara Patterns", &paths::Yara },
{ "Yara Advaned Analysis", &paths::YaraAdvancedAnalysis },
{ "Config", &paths::Config },
{ "Backups", &paths::Backups },
{ "Resources", &paths::Resources },
{ "Constants lists", &paths::Constants },
{ "Custom encodings", &paths::Encodings },
{ "Logs", &paths::Logs },
{ "Recent files", &paths::Recent },
{ "Scripts", &paths::Scripts },
{ "Data inspector scripts", &paths::Inspectors },
{ "Themes", &paths::Themes },
{ "Native Libraries", &paths::Libraries },
{ "Custom data processor nodes", &paths::Nodes },
{ "Layouts", &paths::Layouts },
{ "Workspaces", &paths::Workspaces },
}
};
static_assert(PathTypes.back().first != nullptr, "All path items need to be populated!");
@@ -487,13 +488,13 @@ namespace hex::plugin::builtin {
// Draw the table
ImGui::TableHeadersRow();
for (const auto &[name, type] : PathTypes) {
for (const auto &[name, paths] : PathTypes) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted(name);
ImGui::TableNextColumn();
for (auto &path : fs::getDefaultPaths(type, true)){
for (auto &path : paths->all()){
// Draw hyperlink to paths that exist or red text if they don't
if (wolv::io::fs::isDirectory(path)){
if (ImGuiExt::Hyperlink(wolv::util::toUTF8String(path).c_str())) {

View File

@@ -1,8 +1,8 @@
#include "content/views/view_constants.hpp"
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/default_paths.hpp>
#include <wolv/utils/string.hpp>
#include <wolv/io/file.hpp>
@@ -22,7 +22,7 @@ namespace hex::plugin::builtin {
m_constants.clear();
m_filterIndices.clear();
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Constants)) {
for (const auto &path : paths::Constants.read()) {
if (!wolv::io::fs::exists(path)) continue;
std::error_code error;

View File

@@ -1,13 +1,12 @@
#include "content/views/view_data_inspector.hpp"
#include <hex/ui/imgui_imhex_extensions.h>
#include <hex/providers/provider.hpp>
#include <hex/api/achievement_manager.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>
#include <fonts/codicons_font.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <pl/pattern_language.hpp>
#include <pl/patterns/pattern.hpp>
@@ -134,7 +133,7 @@ namespace hex::plugin::builtin {
m_runtime.setStartAddress(m_startAddress);
// Loop over all files in the inspectors folder and execute them
for (const auto &folderPath : fs::getDefaultPaths(fs::ImHexPath::Inspectors)) {
for (const auto &folderPath : paths::Inspectors.read()) {
for (const auto &entry: std::fs::recursive_directory_iterator(folderPath)) {
const auto &filePath = entry.path();
// Skip non-files and files that don't end with .hexpat

View File

@@ -7,6 +7,7 @@
#include <hex/providers/provider.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>
#include <imnodes.h>
#include <imnodes_internal.h>
@@ -127,7 +128,7 @@ namespace hex::plugin::builtin {
void process() override {
switch (this->getType()) {
case dp::Attribute::Type::Integer: m_value = this->getIntegerOnInput(0); break;
case dp::Attribute::Type::Float: m_value = this->getFloatOnInput(0); break;
case dp::Attribute::Type::Float: m_value = static_cast<long double>(this->getFloatOnInput(0)); break;
case dp::Attribute::Type::Buffer: m_value = this->getBufferOnInput(0); break;
}
}
@@ -568,7 +569,7 @@ namespace hex::plugin::builtin {
m_customNodes.clear();
// Loop over all custom node folders
for (const auto &basePath : fs::getDefaultPaths(fs::ImHexPath::Nodes)) {
for (const auto &basePath : paths::Nodes.read()) {
// Loop over all files in the folder
for (const auto &entry : std::fs::recursive_directory_iterator(basePath)) {
// Skip files that are not .hexnode files

View File

@@ -7,6 +7,7 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/default_paths.hpp>
#include <hex/providers/buffered_reader.hpp>
@@ -19,7 +20,6 @@
#include <popups/popup_file_chooser.hpp>
#include <content/popups/popup_blocking_task.hpp>
#include <content/popups/hex_editor/popup_hex_editor_find.hpp>
#include <wolv/utils/lock.hpp>
#include <pl/patterns/pattern.hpp>
using namespace std::literals::string_literals;
@@ -1053,7 +1053,7 @@ namespace hex::plugin::builtin {
/* Load Encoding File */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.custom_encoding" }, "", 5050, Shortcut::None,
[this]{
const auto basePaths = fs::getDefaultPaths(fs::ImHexPath::Encodings);
const auto basePaths = paths::Encodings.read();
std::vector<std::fs::path> paths;
for (const auto &path : basePaths) {
std::error_code error;

View File

@@ -14,6 +14,7 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/magic.hpp>
#include <hex/helpers/binary_pattern.hpp>
#include <hex/helpers/default_paths.hpp>
#include <hex/providers/memory_provider.hpp>
@@ -239,9 +240,9 @@ namespace hex::plugin::builtin {
if (ImGui::BeginPopup("##pattern_editor_context_menu")) {
// no shortcut for this
if (ImGui::MenuItem("hex.builtin.menu.file.import.pattern_file"_lang, nullptr, false))
importPatternFile();
m_importPatternFile();
if (ImGui::MenuItem("hex.builtin.menu.file.export.pattern_file"_lang, nullptr, false))
exportPatternFile();
m_exportPatternFile();
ImGui::Separator();
@@ -1413,7 +1414,7 @@ namespace hex::plugin::builtin {
bool popupOpen = false;
std::error_code errorCode;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Patterns)) {
for (const auto &dir : paths::Patterns.read()) {
for (auto &entry : std::fs::recursive_directory_iterator(dir, errorCode)) {
task.update();
@@ -1792,11 +1793,11 @@ namespace hex::plugin::builtin {
void ViewPatternEditor::registerMenuItems() {
/* Import Pattern */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.pattern" }, ICON_VS_FILE_CODE, 4050, Shortcut::None,
importPatternFile, ImHexApi::Provider::isValid);
m_importPatternFile, ImHexApi::Provider::isValid);
/* Export Pattern */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.pattern" }, ICON_VS_FILE_CODE, 7050, Shortcut::None,
exportPatternFile, [this] {
m_exportPatternFile, [this] {
return !wolv::util::trim(m_textEditor.GetText()).empty() && ImHexApi::Provider::isValid();
}
);

View File

@@ -38,26 +38,26 @@ namespace hex::plugin::builtin {
m_httpRequest.setTimeout(30'0000);
addCategory("hex.builtin.view.store.tab.patterns", "patterns", fs::ImHexPath::Patterns);
addCategory("hex.builtin.view.store.tab.includes", "includes", fs::ImHexPath::PatternsInclude);
addCategory("hex.builtin.view.store.tab.magic", "magic", fs::ImHexPath::Magic, []{
addCategory("hex.builtin.view.store.tab.patterns", "patterns", &paths::Patterns);
addCategory("hex.builtin.view.store.tab.includes", "includes", &paths::PatternsInclude);
addCategory("hex.builtin.view.store.tab.magic", "magic", &paths::Magic, []{
magic::compile();
});
addCategory("hex.builtin.view.store.tab.nodes", "nodes", fs::ImHexPath::Nodes);
addCategory("hex.builtin.view.store.tab.encodings", "encodings", fs::ImHexPath::Encodings);
addCategory("hex.builtin.view.store.tab.constants", "constants", fs::ImHexPath::Constants);
addCategory("hex.builtin.view.store.tab.themes", "themes", fs::ImHexPath::Themes, [this]{
addCategory("hex.builtin.view.store.tab.nodes", "nodes", &paths::Nodes);
addCategory("hex.builtin.view.store.tab.encodings", "encodings", &paths::Encodings);
addCategory("hex.builtin.view.store.tab.constants", "constants", &paths::Constants);
addCategory("hex.builtin.view.store.tab.themes", "themes", &paths::Themes, [this]{
auto themeFile = wolv::io::File(m_downloadPath, wolv::io::File::Mode::Read);
ThemeManager::addTheme(themeFile.readString());
});
addCategory("hex.builtin.view.store.tab.yara", "yara", fs::ImHexPath::Yara);
addCategory("hex.builtin.view.store.tab.yara", "yara", &paths::Yara);
}
void updateEntryMetadata(StoreEntry &storeEntry, const StoreCategory &category) {
// Check if file is installed already or has an update available
for (const auto &folder : fs::getDefaultPaths(category.path)) {
for (const auto &folder : category.path->write()) {
auto path = folder / std::fs::path(storeEntry.fileName);
if (wolv::io::fs::exists(path)) {
@@ -296,9 +296,9 @@ namespace hex::plugin::builtin {
this->drawStore();
}
bool ViewStore::download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url) {
bool ViewStore::download(const paths::impl::DefaultPath *pathType, const std::string &fileName, const std::string &url) {
bool downloading = false;
for (const auto &folderPath : fs::getDefaultPaths(pathType)) {
for (const auto &folderPath : pathType->write()) {
if (!fs::isPathWritable(folderPath))
continue;
@@ -327,9 +327,9 @@ namespace hex::plugin::builtin {
return true;
}
bool ViewStore::remove(fs::ImHexPath pathType, const std::string &fileName) {
bool ViewStore::remove(const paths::impl::DefaultPath *pathType, const std::string &fileName) {
bool removed = true;
for (const auto &path : fs::getDefaultPaths(pathType)) {
for (const auto &path : pathType->write()) {
const auto filePath = path / fileName;
const auto folderPath = (path / std::fs::path(fileName).stem());
@@ -343,7 +343,7 @@ namespace hex::plugin::builtin {
return removed;
}
void ViewStore::addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback) {
void ViewStore::addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, const paths::impl::DefaultPath *path, std::function<void()> downloadCallback) {
m_categories.push_back({ unlocalizedName, requestName, path, { }, std::move(downloadCallback) });
}

View File

@@ -15,6 +15,7 @@
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>
#include <hex/api/project_file_manager.hpp>
@@ -87,8 +88,8 @@ namespace hex::plugin::builtin {
// Anonymize the log file
{
for (u32 pathType = 0; pathType < u32(fs::ImHexPath::END); pathType++) {
for (auto &folder : fs::getDefaultPaths(static_cast<fs::ImHexPath>(pathType))) {
for (const auto &paths : paths::All) {
for (auto &folder : paths->all()) {
auto parent = wolv::util::toUTF8String(folder.parent_path());
data = wolv::util::replaceStrings(data, parent, "<*****>");
}
@@ -546,7 +547,7 @@ namespace hex::plugin::builtin {
constexpr static auto BackupFileName = "crash_backup.hexproj";
bool hasCrashed = false;
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {
for (const auto &path : paths::Config.read()) {
if (auto crashFilePath = std::fs::path(path) / CrashFileName; wolv::io::fs::exists(crashFilePath)) {
hasCrashed = true;
@@ -646,7 +647,7 @@ namespace hex::plugin::builtin {
// Load info banner texture either locally or from the server
TaskManager::doLater([] {
for (const auto &defaultPath : fs::getDefaultPaths(fs::ImHexPath::Resources)) {
for (const auto &defaultPath : paths::Resources.read()) {
const auto infoBannerPath = defaultPath / "info_banner.png";
if (wolv::io::fs::exists(infoBannerPath)) {
s_infoBannerTexture = ImGuiExt::Texture::fromImage(infoBannerPath, ImGuiExt::Texture::Filter::Linear);

View File

@@ -75,24 +75,29 @@ namespace hex::plugin::builtin {
void drawSidebar(ImVec2 dockSpaceSize, ImVec2 sidebarPos, float sidebarWidth) {
static i32 openWindow = -1;
u32 index = 0;
u32 drawIndex = 0;
ImGui::PushID("SideBarWindows");
for (const auto &[icon, callback, enabledCallback] : ContentRegistry::Interface::impl::getSidebarItems()) {
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index);
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * drawIndex);
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered));
ImGui::BeginDisabled(!(ImHexApi::Provider::isValid() && enabledCallback()));
{
if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) {
if (static_cast<u32>(openWindow) == index)
openWindow = -1;
else
openWindow = index;
if (enabledCallback()) {
drawIndex += 1;
ImGui::BeginDisabled(!ImHexApi::Provider::isValid());
{
if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) {
if (static_cast<u32>(openWindow) == index)
openWindow = -1;
else
openWindow = index;
}
}
ImGui::EndDisabled();
}
ImGui::EndDisabled();
ImGui::PopStyleColor(3);
@@ -122,7 +127,7 @@ namespace hex::plugin::builtin {
}
ImGui::NewLine();
index++;
index += 1;
}
ImGui::PopID();
}