mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-07 04:04:14 +02:00
Merge pull request #1243 from ispyisail/fix/element-long-paths
Fix symbols in deep folders on Windows (paths of 260+ characters)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QStyle>
|
||||
@@ -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")
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlRecord>
|
||||
#include <QDir>
|
||||
#include <QDomDocument>
|
||||
#include <QFileInfo>
|
||||
#include <QFont>
|
||||
@@ -677,6 +678,17 @@ QString QetScriptApi::addElement(int folioIndex, const QString &locationPath, do
|
||||
const QString import_path = location.isFileSystem()
|
||||
? QStringLiteral("import/") + location.collectionPath(false)
|
||||
: location.collectionPath(false);
|
||||
// An element file that exists but cannot be read gives a null
|
||||
// uuid(), which the collision check below would misreport as "a
|
||||
// different element" -- say what actually went wrong instead.
|
||||
if (location.isFileSystem()
|
||||
&& location.pugiXml().document_element().empty()) {
|
||||
const QString file = QDir::toNativeSeparators(
|
||||
QFileInfo(location.fileSystemPath()).absoluteFilePath());
|
||||
log(QStringLiteral("qet.addElement: could not read element '%1' (file '%2', "
|
||||
"%3 characters)").arg(locationPath, file).arg(file.size()));
|
||||
return QString();
|
||||
}
|
||||
const ElementsLocation existing(import_path, m_project);
|
||||
if (existing.exist() && existing.uuid() != location.uuid()) {
|
||||
log(QStringLiteral("qet.addElement: '%1' would collide with a different element "
|
||||
|
||||
Reference in New Issue
Block a user