2022-03-04 11:36:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-03-22 09:34:26 +01:00
|
|
|
#include <optional>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <filesystem>
|
2022-03-04 11:44:11 +01:00
|
|
|
#include <functional>
|
2022-03-04 11:36:37 +01:00
|
|
|
|
|
|
|
#include <nfd.hpp>
|
|
|
|
|
|
|
|
namespace std::fs {
|
|
|
|
using namespace std::filesystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace hex::fs {
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool exists(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::exists(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool createDirectories(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::create_directories(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool isRegularFile(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::is_regular_file(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool copyFile(const std::fs::path &from, const std::fs::path &to, std::fs::copy_options = std::fs::copy_options::none) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::copy_file(from, to, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool isDirectory(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::is_directory(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline bool remove(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::remove(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-06-16 15:42:08 +02:00
|
|
|
[[maybe_unused]]
|
|
|
|
static inline bool removeAll(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
return std::filesystem::remove_all(path, error) && !error;
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
[[maybe_unused]]
|
2022-03-04 11:36:37 +01:00
|
|
|
static inline uintmax_t getFileSize(const std::fs::path &path) {
|
|
|
|
std::error_code error;
|
|
|
|
auto size = std::filesystem::file_size(path, error);
|
|
|
|
|
|
|
|
if (error) return 0;
|
|
|
|
else return size;
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:52:39 +01:00
|
|
|
bool isPathWritable(const std::fs::path &path);
|
2022-03-04 11:36:37 +01:00
|
|
|
|
|
|
|
enum class DialogMode
|
|
|
|
{
|
|
|
|
Open,
|
|
|
|
Save,
|
|
|
|
Folder
|
|
|
|
};
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath = {});
|
2022-03-04 11:36:37 +01:00
|
|
|
|
|
|
|
enum class ImHexPath
|
|
|
|
{
|
|
|
|
Patterns,
|
|
|
|
PatternsInclude,
|
|
|
|
Magic,
|
|
|
|
Python,
|
|
|
|
Plugins,
|
|
|
|
Yara,
|
|
|
|
Config,
|
|
|
|
Resources,
|
|
|
|
Constants,
|
|
|
|
Encodings,
|
|
|
|
Logs
|
|
|
|
};
|
|
|
|
|
2022-03-22 09:34:26 +01:00
|
|
|
std::optional<std::fs::path> getExecutablePath();
|
2022-03-04 11:36:37 +01:00
|
|
|
|
|
|
|
std::vector<std::fs::path> getDefaultPaths(ImHexPath path, bool listNonExisting = false);
|
|
|
|
|
|
|
|
}
|