|
|
@ -47,7 +47,8 @@ UBImportCFF::~UBImportCFF() |
|
|
|
|
|
|
|
|
|
|
|
QStringList UBImportCFF::supportedExtentions() |
|
|
|
QStringList UBImportCFF::supportedExtentions() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return QStringList("iwb"); |
|
|
|
// return QStringList("iwb");
|
|
|
|
|
|
|
|
return QStringList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,8 +125,7 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QuaZip zip(pZipFile.fileName()); |
|
|
|
QuaZip zip(pZipFile.fileName()); |
|
|
|
|
|
|
|
|
|
|
|
if(!zip.open(QuaZip::mdUnzip)) |
|
|
|
if(!zip.open(QuaZip::mdUnzip)) { |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
@ -139,67 +139,48 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
|
|
|
QString documentRootFolder; |
|
|
|
QString documentRootFolder; |
|
|
|
int tmpNumber = 0; |
|
|
|
int tmpNumber = 0; |
|
|
|
QDir rootDir; |
|
|
|
QDir rootDir; |
|
|
|
while (true) |
|
|
|
while (true) { |
|
|
|
{ |
|
|
|
|
|
|
|
QString tempPath = QString("%1/sank%2.%3") |
|
|
|
QString tempPath = QString("%1/sank%2.%3") |
|
|
|
.arg(pDir) |
|
|
|
.arg(pDir) |
|
|
|
.arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm")) |
|
|
|
.arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm")) |
|
|
|
.arg(tmpNumber); |
|
|
|
.arg(tmpNumber); |
|
|
|
if (!rootDir.exists(tempPath)) |
|
|
|
if (!rootDir.exists(tempPath)) { |
|
|
|
{ |
|
|
|
|
|
|
|
documentRootFolder = tempPath; |
|
|
|
documentRootFolder = tempPath; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
tmpNumber++; |
|
|
|
tmpNumber++; |
|
|
|
if (tmpNumber == 100000) |
|
|
|
if (tmpNumber == 100000) { |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Failed to create temporary directory for iwb file"; |
|
|
|
qWarning() << "Import failed. Failed to create temporary directory for iwb file"; |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!rootDir.mkdir(documentRootFolder)) { |
|
|
|
if (!rootDir.mkdir(documentRootFolder)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Couse: failed to create temp folder for cff package"; |
|
|
|
qWarning() << "Import failed. Couse: failed to create temp folder for cff package"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// first we search the metadata.rdf to check the document properties
|
|
|
|
QStringList lst = zip.getFileNameList(); |
|
|
|
for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!zip.getCurrentFileInfo(&info)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
|
|
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile out; |
|
|
|
QFile out; |
|
|
|
char c; |
|
|
|
char c; |
|
|
|
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) |
|
|
|
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) { |
|
|
|
{ |
|
|
|
if(!zip.getCurrentFileInfo(&info)) { |
|
|
|
if(!zip.getCurrentFileInfo(&info)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//TOD UB 4.3 O display error to user or use crash reporter
|
|
|
|
//TOD UB 4.3 O display error to user or use crash reporter
|
|
|
|
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// if(!file.open(QIODevice::ReadOnly)) {
|
|
|
|
if(!file.open(QIODevice::ReadOnly)) |
|
|
|
// qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
|
|
|
|
{ |
|
|
|
// return "";
|
|
|
|
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError(); |
|
|
|
// }
|
|
|
|
return ""; |
|
|
|
file.open(QIODevice::ReadOnly); |
|
|
|
} |
|
|
|
if(file.getZipError()!= UNZ_OK) { |
|
|
|
|
|
|
|
|
|
|
|
if(file.getZipError()!= UNZ_OK) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); |
|
|
|
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); |
|
|
|
|
|
|
|
bool ends = newFileName.endsWith('/'); |
|
|
|
|
|
|
|
if (!ends) { |
|
|
|
|
|
|
|
|
|
|
|
QFileInfo newFileInfo(newFileName); |
|
|
|
QFileInfo newFileInfo(newFileName); |
|
|
|
rootDir.mkpath(newFileInfo.absolutePath()); |
|
|
|
rootDir.mkpath(newFileInfo.absolutePath()); |
|
|
|
|
|
|
|
|
|
|
@ -216,47 +197,39 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
|
|
|
out.close(); |
|
|
|
out.close(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while(file.getChar(&c)) |
|
|
|
while(file.getChar(&c)) |
|
|
|
out.putChar(c); |
|
|
|
out.putChar(c); |
|
|
|
|
|
|
|
|
|
|
|
out.close(); |
|
|
|
out.close(); |
|
|
|
|
|
|
|
|
|
|
|
if(file.getZipError()!=UNZ_OK) |
|
|
|
if(file.getZipError()!=UNZ_OK) { |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(!file.atEnd()) { |
|
|
|
if(!file.atEnd()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: read all but not EOF"; |
|
|
|
qWarning() << "Import failed. Cause: read all but not EOF"; |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file.close(); |
|
|
|
file.close(); |
|
|
|
|
|
|
|
|
|
|
|
if(file.getZipError()!=UNZ_OK) |
|
|
|
if(file.getZipError()!=UNZ_OK) { |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
zip.close(); |
|
|
|
zip.close(); |
|
|
|
|
|
|
|
|
|
|
|
if(zip.getZipError()!=UNZ_OK) |
|
|
|
if(zip.getZipError()!=UNZ_OK) { |
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
|
|
|
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return documentRootFolder; |
|
|
|
return documentRootFolder; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup) |
|
|
|
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(pGroup); // group is defined in the imported file
|
|
|
|
Q_UNUSED(pGroup); // group is defined in the imported file
|
|
|
|