Exemple #1
0
	void VbaProject::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader)
	{
		LONG _end_rec = pReader->GetPos() + pReader->GetLong() + 4;

		pReader->Skip(1); // start attributes
		while (true)
		{
			BYTE _at = pReader->GetUChar_TypeNode();
			if (_at == NSBinPptxRW::g_nodeAttributeEnd)
				break;

			switch (_at)
			{
				case 0:
				{
					std::wstring file_name = pReader->GetString2();

					OOX::CPath inputPath = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media")  + FILE_SEPARATOR_STR + file_name;
					OOX::CPath outputPath = pReader->m_pRels->m_pManager->GetDstFolder() + FILE_SEPARATOR_STR + _T("vbaProject.bin");

					NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath());

					set_filename(outputPath.GetPath(), false);
					
				}break;

				default:
					break;
			}
		}
		pReader->Seek(_end_rec);
	}
_UINT32 CPPTXFile::OpenDirectoryToPPTY(std::wstring bsInput, std::wstring bsOutput)
{
	OOX::CPath pathInputDirectory = bsInput;

	RELEASEOBJECT(m_pPptxDocument);
	m_pPptxDocument = new PPTX::Document();

	if (!m_pPptxDocument->isValid(pathInputDirectory.GetPath())) // true ???
	{
		RELEASEOBJECT(m_pPptxDocument);
		return AVS_FILEUTILS_ERROR_CONVERT;
	}

	m_pPptxDocument->read(pathInputDirectory.GetPath() + FILE_SEPARATOR_STR, (PPTX::IPPTXEvent*)this);
	if(GetPercent() < 1000000)
	{
		RELEASEOBJECT(m_pPptxDocument);
		return AVS_FILEUTILS_ERROR_CONVERT;
	}
	smart_ptr<PPTX::Presentation> presentation = m_pPptxDocument->Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
	if (!presentation.is_init())
	{
        NSDirectory::DeleteDirectory(m_strTempDir, false);
		return AVS_FILEUTILS_ERROR_CONVERT;
	}

	m_strDirectory = pathInputDirectory.GetDirectory();

	NSBinPptxRW::CBinaryFileWriter oBinaryWriter;
	oBinaryWriter.m_pCommon->CheckFontPicker();
	oBinaryWriter.m_pCommon->m_pNativePicker->Init(m_strFontDirectory);

	OOX::CPath pathDstFileOutput = bsOutput;
	
	OOX::CPath pathMedia = pathDstFileOutput.GetDirectory() + FILE_SEPARATOR_STR + _T("media");

	m_strMediaDirectory = pathMedia.GetPath();
	oBinaryWriter.m_strMainFolder = pathDstFileOutput.GetDirectory();

 	oBinaryWriter.m_pCommon->m_pMediaManager->m_strDstMedia = m_strMediaDirectory;
	oBinaryWriter.m_pCommon->m_pMediaManager->SetFontManager(oBinaryWriter.m_pCommon->m_pNativePicker->m_pFontManager);

    NSDirectory::CreateDirectory(m_strMediaDirectory);

    if (!m_strEmbeddedFontsDirectory.empty())
	{
        NSDirectory::CreateDirectory(m_strEmbeddedFontsDirectory);

		if (NULL != oBinaryWriter.m_pCommon->m_pFontPicker)
		{
            oBinaryWriter.m_pCommon->m_pNativePicker->m_bIsEmbeddedFonts = true;
			oBinaryWriter.m_pCommon->m_pNativePicker->m_oEmbeddedFonts.m_strEmbeddedFontsFolder = m_strEmbeddedFontsDirectory;
		}
	}

	PPTX2EditorAdvanced::Convert(oBinaryWriter, *m_pPptxDocument, m_strDirectory, pathDstFileOutput.GetPath(), m_bIsNoBase64);

	return S_OK;
}
_UINT32 CPPTXFile::ConvertPPTYToPPTX(std::wstring bsInput, std::wstring bsOutput, std::wstring bsThemesFolder)//bsOutput и файл и директория может быть 
{
	OOX::CPath pathLocalTempDirectory;
	
	if (m_fCallbackCompress)//если компрессора нет - конвертим в назначеную директорию 
		pathLocalTempDirectory = m_strTempDir ;
	else
		pathLocalTempDirectory = bsOutput; //выходной файл - папка

#ifdef _DEBUG
	#if defined(_WIN32) || defined (_WIN64)
		if (m_fCallbackCompress)
			pathLocalTempDirectory = _T("C:\\PPTMemory\\PPTX_test");
	#endif
#endif


	NSBinPptxRW::CPPTXWriter oWriter;
	oWriter.Init(pathLocalTempDirectory.GetPath());

	CFile oFileBinary;
	oFileBinary.OpenFile((std::wstring)bsInput);	
		LONG lFileSize = (LONG)oFileBinary.GetFileSize();
		BYTE* pSrcBuffer = new BYTE[lFileSize];
		oFileBinary.ReadFile(pSrcBuffer, (DWORD)lFileSize);
	oFileBinary.CloseFile();
	
	std::wstring strBsInput = bsInput;
    std::wstring srcFolder = NSDirectory::GetFolderPath(strBsInput);

	oWriter.OpenPPTY(pSrcBuffer, lFileSize, srcFolder, bsThemesFolder);
	
	RELEASEARRAYOBJECTS(pSrcBuffer);
	
	_UINT32 hRes = 0;

	if (m_fCallbackCompress)
	{
        std::wstring strOutput = bsOutput;
        std::wstring strInput = pathLocalTempDirectory.GetPath();

        hRes = m_fCallbackCompress(m_pCallbackArg, strInput, strOutput) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;

        NSDirectory::DeleteDirectory(strInput);
	}
	return hRes;
}
	void XDocument::Save(const OOX::CPath& path)
	{
		std::ofstream file(path.GetPath());
		if (!file.bad())
		{
			file << ToString();
			file.close();
		}
	}
		void DefaultTable::add(const OOX::CPath& path)
		{
			const std::wstring extension = std::wstring(OOX::CSystemUtility::GetFileExtention(path.GetPath()));
			
			if (std::find(begin(), end(), extension) == end())
				m_items.push_back(extension);

			
			
			
		}
