1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-13 01:20:34 +02:00

keep ext of originalName of ResourcePath so that it can safely reconstruct

This commit is contained in:
nick huang
2024-10-30 05:42:08 +08:00
parent 3a45e6dae1
commit d0f855b68b
5 changed files with 17 additions and 15 deletions

View File

@ -178,10 +178,10 @@ void AssetGenerator::createCombatUnitNumberWindow()
if(CResourceHandler::get()->existsResource(savePathDefault)) // overridden by mod, no generation if(CResourceHandler::get()->existsResource(savePathDefault)) // overridden by mod, no generation
return; return;
if(!CResourceHandler::get("local")->createResource(savePathDefault.getOriginalName() + ".png") || if(!CResourceHandler::get("local")->createResource(savePathDefault.getOriginalName()) ||
!CResourceHandler::get("local")->createResource(savePathNeutral.getOriginalName() + ".png") || !CResourceHandler::get("local")->createResource(savePathNeutral.getOriginalName()) ||
!CResourceHandler::get("local")->createResource(savePathPositive.getOriginalName() + ".png") || !CResourceHandler::get("local")->createResource(savePathPositive.getOriginalName()) ||
!CResourceHandler::get("local")->createResource(savePathNegative.getOriginalName() + ".png")) !CResourceHandler::get("local")->createResource(savePathNegative.getOriginalName()))
return; return;
auto locator = ImageLocator(ImagePath::builtin("CMNUMWIN")); auto locator = ImageLocator(ImagePath::builtin("CMNUMWIN"));

View File

@ -155,11 +155,11 @@ CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
if(settings["lobby"]["mapPreview"].Bool() && p.tabType != ESelectionScreen::campaignList) if(settings["lobby"]["mapPreview"].Bool() && p.tabType != ESelectionScreen::campaignList)
{ {
ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); ResourcePath res = ResourcePath(p.resource.getOriginalName(), EResType::MAP);
std::unique_ptr<CMap> campaignMap = nullptr; std::unique_ptr<CMap> campaignMap = nullptr;
if(p.tabType != ESelectionScreen::newGame && config["variables"]["mapPreviewForSaves"].Bool()) if(p.tabType != ESelectionScreen::newGame && config["variables"]["mapPreviewForSaves"].Bool())
{ {
CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::SAVEGAME)), ESerializationVersion::MINIMAL); CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getOriginalName(), EResType::SAVEGAME)), ESerializationVersion::MINIMAL);
lf.checkMagicBytes(SAVEGAME_MAGIC); lf.checkMagicBytes(SAVEGAME_MAGIC);
auto mapHeader = std::make_unique<CMapHeader>(); auto mapHeader = std::make_unique<CMapHeader>();
@ -196,7 +196,8 @@ CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
{ {
if(p.date.empty()) if(p.date.empty())
{ {
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), p.tabType == ESelectionScreen::campaignList ? EResType::CAMPAIGN : EResType::MAP))); std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getOriginalName(),
p.tabType == ESelectionScreen::campaignList ? EResType::CAMPAIGN : EResType::MAP)));
w->setText(TextOperations::getFormattedDateTimeLocal(time)); w->setText(TextOperations::getFormattedDateTimeLocal(time));
} }
else else

View File

@ -26,7 +26,8 @@ static inline EResType readType(const std::string& name)
return EResTypeHelper::getTypeFromExtension(FileInfo::GetExtension(name).to_string()); return EResTypeHelper::getTypeFromExtension(FileInfo::GetExtension(name).to_string());
} }
static inline std::string readName(std::string name, bool uppercase) static inline std::string readName(std::string name, bool uppercase, bool chopExt = true);
static inline std::string readName(std::string name, bool uppercase, bool chopExt)
{ {
const auto dotPos = name.find_last_of('.'); const auto dotPos = name.find_last_of('.');
@ -38,7 +39,7 @@ static inline std::string readName(std::string name, bool uppercase)
if((delimPos == std::string::npos || delimPos < dotPos) && dotPos != std::string::npos) if((delimPos == std::string::npos || delimPos < dotPos) && dotPos != std::string::npos)
{ {
auto type = EResTypeHelper::getTypeFromExtension(name.substr(dotPos)); auto type = EResTypeHelper::getTypeFromExtension(name.substr(dotPos));
if(type != EResType::OTHER) if(type != EResType::OTHER && chopExt)
name.resize(dotPos); name.resize(dotPos);
} }
@ -51,19 +52,19 @@ static inline std::string readName(std::string name, bool uppercase)
ResourcePath::ResourcePath(const std::string & name_): ResourcePath::ResourcePath(const std::string & name_):
type(readType(name_)), type(readType(name_)),
name(readName(name_, true)), name(readName(name_, true)),
originalName(readName(name_, false)) originalName(readName(name_, false, false))
{} {}
ResourcePath::ResourcePath(const std::string & name_, EResType type_): ResourcePath::ResourcePath(const std::string & name_, EResType type_):
type(type_), type(type_),
name(readName(name_, true)), name(readName(name_, true)),
originalName(readName(name_, false)) originalName(readName(name_, false, false))
{} {}
ResourcePath::ResourcePath(const JsonNode & name, EResType type): ResourcePath::ResourcePath(const JsonNode & name, EResType type):
type(type), type(type),
name(readName(name.String(), true)), name(readName(name.String(), true)),
originalName(readName(name.String(), false)) originalName(readName(name.String(), false, false))
{ {
} }
@ -76,7 +77,7 @@ void ResourcePath::serializeJson(JsonSerializeFormat & handler)
if (node.isString()) if (node.isString())
{ {
name = readName(node.String(), true); name = readName(node.String(), true);
originalName = readName(node.String(), false); originalName = readName(node.String(), false, false);
return; return;
} }
} }

View File

@ -38,7 +38,7 @@ static JsonNode loadModSettings(const JsonPath & path)
return JsonNode(path); return JsonNode(path);
} }
// Probably new install. Create initial configuration // Probably new install. Create initial configuration
CResourceHandler::get("local")->createResource(path.getOriginalName() + ".json"); CResourceHandler::get("local")->createResource(path.getOriginalName());
return JsonNode(); return JsonNode();
} }

View File

@ -111,7 +111,7 @@ TEST(MapManager, DrawTerrain_View)
{ {
try try
{ {
const ResourcePath testMap("test/TerrainViewTest", EResType::MAP); const ResourcePath testMap("test/TerrainViewTest.h3m", EResType::MAP);
// Load maps and json config // Load maps and json config
CMapService mapService; CMapService mapService;
const auto originalMap = mapService.loadMap(testMap, nullptr); const auto originalMap = mapService.loadMap(testMap, nullptr);