QString CWizHtmlCollector::ToResourceFileName(const QString& strFileName) { if (m_bMainPage) { return "index_files/" + WizExtractFileName(strFileName); } else { return WizExtractFileName(strFileName); } }
bool CWizDatabase::AddAttachment(const WIZDOCUMENTDATA& document, const CString& strFileName, WIZDOCUMENTATTACHMENTDATA& dataRet) { CString strMD5 = ::WizMd5FileString(strFileName); if (!CreateAttachment(document.strGUID, WizExtractFileName(strFileName), strFileName, "", strMD5, dataRet)) return false; if (!::WizCopyFile(strFileName, GetAttachmentFileName(dataRet.strGUID), false)) { DeleteAttachment(dataRet, false); return false; } SetAttachmentDataDownloaded(dataRet.strGUID, true); UpdateDocumentAttachmentCount(document.strGUID); return true; }
bool WizHtml2Zip(const QString& strHtml, const CWizStdStringArray& arrayResource, \ const QString& strMetaText, const QString& strZipFileName) { CWizZipFile zip; if (!zip.open(strZipFileName)) return false; CString strIndexFileName = Utils::PathResolve::tempPath() + WizIntToStr(GetTickCount()) + ".html"; //if (!::WizSaveUnicodeTextToUnicodeFile(strIndexFileName, strHtml)) if (!::WizSaveUnicodeTextToUtf8File(strIndexFileName, strHtml)) return false; CString strMetaFileName = Utils::PathResolve::tempPath() + WizIntToStr(GetTickCount()) + ".xml"; if (!::WizSaveUnicodeTextToUtf8File(strMetaFileName, strMetaText)) return false; if (!zip.compressFile(strIndexFileName, "index.html")) return false; int failed = 0; if (!zip.compressFile(strMetaFileName, "meta.xml")) failed++; for (CWizStdStringArray::const_iterator it = arrayResource.begin(); it != arrayResource.end(); it++) { CString strFileName = *it; CString strNameInZip = "index_files/" + WizExtractFileName(strFileName); if (!zip.compressFile(strFileName, strNameInZip)) { failed++; } } return zip.close(); }
bool WizFolder2Zip(const QString &strFolder, const QString &strMetaText, \ const QString &strZipFileName, const QString &indexFile /*= "index.html"*/, \ const QString &strResourceFolder /*= "index_files"*/) { CWizZipFile zip; if (!zip.open(strZipFileName)) return false; CString strIndexFileName = strFolder + indexFile; CString strMetaFileName = Utils::PathResolve::tempPath() + WizIntToStr(GetTickCount()) + ".xml"; if (!::WizSaveUnicodeTextToUtf8File(strMetaFileName, strMetaText)) return false; if (!zip.compressFile(strIndexFileName, "index.html")) return false; int failed = 0; if (!zip.compressFile(strMetaFileName, "meta.xml")) failed++; QDir dir(strFolder + strResourceFolder); QStringList strResourceList = dir.entryList(QDir::Files, QDir::NoSort); for (QStringList::const_iterator it = strResourceList.begin(); it != strResourceList.end(); it++) { QString strFileName =dir.path() +"/" + *it; QString strNameInZip = "index_files/" + WizExtractFileName(strFileName); if (!zip.compressFile(strFileName, strNameInZip)) { failed++; } } return zip.close(); }
void CWizFileReader::run() { int nTotal = m_files.count(); for (int i = 0; i < nTotal; i++) { QString strFile = m_files.at(i); QFileInfo fi(strFile); QString strHtml; QStringList textExtList, imageExtList, rtfExtList, docExtList, htmlExtList; textExtList << "txt" << "md" << "markdown" << "mht" << "cpp" << "h"; imageExtList << "jpg" << "png" << "gif" << "tiff" << "jpeg" << "bmp" << "svg"; rtfExtList << "rtf"; docExtList << "doc" << "docx" << "pages"; htmlExtList << "html" << "htm"; #ifdef Q_OS_MAC QStringList webExtList; webExtList << "webarchive"; #endif bool addAttach = false; QString docType = fi.suffix(); if (textExtList.contains(docType,Qt::CaseInsensitive)) { strHtml = loadTextFileToHtml(strFile); } else if (imageExtList.contains(docType,Qt::CaseInsensitive)) { strHtml = loadImageFileToHtml(strFile); } else if (htmlExtList.contains(docType, Qt::CaseInsensitive)) { strHtml = loadHtmlFileToHtml(strFile); QString strTitle = WizExtractFileName(strFile); emit htmlFileloaded(strFile, strHtml, strTitle); continue; } #ifdef Q_OS_MAC else if (rtfExtList.contains(docType, Qt::CaseInsensitive)) { if (!documentToHtml(strFile, RTFTextDocumentType, strHtml)) continue; WizGetBodyContentFromHtml(strHtml, true); addAttach = true; } else if (docExtList.contains(docType)) { if (!documentToHtml(strFile, DocFormatTextDocumentType, strHtml)) continue; WizGetBodyContentFromHtml(strHtml, true); addAttach = true; } else if (webExtList.contains(docType)) { if (!documentToHtml(strFile, WebArchiveTextDocumentType, strHtml)) continue; WizGetBodyContentFromHtml(strHtml, true); } else { emit fileLoadFailed(strFile); } #endif QString strTitle = WizExtractFileName(strFile); if (addAttach) { emit richTextFileLoaded(strHtml, strTitle, strFile); } else if (!strHtml.isEmpty()) { emit fileLoaded(strHtml, strTitle); } emit loadProgress(nTotal, i + 1); } emit loadFinished(); m_files.clear(); }