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; }
bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName) { COfficeUtils OfficeUtils(NULL); ULONG nBufferSize = 0; BYTE *pBuffer = NULL; HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"[Content_Types].xml", &pBuffer, nBufferSize); if (hresult == S_OK && 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); std::string::size_type res1 = std::string::npos; std::string::size_type res = 0; if (std::string::npos != strContentTypes.find(docxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; } else if (std::string::npos != strContentTypes.find(docmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(dotxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX; } else if (std::string::npos != strContentTypes.find(dotmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(xlsxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX; } else if (std::string::npos != strContentTypes.find(xlsmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(xltxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX; } else if (std::string::npos != strContentTypes.find(xltmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(pptxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX; } else if (std::string::npos != strContentTypes.find(pptmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(ppsmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM; bMacroEnabled = true; } else if (std::string::npos != strContentTypes.find(ppsxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX; } else if (std::string::npos != strContentTypes.find(potxFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX; } else if (std::string::npos != strContentTypes.find(potmFormatLine)) { nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM; bMacroEnabled = true; } delete []pBuffer; pBuffer = NULL; if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN) return true; } return false; }