1
0
mirror of synced 2025-02-20 04:01:01 +01:00

sys: std::filesystem -> fs

This commit is contained in:
WerWolv 2022-01-13 14:33:30 +01:00
parent 27c08c1edf
commit c88d428fb5
24 changed files with 69 additions and 63 deletions

View File

@ -5,6 +5,7 @@
#include <hex/views/view.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/paths.hpp>
#include <string_view>
#include <dlfcn.h>
@ -53,7 +54,7 @@ namespace hex {
public:
PluginManager() = delete;
static bool load(const std::string &pluginFolder);
static bool load(const fs::path &pluginFolder);
static void unload();
static void reload();
@ -62,7 +63,7 @@ namespace hex {
}
private:
static inline std::string s_pluginFolder;
static inline fs::path s_pluginFolder;
static inline std::vector<Plugin> s_plugins;
};

View File

@ -65,7 +65,7 @@ namespace hex {
ImGui::Texture m_bannerTexture = { 0 };
ImGui::Texture m_logoTexture = { 0 };
std::filesystem::path m_safetyBackupPath;
fs::path m_safetyBackupPath;
std::list<std::string> m_popupsToOpen;
std::vector<int> m_pressedKeys;

View File

@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
private:
pl::PatternLanguage *m_parserRuntime, *m_evaluatorRuntime;
std::vector<std::filesystem::path> m_possiblePatternFiles;
std::vector<fs::path> m_possiblePatternFiles;
u32 m_selectedPatternFile = 0;
bool m_runAutomatically = false;

View File

@ -42,7 +42,7 @@ namespace hex::plugin::builtin {
Net m_net;
std::future<Response<std::string>> m_apiRequest;
std::future<Response<void>> m_download;
std::filesystem::path m_downloadPath;
fs::path m_downloadPath;
std::vector<StoreEntry> m_patterns, m_includes, m_magics, m_constants, m_yara;

View File

@ -138,7 +138,7 @@ namespace hex::plugin::builtin::prv {
}
std::string FileProvider::getName() const {
return std::filesystem::path(this->m_path).filename().string();
return fs::path(this->m_path).filename().string();
}
std::vector<std::pair<std::string, std::string>> FileProvider::getDataInformation() const {

View File

@ -7,6 +7,7 @@
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/literals.hpp>
#include <hex/helpers/paths.hpp>
#include <algorithm>
#include <chrono>
@ -506,7 +507,7 @@ namespace hex::plugin::builtin {
static hex::Net net;
static std::future<Response<std::string>> uploadProcess;
static std::filesystem::path currFile;
static fs::path currFile;
static std::vector<UploadedFile> links;
bool uploading = uploadProcess.valid() && uploadProcess.wait_for(0s) != std::future_status::ready;
@ -899,7 +900,7 @@ namespace hex::plugin::builtin {
s32 index = 0;
for (auto &file : files) {
if (ImGui::Selectable(std::filesystem::path(file).filename().string().c_str(), index == selectedIndex))
if (ImGui::Selectable(fs::path(file).filename().string().c_str(), index == selectedIndex))
selectedIndex = index;
index++;
}
@ -993,7 +994,7 @@ namespace hex::plugin::builtin {
File input(file, File::Mode::Read);
if (!input.isValid()) {
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, std::filesystem::path(file).filename().string()));
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, fs::path(file).filename().string()));
return;
}

View File

@ -26,9 +26,9 @@ namespace hex::plugin::builtin {
this->m_filterIndices.clear();
for (auto &path : hex::getPath(ImHexPath::Constants)) {
if (!std::filesystem::exists(path)) continue;
if (!fs::exists(path)) continue;
for (auto &file : std::filesystem::directory_iterator(path)) {
for (auto &file : fs::directory_iterator(path)) {
if (!file.is_regular_file()) continue;
try {

View File

@ -105,7 +105,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
for (auto &path : hex::getPath(type))
ImGui::TextUnformatted(path.c_str());
ImGui::TextUnformatted(path.string().c_str());
}
ImGui::EndTable();

View File

@ -16,7 +16,6 @@
namespace hex::plugin::builtin {
using namespace hex::literals;
namespace fs = std::filesystem;
static const TextEditor::LanguageDefinition& PatternLanguage() {
static bool initialized = false;
@ -136,7 +135,7 @@ namespace hex::plugin::builtin {
std::error_code errorCode;
for (const auto &dir : hex::getPath(ImHexPath::Patterns)) {
for (auto &entry : std::filesystem::directory_iterator(dir, errorCode)) {
for (auto &entry : fs::directory_iterator(dir, errorCode)) {
foundCorrectType = false;
if (!entry.is_regular_file())
continue;
@ -521,7 +520,7 @@ namespace hex::plugin::builtin {
entries.resize(this->m_possiblePatternFiles.size());
for (u32 i = 0; i < entries.size(); i++) {
entries[i] = std::filesystem::path(this->m_possiblePatternFiles[i]).filename().string();
entries[i] = fs::path(this->m_possiblePatternFiles[i]).filename().string();
}
if (ImGui::BeginListBox("##patterns_accept", ImVec2(-FLT_MIN, 0))) {

View File

@ -8,20 +8,19 @@
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/magic.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/paths.hpp>
#include <fstream>
#include <filesystem>
#include <functional>
#include <nlohmann/json.hpp>
#include <microtar.h>
#include <hex/helpers/file.hpp>
namespace hex::plugin::builtin {
using namespace std::literals::string_literals;
using namespace std::literals::chrono_literals;
namespace fs = std::filesystem;
ViewStore::ViewStore() : View("hex.builtin.view.store.name") {
this->refresh();

View File

@ -3,6 +3,7 @@
#include <hex/providers/provider.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/paths.hpp>
#include <hex/helpers/logger.hpp>
#include <yara.h>
@ -13,8 +14,6 @@
namespace hex::plugin::builtin {
namespace fs = std::filesystem;
ViewYara::ViewYara() : View("hex.builtin.view.yara.name") {
yr_initialize();

View File

@ -2,6 +2,8 @@
#include <hex.hpp>
#include <hex/helpers/concepts.hpp>
#include <hex/helpers/paths.hpp>
#include <hex/pattern_language/token.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>

View File

@ -12,6 +12,8 @@
#include <nlohmann/json_fwd.hpp>
#include <curl/system.h>
#include <hex/helpers/paths.hpp>
using CURL = void;
struct curl_slist;
@ -36,8 +38,8 @@ namespace hex {
std::future<Response<std::string>> getString(const std::string &url, u32 timeout = 2000);
std::future<Response<nlohmann::json>> getJson(const std::string &url, u32 timeout = 2000);
std::future<Response<std::string>> uploadFile(const std::string &url, const std::filesystem::path &filePath, u32 timeout = 2000);
std::future<Response<void>> downloadFile(const std::string &url, const std::filesystem::path &filePath, u32 timeout = 2000);
std::future<Response<std::string>> uploadFile(const std::string &url, const fs::path &filePath, u32 timeout = 2000);
std::future<Response<void>> downloadFile(const std::string &url, const fs::path &filePath, u32 timeout = 2000);
[[nodiscard]]
std::string encode(const std::string &input);

View File

@ -2,9 +2,12 @@
#include <string>
#include <vector>
#include <filesystem>
namespace hex {
namespace fs = std::filesystem;
enum class ImHexPath {
Patterns,
PatternsInclude,
@ -19,6 +22,6 @@ namespace hex {
std::string getExecutablePath();
std::vector<std::string> getPath(ImHexPath path, bool listNonExisting = false);
std::vector<fs::path> getPath(ImHexPath path, bool listNonExisting = false);
}

View File

@ -8,7 +8,7 @@
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <filesystem>
#include <hex/helpers/paths.hpp>
namespace hex {
@ -29,7 +29,7 @@ namespace hex {
ProjectFile::s_hasUnsavedChanged = true;
if (setWindowTitle)
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(getFilePath()).filename().string());
EventManager::post<RequestChangeWindowTitle>(fs::path(getFilePath()).filename().string());
}
[[nodiscard]] static const std::string& getProjectFilePath() {
@ -48,7 +48,7 @@ namespace hex {
static void setFilePath(const std::string &filePath) {
ProjectFile::s_filePath = filePath;
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(filePath).filename().string());
EventManager::post<RequestChangeWindowTitle>(fs::path(filePath).filename().string());
}

View File

@ -2,6 +2,7 @@
#include <hex/helpers/shared_data.hpp>
#include <hex/helpers/paths.hpp>
#include <hex/helpers/logger.hpp>
#include <filesystem>
#include <fstream>
@ -15,7 +16,7 @@ namespace hex {
void ContentRegistry::Settings::load() {
bool loaded = false;
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
std::ifstream settingsFile(dir + "/settings.json");
std::ifstream settingsFile(dir / "settings.json");
if (settingsFile.good()) {
settingsFile >> getSettingsData();
@ -30,7 +31,7 @@ namespace hex {
void ContentRegistry::Settings::store() {
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
std::ofstream settingsFile(dir + "/settings.json", std::ios::trunc);
std::ofstream settingsFile(dir / "settings.json", std::ios::trunc);
if (settingsFile.good()) {
settingsFile << getSettingsData();

View File

@ -182,8 +182,8 @@ namespace hex {
Py_SetProgramName(Py_DecodeLocale((SharedData::mainArgv)[0], nullptr));
for (const auto &dir : hex::getPath(ImHexPath::Python)) {
if (std::filesystem::exists(std::filesystem::path(dir + "/lib/python" PYTHON_VERSION_MAJOR_MINOR))) {
Py_SetPythonHome(Py_DecodeLocale(dir.c_str(), nullptr));
if (fs::exists(fs::path(dir / "lib" / "python" PYTHON_VERSION_MAJOR_MINOR))) {
Py_SetPythonHome(Py_DecodeLocale(dir.string().c_str(), nullptr));
break;
}
}

View File

@ -25,7 +25,7 @@ namespace hex::magic {
std::error_code error;
for (const auto &dir : hex::getPath(ImHexPath::Magic)) {
for (const auto &entry : std::filesystem::directory_iterator(dir, error)) {
for (const auto &entry : fs::directory_iterator(dir, error)) {
if (entry.is_regular_file() && ((sourceFiles && entry.path().extension().empty()) || (!sourceFiles && entry.path().extension() == ".mgc")))
magicFiles += entry.path().string() + MAGIC_PATH_SEPARATOR;
}

View File

@ -168,7 +168,7 @@ namespace hex {
});
}
std::future<Response<std::string>> Net::uploadFile(const std::string &url, const std::filesystem::path &filePath, u32 timeout) {
std::future<Response<std::string>> Net::uploadFile(const std::string &url, const fs::path &filePath, u32 timeout) {
this->m_transmissionActive.lock();
return std::async(std::launch::async, [=, this] {
@ -211,7 +211,7 @@ namespace hex {
});
}
std::future<Response<void>> Net::downloadFile(const std::string &url, const std::filesystem::path &filePath, u32 timeout) {
std::future<Response<void>> Net::downloadFile(const std::string &url, const fs::path &filePath, u32 timeout) {
this->m_transmissionActive.lock();
return std::async(std::launch::async, [=, this]{

View File

@ -36,14 +36,14 @@ namespace hex {
#endif
}
std::vector<std::string> getPath(ImHexPath path, bool listNonExisting) {
std::vector<std::string> result;
std::vector<fs::path> getPath(ImHexPath path, bool listNonExisting) {
std::vector<fs::path> result;
#if defined(OS_WINDOWS)
const auto exePath = getExecutablePath();
const auto parentDir = std::filesystem::path(exePath).parent_path();
const auto parentDir = fs::path(exePath).parent_path();
std::filesystem::path appDataDir;
fs::path appDataDir;
{
LPWSTR wAppDataPath = nullptr;
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &wAppDataPath)))
@ -53,7 +53,7 @@ namespace hex {
CoTaskMemFree(wAppDataPath);
}
std::vector<std::filesystem::path> paths = { parentDir, appDataDir / "imhex" };
std::vector<fs::path> paths = { parentDir, appDataDir / "imhex" };
switch (path) {
case ImHexPath::Patterns:
@ -103,9 +103,9 @@ namespace hex {
#elif defined(OS_MACOS)
// Get path to special directories
const auto exePath = getExecutablePath();
const std::filesystem::path applicationSupportDir(getMacApplicationSupportDirectoryPath());
const fs::path applicationSupportDir(getMacApplicationSupportDirectoryPath());
std::vector<std::filesystem::path> paths = { exePath, applicationSupportDir };
std::vector<fs::path> paths = { exePath, applicationSupportDir };
switch (path) {
case ImHexPath::Patterns:
@ -140,8 +140,8 @@ namespace hex {
default: __builtin_unreachable();
}
#else
std::vector<std::filesystem::path> configDirs = xdg::ConfigDirs();
std::vector<std::filesystem::path> dataDirs = xdg::DataDirs();
std::vector<fs::path> configDirs = xdg::ConfigDirs();
std::vector<fs::path> dataDirs = xdg::DataDirs();
configDirs.insert(configDirs.begin(), xdg::ConfigHomeDir());
dataDirs.insert(dataDirs.begin(), xdg::DataHomeDir());
@ -152,7 +152,7 @@ namespace hex {
const auto exePath = getExecutablePath();
if (!exePath.empty())
dataDirs.emplace(dataDirs.begin(), std::filesystem::path(exePath.data()).parent_path());
dataDirs.emplace(dataDirs.begin(), fs::path(exePath.data()).parent_path());
switch (path) {
case ImHexPath::Patterns:
@ -197,7 +197,7 @@ namespace hex {
if (!listNonExisting) {
result.erase(std::remove_if(result.begin(), result.end(), [](const auto& path){
return !std::filesystem::is_directory(path);
return !fs::is_directory(path);
}), result.end());
}

View File

@ -67,8 +67,8 @@ namespace hex::pl {
if (includeFile[0] != '/') {
for (const auto &dir : hex::getPath(ImHexPath::PatternsInclude)) {
std::string tempPath = hex::format("{0}/{1}", dir.c_str(), includeFile.c_str());
if (std::filesystem::exists(tempPath)) {
std::string tempPath = hex::format("{0}/{1}", dir.string().c_str(), includeFile.c_str());
if (fs::exists(tempPath)) {
includePath = tempPath;
break;
}

View File

@ -1,13 +1,12 @@
#include "helpers/plugin_manager.hpp"
#include <hex/helpers/logger.hpp>
#include <hex/helpers/paths.hpp>
#include <filesystem>
namespace hex {
namespace fs = std::filesystem;
// hex::plugin::<pluginName>::internal::initializePlugin()
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin{0}{1}8internal16initializePluginEv";
constexpr auto GetPluginNameSymbol = "_ZN3hex6plugin{0}{1}8internal13getPluginNameEv";
@ -84,13 +83,13 @@ namespace hex {
this->m_setImGuiContextFunction(ctx);
}
bool PluginManager::load(const std::string &pluginFolder) {
if (!std::filesystem::exists(pluginFolder))
bool PluginManager::load(const fs::path &pluginFolder) {
if (!fs::exists(pluginFolder))
return false;
PluginManager::s_pluginFolder = pluginFolder;
for (auto& pluginPath : std::filesystem::directory_iterator(pluginFolder)) {
for (auto& pluginPath : fs::directory_iterator(pluginFolder)) {
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug")
PluginManager::s_plugins.emplace_back(pluginPath.path().string());
}

View File

@ -25,7 +25,7 @@ namespace hex::init {
static bool checkForUpdates() {
hex::Net net;
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 200).get();
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get();
if (releases.code != 200)
return false;
@ -72,7 +72,7 @@ namespace hex::init {
for (auto path : paths) {
for (auto &folder : hex::getPath(path, true)) {
try {
std::filesystem::create_directories(folder);
fs::create_directories(folder);
} catch (...) {
result = false;
}
@ -92,10 +92,10 @@ namespace hex::init {
fonts = IM_NEW(ImFontAtlas)();
cfg = { };
std::string fontFile;
fs::path fontFile;
for (const auto &dir : hex::getPath(ImHexPath::Resources)) {
auto path = dir + "/font.ttf";
if (std::filesystem::exists(path)) {
auto path = dir / "font.ttf";
if (fs::exists(path)) {
fontFile = path;
break;
}
@ -146,7 +146,7 @@ namespace hex::init {
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = fontSize * SharedData::fontScale;
fonts->AddFontFromFileTTF(fontFile.c_str(), std::floor(fontSize * SharedData::fontScale), &cfg, ranges.Data); // Needs conversion to char for Windows
fonts->AddFontFromFileTTF(fontFile.string().c_str(), std::floor(fontSize * SharedData::fontScale), &cfg, ranges.Data); // Needs conversion to char for Windows
}
cfg.MergeMode = true;

View File

@ -237,7 +237,7 @@ namespace hex {
return;
for (const auto &path : hex::getPath(ImHexPath::Config)) {
if (ProjectFile::store((std::filesystem::path(path) / CrashBackupFileName).string()))
if (ProjectFile::store((fs::path(path) / CrashBackupFileName).string()))
break;
}
});
@ -247,7 +247,7 @@ namespace hex {
});
for (const auto &path : hex::getPath(ImHexPath::Config)) {
if (auto filePath = std::filesystem::path(path) / CrashBackupFileName; std::filesystem::exists(filePath)) {
if (auto filePath = fs::path(path) / CrashBackupFileName; fs::exists(filePath)) {
this->m_safetyBackupPath = filePath;
View::doLater([]{ ImGui::OpenPopup("hex.safety_backup.title"_lang); });
}
@ -478,14 +478,14 @@ namespace hex {
ProjectFile::markDirty();
ProjectFile::clearProjectFilePath();
std::filesystem::remove(this->m_safetyBackupPath);
fs::remove(this->m_safetyBackupPath);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5);
if (ImGui::Button("hex.safety_backup.delete"_lang, ImVec2(width / 3, 0))) {
std::filesystem::remove(this->m_safetyBackupPath);
fs::remove(this->m_safetyBackupPath);
ImGui::CloseCurrentPopup();
}
@ -630,7 +630,7 @@ namespace hex {
{
if (!SharedData::recentFilePaths.empty()) {
for (auto &path : SharedData::recentFilePaths) {
if (ImGui::BulletHyperlink(std::filesystem::path(path).filename().string().c_str())) {
if (ImGui::BulletHyperlink(fs::path(path).filename().string().c_str())) {
EventManager::post<RequestOpenFile>(path);
break;
}
@ -997,7 +997,7 @@ namespace hex {
static std::string iniFileName;
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
if (std::filesystem::exists(dir)) {
iniFileName = dir + "/interface.ini";
iniFileName = (dir / "interface.ini").string();
break;
}
}