| 27 | } |
| 28 | |
| 29 | bool WizFileExporter::exportNote( |
| 30 | const WIZDOCUMENTDATA &doc, |
| 31 | const QString &destFolder, |
| 32 | const ExportFormat format, |
| 33 | bool compress /*= false*/, |
| 34 | bool exportMetaInfo /*= true*/, |
| 35 | bool noTitleFolderIfPossible /*= false*/, |
| 36 | QString *errorMsg /*= nullptr*/) |
| 37 | { |
| 38 | WizDatabase& db = m_dbMgr.db(doc.strKbGUID); |
| 39 | if (!WizMakeSureDocumentExistAndBlockWidthEventloop(db, doc)) { |
| 40 | if (errorMsg) |
| 41 | *errorMsg = "Can't download document: " + doc.strTitle; |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | CString folder = doc.strTitle; |
| 46 | WizMakeValidFileNameNoPath(folder); |
| 47 | |
| 48 | QDir docFolder(destFolder); |
| 49 | if (!docFolder.mkpath(folder)) { |
| 50 | if (errorMsg) |
| 51 | *errorMsg = "Can't make directory: " + |
| 52 | docFolder.filePath(folder); |
| 53 | return false; |
| 54 | } |
| 55 | docFolder.cd(folder); |
| 56 | |
| 57 | // Write meta info |
| 58 | if (exportMetaInfo) { |
| 59 | if (!writeDocumentInfoToJsonFile(doc, docFolder.filePath("metainfo.json"))) { |
| 60 | if (errorMsg) |
| 61 | *errorMsg = "Can't save meta info to json file: " + |
| 62 | docFolder.filePath("metainfo.json"); |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Export attachments, download if neccessary |
| 68 | CWizDocumentAttachmentDataArray arrayAttachment; |
| 69 | db.getDocumentAttachments(doc.strGUID, arrayAttachment); |
| 70 | if (!arrayAttachment.empty()) |
| 71 | docFolder.mkpath("attachments"); |
| 72 | for (auto &att : arrayAttachment) { |
| 73 | if (!exportAttachment(att, docFolder.filePath("attachments"))) { |
| 74 | if (errorMsg) |
| 75 | *errorMsg = "Can't export attachment: " + |
| 76 | att.strName.remove(0, GUIDLEN); |
| 77 | return false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // Unzip index.html and index_files/ |
| 82 | QString strHtmlFile = docFolder.filePath("index.html"); |
| 83 | if (db.documentToHtmlFile(doc, docFolder.absolutePath() + "/")) { |
| 84 | QFile file(strHtmlFile); |
| 85 | if (!file.open(QIODevice::ReadOnly)) { |
| 86 | return false; |
no test coverage detected