From f0b60cf166510436419a978c53c6b82c07a247e5 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:56:20 +0200 Subject: [PATCH] suggestions; use internally uppercase; fix; fullname --- client/lobby/SelectionTab.cpp | 21 +++++++++++++++------ lib/filesystem/ResourceID.cpp | 10 ++++++---- lib/filesystem/ResourceID.h | 4 ++++ lib/mapping/CMapInfo.cpp | 20 +++++++++++++++++--- lib/mapping/CMapInfo.h | 2 ++ 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index ec26af22f..bb0f6adc6 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -242,6 +242,7 @@ void SelectionTab::toggleMode() case ESelectionScreen::saveGame: parseSaves(getFiles("Saves/", EResType::SAVEGAME)); inputName->enable(); + inputName->activate(); restoreLastSelection(); break; @@ -347,7 +348,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition) if(!curItems[py]->isFolder) { - std::string text = boost::str(boost::format("{%1%}\r\n\r\n%2%:\r\n%3%") % curItems[py]->getName() % CGI->generaltexth->translate("vcmi.lobby.filename") % curItems[py]->fileURI); + std::string text = boost::str(boost::format("{%1%}\r\n\r\n%2%:\r\n%3%") % curItems[py]->getName() % CGI->generaltexth->translate("vcmi.lobby.filename") % curItems[py]->fullFileURI); if(curItems[py]->date != "") text += boost::str(boost::format("\r\n\r\n%1%:\r\n%2%") % CGI->generaltexth->translate("vcmi.lobby.creationDate") % curItems[py]->date); @@ -414,7 +415,7 @@ void SelectionTab::filter(int size, bool selectFirst) { if((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList) { - auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->fileURI); + auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->originalFileURI); if(parentExists) { @@ -618,8 +619,16 @@ int SelectionTab::getLine(const Point & clickPos) const void SelectionTab::selectFileName(std::string fname) { - auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(fname); - curFolder = baseFolder != "" ? baseFolder + "/" : ""; + boost::to_upper(fname); + + for(int i = (int)allItems.size() - 1; i >= 0; i--) + { + if(allItems[i]->fileURI == fname) + { + auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(allItems[i]->originalFileURI); + curFolder = baseFolder != "" ? baseFolder + "/" : ""; + } + } for(int i = (int)curItems.size() - 1; i >= 0; i--) { @@ -776,12 +785,12 @@ std::unordered_set SelectionTab::getFiles(std::string dirURI, int re boost::to_upper(dirURI); CResourceHandler::get()->updateFilteredFiles([&](const std::string & mount) { - return boost::algorithm::starts_with(boost::algorithm::to_upper_copy(mount), dirURI); + return boost::algorithm::starts_with(mount, dirURI); }); std::unordered_set ret = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident) { - return ident.getType() == resType && boost::algorithm::starts_with(boost::algorithm::to_upper_copy(ident.getName()), dirURI); + return ident.getType() == resType && boost::algorithm::starts_with(ident.getName(), dirURI); }); return ret; diff --git a/lib/filesystem/ResourceID.cpp b/lib/filesystem/ResourceID.cpp index 49fe24bba..401d89ef1 100644 --- a/lib/filesystem/ResourceID.cpp +++ b/lib/filesystem/ResourceID.cpp @@ -45,7 +45,7 @@ static inline EResType::Type readType(const std::string& name) return EResTypeHelper::getTypeFromExtension(FileInfo::GetExtension(name).to_string()); } -static inline std::string readName(std::string name, EResType::Type type) +static inline std::string readName(std::string name, bool uppercase) { const auto dotPos = name.find_last_of('.'); @@ -61,7 +61,7 @@ static inline std::string readName(std::string name, EResType::Type type) name.resize(dotPos); } - if(type != EResType::MAP && type != EResType::CAMPAIGN && type != EResType::SAVEGAME) + if(uppercase) toUpper(name); return name; @@ -76,12 +76,14 @@ ResourceID::ResourceID() ResourceID::ResourceID(std::string name_): type{readType(name_)}, - name{readName(std::move(name_), readType(name_))} + name{readName(name_, true)}, + originalName{readName(std::move(name_), false)} {} ResourceID::ResourceID(std::string name_, EResType::Type type_): type{type_}, - name{readName(std::move(name_), type_)} + name{readName(name_, true)}, + originalName{readName(std::move(name_), false)} {} #if 0 std::string ResourceID::getName() const diff --git a/lib/filesystem/ResourceID.h b/lib/filesystem/ResourceID.h index de29dec48..0e597bd74 100644 --- a/lib/filesystem/ResourceID.h +++ b/lib/filesystem/ResourceID.h @@ -99,6 +99,7 @@ public: } std::string getName() const {return name;} + std::string getOriginalName() const {return originalName;} EResType::Type getType() const {return type;} //void setName(std::string name); //void setType(EResType::Type type); @@ -112,6 +113,9 @@ private: /** Specifies the resource name. No extension so .pcx and .png can override each other, always in upper case. **/ std::string name; + + /** name in original case **/ + std::string originalName; }; /** diff --git a/lib/mapping/CMapInfo.cpp b/lib/mapping/CMapInfo.cpp index 734a80265..ee1e74a0f 100644 --- a/lib/mapping/CMapInfo.cpp +++ b/lib/mapping/CMapInfo.cpp @@ -43,7 +43,10 @@ void CMapInfo::mapInit(const std::string & fname) { fileURI = fname; CMapService mapService; - mapHeader = mapService.loadMapHeader(ResourceID(fname, EResType::MAP)); + ResourceID resource = ResourceID(fname, EResType::MAP); + originalFileURI = resource.getOriginalName(); + fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string(); + mapHeader = mapService.loadMapHeader(resource); countPlayers(); } @@ -55,9 +58,17 @@ void CMapInfo::saveInit(const ResourceID & file) mapHeader = std::make_unique(); lf >> *(mapHeader) >> scenarioOptionsOfSave; fileURI = file.getName(); + originalFileURI = file.getOriginalName(); + fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file)).string(); countPlayers(); std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file)); - date = std::asctime(std::localtime(&time)); + + std::tm tm = *std::localtime(&time); + std::stringstream s; + s.imbue(std::locale("")); + s << std::put_time(&tm, "%x %X"); + date = s.str(); + // We absolutely not need this data for lobby and server will read it from save // FIXME: actually we don't want them in CMapHeader! mapHeader->triggeredEvents.clear(); @@ -65,6 +76,9 @@ void CMapInfo::saveInit(const ResourceID & file) void CMapInfo::campaignInit() { + ResourceID resource = ResourceID(fileURI, EResType::CAMPAIGN); + originalFileURI = resource.getOriginalName(); + fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string(); campaign = CampaignHandler::getHeader(fileURI); } @@ -105,7 +119,7 @@ std::string CMapInfo::getNameForList() const { // TODO: this could be handled differently std::vector path; - boost::split(path, fileURI, boost::is_any_of("\\/")); + boost::split(path, originalFileURI, boost::is_any_of("\\/")); return path[path.size()-1]; } else diff --git a/lib/mapping/CMapInfo.h b/lib/mapping/CMapInfo.h index 5724988bd..219969c4a 100644 --- a/lib/mapping/CMapInfo.h +++ b/lib/mapping/CMapInfo.h @@ -28,6 +28,8 @@ public: std::unique_ptr campaign; //may be nullptr if scenario StartInfo * scenarioOptionsOfSave; // Options with which scenario has been started (used only with saved games) std::string fileURI; + std::string originalFileURI; + std::string fullFileURI; std::string date; int amountOfPlayersOnMap; int amountOfHumanControllablePlayers;