Exemple #6
0
int Binary_HdrFtrTableReader::ReadHdrFtrItem(BYTE type, long length, void* poResult)
{
	int res = c_oSerConstants::ReadOk;
	if ( c_oSerHdrFtrTypes::HdrFtr_Content == type )
	{
		Writers::HdrFtrItem* poHdrFtrItem = NULL;
		switch(nCurHeaderType)
		{
		case c_oSerHdrFtrTypes::HdrFtr_First:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrFirst);break;
		case c_oSerHdrFtrTypes::HdrFtr_Even:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrEven);break;
		case c_oSerHdrFtrTypes::HdrFtr_Odd:poHdrFtrItem = new Writers::HdrFtrItem(SimpleTypes::hdrftrDefault);break;
		}
		if(NULL != poHdrFtrItem)
		{
			if(nCurType == c_oSerHdrFtrTypes::Header)
			{
				m_oHeaderFooterWriter.m_aHeaders.push_back(poHdrFtrItem);
                poHdrFtrItem->m_sFilename = L"header" + std::to_wstring((int)m_oHeaderFooterWriter.m_aHeaders.size()) + L".xml";
			}
			else
			{
				m_oHeaderFooterWriter.m_aFooters.push_back(poHdrFtrItem);
                poHdrFtrItem->m_sFilename = L"footer" + std::to_wstring((int)m_oHeaderFooterWriter.m_aFooters.size()) + L".xml";
			}
			m_oFileWriter.m_pDrawingConverter->SetDstContentRels();
			Binary_DocumentTableReader oBinary_DocumentTableReader(m_oBufferedStream, m_oFileWriter, poHdrFtrItem->Header, m_pComments);
			READ1_DEF(length, res, this->ReadHdrFtrItemContent, &oBinary_DocumentTableReader);

            OOX::CPath fileRelsPath = m_oFileWriter.m_oDocumentWriter.m_sDir +	FILE_SEPARATOR_STR + L"word" + 
																				FILE_SEPARATOR_STR + L"_rels"+ 
																				FILE_SEPARATOR_STR + poHdrFtrItem->m_sFilename + L".rels";

            m_oFileWriter.m_pDrawingConverter->SaveDstContentRels(fileRelsPath.GetPath());
		}
	}
	else
		res = c_oSerConstants::ReadUnknown;
	return res;
}
_UINT32 CPPTXFile::OpenFileToPPTY(std::wstring bsInput, std::wstring bsOutput)
{
    if (m_strTempDir.empty())
	{
        m_strTempDir = NSDirectory::GetTempPath();
	}

    NSDirectory::CreateDirectory(m_strTempDir);

    OOX::CPath pathLocalInputTemp = NSDirectory::CreateDirectoryWithUniqueName(m_strTempDir);

	bool notDeleteInput = false;

	if (m_fCallbackExtract)
	{
        std::wstring strInput = bsInput;
        std::wstring strOutput = pathLocalInputTemp.GetPath();

        if(!m_fCallbackExtract(m_pCallbackArg, strInput , strOutput))
		{
			pathLocalInputTemp = bsInput;
			notDeleteInput = true;
		}
	}
	else
	{
		pathLocalInputTemp = bsInput;
		notDeleteInput = true;
	}
	std::wstring bsLocalInputTemp= pathLocalInputTemp.GetPath();

	_UINT32 hr = OpenDirectoryToPPTY(bsLocalInputTemp, bsOutput);

	if (notDeleteInput == false)
        NSDirectory::DeleteDirectory(pathLocalInputTemp.GetPath());
	
	return hr;
}
	void FontTable::read(const OOX::CPath& oPath)
	{
		m_fonts.clear();

		XmlUtils::CXmlNode oFonts;
		oFonts.FromXmlFile( oPath.GetPath(), true );

		if ( _T("w:fonts") == oFonts.GetName() )
		{
			XmlUtils::CXmlNodes oFontList;
			oFonts.GetNodes( _T("w:font"), oFontList );

			for ( int nFontIndex = 0; nFontIndex < oFontList.GetCount(); ++nFontIndex )
			{
				XmlUtils::CXmlNode oFontNode;
				if ( oFontList.GetAt( nFontIndex, oFontNode ) )
				{
					Font oFont;
					oFont.fromXML( oFontNode );
					m_fonts.push_back( oFont );
				}
			}
		}
	}
