для стыковки с docxFile2 как код: код лежащий в PPTXFile поменял namespace OOX -> PPTX; отделение com интерфейса от логики.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@58310 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
Sergey.Konovalov
2014-09-17 14:53:02 +00:00
committed by Alexander Trofimov
parent 30fd8af8b5
commit 6847df2da0
88 changed files with 5246 additions and 4714 deletions

View File

@ -0,0 +1,396 @@
#include "stdafx.h"
#include "ASCOfficePPTXFile.h"
#include "PPTXFormat/PPTXEvent.h"
#include "../../../../Common/GdiPlusEx.h"
#include <shellapi.h>
#include <shlobj.h>
#include <shlwapi.h>
#pragma comment( lib, "shell32.lib" ) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> shell32.lib
#include "Editor\PPTXWriter.h"
CPPTXFile::CPPTXFile(load_from_resource fCallbackResource, extract_to_directory fCallbackExtract, compress_from_directory fCallbackCompress, progress_operation fCallbackProgress, void* pCallbackArg)
{
WCHAR buffer[4096];
GetTempPathW(4096, buffer);
m_strTempDir = CStringW(buffer);
GetLongPathNameW(m_strTempDir.GetString(), buffer, 4096);
m_strTempDir = CStringW(buffer) + CStringW("_PPTX\\");
//
m_strFontDirectory = _T("");
m_strMediaDirectory = _T("");
m_bIsUseSystemFonts = FALSE;
m_strEmbeddedFontsDirectory = _T("");
m_strFolderThemes = _T("");
m_fCallbackResource = fCallbackResource;
m_fCallbackExtract = fCallbackExtract;
m_fCallbackCompress = fCallbackCompress;
m_fCallbackProgress = fCallbackProgress;
m_pCallbackArg = pCallbackArg;
m_pFolder = NULL;
//m_pOfficeUtils = NULL;
//if (S_OK != CoCreateInstance(__uuidof(OfficeUtils::COfficeUtils), NULL, CLSCTX_INPROC_SERVER, __uuidof(OfficeUtils::IOfficeUtils),(void**)&m_pOfficeUtils))
// return S_FALSE;
m_pInit = new CGdiPlusInit();
m_pInit->Init();
}
CPPTXFile::~CPPTXFile()
{
RELEASEOBJECT(m_pFolder);
RELEASEOBJECT(m_pInit);
}
HRESULT CPPTXFile::LoadFromFile(BSTR sSrcFileName, BSTR sDstPath, BSTR sXMLOptions)
{
CStringW localTempDir(sDstPath);
if((sDstPath != NULL) || (localTempDir != ""))
{
int res = SHCreateDirectoryExW(NULL, localTempDir.GetString(), NULL);
if((res != ERROR_SUCCESS) && (res != ERROR_ALREADY_EXISTS) && (res != ERROR_FILE_EXISTS))
return S_FALSE;
put_TempDirectory(sDstPath);
}
else
{
int res = SHCreateDirectoryExW(NULL, m_strTempDir, NULL);
if((res != ERROR_SUCCESS) && (res != ERROR_ALREADY_EXISTS) && (res != ERROR_FILE_EXISTS))
return S_FALSE;
}
localTempDir = m_strTempDir;
/*
SHFILEOPSTRUCTW shfos;
ZeroMemory(&shfos, sizeof(shfos));
shfos.wFunc = FO_DELETE;
CStringW _local = localTempDir + CStringW(L"*.*");
_local.AppendChar(0);
_local.AppendChar(0);
shfos.pFrom = _local.GetString();
shfos.fFlags = FOF_SILENT + FOF_NOCONFIRMATION;
if(SHFileOperationW(&shfos) != 0)
return S_FALSE;
*/
if(!m_fCallbackExtract(m_pCallbackArg, CString(sSrcFileName), localTempDir))
return S_FALSE;
RELEASEOBJECT(m_pFolder);
m_pFolder = new PPTX::Folder();
if(!m_pFolder->isValid(localTempDir))
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
m_pFolder->read(localTempDir, (PPTX::IPPTXEvent*)this);
if(GetPercent() < 1000000)
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
smart_ptr<PPTX::Presentation> presentation = m_pFolder->get(PPTX::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
if (!presentation.is_init())
{
RemoveDirOrFile(m_strTempDir, false);
return S_FALSE;
}
m_strDirectory = (CString)sSrcFileName;
int nIndex = m_strDirectory.ReverseFind(TCHAR('\\'));
if (-1 != nIndex)
m_strDirectory = m_strDirectory.Mid(0, nIndex);
return S_OK;
}
HRESULT CPPTXFile::SaveToFile(BSTR sDstFileName, BSTR sSrcPath, BSTR sXMLOptions)
{
if (NULL == m_pFolder)
return S_FALSE;
OOX::CPath oPath;
oPath.m_strFilename = CString(sSrcPath);
m_pFolder->write(oPath);
return m_fCallbackCompress(m_pCallbackArg, CString(sSrcPath), CString(sDstFileName)) ? S_OK : S_FALSE;
}
HRESULT CPPTXFile::get_TempDirectory(BSTR* pVal)
{
*pVal = m_strTempDir.AllocSysString();
return S_OK;
}
HRESULT CPPTXFile::put_TempDirectory(BSTR newVal)
{
CStringW TempStr(newVal);
if(PathIsDirectoryW(TempStr.GetString()))
{
if(TempStr.Right(1) != L"\\")
TempStr += L"\\";
m_strTempDir = TempStr;
return S_OK;
}
return S_FALSE;
}
HRESULT CPPTXFile::GetDVDXml(BSTR* pbstrPTTXml)
{
return S_OK;
}
HRESULT CPPTXFile::GetBluRayXml(BSTR* pbstrDVDXml)
{
return S_OK;
}
HRESULT CPPTXFile::get_DrawingXml(BSTR* pVal)
{
if ((NULL == m_pFolder) || (NULL == pVal))
return S_FALSE;
return S_OK;
}
HRESULT CPPTXFile::SetAdditionalParam(BSTR ParamName, VARIANT ParamValue)
{
CString sParamName; sParamName = ParamName;
if (_T("EmbeddedFontsDirectory") == sParamName && ParamValue.vt == VT_BSTR)
{
m_strEmbeddedFontsDirectory = ParamValue.bstrVal;
return S_OK;
}
return S_OK;
}
HRESULT CPPTXFile::GetAdditionalParam(BSTR ParamName, VARIANT* ParamValue)
{
if (NULL == ParamValue)
return S_FALSE;
return S_OK;
}
bool CPPTXFile::Progress(long ID, long Percent)
{
percent = Percent;
return m_fCallbackProgress(m_pCallbackArg, ID, Percent);
}
// to PPTY
HRESULT CPPTXFile::SetMediaDir(BSTR bsMediaDir)
{
m_strMediaDirectory = bsMediaDir;
return S_OK;
}
HRESULT CPPTXFile::SetFontDir(BSTR bsFontDir)
{
m_strFontDirectory = bsFontDir;
return S_OK;
}
HRESULT CPPTXFile::SetThemesDir(BSTR bsDir)
{
m_strFolderThemes = bsDir;
return S_OK;
}
HRESULT CPPTXFile::SetUseSystemFonts(VARIANT_BOOL useSystemFonts)
{
m_bIsUseSystemFonts = (VARIANT_TRUE == useSystemFonts);
return S_OK;
}
HRESULT CPPTXFile::OpenFileToPPTY(BSTR bsInput, BSTR bsOutput)
{
int res = SHCreateDirectoryExW(NULL, m_strTempDir, NULL);
if((res != ERROR_SUCCESS) && (res != ERROR_ALREADY_EXISTS) && (res != ERROR_FILE_EXISTS))
return S_FALSE;
if(!m_fCallbackExtract(m_pCallbackArg, CString(bsInput), m_strTempDir))
return S_FALSE;
RELEASEOBJECT(m_pFolder);
m_pFolder = new PPTX::Folder();
if (!m_pFolder->isValid(m_strTempDir))
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
m_pFolder->read(m_strTempDir, (PPTX::IPPTXEvent*)this);
if(GetPercent() < 1000000)
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
smart_ptr<PPTX::Presentation> presentation = m_pFolder->get(PPTX::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
if (!presentation.is_init())
{
RemoveDirOrFile(m_strTempDir, false);
return S_FALSE;
}
m_strDirectory = (CString)bsInput;
int nIndex = m_strDirectory.ReverseFind(TCHAR('\\'));
if (-1 != nIndex)
m_strDirectory = m_strDirectory.Mid(0, nIndex);
NSBinPptxRW::CBinaryFileWriter oBinaryWriter;
oBinaryWriter.m_oCommon.CheckFontPicker();
oBinaryWriter.m_oCommon.m_pNativePicker->Init(m_strFontDirectory);
CString sDstFileOutput = bsOutput;
m_strMediaDirectory = sDstFileOutput;
nIndex = m_strMediaDirectory.ReverseFind(TCHAR('\\'));
if (-1 != nIndex)
m_strMediaDirectory = m_strMediaDirectory.Mid(0, nIndex);
oBinaryWriter.m_strMainFolder = m_strMediaDirectory;
m_strMediaDirectory = m_strMediaDirectory + _T("\\media");
oBinaryWriter.m_oCommon.m_oImageManager.m_strDstMedia = m_strMediaDirectory;
CDirectory::CreateDirectory(m_strMediaDirectory);
if (_T("") != m_strEmbeddedFontsDirectory)
{
CDirectory::CreateDirectory(m_strEmbeddedFontsDirectory);
if (NULL != oBinaryWriter.m_oCommon.m_pFontPicker)
{
oBinaryWriter.m_oCommon.m_pNativePicker->m_bIsEmbeddedFonts = TRUE;
oBinaryWriter.m_oCommon.m_pNativePicker->m_oEmbeddedFonts.m_strEmbeddedFontsFolder = m_strEmbeddedFontsDirectory;
}
}
PPTX2EditorAdvanced::Convert(oBinaryWriter, *m_pFolder, m_strDirectory, sDstFileOutput);
return S_OK;
}
HRESULT CPPTXFile::OpenDirectoryToPPTY(BSTR bsInput, BSTR bsOutput)
{
RELEASEOBJECT(m_pFolder);
m_pFolder = new PPTX::Folder();
if (!m_pFolder->isValid((CString)bsInput))
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
m_pFolder->read((CString)bsInput, (PPTX::IPPTXEvent*)this);
if(GetPercent() < 1000000)
{
RELEASEOBJECT(m_pFolder);
return S_FALSE;
}
smart_ptr<PPTX::Presentation> presentation = m_pFolder->get(PPTX::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
if (!presentation.is_init())
{
RemoveDirOrFile(m_strTempDir, false);
return S_FALSE;
}
m_strDirectory = (CString)bsInput;
int nIndex = m_strDirectory.ReverseFind(TCHAR('\\'));
if (-1 != nIndex)
m_strDirectory = m_strDirectory.Mid(0, nIndex);
NSBinPptxRW::CBinaryFileWriter oBinaryWriter;
oBinaryWriter.m_oCommon.CheckFontPicker();
oBinaryWriter.m_oCommon.m_pNativePicker->Init(m_strFontDirectory);
CString sDstFileOutput = (CString)bsOutput;
m_strMediaDirectory = sDstFileOutput;
nIndex = m_strMediaDirectory.ReverseFind(TCHAR('\\'));
if (-1 != nIndex)
m_strMediaDirectory = m_strMediaDirectory.Mid(0, nIndex);
oBinaryWriter.m_strMainFolder = m_strMediaDirectory;
m_strMediaDirectory = m_strMediaDirectory + _T("\\media");
oBinaryWriter.m_oCommon.m_oImageManager.m_strDstMedia = m_strMediaDirectory;
CDirectory::CreateDirectory(m_strMediaDirectory);
PPTX2EditorAdvanced::Convert(oBinaryWriter, *m_pFolder, m_strDirectory, sDstFileOutput);
return S_OK;
}
HRESULT CPPTXFile::ConvertPPTYToPPTX(BSTR bsInput, BSTR bsOutput)
{
#ifdef _DEBUG
m_strTempDir = _T("C:\\PPTMemory\\PPTX_test");
#endif
int len = m_strTempDir.GetLength();
while (len != 0 && m_strTempDir[len - 1] == (TCHAR)'\\')
{
m_strTempDir.Delete(len - 1);
--len;
}
NSBinPptxRW::CPPTXWriter oWriter(m_fCallbackResource, m_pCallbackArg);
oWriter.Init(m_strTempDir);
CFile oFileBinary;
oFileBinary.OpenFile((CString)bsInput);
LONG lFileSize = (LONG)oFileBinary.GetFileSize();
BYTE* pSrcBuffer = new BYTE[lFileSize];
oFileBinary.ReadFile(pSrcBuffer, (DWORD)lFileSize);
oFileBinary.CloseFile();
CString srcFolder = CDirectory::GetFolderPath((CString)bsInput);
oWriter.OpenPPTY(pSrcBuffer, lFileSize, srcFolder, m_strFolderThemes);
RELEASEARRAYOBJECTS(pSrcBuffer);
HRESULT hRes = m_fCallbackCompress(m_pCallbackArg, m_strTempDir, CString(bsOutput)) ? S_OK : S_FALSE;
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
RemoveDirOrFile(m_strTempDir);
return hRes;
}
INT32 CPPTXFile::RemoveDirOrFile(CString sPath, bool bIsRemoveHead)
{
DWORD dwFileAttrib = ::GetFileAttributes( sPath );
if( dwFileAttrib != INVALID_FILE_ATTRIBUTES )
{
DWORD dwResult = 0;
if( 0 != (FILE_ATTRIBUTE_DIRECTORY & dwFileAttrib) )
{
HANDLE Handle;
WIN32_FIND_DATA FindData;
DWORDLONG Result = 0;
Handle = FindFirstFile( ( sPath + _T("\\*.*") ), &FindData );
if ( Handle == INVALID_HANDLE_VALUE )
return 0;
do
{
BOOL bRes = TRUE;
if( ( CString( FindData.cFileName ) != _T(".") ) && ( CString( FindData.cFileName ) != _T("..") ) )
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
Result += RemoveDirOrFile( sPath + _T("\\") + FindData.cFileName ); //
else
bRes = DeleteFile( sPath + _T("\\") + FindData.cFileName );
if( FALSE == bRes )
dwResult += 1;
}
while( FindNextFile( Handle, &FindData ) != 0 );
FindClose( Handle );
if (bIsRemoveHead)
{
BOOL bRes = RemoveDirectory( sPath );
if( FALSE == bRes )
dwResult += 1;
}
}
else
{
if( FALSE == DeleteFile( sPath ) )
dwResult = 1;
}
return dwResult;
}// 0 - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return 0;
}