From 4b6fd719cb532846b33fde6d28d7a1f780133958 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 5 Aug 2020 16:18:45 +0300 Subject: [PATCH] Batch mode --- HtmlFile2/htmlfile2.cpp | 25 ++++++++++++++++++++++++- HtmlFile2/htmlfile2.h | 2 ++ HtmlFile2/test/main.cpp | 26 ++++++++++++++++++++------ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index 9ee556e326..3232f22798 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -28,11 +28,11 @@ public: std::wstring m_sSrc; // Директория источника std::wstring m_sDst; // Директория назначения -private: std::map m_mStyles; // Стили в document.xml. Хранятся как (имя тэга, его стиль) std::wstring m_sBase; // Полный базовый адрес +private: int m_nImageId; // ID картинки int m_nFootnoteId; // ID сноски int m_nHyperlinkId; // ID ссылки @@ -808,3 +808,26 @@ HRESULT CHtmlFile2::Open(const std::wstring& sSrc, const std::wstring& sDst, CHt NSFile::CFileBinary::Remove(m_internal->m_sTmp + L"/res.xhtml"); return S_OK; } + +HRESULT CHtmlFile2::OpenBatch(const std::vector& sSrc, const std::wstring& sDst, CHtmlParams* oParams) +{ + + m_internal->m_sDst = sDst; + m_internal->CreateDocxEmpty(); + + for(std::wstring sS : sSrc) + { + m_internal->m_sSrc = NSSystemPath::GetDirectoryName(sS); + m_internal->htmlXhtml(sS); + if(!m_internal->readSrc()) + return S_FALSE; + NSFile::CFileBinary::Remove(m_internal->m_sTmp + L"/res.xhtml"); + + m_internal->m_oLightReader.Clear(); + m_internal->m_mStyles.clear(); + m_internal->m_sBase = L""; + } + + m_internal->write(); + return S_OK; +} diff --git a/HtmlFile2/htmlfile2.h b/HtmlFile2/htmlfile2.h index b1dbc79155..5434b4e9d5 100644 --- a/HtmlFile2/htmlfile2.h +++ b/HtmlFile2/htmlfile2.h @@ -2,6 +2,7 @@ #define _HTMLFILE2_HTMLFILE2_H #include +#include #include "../DesktopEditor/common/Types.h" #ifndef HTMLFILE2_USE_DYNAMIC_LIBRARY @@ -28,6 +29,7 @@ public: bool IsHtmlFile(const std::wstring& sFile); void SetTmpDirectory(const std::wstring& sFolder); HRESULT Open(const std::wstring& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL); + HRESULT OpenBatch(const std::vector& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL); }; #endif // _HTMLFILE2_HTMLFILE2_H diff --git a/HtmlFile2/test/main.cpp b/HtmlFile2/test/main.cpp index fe07d93e3b..bb81432f9c 100644 --- a/HtmlFile2/test/main.cpp +++ b/HtmlFile2/test/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "../htmlfile2.h" #include "../../DesktopEditor/common/File.h" #include "../../DesktopEditor/common/Directory.h" @@ -6,24 +7,37 @@ int main() { + bool bBatchMode = true; CHtmlFile2 oFile; - // Файл, который открываем - std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test4.xhtml"; - - // Директория, где будем создавать xhtml + // Директория, где будем создавать docx std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/res"; NSDirectory::DeleteDirectory(sOutputDirectory); NSDirectory::CreateDirectory(sOutputDirectory); oFile.SetTmpDirectory(sOutputDirectory); + HRESULT nResConvert = S_FALSE; - HRESULT nResConvert = oFile.Open(sFile, sOutputDirectory); + if(bBatchMode) + { + std::vector arrFiles{NSFile::GetProcessDirectory() + L"/../../../examples/test1.html", + NSFile::GetProcessDirectory() + L"/../../../examples/test2.xhtml", + NSFile::GetProcessDirectory() + L"/../../../examples/test3.xhtml", + NSFile::GetProcessDirectory() + L"/../../../examples/test4.xhtml"}; + nResConvert = oFile.OpenBatch(arrFiles, sOutputDirectory); + } + else + { + // Файл, который открываем + std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test4.xhtml"; + nResConvert = oFile.Open(sFile, sOutputDirectory); + + } if(nResConvert == S_OK) { std::cout << "Success" << std::endl; COfficeUtils oZip; - oZip.CompressFileOrDirectory(sOutputDirectory, sOutputDirectory + L"/" + NSFile::GetFileName(sFile) + L".docx"); + oZip.CompressFileOrDirectory(sOutputDirectory, sOutputDirectory + L"/Aggregate.docx"); } else std::cout << "Failure" << std::endl;