diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 13059ad0..266e9a9f 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -408,7 +408,7 @@ namespace Components { std::string hash; - for(int i = 0; i < ARRAYSIZE(Maps::UserMapFiles); ++i) + for (std::size_t i = 0; i < ARRAYSIZE(Maps::UserMapFiles); ++i) { std::string filePath = Utils::String::VA("usermaps/%s/%s%s", map.data(), map.data(), Maps::UserMapFiles[i]); if (Utils::IO::FileExists(filePath)) diff --git a/src/Utils/IO.cpp b/src/Utils/IO.cpp index d0522fd7..9b720ed7 100644 --- a/src/Utils/IO.cpp +++ b/src/Utils/IO.cpp @@ -68,7 +68,7 @@ namespace Utils return DeleteFileA(file.data()) == TRUE; } - size_t FileSize(const std::string& file) + std::size_t FileSize(const std::string& file) { if (FileExists(file)) { @@ -77,7 +77,7 @@ namespace Utils if (stream.good()) { stream.seekg(0, std::ios::end); - return static_cast(stream.tellg()); + return static_cast(stream.tellg()); } } @@ -89,21 +89,21 @@ namespace Utils return std::filesystem::create_directories(dir); } - bool DirectoryExists(const std::string& directory) + bool DirectoryExists(const std::filesystem::path& directory) { return std::filesystem::is_directory(directory); } - bool DirectoryIsEmpty(const std::string& directory) + bool DirectoryIsEmpty(const std::filesystem::path& directory) { return std::filesystem::is_empty(directory); } - std::vector ListFiles(const std::string& dir) + std::vector ListFiles(const std::filesystem::path& directory) { std::vector files; - for (auto& file : std::filesystem::directory_iterator(dir)) + for (auto& file : std::filesystem::directory_iterator(directory)) { files.push_back(file.path().generic_string()); } diff --git a/src/Utils/IO.hpp b/src/Utils/IO.hpp index 16c0198c..199a8e16 100644 --- a/src/Utils/IO.hpp +++ b/src/Utils/IO.hpp @@ -1,18 +1,15 @@ #pragma once -namespace Utils +namespace Utils::IO { - namespace IO - { - bool FileExists(const std::string& file); - bool WriteFile(const std::string& file, const std::string& data, bool append = false); - bool ReadFile(const std::string& file, std::string* data); - std::string ReadFile(const std::string& file); - bool RemoveFile(const std::string& file); - size_t FileSize(const std::string& file); - bool CreateDir(const std::string& dir); - bool DirectoryExists(const std::string& file); - bool DirectoryIsEmpty(const std::string& file); - std::vector ListFiles(const std::string& dir); - } + bool FileExists(const std::string& file); + bool WriteFile(const std::string& file, const std::string& data, bool append = false); + bool ReadFile(const std::string& file, std::string* data); + std::string ReadFile(const std::string& file); + bool RemoveFile(const std::string& file); + std::size_t FileSize(const std::string& file); + bool CreateDir(const std::string& dir); + bool DirectoryExists(const std::filesystem::path& file); + bool DirectoryIsEmpty(const std::filesystem::path& file); + std::vector ListFiles(const std::filesystem::path& directory); } diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index 178465dc..f7740ff5 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -2,14 +2,9 @@ namespace Utils { - Library Library::Load(const std::string& name) - { - return Library(LoadLibraryA(name.data())); - } - Library Library::Load(const std::filesystem::path& path) { - return Library::Load(path.generic_string()); + return Library(LoadLibraryA(path.generic_string().data())); } Library Library::GetByAddress(void* address) @@ -66,31 +61,34 @@ namespace Utils if (!this->isValid()) return {}; - auto path = this->getPath(); - const auto pos = path.find_last_of("/\\"); + const auto path = this->getPath(); + const auto generic_path = path.generic_string(); + const auto pos = generic_path.find_last_of("/\\"); if (pos == std::string::npos) - return path; + { + return generic_path; + } - return path.substr(pos + 1); + return generic_path.substr(pos + 1); } - std::string Library::getPath() const + std::filesystem::path Library::getPath() const { if (!this->isValid()) return {}; - char name[MAX_PATH] = {0}; - GetModuleFileNameA(this->module_, name, sizeof(name)); + wchar_t name[MAX_PATH] = {0}; + GetModuleFileNameW(this->module_, name, MAX_PATH); - return name; + return {name}; } - std::string Library::getFolder() const + std::filesystem::path Library::getFolder() const { if (!this->isValid()) return {}; - const auto path = std::filesystem::path(this->getPath()); + const auto path = this->getPath(); return path.parent_path().generic_string(); } diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index bd5eddf3..367d9d08 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -5,7 +5,6 @@ namespace Utils class Library { public: - static Library Load(const std::string& name); static Library Load(const std::filesystem::path& path); static Library GetByAddress(void* address); @@ -21,23 +20,22 @@ namespace Utils operator bool() const; operator HMODULE() const; - bool isValid() const; - HMODULE getModule() const; - std::string getName() const; - std::string getPath() const; - std::string getFolder() const; - std::uint8_t* getPtr() const; + [[nodiscard]] bool isValid() const; + [[nodiscard]] HMODULE getModule() const; + [[nodiscard]] std::string getName() const; + [[nodiscard]] std::filesystem::path getPath() const; + [[nodiscard]] std::filesystem::path getFolder() const; void free(); template - T getProc(const std::string& process) const + [[nodiscard]] T getProc(const std::string& process) const { if (!this->isValid()) T{}; return reinterpret_cast(GetProcAddress(this->module_, process.data())); } template - std::function get(const std::string& process) const + [[nodiscard]] std::function get(const std::string& process) const { if (!this->isValid()) return std::function(); return static_cast(this->getProc(process));