_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; }
std::wstring COfficeOdfFileW::DetectTypeDocument(const std::wstring & pathOOX) { std::wstring sRes; CFile file; CString fileContentType = std_string2string(pathOOX + FILE_SEPARATOR_STR + L"[Content_Types].xml"); if (file.OpenFile(fileContentType) != S_OK) return sRes; int nBufferSize = min (file.GetFileSize(), 4096); BYTE *pBuffer = new BYTE[nBufferSize]; file.ReadFile(pBuffer, nBufferSize); file.CloseFile(); if (pBuffer != NULL) { const char *docxFormatLine = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"; const char *dotxFormatLine = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml"; const char *docmFormatLine = "application/vnd.ms-word.document.macroEnabled.main+xml"; const char *dotmFormatLine = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml"; const char *xlsxFormatLine = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"; const char *xltxFormatLine = "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"; const char *xlsmFormatLine = "application/vnd.ms-excel.sheet.macroEnabled.main+xml"; const char *xltmFormatLine = "application/vnd.ms-excel.template.macroEnabled.main+xml"; const char *pptxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"; const char *ppsxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml"; const char *potxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml"; const char *pptmFormatLine = "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml"; const char *ppsmFormatLine = "application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml"; const char *potmFormatLine = "application/vnd.ms-powerpoint.template.macroEnabled.main+xml"; std::string strContentTypes((char*)pBuffer, nBufferSize); int res = 0; if ( (res = strContentTypes.find(docxFormatLine))>0 || (res = strContentTypes.find(dotxFormatLine))>0 || (res = strContentTypes.find(docmFormatLine))>0 || (res = strContentTypes.find(dotmFormatLine))>0) { sRes = L"text"; } else if ((res = strContentTypes.find(xlsxFormatLine))>0 || (res = strContentTypes.find(xltxFormatLine))>0 || (res = strContentTypes.find(xlsmFormatLine))>0 || (res = strContentTypes.find(xltmFormatLine))>0) { sRes = L"spreadsheet"; } else if ((res = strContentTypes.find(pptxFormatLine) > 0) || /*(res = strContentTypes.find(ppsxFormatLine))>0 ||*/ (res = strContentTypes.find(potxFormatLine))>0 || (res = strContentTypes.find(pptmFormatLine))>0 || (res = strContentTypes.find(ppsmFormatLine))>0 || (res = strContentTypes.find(potmFormatLine))>0 || (res = strContentTypes.find(ppsxFormatLine)) >0 ) { } delete []pBuffer; pBuffer = NULL; } return sRes; }