MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / exportNote

Method exportNote

src/WizFileExporter.cpp:29–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29bool 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;

Callers 1

foreachFunction · 0.80

Calls 12

filePathMethod · 0.80
documentToHtmlFileMethod · 0.80
lengthMethod · 0.80
emptyMethod · 0.45
removeMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
fileNameMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected