sys: Moved more functions to libwolv

This commit is contained in:
WerWolv
2023-03-12 18:43:05 +01:00
parent 0dafb3d230
commit fb2e668589
22 changed files with 56 additions and 97 deletions

View File

@@ -6,6 +6,8 @@
#include <hex/helpers/utils.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <wolv/utils/string.hpp>
#include <bitset>
#include <filesystem>
@@ -259,12 +261,12 @@ namespace hex::plugin::builtin {
}
std::string DiskProvider::getName() const {
return hex::toUTF8String(this->m_path);
return wolv::util::toUTF8String(this->m_path);
}
std::vector<std::pair<std::string, std::string>> DiskProvider::getDataDescription() const {
return {
{ "hex.builtin.provider.disk.selected_disk"_lang, hex::toUTF8String(this->m_path) },
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(this->m_path) },
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(this->m_diskSize) },
{ "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(this->m_sectorSize) }
};
@@ -341,7 +343,7 @@ namespace hex::plugin::builtin {
}
nlohmann::json DiskProvider::storeSettings(nlohmann::json settings) const {
settings["path"] = hex::toUTF8String(this->m_path);
settings["path"] = wolv::util::toUTF8String(this->m_path);
return Provider::storeSettings(settings);
}
@@ -365,7 +367,7 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> DiskProvider::queryInformation(const std::string &category, const std::string &argument) {
if (category == "file_path")
return hex::toUTF8String(this->m_path);
return wolv::util::toUTF8String(this->m_path);
else if (category == "sector_size")
return this->m_sectorSize;
else

View File

@@ -9,6 +9,8 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <wolv/utils/string.hpp>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {
@@ -169,13 +171,13 @@ namespace hex::plugin::builtin {
}
std::string FileProvider::getName() const {
return hex::toUTF8String(this->m_path.filename());
return wolv::util::toUTF8String(this->m_path.filename());
}
std::vector<std::pair<std::string, std::string>> FileProvider::getDataDescription() const {
std::vector<std::pair<std::string, std::string>> result;
result.emplace_back("hex.builtin.provider.file.path"_lang, hex::toUTF8String(this->m_path));
result.emplace_back("hex.builtin.provider.file.path"_lang, wolv::util::toUTF8String(this->m_path));
result.emplace_back("hex.builtin.provider.file.size"_lang, hex::toByteString(this->getActualSize()));
if (this->m_fileStats.has_value()) {
@@ -189,11 +191,11 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> FileProvider::queryInformation(const std::string &category, const std::string &argument) {
if (category == "file_path")
return hex::toUTF8String(this->m_path);
return wolv::util::toUTF8String(this->m_path);
else if (category == "file_name")
return hex::toUTF8String(this->m_path.filename());
return wolv::util::toUTF8String(this->m_path.filename());
else if (category == "file_extension")
return hex::toUTF8String(this->m_path.extension());
return wolv::util::toUTF8String(this->m_path.extension());
else if (category == "creation_time")
return this->m_fileStats->st_ctime;
else if (category == "access_time")
@@ -253,9 +255,9 @@ namespace hex::plugin::builtin {
nlohmann::json FileProvider::storeSettings(nlohmann::json settings) const {
std::string path;
if (auto projectPath = ProjectFile::getPath(); !projectPath.empty())
path = hex::toUTF8String(std::fs::proximate(this->m_path, projectPath.parent_path()));
path = wolv::util::toUTF8String(std::fs::proximate(this->m_path, projectPath.parent_path()));
if (path.empty())
path = hex::toUTF8String(this->m_path);
path = wolv::util::toUTF8String(this->m_path);
settings["path"] = path;

View File

@@ -10,6 +10,7 @@
#include <nlohmann/json.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/string.hpp>
namespace hex::plugin::builtin {
@@ -222,7 +223,7 @@ namespace hex::plugin::builtin {
}
[[nodiscard]] std::string IntelHexProvider::getName() const {
return hex::format("hex.builtin.provider.intel_hex.name"_lang, hex::toUTF8String(this->m_sourceFilePath.filename()));
return hex::format("hex.builtin.provider.intel_hex.name"_lang, wolv::util::toUTF8String(this->m_sourceFilePath.filename()));
}
bool IntelHexProvider::handleFilePicker() {
@@ -274,7 +275,7 @@ namespace hex::plugin::builtin {
}
nlohmann::json IntelHexProvider::storeSettings(nlohmann::json settings) const {
settings["path"] = hex::toUTF8String(this->m_sourceFilePath);
settings["path"] = wolv::util::toUTF8String(this->m_sourceFilePath);
return Provider::storeSettings(settings);
}

View File

@@ -7,6 +7,7 @@
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/utils/string.hpp>
namespace hex::plugin::builtin {
@@ -199,7 +200,7 @@ namespace hex::plugin::builtin {
}
[[nodiscard]] std::string MotorolaSRECProvider::getName() const {
return hex::format("hex.builtin.provider.motorola_srec.name"_lang, hex::toUTF8String(this->m_sourceFilePath.filename()));
return hex::format("hex.builtin.provider.motorola_srec.name"_lang, wolv::util::toUTF8String(this->m_sourceFilePath.filename()));
}
bool MotorolaSRECProvider::handleFilePicker() {

View File

@@ -402,7 +402,7 @@ namespace hex::plugin::builtin {
if (ImGui::IconButton(ICON_VS_FOLDER_OPENED, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
return fs::openFileBrowser(fs::DialogMode::Open, { { "TTF Font", "ttf" }, { "OTF Font", "otf" } },
[&](const std::fs::path &path) {
fontPath = hex::toUTF8String(path);
fontPath = wolv::util::toUTF8String(path);
setting = fontPath;
});
}
@@ -461,7 +461,7 @@ namespace hex::plugin::builtin {
} else {
for (size_t n = 0; n < userFolders.size(); n++) {
const bool isSelected = (currentItemIndex == n);
if (ImGui::Selectable(hex::toUTF8String(userFolders.at(n)).c_str(), isSelected)) { currentItemIndex = n; }
if (ImGui::Selectable(wolv::util::toUTF8String(userFolders.at(n)).c_str(), isSelected)) { currentItemIndex = n; }
if (isSelected) { ImGui::SetItemDefaultFocus(); }
}
ImGui::EndListBox();
@@ -576,7 +576,7 @@ namespace hex::plugin::builtin {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Resources)) {
auto path = dir / "font.ttf";
if (wolv::io::fs::exists(path)) {
log::info("Loading custom front from {}", hex::toUTF8String(path));
log::info("Loading custom front from {}", wolv::util::toUTF8String(path));
fontFile = path;
break;

View File

@@ -619,7 +619,7 @@ namespace hex::plugin::builtin {
try {
auto json = nlohmann::json::parse(response.body);
links.push_back({
hex::toUTF8String(currFile.filename()),
wolv::util::toUTF8String(currFile.filename()),
json["data"]["file"]["url"]["short"],
json["data"]["file"]["metadata"]["size"]["readable"]
});
@@ -974,7 +974,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginListBox("##files", { -FLT_MIN, 10 * ImGui::GetTextLineHeightWithSpacing() })) {
u32 index = 0;
for (auto &file : files) {
if (ImGui::Selectable(hex::toUTF8String(file).c_str(), index == selectedIndex))
if (ImGui::Selectable(wolv::util::toUTF8String(file).c_str(), index == selectedIndex))
selectedIndex = index;
index++;
}
@@ -1064,7 +1064,7 @@ namespace hex::plugin::builtin {
wolv::io::File input(file, wolv::io::File::Mode::Read);
if (!input.isValid()) {
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, hex::toUTF8String(file)));
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, wolv::util::toUTF8String(file)));
return;
}

View File

@@ -150,7 +150,7 @@ namespace hex::plugin::builtin {
ImGui::PushID(index);
bool selected = s_selectableFileIndices.contains(index);
if (ImGui::Selectable(hex::toUTF8String(path.filename()).c_str(), selected)) {
if (ImGui::Selectable(wolv::util::toUTF8String(path.filename()).c_str(), selected)) {
if (!s_selectableFileMultiple) {
s_selectableFileIndices.clear();
s_selectableFileIndices.insert(index);

View File

@@ -172,9 +172,9 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
for (auto &path : fs::getDefaultPaths(type, true)){
if(wolv::io::fs::isDirectory(path)){
ImGui::TextUnformatted(hex::toUTF8String(path).c_str());
ImGui::TextUnformatted(wolv::util::toUTF8String(path).c_str());
}else{
ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), hex::toUTF8String(path).c_str());
ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), wolv::util::toUTF8String(path).c_str());
}
}
}

View File

@@ -4,6 +4,8 @@
#include <hex/helpers/logger.hpp>
#include <hex/helpers/utils.hpp>
#include <wolv/utils/string.hpp>
#include <fstream>
#include <filesystem>
#include <nlohmann/json.hpp>
@@ -54,7 +56,7 @@ namespace hex::plugin::builtin {
this->m_constants.push_back(constant);
}
} catch (...) {
log::error("Failed to parse constants file {}", hex::toUTF8String(file.path()));
log::error("Failed to parse constants file {}", wolv::util::toUTF8String(file.path()));
continue;
}
}

View File

@@ -506,13 +506,13 @@ namespace hex::plugin::builtin {
entries.resize(this->m_possiblePatternFiles.size());
for (u32 i = 0; i < entries.size(); i++) {
entries[i] = hex::toUTF8String(this->m_possiblePatternFiles[i].filename());
entries[i] = wolv::util::toUTF8String(this->m_possiblePatternFiles[i].filename());
}
if (ImGui::BeginListBox("##patterns_accept", ImVec2(-FLT_MIN, 0))) {
u32 index = 0;
for (auto &path : this->m_possiblePatternFiles) {
if (ImGui::Selectable(hex::toUTF8String(path.filename()).c_str(), index == this->m_selectedPatternFile))
if (ImGui::Selectable(wolv::util::toUTF8String(path.filename()).c_str(), index == this->m_selectedPatternFile))
this->m_selectedPatternFile = index;
index++;
}

View File

@@ -80,8 +80,8 @@ namespace hex::plugin::builtin {
auto &extraData = ProviderExtraData::get(provider).yara;
for (auto &[name, path] : extraData.rules) {
data["rules"].push_back({
{ "name", hex::toUTF8String(name) },
{ "path", hex::toUTF8String(path) }
{ "name", wolv::util::toUTF8String(name) },
{ "path", wolv::util::toUTF8String(path) }
});
}
@@ -109,7 +109,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginListBox("##rules", ImVec2(-FLT_MIN, ImGui::GetTextLineHeightWithSpacing() * 5))) {
for (u32 i = 0; i < rules.size(); i++) {
const bool selected = (this->m_selectedRule == i);
if (ImGui::Selectable(hex::toUTF8String(rules[i].first).c_str(), selected)) {
if (ImGui::Selectable(wolv::util::toUTF8String(rules[i].first).c_str(), selected)) {
this->m_selectedRule = i;
}
}
@@ -264,7 +264,7 @@ namespace hex::plugin::builtin {
yr_compiler_destroy(compiler);
};
auto currFilePath = hex::toUTF8String(wolv::io::fs::toShortPath(filePath));
auto currFilePath = wolv::util::toUTF8String(wolv::io::fs::toShortPath(filePath));
yr_compiler_set_include_callback(
compiler,