sys: Bunch of cleanup, use fs::path instead of std::string for paths

This commit is contained in:
WerWolv
2022-01-16 01:51:31 +01:00
parent ed8ee35a86
commit a70ece7b9c
32 changed files with 206 additions and 292 deletions

View File

@@ -6,31 +6,23 @@
#include <string_view>
#include <vector>
namespace hex {
#include <hex/helpers/paths.hpp>
template<typename T>
struct SizeSorter {
bool operator() (const T& lhs, const T& rhs) const {
return lhs.size() < rhs.size();
}
};
namespace hex {
class EncodingFile {
public:
enum class Type {
Thingy,
CSV
Thingy
};
EncodingFile() = default;
EncodingFile(Type type, const std::string &path);
EncodingFile(Type type, const fs::path &path);
[[nodiscard]] std::pair<std::string_view, size_t> getEncodingFor(const std::vector<u8> &buffer) const;
[[nodiscard]] size_t getLongestSequence() const { return this->m_longestSequence; }
bool valid() const {
return this->m_valid;
}
[[nodiscard]] bool valid() const { return this->m_valid; }
private:
void parseThingyFile(std::ifstream &content);

View File

@@ -6,6 +6,8 @@
#include <string>
#include <vector>
#include <hex/helpers/paths.hpp>
#if defined(OS_MACOS)
#define off64_t off_t
#define fopen64 fopen
@@ -24,7 +26,7 @@ namespace hex {
Create
};
explicit File(const std::string &path, Mode mode);
explicit File(const fs::path &path, Mode mode);
File();
File(const File&) = delete;
File(File &&other) noexcept;
@@ -51,11 +53,11 @@ namespace hex {
void remove();
auto getHandle() { return this->m_file; }
const std::string& getPath() { return this->m_path; }
const fs::path& getPath() { return this->m_path; }
private:
FILE *m_file;
std::string m_path;
fs::path m_path;
};
}

View File

@@ -3,6 +3,8 @@
#include <string>
#include <string_view>
#include <hex/helpers/paths.hpp>
struct _object;
typedef struct _object PyObject;
@@ -14,12 +16,12 @@ namespace hex {
public:
LoaderScript() = delete;
static bool processFile(const std::string &scriptPath);
static bool processFile(const fs::path &scriptPath);
static void setFilePath(const std::string &filePath) { LoaderScript::s_filePath = filePath; }
static void setFilePath(const fs::path &filePath) { LoaderScript::s_filePath = filePath; }
static void setDataProvider(prv::Provider* provider) { LoaderScript::s_dataProvider = provider; }
private:
static inline std::string s_filePath;
static inline fs::path s_filePath;
static inline prv::Provider* s_dataProvider;
static PyObject* Py_getFilePath(PyObject *self, PyObject *args);

View File

@@ -16,8 +16,8 @@ namespace hex {
public:
ProjectFile() = delete;
static bool load(const std::string &filePath);
static bool store(std::string filePath = "");
static bool load(const fs::path &filePath);
static bool store(fs::path filePath = { });
[[nodiscard]] static bool hasUnsavedChanges() {
return ProjectFile::s_hasUnsavedChanged;
@@ -32,7 +32,7 @@ namespace hex {
EventManager::post<RequestChangeWindowTitle>(fs::path(getFilePath()).filename().string());
}
[[nodiscard]] static const std::string& getProjectFilePath() {
[[nodiscard]] static const fs::path& getProjectFilePath() {
return ProjectFile::s_currProjectFilePath;
}
@@ -41,14 +41,14 @@ namespace hex {
}
[[nodiscard]] static const std::string& getFilePath() {
[[nodiscard]] static const fs::path& getFilePath() {
return ProjectFile::s_filePath;
}
static void setFilePath(const std::string &filePath) {
static void setFilePath(const fs::path &filePath) {
ProjectFile::s_filePath = filePath;
EventManager::post<RequestChangeWindowTitle>(fs::path(filePath).filename().string());
EventManager::post<RequestChangeWindowTitle>(filePath.filename().string());
}
@@ -92,10 +92,10 @@ namespace hex {
}
private:
static std::string s_currProjectFilePath;
static fs::path s_currProjectFilePath;
static bool s_hasUnsavedChanged;
static std::string s_filePath;
static fs::path s_filePath;
static std::string s_pattern;
static Patches s_patches;
static std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;

View File

@@ -94,7 +94,7 @@ namespace hex {
static std::vector<ContentRegistry::DataFormatter::impl::Entry> dataFormatters;
static std::vector<ContentRegistry::FileHandler::impl::Entry> fileHandlers;
static std::list<std::string> recentFilePaths;
static std::list<fs::path> recentFilePaths;
static int mainArgc;
static char **mainArgv;

View File

@@ -3,6 +3,7 @@
#include <hex.hpp>
#include <hex/helpers/concepts.hpp>
#include <hex/helpers/paths.hpp>
#include <array>
#include <bit>
@@ -221,7 +222,7 @@ namespace hex {
Folder
};
void openFileBrowser(const std::string &title, DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::string)> &callback, const std::string &defaultPath = {});
void openFileBrowser(const std::string &title, DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(fs::path)> &callback, const std::string &defaultPath = {});
float float16ToFloat32(u16 float16);