mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
sys: Tons of long overdue cleanup
- std::string -> const std::string& where needed - Added a FileIO abstraction class - Fixed recent files not updating - Removed localization file from global include - Renamed lang to pattern_language/pl - Renamed EventFileDropped to RequestFileOpen
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace hex {
|
||||
@@ -22,10 +23,10 @@ namespace hex {
|
||||
};
|
||||
|
||||
EncodingFile() = default;
|
||||
EncodingFile(Type type, std::string_view path);
|
||||
EncodingFile(Type type, const std::string &path);
|
||||
|
||||
std::pair<std::string_view, size_t> getEncodingFor(const std::vector<u8> &buffer) const;
|
||||
size_t getLongestSequence() const { return this->m_longestSequence; }
|
||||
[[nodiscard]] std::pair<std::string_view, size_t> getEncodingFor(const std::vector<u8> &buffer) const;
|
||||
[[nodiscard]] size_t getLongestSequence() const { return this->m_longestSequence; }
|
||||
|
||||
private:
|
||||
void parseThingyFile(std::ifstream &content);
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace hex {
|
||||
public:
|
||||
LoaderScript() = delete;
|
||||
|
||||
static bool processFile(std::string_view scriptPath);
|
||||
static bool processFile(const std::string &scriptPath);
|
||||
|
||||
static void setFilePath(std::string_view filePath) { LoaderScript::s_filePath = filePath; }
|
||||
static void setFilePath(const std::string &filePath) { LoaderScript::s_filePath = filePath; }
|
||||
static void setDataProvider(prv::Provider* provider) { LoaderScript::s_dataProvider = provider; }
|
||||
private:
|
||||
static inline std::string s_filePath;
|
||||
|
||||
@@ -15,15 +15,15 @@ namespace hex {
|
||||
|
||||
class Plugin {
|
||||
public:
|
||||
Plugin(std::string_view path);
|
||||
Plugin(const std::string &path);
|
||||
Plugin(const Plugin&) = delete;
|
||||
Plugin(Plugin &&other) noexcept;
|
||||
~Plugin();
|
||||
|
||||
void initializePlugin() const;
|
||||
std::string getPluginName() const;
|
||||
std::string getPluginAuthor() const;
|
||||
std::string getPluginDescription() const;
|
||||
[[nodiscard]] std::string getPluginName() const;
|
||||
[[nodiscard]] std::string getPluginAuthor() const;
|
||||
[[nodiscard]] std::string getPluginDescription() const;
|
||||
void setImGuiContext(ImGuiContext *ctx) const;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace hex {
|
||||
SetImGuiContextFunc m_setImGuiContextFunction = nullptr;
|
||||
|
||||
template<typename T>
|
||||
auto getPluginFunction(std::string_view pluginName, std::string_view symbol) {
|
||||
auto getPluginFunction(const std::string &pluginName, const std::string &symbol) {
|
||||
auto symbolName = hex::format(symbol.data(), pluginName.length(), pluginName.data());
|
||||
return reinterpret_cast<T>(dlsym(this->m_handle, symbolName.c_str()));
|
||||
};
|
||||
@@ -53,7 +53,7 @@ namespace hex {
|
||||
public:
|
||||
PluginManager() = delete;
|
||||
|
||||
static bool load(std::string_view pluginFolder);
|
||||
static bool load(const std::string &pluginFolder);
|
||||
static void unload();
|
||||
static void reload();
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace hex {
|
||||
public:
|
||||
ProjectFile() = delete;
|
||||
|
||||
static bool load(std::string_view filePath);
|
||||
static bool store(std::string_view filePath = "");
|
||||
static bool load(const std::string &filePath);
|
||||
static bool store(std::string filePath = "");
|
||||
|
||||
[[nodiscard]] static bool hasUnsavedChanges() {
|
||||
return ProjectFile::s_hasUnsavedChanged;
|
||||
@@ -32,7 +32,7 @@ namespace hex {
|
||||
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(getFilePath()).filename().string());
|
||||
}
|
||||
|
||||
[[nodiscard]] static std::string getProjectFilePath() {
|
||||
[[nodiscard]] static const std::string& getProjectFilePath() {
|
||||
return ProjectFile::s_currProjectFilePath;
|
||||
}
|
||||
|
||||
@@ -41,22 +41,22 @@ namespace hex {
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] static std::string getFilePath() {
|
||||
[[nodiscard]] static const std::string& getFilePath() {
|
||||
return ProjectFile::s_filePath;
|
||||
}
|
||||
|
||||
static void setFilePath(std::string_view filePath) {
|
||||
static void setFilePath(const std::string &filePath) {
|
||||
ProjectFile::s_filePath = filePath;
|
||||
|
||||
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(filePath).filename().string());
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] static std::string getPattern() {
|
||||
[[nodiscard]] static const std::string& getPattern() {
|
||||
return ProjectFile::s_pattern;
|
||||
}
|
||||
|
||||
static void setPattern(std::string_view pattern) {
|
||||
static void setPattern(const std::string &pattern) {
|
||||
markDirty();
|
||||
ProjectFile::s_pattern = pattern;
|
||||
}
|
||||
@@ -82,11 +82,11 @@ namespace hex {
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] static const std::string_view getDataProcessorContent() {
|
||||
[[nodiscard]] static const std::string& getDataProcessorContent() {
|
||||
return ProjectFile::s_dataProcessorContent;
|
||||
}
|
||||
|
||||
static void setDataProcessorContent(std::string_view json) {
|
||||
static void setDataProcessorContent(const std::string &json) {
|
||||
markDirty();
|
||||
ProjectFile::s_dataProcessorContent = json;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ struct GLFWwindow;
|
||||
|
||||
namespace hex::init {
|
||||
|
||||
using TaskFunction = std::function<bool()>;
|
||||
|
||||
class WindowSplash {
|
||||
public:
|
||||
WindowSplash(int &argc, char **&argv);
|
||||
@@ -17,7 +19,7 @@ namespace hex::init {
|
||||
|
||||
bool loop();
|
||||
|
||||
void addStartupTask(std::string_view taskName, const std::function<bool()> &task) {
|
||||
void addStartupTask(const std::string &taskName, const TaskFunction &task) {
|
||||
this->m_tasks.emplace_back(taskName, task);
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ namespace hex::init {
|
||||
|
||||
std::future<bool> processTasksAsync();
|
||||
|
||||
std::vector<std::pair<std::string, std::function<bool()>>> m_tasks;
|
||||
std::vector<std::pair<std::string, TaskFunction>> m_tasks;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace hex::prv {
|
||||
|
||||
class FileProvider : public Provider {
|
||||
public:
|
||||
explicit FileProvider(std::string_view path);
|
||||
explicit FileProvider(std::string path);
|
||||
~FileProvider() override;
|
||||
|
||||
bool isAvailable() override;
|
||||
@@ -42,20 +42,20 @@ namespace hex::prv {
|
||||
|
||||
private:
|
||||
#if defined(OS_WINDOWS)
|
||||
HANDLE m_file;
|
||||
HANDLE m_mapping;
|
||||
HANDLE m_file = INVALID_HANDLE_VALUE;
|
||||
HANDLE m_mapping = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
int m_file;
|
||||
int m_file = -1;
|
||||
#endif
|
||||
|
||||
std::string m_path;
|
||||
void *m_mappedFile;
|
||||
size_t m_fileSize;
|
||||
void *m_mappedFile = nullptr;
|
||||
size_t m_fileSize = 0;
|
||||
|
||||
bool m_fileStatsValid = false;
|
||||
struct stat m_fileStats = { 0 };
|
||||
|
||||
bool m_readable, m_writable;
|
||||
bool m_readable = false, m_writable = false;
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace hex {
|
||||
this->m_focusInputTextBox = true;
|
||||
}
|
||||
|
||||
std::vector<CommandResult> getCommandResults(std::string_view command);
|
||||
std::vector<CommandResult> getCommandResults(const std::string &command);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace hex {
|
||||
void processNodes();
|
||||
|
||||
std::string saveNodes();
|
||||
void loadNodes(std::string_view data);
|
||||
void loadNodes(const std::string &data);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -57,18 +57,18 @@ namespace hex {
|
||||
void drawGotoPopup();
|
||||
void drawEditPopup();
|
||||
|
||||
bool createFile(std::string_view path);
|
||||
void openFile(std::string_view path);
|
||||
bool saveToFile(std::string_view path, const std::vector<u8>& data);
|
||||
bool loadFromFile(std::string_view path, std::vector<u8>& data);
|
||||
bool createFile(const std::string &path);
|
||||
void openFile(const std::string &path);
|
||||
bool saveToFile(const std::string &path, const std::vector<u8>& data);
|
||||
bool loadFromFile(const std::string &path, std::vector<u8>& data);
|
||||
|
||||
enum class Language { C, Cpp, CSharp, Rust, Python, Java, JavaScript };
|
||||
void copyBytes();
|
||||
void pasteBytes();
|
||||
void copyString();
|
||||
void copyLanguageArray(Language language);
|
||||
void copyHexView();
|
||||
void copyHexViewHTML();
|
||||
void copyBytes() const;
|
||||
void pasteBytes() const;
|
||||
void copyString() const;
|
||||
void copyLanguageArray(Language language) const;
|
||||
void copyHexView() const;
|
||||
void copyHexViewHTML() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace hex {
|
||||
void drawMenu() override;
|
||||
|
||||
private:
|
||||
std::vector<lang::PatternData*> m_sortedPatternData;
|
||||
std::vector<pl::PatternData*> m_sortedPatternData;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
#include <hex/lang/evaluator.hpp>
|
||||
#include <hex/lang/pattern_language.hpp>
|
||||
#include <hex/pattern_language/evaluator.hpp>
|
||||
#include <hex/pattern_language/pattern_language.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
@@ -26,16 +26,16 @@ namespace hex {
|
||||
void drawContent() override;
|
||||
|
||||
private:
|
||||
lang::PatternLanguage *m_patternLanguageRuntime;
|
||||
pl::PatternLanguage *m_patternLanguageRuntime;
|
||||
std::vector<std::string> m_possiblePatternFiles;
|
||||
int m_selectedPatternFile = 0;
|
||||
bool m_runAutomatically = false;
|
||||
bool m_evaluatorRunning = false;
|
||||
|
||||
TextEditor m_textEditor;
|
||||
std::vector<std::pair<lang::LogConsole::Level, std::string>> m_console;
|
||||
std::vector<std::pair<pl::LogConsole::Level, std::string>> m_console;
|
||||
|
||||
void loadPatternFile(std::string_view path);
|
||||
void loadPatternFile(const std::string &path);
|
||||
void clearPatternData();
|
||||
void parsePattern(char *buffer);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user