Commit 89aba918 authored by ElenaSubbotina's avatar ElenaSubbotina

OoxFormat - read/write vbaProject in binary

parent 47c1e6f6
......@@ -39,6 +39,7 @@
#include "../../Common/DocxFormat/Source/DocxFormat/Media/ActiveX.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/Video.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/Audio.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h"
#include "../../Common/Base64.h"
......
......@@ -63,6 +63,7 @@
#include "../../Common/DocxFormat/Source/DocxFormat/Media/Video.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/OleObject.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/ActiveX.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h"
#include "../../Common/DocxFormat/Source/DocxFormat/External/HyperLink.h"
#include "../../Common/DocxFormat/Source/DocxFormat/External/ExternalImage.h"
#include "../../Common/DocxFormat/Source/DocxFormat/External/ExternalAudio.h"
......
......@@ -42,6 +42,8 @@
#include "../../../Common/DocxFormat/Source/DocxFormat/Media/Audio.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/Media/Video.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/Media/ActiveX.h"
namespace PPTX
{
namespace Logic
......
......@@ -78,8 +78,11 @@ namespace OOX
{
return m_filename;
}
void copy_to(const CPath& path) const
virtual void copy_to(const CPath& path) const
{
OOX::CPath pathSaveItem = path + FILE_SEPARATOR_STR + m_filename.GetFilename();
NSFile::CFileBinary::Copy(m_filename.GetPath(), pathSaveItem.GetPath());
}
virtual const CPath DefaultDirectory() const
{
......
......@@ -182,8 +182,6 @@ namespace OOX
return smart_ptr<OOX::File>(new OOX::ActiveX_xml( oRootPath, oFileName ));
else if ( pRelation->Type() == OOX::FileTypes::ActiveX_bin)
return smart_ptr<OOX::File>(new OOX::ActiveX_bin( oFileName ));
else if ( pRelation->Type() == OOX::FileTypes::VbaProject)
return smart_ptr<OOX::File>(new OOX::VbaProject( oRootPath, oFileName ));
return smart_ptr<OOX::File>( new UnknowTypeFile() );
}
......
......@@ -191,7 +191,8 @@ namespace BinXlsxRW
PivotCache = 8,
ExternalBook = 9,
OleLink = 10,
DdeLink = 11
DdeLink = 11,
VbaProject = 12
};}
namespace c_oSerWorkbookPrTypes{enum c_oSerWorkbookPrTypes
{
......
......@@ -38,6 +38,7 @@
#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/OleObject.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/ActiveX.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h"
#include "../../Common/OfficeFileFormats.h"
#include "../../Common/Base64.h"
......@@ -1521,6 +1522,14 @@ namespace BinXlsxRW
WriteExternalReferences(workbook.m_oExternalReferences.get(), workbook);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
smart_ptr<OOX::File> vbaProject = workbook.Get(OOX::FileTypes::VbaProject);
if (vbaProject.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::VbaProject);
WriteVbaProject (vbaProject.smart_dynamic_cast<OOX::VbaProject>());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
};
void WriteWorkbookPr(const OOX::Spreadsheet::CWorkbookPr& workbookPr)
{
......@@ -1925,7 +1934,6 @@ namespace BinXlsxRW
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteDefinedName(const OOX::Spreadsheet::CDefinedName& definedName)
{
int nCurPos = 0;
......@@ -1961,7 +1969,19 @@ namespace BinXlsxRW
m_oBcw.m_oStream.WriteBYTE(c_oSerDefinedNameTypes::Comment);
m_oBcw.m_oStream.WriteStringW(definedName.m_oComment.get2());
}
};
}
void WriteVbaProject(smart_ptr<OOX::VbaProject> & fileVbaProject)
{
std::wstring file_name = fileVbaProject->filename().GetFilename();
m_oBcw.m_oStream.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
m_oBcw.m_oStream.WriteString1(0, file_name);
m_oBcw.m_oStream.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
//... todooo write parsing vba project
//copy file bin
fileVbaProject->copy_to(m_oBcw.m_oStream.m_pCommon->m_pImageManager->m_strDstMedia);
}
};
class BinaryWorksheetTableWriter
{
......
......@@ -36,6 +36,8 @@
#include "../../Common/ATLDefine.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Sparkline.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h"
#include "../../DesktopEditor/common/Path.h"
#include "../../DesktopEditor/common/Directory.h"
......@@ -1504,8 +1506,10 @@ namespace BinXlsxRW {
{
OOX::Spreadsheet::CWorkbook& m_oWorkbook;
std::map<long, NSCommon::smart_ptr<OOX::File>>& m_mapPivotCacheDefinitions;
const std::wstring& m_sDestinationDir;
public:
BinaryWorkbookTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook, std::map<long, NSCommon::smart_ptr<OOX::File>>& mapPivotCacheDefinitions):Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook), m_mapPivotCacheDefinitions(mapPivotCacheDefinitions)
BinaryWorkbookTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook, std::map<long, NSCommon::smart_ptr<OOX::File>>& mapPivotCacheDefinitions, const std::wstring& sDestinationDir)
: Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook), m_mapPivotCacheDefinitions(mapPivotCacheDefinitions), m_sDestinationDir(sDestinationDir)
{
}
int Read()
......@@ -1542,6 +1546,10 @@ namespace BinXlsxRW {
res = Read1(length, &BinaryWorkbookTableReader::ReadPivotCaches, this, poResult);
m_oWorkbook.m_oPivotCachesXml->append(L"</pivotCaches>");
}
else if(c_oSerWorkbookTypes::VbaProject == type)
{
res = Read1(length, &BinaryWorkbookTableReader::ReadVbaProject, this, poResult);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
......@@ -2068,7 +2076,7 @@ namespace BinXlsxRW {
else
res = c_oSerConstants::ReadUnknown;
return res;
};
}
int ReadPivotCache(BYTE type, long length, void* poResult)
{
PivotCachesTemp* pPivotCachesTemp = static_cast<PivotCachesTemp*>(poResult);
......@@ -2090,13 +2098,36 @@ namespace BinXlsxRW {
else
res = c_oSerConstants::ReadUnknown;
return res;
};
}
int ReadVbaProject(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
if(c_oSerWorkbookTypes::VbaProject == type)
{
std::wstring file_name = m_oBufferedStream.GetString3(length);
OOX::CPath inputPath = m_oBufferedStream.m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + file_name;
OOX::CPath outputPath = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + _T("vbaProject.bin");
NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath());
smart_ptr<OOX::VbaProject> oFile;
oFile->set_filename(outputPath);
const OOX::RId oRId = m_oWorkbook.Add(oFile.smart_dynamic_cast<OOX::File>());
return res;
}
else
res = c_oSerConstants::ReadUnknown;
}
};
class BinaryCommentReader : public Binary_CommonReader<BinaryCommentReader>
{
OOX::Spreadsheet::CWorksheet* m_pCurWorksheet;
public:
BinaryCommentReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorksheet* pCurWorksheet):Binary_CommonReader(oBufferedStream),m_pCurWorksheet(pCurWorksheet)
BinaryCommentReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorksheet* pCurWorksheet)
: Binary_CommonReader(oBufferedStream), m_pCurWorksheet(pCurWorksheet)
{
}
int Read(long length, void* poResult)
......@@ -4414,7 +4445,7 @@ namespace BinXlsxRW {
if(-1 != nWorkbookOffBits)
{
oBufferedStream.Seek(nWorkbookOffBits);
res = BinaryWorkbookTableReader(oBufferedStream, *pWorkbook, m_mapPivotCacheDefinitions).Read();
res = BinaryWorkbookTableReader(oBufferedStream, *pWorkbook, m_mapPivotCacheDefinitions, sOutDir).Read();
if(c_oSerConstants::ReadOk != res)
return res;
}
......
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