Fix backslash interpretation in IconFile and Image statements

This commit is contained in:
Dan Paulat 2023-10-09 23:36:21 -05:00
parent c5a56680ea
commit 8326b2f2bf
3 changed files with 12 additions and 6 deletions

View file

@ -6,6 +6,7 @@
#include <execution> #include <execution>
#include <QDir>
#include <QUrl> #include <QUrl>
#include <boost/unordered/unordered_flat_map.hpp> #include <boost/unordered/unordered_flat_map.hpp>
@ -44,7 +45,8 @@ struct PlacefileIconInfo
{ {
// Resolve using base URL // Resolve using base URL
auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString)); auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString));
auto relativeUrl = QUrl(QString::fromStdString(iconFile->filename_)); auto relativeUrl = QUrl(QDir::fromNativeSeparators(
QString::fromStdString(iconFile->filename_)));
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString(); resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString();
} }

View file

@ -3,6 +3,7 @@
#include <scwx/qt/util/texture_atlas.hpp> #include <scwx/qt/util/texture_atlas.hpp>
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
#include <QDir>
#include <QUrl> #include <QUrl>
#include <boost/unordered/unordered_flat_map.hpp> #include <boost/unordered/unordered_flat_map.hpp>
@ -39,8 +40,9 @@ struct PlacefileImageInfo
{ {
// Resolve using base URL // Resolve using base URL
auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString)); auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString));
auto relativeUrl = QUrl(QString::fromStdString(imageFile)); auto relativeUrl =
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString(); QUrl(QDir::fromNativeSeparators(QString::fromStdString(imageFile)));
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString();
} }
void UpdateTextureInfo(); void UpdateTextureInfo();

View file

@ -765,8 +765,9 @@ PlacefileManager::Impl::LoadImageResources(
[&baseUrl](auto& iconFile) [&baseUrl](auto& iconFile)
{ {
// Resolve target URL relative to base URL // Resolve target URL relative to base URL
QUrl fileUrl = QString filePath =
QUrl(QString::fromStdString(iconFile->filename_)); QString::fromStdString(iconFile->filename_);
QUrl fileUrl = QUrl(QDir::fromNativeSeparators(filePath));
QUrl resolvedUrl = baseUrl.resolved(fileUrl); QUrl resolvedUrl = baseUrl.resolved(fileUrl);
return resolvedUrl.toString().toStdString(); return resolvedUrl.toString().toStdString();
@ -783,7 +784,8 @@ PlacefileManager::Impl::LoadImageResources(
std::static_pointer_cast<gr::Placefile::ImageDrawItem>(di) std::static_pointer_cast<gr::Placefile::ImageDrawItem>(di)
->imageFile_; ->imageFile_;
QUrl fileUrl = QUrl(QString::fromStdString(imageFile)); QString filePath = QString::fromStdString(imageFile);
QUrl fileUrl = QUrl(QDir::fromNativeSeparators(filePath));
QUrl resolvedUrl = baseUrl.resolved(fileUrl); QUrl resolvedUrl = baseUrl.resolved(fileUrl);
std::string urlString = resolvedUrl.toString().toStdString(); std::string urlString = resolvedUrl.toString().toStdString();