From af184ed986350c3ddd476eead7495a3384bb6e04 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Fri, 2 Oct 2026 22:22:18 +1300 Subject: [PATCH] Read symbol files through QFile so paths past 260 characters work on Windows ElementsLocation::pugiXml() and the qet_directory name lookup opened files with pugixml's load_file(), which on Windows fails once the full path reaches MAX_PATH. QFile handles long paths, so exist() and the import succeeded while uuid(), the name, the informations and the thumbnail of the same symbol came back empty. Read the bytes with QFile and hand them to load_buffer(). Reported on #1178 as a false collision from qet.addElement. Co-Authored-By: Claude Opus 5.5 --- sources/ElementsCollection/elementslocation.cpp | 12 ++++++++++-- .../ElementsCollection/fileelementcollectionitem.cpp | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sources/ElementsCollection/elementslocation.cpp b/sources/ElementsCollection/elementslocation.cpp index 7c34f923a..0e8a94c7a 100644 --- a/sources/ElementsCollection/elementslocation.cpp +++ b/sources/ElementsCollection/elementslocation.cpp @@ -709,12 +709,20 @@ pugi::xml_document ElementsLocation::pugiXml() const #endif if (!m_project) { + //Read through QFile, not pugi's load_file(): on Windows load_file() + //fails once the full path reaches MAX_PATH (260 characters), while + //QFile handles long paths. + QFile file(m_file_system_path); + if (!file.open(QIODevice::ReadOnly)) { + return docu; + } + const QByteArray data = file.readAll(); #ifndef Q_OS_LINUX - if (docu.load_file(m_file_system_path.toStdWString().c_str())) { + if (docu.load_buffer(data.constData(), data.size())) { docu.save(m_string_stream); } #else - docu.load_file(m_file_system_path.toStdWString().c_str()); + docu.load_buffer(data.constData(), data.size()); #endif } else diff --git a/sources/ElementsCollection/fileelementcollectionitem.cpp b/sources/ElementsCollection/fileelementcollectionitem.cpp index 7b9d3ea98..805c3fc27 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.cpp +++ b/sources/ElementsCollection/fileelementcollectionitem.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -178,7 +179,12 @@ QString FileElementCollectionItem::localName() bool readable = false; QString str(fileSystemPath() % "/qet_directory"); pugi::xml_document docu; - if (docu.load_file(str.toStdWString().c_str())) + // QFile rather than pugi's load_file(), which fails on + // Windows once the full path reaches 260 characters. + QFile file(str); + const QByteArray data = file.open(QIODevice::ReadOnly) + ? file.readAll() : QByteArray(); + if (!data.isEmpty() && docu.load_buffer(data.constData(), data.size())) { if (QString(docu.document_element().name()) == "qet-directory")