Use canonical file paths for filenames in model (#275)
This commit is contained in:
@@ -61,14 +61,24 @@ namespace glabels
|
||||
return;
|
||||
}
|
||||
|
||||
model->setFileName( fileName );
|
||||
model->clearModified();
|
||||
|
||||
QDomDocument doc;
|
||||
createDoc( doc, model );
|
||||
|
||||
QByteArray buffer = doc.toByteArray( 2 );
|
||||
file.write( buffer.data(), buffer.size() );
|
||||
|
||||
file.close();
|
||||
|
||||
QFileInfo fileInfo( fileName );
|
||||
if ( !fileInfo.exists() )
|
||||
{
|
||||
qWarning() << "Error:" << fileName << "does not exist after writing!";
|
||||
return;
|
||||
}
|
||||
auto canonName = fileInfo.canonicalFilePath();
|
||||
|
||||
model->setFileName( canonName );
|
||||
model->clearModified();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,11 +55,19 @@ namespace glabels
|
||||
Model*
|
||||
XmlLabelParser::readFile( const QString& fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
QFileInfo fileInfo( fileName );
|
||||
if ( !fileInfo.exists() )
|
||||
{
|
||||
qWarning() << fileName << "does not exist!";
|
||||
return nullptr;
|
||||
}
|
||||
auto canonName = fileInfo.canonicalFilePath();
|
||||
|
||||
QFile file( canonName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly ) )
|
||||
{
|
||||
qWarning() << "Error: Cannot read file" << fileName
|
||||
qWarning() << "Error: Cannot read file" << canonName
|
||||
<< ":" << file.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
@@ -71,6 +79,7 @@ namespace glabels
|
||||
int errorColumn;
|
||||
|
||||
QByteArray rawData = file.readAll();
|
||||
file.close();
|
||||
if ( ((rawData[0]&0xFF) == 0x1F) && ((rawData[1]&0xFF) == 0x8b) ) // gzip magic number 0x1F, 0x8B
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
@@ -105,7 +114,7 @@ namespace glabels
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return parseRootNode( root, fileName );
|
||||
return parseRootNode( root, canonName );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@ void TestXmlLabel::parser_3ReadFile()
|
||||
Model* model = XmlLabelParser::readFile( glabelsFileInfo.absoluteFilePath() );
|
||||
QVERIFY( model );
|
||||
|
||||
QCOMPARE( model->fileName(), glabelsFileInfo.filePath() );
|
||||
QCOMPARE( model->fileName(), glabelsFileInfo.canonicalFilePath() );
|
||||
|
||||
QCOMPARE( model->tmplate().brand(), QString( "Avery" ) );
|
||||
QCOMPARE( model->tmplate().part(), QString( "5395" ) );
|
||||
|
||||
Reference in New Issue
Block a user