mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
sys: std::filesystem -> fs
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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))) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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]{
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user