Exemple #9
0
	void VbaProject::write(const OOX::CPath& filename, const OOX::CPath& directory, CContentTypes& content) const
	{
		content.Registration( type().OverrideType(), directory, filename.GetFilename() );
		IFileContainer::Write( filename, directory, content );
	}
Exemple #10
0
	long Document::CountFiles(const OOX::CPath& path)
	{
		return OOX::CSystemUtility::GetFilesCount(path.GetDirectory(), true);
	}
	void WordprocessingDocument::SaveDocument(bool &bMacros)
	{
		std::wstring pathWord = m_strOutputPath + FILE_SEPARATOR_STR + L"word" ;
		NSDirectory::CreateDirectory( pathWord );

		if (bMacros && docFile->GetStorage()->isDirectory(L"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, L"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();
		}
		OOX::CContentTypes oContentTypes;
		OOX::CPath pathDocProps = m_strOutputPath + FILE_SEPARATOR_STR + _T("docProps");
		NSDirectory::CreateDirectory(pathDocProps.GetPath());
		
		OOX::CPath DocProps = std::wstring(_T("docProps"));

		OOX::CApp* pApp = new OOX::CApp(NULL);
		if (pApp)
		{
			std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvApplicationName);
			if (sApplication.empty())
				sApplication = NSSystemUtils::gc_EnvApplicationNameDefault;
			pApp->SetApplication(sApplication);
	#if defined(INTVER)
			pApp->SetAppVersion(VALUE2STR(INTVER));
	#endif
			pApp->SetDocSecurity(0);
			pApp->SetScaleCrop(false);
			pApp->SetLinksUpToDate(false);
			pApp->SetSharedDoc(false);
			pApp->SetHyperlinksChanged(false);
			
			pApp->write(pathDocProps + FILE_SEPARATOR_STR + _T("app.xml"), DocProps, oContentTypes);
			delete pApp;
		}				
		OOX::CCore* pCore = new OOX::CCore(NULL);
		if (pCore)
		{
			pCore->SetCreator(_T(""));
			pCore->SetLastModifiedBy(_T(""));
			pCore->write(pathDocProps + FILE_SEPARATOR_STR + _T("core.xml"), DocProps, oContentTypes);
			delete pCore;
		} 
		RegisterDocPr();

		WritePackage();

		//Write main content. (word directory)

        SaveToFile(pathWord, std::wstring( L"document.xml" ),		DocumentXML );
        SaveToFile(pathWord, std::wstring( L"fontTable.xml" ),      FontTableXML );
        SaveToFile(pathWord, std::wstring( L"styles.xml" ),         StyleSheetXML );
        SaveToFile(pathWord, std::wstring( L"footnotes.xml" ),      FootnotesXML );
        SaveToFile(pathWord, std::wstring( L"endnotes.xml" ),		EndnotesXML );
        SaveToFile(pathWord, std::wstring( L"numbering.xml" ),      NumberingXML );
        SaveToFile(pathWord, std::wstring( L"comments.xml" ),		CommentsXML );
        SaveToFile(pathWord, std::wstring( L"settings.xml" ),		SettingsXML );
        SaveToFile(pathWord, std::wstring( L"customizations.xml" ), CommandTableXML );

		if (!ImagesList.empty())
		{
            std::wstring pathMedia = pathWord + FILE_SEPARATOR_STR + L"media";
 
            NSDirectory::CreateDirectory(pathMedia);

			int i = 1;

			for (std::list<ImageFileStructure>::iterator iter = ImagesList.begin(); iter != ImagesList.end(); ++iter)
			{
				unsigned char* bytes = NULL;
				bytes = new unsigned char[iter->data.size()];
				if (bytes) 
				{
					copy(iter->data.begin(), iter->data.end(), bytes);

					if (Global::msoblipDIB == iter->blipType)
					{//user_manual_v52.doc						
                        std::wstring file_name = pathMedia + FILE_SEPARATOR_STR + L"image" + FormatUtils::IntToWideString(i++);
						iter->blipType = ImageHelper::SaveImageToFileFromDIB(bytes, iter->data.size(), file_name);
					}
					else
					{
                        SaveToFile(pathMedia, std::wstring(L"image" ) + FormatUtils::IntToWideString(i++) + iter->ext, (void*)bytes, (unsigned int)iter->data.size());
					}
					
					RELEASEARRAYOBJECTS(bytes);
				}
			}
		}

		if (!OleObjectsList.empty())
		{
            std::wstring pathObjects = pathWord + FILE_SEPARATOR_STR + L"embeddings" ;
            NSDirectory::CreateDirectory( pathObjects );

			int i = 1;
			for (std::list<OleObjectFileStructure>::iterator iter = OleObjectsList.begin(); iter != OleObjectsList.end(); ++iter)
			{
                std::wstring fileName = pathObjects + FILE_SEPARATOR_STR  + L"oleObject" + FormatUtils::IntToWideString(i++) + iter->ext;

				if (!iter->data.empty())
				{
					SaveEmbeddedObject(fileName, *iter);
				}
				else
				{
					SaveOLEObject( fileName, *iter );	
				}
			}
		}

		int headersCount = 0;
		int footersCount = 0;

		for (std::list<std::wstring>::iterator iter = HeaderXMLList.begin(); iter != HeaderXMLList.end(); ++iter)
		{
            SaveToFile(pathWord, ( std::wstring( L"header" ) + FormatUtils::IntToWideString(++headersCount) + std::wstring( L".xml" ) ), *iter);
		}

		for (std::list<std::wstring>::iterator iter = FooterXMLList.begin(); iter != FooterXMLList.end(); ++iter)
		{
            SaveToFile(pathWord, ( std::wstring( L"footer" ) + FormatUtils::IntToWideString(++footersCount) + std::wstring( L".xml" ) ), *iter);
		}
	}