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

@@ -1,8 +1,10 @@
#pragma once
#include <hex/api/achievement_manager.hpp>
#include <hex/ui/view.hpp>
#include <hex/providers/provider.hpp>
#include <hex/ui/popup.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/default_paths.hpp>
#include <pl/pattern_language.hpp>
#include <pl/core/errors/error.hpp>
@@ -14,8 +16,7 @@
#include <functional>
#include <TextEditor.h>
#include "popups/popup_file_chooser.hpp"
#include "hex/api/achievement_manager.hpp"
#include <popups/popup_file_chooser.hpp>
namespace pl::ptrn { class Pattern; }
@@ -261,9 +262,9 @@ namespace hex::plugin::builtin {
void registerMenuItems();
void registerHandlers();
std::function<void()> importPatternFile = [&] {
std::function<void()> m_importPatternFile = [this] {
auto provider = ImHexApi::Provider::get();
const auto basePaths = fs::getDefaultPaths(fs::ImHexPath::Patterns);
const auto basePaths = paths::Patterns.read();
std::vector<std::fs::path> paths;
for (const auto &imhexPath : basePaths) {
@@ -284,7 +285,7 @@ namespace hex::plugin::builtin {
);
};
std::function<void()> exportPatternFile = [&] {
std::function<void()> m_exportPatternFile = [this] {
fs::openFileBrowser(
fs::DialogMode::Save, { {"Pattern", "hexpat"} },
[this](const auto &path) {

View File

@@ -7,6 +7,7 @@
#include <hex/api/task_manager.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/default_paths.hpp>
#include <future>
#include <string>
@@ -40,7 +41,7 @@ namespace hex::plugin::builtin {
struct StoreCategory {
UnlocalizedString unlocalizedName;
std::string requestName;
fs::ImHexPath path;
const paths::impl::DefaultPath* path;
std::vector<StoreEntry> entries;
std::function<void()> downloadCallback;
};
@@ -66,10 +67,10 @@ namespace hex::plugin::builtin {
void refresh();
void parseResponse();
void addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback = []{});
void addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, const paths::impl::DefaultPath *path, std::function<void()> downloadCallback = []{});
bool download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url);
bool remove(fs::ImHexPath pathType, const std::string &fileName);
bool download(const paths::impl::DefaultPath *pathType, const std::string &fileName, const std::string &url);
bool remove(const paths::impl::DefaultPath *pathType, const std::string &fileName);
private:
HttpRequest m_httpRequest = HttpRequest("GET", "");