From 6f6b5ba04b8d814b84d853999830e381ab723e35 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 17 Jul 2022 17:54:06 +0400 Subject: [PATCH] Some refactoring --- components/fontloader/fontloader.cpp | 16 ++++++-------- components/misc/pathhelpers.hpp | 22 +++++++++++++++++++ components/myguiplatform/myguidatamanager.cpp | 9 ++++---- components/resource/stats.cpp | 2 +- files/CMakeLists.txt | 2 ++ files/data/CMakeLists.txt | 2 -- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/components/fontloader/fontloader.cpp b/components/fontloader/fontloader.cpp index ffd9d82555..200309e091 100644 --- a/components/fontloader/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -1,6 +1,5 @@ #include "fontloader.hpp" -#include #include #include #include @@ -199,10 +198,10 @@ namespace Gui void FontLoader::loadBitmapFonts(bool exportToFile) { - for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/")) + for (const auto& path : mVFS->getRecursiveDirectoryIterator("Fonts/")) { - if (Misc::getFileExtension(name) == "fnt") - loadBitmapFont(name, exportToFile); + if (Misc::getFileExtension(path) == "fnt") + loadBitmapFont(path, exportToFile); } } @@ -218,11 +217,10 @@ namespace Gui std::string oldDataPath = dataManager->getDataPath(""); dataManager->setResourcePath("fonts"); - for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/")) + for (const auto& path : mVFS->getRecursiveDirectoryIterator("Fonts/")) { - std::filesystem::path path = name; - if (Misc::getFileExtension(name) == "omwfont") - MyGUI::ResourceManager::getInstance().load(path.filename().string()); + if (Misc::getFileExtension(path) == "omwfont") + MyGUI::ResourceManager::getInstance().load(std::string(Misc::getFileName(path))); } dataManager->setResourcePath(oldDataPath); @@ -344,7 +342,7 @@ namespace Gui MyGUI::xml::Document xmlDocument; MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont"); - const std::string baseName = Misc::StringUtils::lowerCase(std::filesystem::path(mVFS->getAbsoluteFileName(fileName)).stem().string()); + std::string baseName(Misc::stemFile(fileName)); root->addAttribute("name", getInternalFontName(baseName)); MyGUI::xml::ElementPtr defaultHeight = root->createChild("Property"); diff --git a/components/misc/pathhelpers.hpp b/components/misc/pathhelpers.hpp index 88913a1f7b..ee6ba8e0d5 100644 --- a/components/misc/pathhelpers.hpp +++ b/components/misc/pathhelpers.hpp @@ -14,6 +14,28 @@ namespace Misc } return {}; } + + inline std::string_view getFileName(std::string_view path) + { + if (auto namePos = path.find_last_of("/\\"); namePos != std::string::npos) + { + path.remove_prefix(namePos + 1); + } + + return path; + } + + inline std::string_view stemFile(std::string_view path) + { + path = getFileName(path); + + if (auto extPos = path.find_last_of("."); extPos != std::string::npos) + { + path.remove_suffix(path.size() - extPos); + } + + return path; + } } #endif diff --git a/components/myguiplatform/myguidatamanager.cpp b/components/myguiplatform/myguidatamanager.cpp index 1eefa6b81d..87e20dbe85 100644 --- a/components/myguiplatform/myguidatamanager.cpp +++ b/components/myguiplatform/myguidatamanager.cpp @@ -22,10 +22,9 @@ MyGUI::IDataStream *DataManager::getData(const std::string &name) const { // Note: MyGUI is supposed to read/free input steam itself, // so copy data from VFS stream to the string stream and pass it to MyGUI. - Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "\\" + name); + Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "/" + name); std::istream* fileStream = streamPtr.get(); - std::unique_ptr dataStream; - dataStream.reset(new std::stringstream); + auto dataStream = std::make_unique(); *dataStream << fileStream->rdbuf(); return new MyGUI::DataStream(dataStream.release()); } @@ -37,7 +36,7 @@ void DataManager::freeData(MyGUI::IDataStream *data) bool DataManager::isDataExist(const std::string &name) const { - return mVfs->exists(mResourcePath + "\\" + name); + return mVfs->exists(mResourcePath + "/" + name); } void DataManager::setVfs(const VFS::Manager* vfs) @@ -61,7 +60,7 @@ const std::string &DataManager::getDataPath(const std::string &name) const if (!isDataExist(name)) return result; - result = mResourcePath + "\\" + name; + result = mResourcePath + "/" + name; return result; } diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index d578259033..84588d4ab9 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -30,7 +30,7 @@ static bool collectStatFrameRate = false; static bool collectStatUpdate = false; static bool collectStatEngine = false; -inline static std::string sFontName = "Fonts\\DejaVuLGCSansMono.ttf"; +static std::string sFontName = "Fonts/DejaVuLGCSansMono.ttf"; static void setupStatCollection() { diff --git a/files/CMakeLists.txt b/files/CMakeLists.txt index b7b4b4cd23..587c3fa1d3 100644 --- a/files/CMakeLists.txt +++ b/files/CMakeLists.txt @@ -1,3 +1,5 @@ add_subdirectory(shaders) add_subdirectory(data) add_subdirectory(lua_api) + +copy_resource_file("launcher/images/openmw.png" "${OPENMW_RESOURCES_ROOT}" "resources/openmw.png") diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt index 63df2f53b5..1130524e45 100644 --- a/files/data/CMakeLists.txt +++ b/files/data/CMakeLists.txt @@ -162,5 +162,3 @@ set(BUILTIN_DATA_FILES foreach (f ${BUILTIN_DATA_FILES}) copy_resource_file("${CMAKE_CURRENT_SOURCE_DIR}/${f}" "${OPENMW_RESOURCES_ROOT}" "resources/vfs/${f}") endforeach (f) - -copy_resource_file("../launcher/images/openmw.png" "${OPENMW_RESOURCES_ROOT}" "resources/openmw.png")