Commit d8c7d414 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormat - vba macros

parent b69051a5
...@@ -157,6 +157,7 @@ namespace OpenXmlRelationshipTypes ...@@ -157,6 +157,7 @@ namespace OpenXmlRelationshipTypes
static const wchar_t* OleObject = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"; static const wchar_t* OleObject = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
static const wchar_t* GlossaryDocument = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument"; static const wchar_t* GlossaryDocument = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument";
static const wchar_t* Package = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"; static const wchar_t* Package = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
static const wchar_t* VbaProject = L"http://schemas.microsoft.com/office/2006/relationships/vbaProject";
} }
namespace MicrosoftWordRelationshipTypes namespace MicrosoftWordRelationshipTypes
......
...@@ -65,7 +65,7 @@ namespace DocFileFormat ...@@ -65,7 +65,7 @@ namespace DocFileFormat
{ {
ConversionContext context( doc, docx ); ConversionContext context( doc, docx );
//Write styles.xml //Write styles.xml
if (doc->Styles) if (doc->Styles)
{ {
StyleSheetMapping styleSheetMapping( &context ); StyleSheetMapping styleSheetMapping( &context );
...@@ -88,9 +88,7 @@ namespace DocFileFormat ...@@ -88,9 +88,7 @@ namespace DocFileFormat
return S_FALSE; return S_FALSE;
} }
} }
//Write numbering.xml
//Write numbering.xml
if (doc->listTable) if (doc->listTable)
{ {
NumberingMapping numberingMapping( &context ); NumberingMapping numberingMapping( &context );
...@@ -110,7 +108,7 @@ namespace DocFileFormat ...@@ -110,7 +108,7 @@ namespace DocFileFormat
} }
} }
//Write fontTable.xml //Write fontTable.xml
if (doc->FontTable) if (doc->FontTable)
{ {
FontTableMapping fontTableMapping( &context ); FontTableMapping fontTableMapping( &context );
...@@ -130,7 +128,7 @@ namespace DocFileFormat ...@@ -130,7 +128,7 @@ namespace DocFileFormat
} }
} }
//write the footnotes //write the footnotes
FootnotesMapping footnotesMapping( &context ); FootnotesMapping footnotesMapping( &context );
doc->Convert( &footnotesMapping ); doc->Convert( &footnotesMapping );
...@@ -147,7 +145,7 @@ namespace DocFileFormat ...@@ -147,7 +145,7 @@ namespace DocFileFormat
} }
} }
//write the endnotes //write the endnotes
EndnotesMapping endnotesMapping( &context ); EndnotesMapping endnotesMapping( &context );
doc->Convert( &endnotesMapping ); doc->Convert( &endnotesMapping );
...@@ -164,7 +162,7 @@ namespace DocFileFormat ...@@ -164,7 +162,7 @@ namespace DocFileFormat
} }
} }
//write the comments //write the comments
CommentsMapping commentsMapping( &context ); CommentsMapping commentsMapping( &context );
doc->Convert( &commentsMapping ); doc->Convert( &commentsMapping );
...@@ -181,13 +179,13 @@ namespace DocFileFormat ...@@ -181,13 +179,13 @@ namespace DocFileFormat
} }
} }
//write settings.xml at last because of the rsid list //write settings.xml at last because of the rsid list
if (doc->DocProperties) if (doc->DocProperties)
{ {
SettingsMapping settingsMapping( &context ); SettingsMapping settingsMapping( &context );
doc->DocProperties->Convert( &settingsMapping ); doc->DocProperties->Convert( &settingsMapping );
} }
if ( progress != NULL ) if ( progress != NULL )
{ {
progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 975000 ); progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 975000 );
...@@ -204,7 +202,7 @@ namespace DocFileFormat ...@@ -204,7 +202,7 @@ namespace DocFileFormat
return S_OK; return S_OK;
} }
long Converter::LoadAndConvert(const std::wstring& strSrcFile, const std::wstring& strDstDirectory, const std::wstring& password, const ProgressCallback* progress) long Converter::LoadAndConvert(const std::wstring& strSrcFile, const std::wstring& strDstDirectory, const std::wstring& password, const ProgressCallback* progress, bool &bMacros)
{ {
long result = S_FALSE; long result = S_FALSE;
...@@ -219,7 +217,7 @@ namespace DocFileFormat ...@@ -219,7 +217,7 @@ namespace DocFileFormat
if (result == S_OK) if (result == S_OK)
{ {
docx.SaveDocument(); docx.SaveDocument(bMacros);
if (progress)progress->OnProgress(progress->caller, DOC_ONPROGRESSEVENT_ID, 1000000); if (progress)progress->OnProgress(progress->caller, DOC_ONPROGRESSEVENT_ID, 1000000);
......
...@@ -48,7 +48,7 @@ namespace DocFileFormat ...@@ -48,7 +48,7 @@ namespace DocFileFormat
std::wstring m_sTempFolder; std::wstring m_sTempFolder;
long LoadAndConvert(const std::wstring & strSrcFile, const std::wstring & strDstDirectory, const std::wstring & password, const ProgressCallback* progress); long LoadAndConvert(const std::wstring & strSrcFile, const std::wstring & strDstDirectory, const std::wstring & password, const ProgressCallback* progress, bool &bMacros);
private: private:
long Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress); long Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress);
......
...@@ -50,8 +50,7 @@ namespace DocFileFormat ...@@ -50,8 +50,7 @@ namespace DocFileFormat
void MainDocumentMapping::Apply(IVisitable* visited) void MainDocumentMapping::Apply(IVisitable* visited)
{ {
m_document = static_cast<WordDocument*>(visited); m_document = static_cast<WordDocument*>(visited);
m_context->_docx->RegisterDocument();
// Header // Header
m_pXmlWriter->WriteNodeBegin(L"?xml version=\"1.0\" encoding=\"UTF-8\"?"); m_pXmlWriter->WriteNodeBegin(L"?xml version=\"1.0\" encoding=\"UTF-8\"?");
m_pXmlWriter->WriteNodeBegin(L"w:document", TRUE ); m_pXmlWriter->WriteNodeBegin(L"w:document", TRUE );
......
...@@ -73,7 +73,6 @@ namespace DocFileFormat ...@@ -73,7 +73,6 @@ namespace DocFileFormat
NSDirectory::CreateDirectory( m_strOutputPath + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"_rels" ); NSDirectory::CreateDirectory( m_strOutputPath + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"_rels" );
WriteRelsFile( DocumentRelationshipsFile ); WriteRelsFile( DocumentRelationshipsFile );
WriteRelsFile( FootnotesRelationshipsFile ); WriteRelsFile( FootnotesRelationshipsFile );
...@@ -199,7 +198,14 @@ namespace DocFileFormat ...@@ -199,7 +198,14 @@ namespace DocFileFormat
{ {
return AddPart( L"word", L"document.xml", WordprocessingMLContentTypes::MainDocument, L""); return AddPart( L"word", L"document.xml", WordprocessingMLContentTypes::MainDocument, L"");
} }
int OpenXmlPackage::RegisterDocumentMacros()
{
return AddPart( L"word", L"document.xml", WordprocessingMLContentTypes::MainDocumentMacro, L"");
}
int OpenXmlPackage::RegisterVbaProject()
{
return AddPart( L"word", L"vbaProject.bin", MicrosoftWordContentTypes::VbaProject, OpenXmlRelationshipTypes::VbaProject );
}
int OpenXmlPackage::RegisterFontTable() int OpenXmlPackage::RegisterFontTable()
{ {
return AddPart( L"word", L"fontTable.xml", WordprocessingMLContentTypes::FontTable, OpenXmlRelationshipTypes::FontTable ); return AddPart( L"word", L"fontTable.xml", WordprocessingMLContentTypes::FontTable, OpenXmlRelationshipTypes::FontTable );
......
...@@ -118,6 +118,8 @@ namespace DocFileFormat ...@@ -118,6 +118,8 @@ namespace DocFileFormat
class OpenXmlPackage class OpenXmlPackage
{ {
public:
const WordDocument* docFile;
private: private:
ContentTypesFile DocumentContentTypesFile; ContentTypesFile DocumentContentTypesFile;
RelationshipsFile MainRelationshipsFile; RelationshipsFile MainRelationshipsFile;
...@@ -137,8 +139,6 @@ namespace DocFileFormat ...@@ -137,8 +139,6 @@ namespace DocFileFormat
int _footerCounter; int _footerCounter;
int _oleCounter; int _oleCounter;
const WordDocument* docFile;
int AddHeaderPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" ); int AddHeaderPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" );
int AddFooterPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" ); int AddFooterPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" );
int AddFootnotesPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" ); int AddFootnotesPart( const std::wstring& fileName, const std::wstring& relationshipType = L"", const std::wstring& targetMode = L"" );
...@@ -166,6 +166,7 @@ namespace DocFileFormat ...@@ -166,6 +166,7 @@ namespace DocFileFormat
HRESULT SaveEmbeddedObject ( const std::wstring& fileName, const std::string& data ); HRESULT SaveEmbeddedObject ( const std::wstring& fileName, const std::string& data );
int RegisterDocument(); int RegisterDocument();
int RegisterDocumentMacros();
int RegisterFontTable(); int RegisterFontTable();
int RegisterNumbering(); int RegisterNumbering();
int RegisterSettings(); int RegisterSettings();
...@@ -179,5 +180,6 @@ namespace DocFileFormat ...@@ -179,5 +180,6 @@ namespace DocFileFormat
int RegisterOLEObject ( const IMapping* mapping, const std::wstring& objectType ); int RegisterOLEObject ( const IMapping* mapping, const std::wstring& objectType );
int RegisterPackage ( const IMapping* mapping, const std::wstring& objectType); int RegisterPackage ( const IMapping* mapping, const std::wstring& objectType);
int RegisterExternalOLEObject( const IMapping* mapping, const std::wstring& objectType, const std::wstring& uri ); int RegisterExternalOLEObject( const IMapping* mapping, const std::wstring& objectType, const std::wstring& uri );
int RegisterVbaProject();
}; };
} }
...@@ -42,7 +42,6 @@ namespace DocFileFormat ...@@ -42,7 +42,6 @@ namespace DocFileFormat
{ {
} }
~StructuredStorageReader() ~StructuredStorageReader()
{ {
if(m_pStorage) if(m_pStorage)
...@@ -62,6 +61,12 @@ namespace DocFileFormat ...@@ -62,6 +61,12 @@ namespace DocFileFormat
} }
return false; return false;
} }
bool isDirectory( const std::string& name )
{
if (!m_pStorage) return false;
return m_pStorage->isDirectory(name);
}
bool GetStream (const char *path, POLE::Stream** ppStream) bool GetStream (const char *path, POLE::Stream** ppStream)
{ {
...@@ -79,8 +84,78 @@ namespace DocFileFormat ...@@ -79,8 +84,78 @@ namespace DocFileFormat
{ {
return m_pStorage; return m_pStorage;
} }
void copy( int indent, std::string path, POLE::Storage * storageOut, bool withRoot = true)
{
std::list<std::string> entries, entries_sort;
entries = m_pStorage->entries( path );
for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
{
std::string name = *it;
std::string fullname = path + name;
if( m_pStorage->isDirectory( fullname ) )
{
entries_sort.push_back(name);
}
else
{
entries_sort.push_front(name);
}
}
//for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
for( std::list<std::string>::iterator it = entries_sort.begin(); it != entries_sort.end(); it++ )
{
std::string name = *it;
std::string fullname = path + name;
if( m_pStorage->isDirectory( fullname ) )
{
copy( indent + 1, fullname + "/", storageOut, withRoot );
}
else
{
copy_stream(fullname, storageOut, withRoot);
}
}
}
private: private:
void copy_stream(std::string streamName, POLE::Storage * storageOut, bool withRoot = true)
{
POLE::Stream *stream = new POLE::Stream(m_pStorage, streamName);
if (!stream) return;
stream->seek(0);
int size_stream = stream->size();
if (withRoot == false)
{
int pos = streamName.find("/");
if (pos >= 0)
streamName = streamName.substr(pos + 1);
}
POLE::Stream *streamNew = new POLE::Stream(storageOut, streamName, true, size_stream);
if (!streamNew) return;
unsigned char* data_stream = new unsigned char[size_stream];
if (data_stream)
{
stream->read(data_stream, size_stream);
streamNew->write(data_stream, size_stream);
delete []data_stream;
data_stream = NULL;
}
streamNew->flush();
delete streamNew;
delete stream;
}
POLE::Storage* m_pStorage; POLE::Storage* m_pStorage;
}; };
......
...@@ -528,11 +528,24 @@ namespace DocFileFormat ...@@ -528,11 +528,24 @@ namespace DocFileFormat
} }
void WordDocument::DecryptStream( int level, std::string path, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor) void WordDocument::DecryptStream( int level, std::string path, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor)
{ {
std::list<std::string> entries; std::list<std::string> entries, entries_sort;
entries = storageIn->entries( path ); entries = storageIn->entries( path );
std::list<std::string>::iterator it; for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
for( it = entries.begin(); it != entries.end(); ++it ) {
std::string name = *it;
std::string fullname = path + name;
if( storageIn->isDirectory( fullname ) )
{
entries_sort.push_back(name);
}
else
{
entries_sort.push_front(name);
}
}
for( std::list<std::string>::iterator it = entries_sort.begin(); it != entries_sort.end(); ++it )
{ {
std::string name = *it; std::string name = *it;
std::string fullname = path + name; std::string fullname = path + name;
......
...@@ -99,18 +99,17 @@ namespace DocFileFormat ...@@ -99,18 +99,17 @@ namespace DocFileFormat
bool bOlderVersion; bool bOlderVersion;
int document_code_page; int document_code_page;
inline StructuredStorageReader* GetStorage() const
{
return m_pStorage;
}
private: private:
bool DecryptOfficeFile (CRYPT::Decryptor* Decryptor); bool DecryptOfficeFile (CRYPT::Decryptor* Decryptor);
bool DecryptStream (std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor); bool DecryptStream (std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor);
void DecryptStream (int level, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor); void DecryptStream (int level, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor);
inline StructuredStorageReader* GetStorage() const
{
return m_pStorage;
}
inline OfficeArtContent* GetOfficeArt () inline OfficeArtContent* GetOfficeArt ()
{ {
return officeArtContent; return officeArtContent;
......
...@@ -180,10 +180,37 @@ namespace DocFileFormat ...@@ -180,10 +180,37 @@ namespace DocFileFormat
{ {
} }
void WordprocessingDocument::SaveDocument() void WordprocessingDocument::SaveDocument(bool &bMacros)
{ {
std::wstring pathWord = m_strOutputPath + FILE_SEPARATOR_STR + L"word" ; std::wstring pathWord = m_strOutputPath + FILE_SEPARATOR_STR + L"word" ;
NSDirectory::CreateDirectory( pathWord ); NSDirectory::CreateDirectory( pathWord );
if (bMacros && docFile->GetStorage()->isDirectory("Macros"))
{
std::wstring sVbaProjectFile = pathWord + FILE_SEPARATOR_STR + L"vbaProject.bin";
POLE::Storage *storageVbaProject = new POLE::Storage(sVbaProjectFile.c_str());
if ((storageVbaProject) && (storageVbaProject->open(true, true)))
{
docFile->GetStorage()->copy(0, "Macros/", storageVbaProject, false);
storageVbaProject->close();
delete storageVbaProject;
RegisterDocumentMacros();
RegisterVbaProject();
//output_document->get_xl_files().add_vba_project();
}
else bMacros = false;
}
else
bMacros = false;
if (!bMacros)
{
RegisterDocument();
}
WritePackage(); WritePackage();
......
...@@ -76,6 +76,7 @@ namespace DocFileFormat ...@@ -76,6 +76,7 @@ namespace DocFileFormat
public: public:
WordprocessingDocument(const std::wstring & _docxDirectory, const WordDocument* _docFile); WordprocessingDocument(const std::wstring & _docxDirectory, const WordDocument* _docFile);
virtual ~WordprocessingDocument(); virtual ~WordprocessingDocument();
void SaveDocument();
void SaveDocument(bool &bMacros);
}; };
} }
\ No newline at end of file
...@@ -34,14 +34,14 @@ ...@@ -34,14 +34,14 @@
#include "../DocDocxConverter/Converter.h" #include "../DocDocxConverter/Converter.h"
#include "../../OfficeUtils/src/OfficeUtils.h" #include "../../OfficeUtils/src/OfficeUtils.h"
HRESULT COfficeDocFile::LoadFromFile(const std::wstring & docFile, const std::wstring & docxDirectory, const std::wstring & password, ProgressCallback *ffCallBack ) HRESULT COfficeDocFile::LoadFromFile(const std::wstring & docFile, const std::wstring & docxDirectory, const std::wstring & password, bool &bMacros, ProgressCallback *ffCallBack)
{ {
HRESULT hr = S_FALSE; HRESULT hr = S_FALSE;
DocFileFormat::Converter docToDocx; DocFileFormat::Converter docToDocx;
docToDocx.m_sTempFolder = m_sTempFolder; docToDocx.m_sTempFolder = m_sTempFolder;
hr= docToDocx.LoadAndConvert(docFile, docxDirectory, password, ffCallBack); hr= docToDocx.LoadAndConvert(docFile, docxDirectory, password, ffCallBack, bMacros);
return hr; return hr;
} }
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
std::wstring m_sTempFolder; std::wstring m_sTempFolder;
HRESULT LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstFileName, const std::wstring & password, ProgressCallback *ffCallBack = NULL); HRESULT LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstFileName, const std::wstring & password, bool &bMacros, ProgressCallback *ffCallBack = NULL);
HRESULT SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcFileName, ProgressCallback *ffCallBack = NULL); HRESULT SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcFileName, ProgressCallback *ffCallBack = NULL);
}; };
......
...@@ -54,17 +54,27 @@ int _tmain(int argc, _TCHAR* argv[]) ...@@ -54,17 +54,27 @@ int _tmain(int argc, _TCHAR* argv[])
if (argc < 2) return 1; if (argc < 2) return 1;
std::wstring sSrcDoc = argv[1]; std::wstring sSrcDoc = argv[1];
std::wstring sDstDocx = argc > 2 ? argv[2] : sSrcDoc + L"-my.docx"; std::wstring sDstDocx;
std::wstring outputDir = NSDirectory::GetFolderPath(sDstDocx); std::wstring outputDir = NSDirectory::GetFolderPath(sSrcDoc);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir); std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
COfficeDocFile docFile; COfficeDocFile docFile;
docFile.m_sTempFolder = outputDir; docFile.m_sTempFolder = outputDir;
HRESULT hRes = docFile.LoadFromFile( sSrcDoc, dstTempPath, L"password", NULL); bool bMacros = true;
HRESULT hRes = docFile.LoadFromFile( sSrcDoc, dstTempPath, L"password", bMacros, NULL);
if (bMacros)
{
sDstDocx = sSrcDoc + L"-my.docm";
}
else
{
sDstDocx = sSrcDoc + L"-my.docx";
}
if (hRes == S_OK) if (hRes == S_OK)
{ {
COfficeUtils oCOfficeUtils(NULL); COfficeUtils oCOfficeUtils(NULL);
......
...@@ -134,12 +134,26 @@ void CompoundFile::copy_stream(std::string streamName, POLE::Storage * storageOu ...@@ -134,12 +134,26 @@ void CompoundFile::copy_stream(std::string streamName, POLE::Storage * storageOu
void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOut, bool withRoot) void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOut, bool withRoot)
{ {
std::list<std::string> entries; std::list<std::string> entries, entries_sort;
entries = storage_->entries( path ); entries = storage_->entries( path );
std::list<std::string>::iterator it; for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
for( it = entries.begin(); it != entries.end(); ++it ) {
{ std::string name = *it;
std::string fullname = path + name;
if( storage_->isDirectory( fullname ) )
{
entries_sort.push_back(name);
}
else
{
entries_sort.push_front(name);
}
}
//for( std::list<std::string>::iterator it = entries.begin(); it != entries.end(); it++ )
for( std::list<std::string>::iterator it = entries_sort.begin(); it != entries_sort.end(); it++ )
{
std::string name = *it; std::string name = *it;
std::string fullname = path + name; std::string fullname = path + name;
...@@ -151,7 +165,7 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu ...@@ -151,7 +165,7 @@ void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOu
{ {
copy_stream(fullname, storageOut, withRoot); copy_stream(fullname, storageOut, withRoot);
} }
} }
} }
CFStreamPtr CompoundFile::getWorkbookStream() CFStreamPtr CompoundFile::getWorkbookStream()
{ {
......
...@@ -206,6 +206,8 @@ void OfficeArtContainer::loadFields(XLS::CFRecord& record) ...@@ -206,6 +206,8 @@ void OfficeArtContainer::loadFields(XLS::CFRecord& record)
} }
else // If the found record is not implemented or unknown else // If the found record is not implemented or unknown
{ {
if (rh_child.recType == 0xf150)
break;
if (rh_child.size() > record.getDataSize() - container_beginning_ptr) if (rh_child.size() > record.getDataSize() - container_beginning_ptr)
break; break;
try try
......
...@@ -1914,7 +1914,7 @@ namespace NExtractTools ...@@ -1914,7 +1914,7 @@ namespace NExtractTools
// doc -> docx // doc -> docx
int doc2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) int doc2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{ {
std::wstring sResultDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked"); std::wstring sResultDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
NSDirectory::CreateDirectory(sResultDocxDir); NSDirectory::CreateDirectory(sResultDocxDir);
...@@ -1939,12 +1939,66 @@ namespace NExtractTools ...@@ -1939,12 +1939,66 @@ namespace NExtractTools
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD; return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
} }
return AVS_FILEUTILS_ERROR_CONVERT; return AVS_FILEUTILS_ERROR_CONVERT;
} }
int doc2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) int doc2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
COfficeDocFile docFile;
docFile.m_sTempFolder = sTemp;
bool bMacros = false;
long hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), bMacros, NULL);
if (AVS_ERROR_DRM == hRes)
{
if(!params.getDontSaveAdditional())
{
copyOrigin(sFrom, *params.m_sFileTo);
}
return AVS_FILEUTILS_ERROR_CONVERT_DRM;
}
else if (AVS_ERROR_PASSWORD == hRes)
{
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
}
return 0 == hRes ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
// doc -> docm
int doc2docm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{ {
std::wstring sResultDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
NSDirectory::CreateDirectory(sResultDocxDir);
long hRes = doc2docm_dir(sFrom, sResultDocxDir, sTemp, params);
if(SUCCEEDED_X2T(hRes))
{
COfficeUtils oCOfficeUtils(NULL);
if(S_OK == oCOfficeUtils.CompressFileOrDirectory(sResultDocxDir, sTo, true))
return 0;
}
else if (AVS_ERROR_DRM == hRes)
{
if(!params.getDontSaveAdditional())
{
copyOrigin(sFrom, *params.m_sFileTo);
}
return AVS_FILEUTILS_ERROR_CONVERT_DRM;
}
else if (AVS_ERROR_PASSWORD == hRes)
{
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int doc2docm_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
COfficeDocFile docFile; COfficeDocFile docFile;
docFile.m_sTempFolder = sTemp; docFile.m_sTempFolder = sTemp;
long hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), NULL);
bool bMacros = true;
long hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), bMacros, NULL);
if (AVS_ERROR_DRM == hRes) if (AVS_ERROR_DRM == hRes)
{ {
if(!params.getDontSaveAdditional()) if(!params.getDontSaveAdditional())
...@@ -1962,7 +2016,7 @@ namespace NExtractTools ...@@ -1962,7 +2016,7 @@ namespace NExtractTools
// doc -> doct // doc -> doct
int doc2doct (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) int doc2doct (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{ {
// Extract docx to temp directory // Extract docx to temp directory
std::wstring sResultDoctDir = sTemp + FILE_SEPARATOR_STR + _T("doct_unpacked"); std::wstring sResultDoctDir = sTemp + FILE_SEPARATOR_STR + _T("doct_unpacked");
std::wstring sResultDoctFileEditor = sResultDoctDir + FILE_SEPARATOR_STR + _T("Editor.bin"); std::wstring sResultDoctFileEditor = sResultDoctDir + FILE_SEPARATOR_STR + _T("Editor.bin");
...@@ -1978,11 +2032,11 @@ namespace NExtractTools ...@@ -1978,11 +2032,11 @@ namespace NExtractTools
} }
return nRes; return nRes;
} }
// doc -> doct_bin // doc -> doct_bin
int doc2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) int doc2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{ {
std::wstring sResultDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked"); std::wstring sResultDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
NSDirectory::CreateDirectory(sResultDocxDir); NSDirectory::CreateDirectory(sResultDocxDir);
...@@ -1990,7 +2044,9 @@ namespace NExtractTools ...@@ -1990,7 +2044,9 @@ namespace NExtractTools
COfficeDocFile docFile; COfficeDocFile docFile;
docFile.m_sTempFolder = sTemp; docFile.m_sTempFolder = sTemp;
long nRes = docFile.LoadFromFile( sFrom, sResultDocxDir, params.getPassword(), NULL); bool bMacros = true;
long nRes = docFile.LoadFromFile( sFrom, sResultDocxDir, params.getPassword(), bMacros, NULL);
if (SUCCEEDED_X2T(nRes)) if (SUCCEEDED_X2T(nRes))
{ {
...@@ -2017,17 +2073,17 @@ namespace NExtractTools ...@@ -2017,17 +2073,17 @@ namespace NExtractTools
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD; return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
} }
return AVS_FILEUTILS_ERROR_CONVERT; return AVS_FILEUTILS_ERROR_CONVERT;
} }
int docx_dir2doc (const std::wstring &sDocxDir, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) int docx_dir2doc (const std::wstring &sDocxDir, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{ {
return AVS_FILEUTILS_ERROR_CONVERT; return AVS_FILEUTILS_ERROR_CONVERT;
COfficeDocFile docFile; COfficeDocFile docFile;
return /*S_OK == docFile.SaveToFile(sTo, sDocxDir, NULL) ? 0 : */AVS_FILEUTILS_ERROR_CONVERT; return /*S_OK == docFile.SaveToFile(sTo, sDocxDir, NULL) ? 0 : */AVS_FILEUTILS_ERROR_CONVERT;
} }
// doct -> rtf // doct -> rtf
int doct2rtf (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bFromChanges, const std::wstring &sThemeDir, InputParams& params) int doct2rtf (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bFromChanges, const std::wstring &sThemeDir, InputParams& params)
{ {
// Extract docx to temp directory // Extract docx to temp directory
std::wstring sTempUnpackedDOCT = sTemp + FILE_SEPARATOR_STR + _T("doct_unpacked"); std::wstring sTempUnpackedDOCT = sTemp + FILE_SEPARATOR_STR + _T("doct_unpacked");
std::wstring sTempDoctFileEditor = sTempUnpackedDOCT + FILE_SEPARATOR_STR + _T("Editor.bin"); std::wstring sTempDoctFileEditor = sTempUnpackedDOCT + FILE_SEPARATOR_STR + _T("Editor.bin");
...@@ -3943,6 +3999,10 @@ namespace NExtractTools ...@@ -3943,6 +3999,10 @@ namespace NExtractTools
{ {
result = doc2docx (sFileFrom, sFileTo, sTempDir, oInputParams); result = doc2docx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break; }break;
case TCD_DOC2DOCM:
{
result = doc2docm (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_DOCT2RTF: case TCD_DOCT2RTF:
{ {
result = doct2rtf (sFileFrom, sFileTo, sTempDir, bFromChanges, sThemeDir, oInputParams); result = doct2rtf (sFileFrom, sFileTo, sTempDir, bFromChanges, sThemeDir, oInputParams);
......
...@@ -130,6 +130,8 @@ namespace NExtractTools ...@@ -130,6 +130,8 @@ namespace NExtractTools
int doc2doct (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params); int doc2doct (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int doc2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params); int doc2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int docx_dir2doc (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params); int docx_dir2doc (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int doc2docm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int doc2docm_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlsx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params); int xls2xlsx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params); int xls2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
......
...@@ -240,7 +240,7 @@ namespace NExtractTools ...@@ -240,7 +240,7 @@ namespace NExtractTools
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC: case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC:
{ {
if (0 == sExt2.compare(_T(".docx"))) res = TCD_DOC2DOCX; if (0 == sExt2.compare(_T(".docx"))) res = TCD_DOC2DOCX;
else if (0 == sExt2.compare(_T(".docm"))) res = TCD_DOC2DOCX; else if (0 == sExt2.compare(_T(".docm"))) res = TCD_DOC2DOCM;
else if (0 == sExt2.compare(_T(".doct"))) res = TCD_DOC2DOCT; else if (0 == sExt2.compare(_T(".doct"))) res = TCD_DOC2DOCT;
else if (0 == sExt2.compare(_T(".bin"))) res = TCD_DOC2DOCT_BIN; else if (0 == sExt2.compare(_T(".bin"))) res = TCD_DOC2DOCT_BIN;
}break; }break;
......
...@@ -112,7 +112,8 @@ namespace NExtractTools ...@@ -112,7 +112,8 @@ namespace NExtractTools
TCD_DOC2DOCT, TCD_DOC2DOCT,
TCD_DOC2DOCT_BIN, TCD_DOC2DOCT_BIN,
TCD_DOC2DOCX, TCD_DOC2DOCX,
//doc 2 TCD_DOC2DOCM,
//xls 2
TCD_XLS2XLST, TCD_XLS2XLST,
TCD_XLS2XLST_BIN, TCD_XLS2XLST_BIN,
TCD_XLS2XLSX, TCD_XLS2XLSX,
...@@ -956,7 +957,10 @@ namespace NExtractTools ...@@ -956,7 +957,10 @@ namespace NExtractTools
else if (0 == sArg3.compare(_T("doc2docx"))) { else if (0 == sArg3.compare(_T("doc2docx"))) {
res = TCD_DOC2DOCX; res = TCD_DOC2DOCX;
} }
else if (0 == sArg3.compare(_T("rtf2docx"))) { else if (0 == sArg3.compare(_T("doc2docm"))) {
res = TCD_DOC2DOCM;
}
else if (0 == sArg3.compare(_T("rtf2docx"))) {
res = TCD_RTF2DOCX; res = TCD_RTF2DOCX;
} }
else if (0 == sArg3.compare(_T("docx2rtf"))) { else if (0 == sArg3.compare(_T("docx2rtf"))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment