HRESULT COfficeUtils::CompressFileOrDirectory(const std::wstring& _name, const std::wstring& _outputFile, bool bSorted, int method, short level) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring name = _name;//CorrectPathW(_name); std::wstring outputFile = CorrectPathW(_outputFile); #else std::wstring name = _name; std::wstring outputFile = _outputFile; #endif HRESULT result = S_FALSE; if(NSDirectory::Exists(name)) { if ( ZLibZipUtils::ZipDir( name.c_str(), outputFile.c_str(), m_fCallback, bSorted, method, level ) == 0 ) { result = S_OK; } else { result = S_FALSE; } } else if(NSFile::CFileBinary::Exists(name)) { if ( ZLibZipUtils::ZipFile( name.c_str(), outputFile.c_str(), method, level ) == 0 ) { result = S_OK; } else { result = S_FALSE; } } return result; }
HRESULT COfficeUtils::ExtractToDirectory(const std::wstring& _zipFile, const std::wstring& _unzipDir, wchar_t* password, SHORT extract_without_path) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); std::wstring unzipDir = CorrectPathW(_unzipDir); #else std::wstring zipFile = _zipFile; std::wstring unzipDir = _unzipDir; #endif if( ZLibZipUtils::UnzipToDir( zipFile.c_str(), unzipDir.c_str(), m_fCallback, password, ( extract_without_path > 0 ) ? (true) : (false) ) == 0 ) { return S_OK; } else { return S_FALSE; } }
HRESULT COfficeUtils::CompressFilesFromMemory(const std::wstring& _zipFile, const RequestFileCallback& data_source, void* pParam, SHORT compression_level, bool* result) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); #else std::wstring zipFile = _zipFile; #endif *result = ZLibZipUtils::CompressFiles(zipFile.c_str(), data_source, pParam, compression_level) ? true : false; return S_OK; }
HRESULT COfficeUtils::ExtractFilesToMemory(const std::wstring& _zipFile, const ExtractedFileCallback& data_receiver, void* pParam, bool* result) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); #else std::wstring zipFile = _zipFile; #endif *result = ZLibZipUtils::ExtractFiles(zipFile.c_str(), data_receiver, pParam) ? true : false; return S_OK; }
HRESULT COfficeUtils::GetFilesSize(const std::wstring& _zipFile, const std::wstring& searchPattern, ULONG& nCommpressed, ULONG& nUncommpressed) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); #else std::wstring zipFile = _zipFile; #endif if (ZLibZipUtils::GetFilesSize(zipFile.c_str(), searchPattern, nCommpressed, nUncommpressed)) { return S_OK; } else { return S_FALSE; } }
HRESULT COfficeUtils::LoadFileFromArchive(const std::wstring& _zipFile, const std::wstring& filePath, BYTE** fileInBytes, ULONG& nFileSize) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); #else std::wstring zipFile = _zipFile; #endif if( ZLibZipUtils::LoadFileFromArchive( zipFile.c_str(), filePath.c_str(), fileInBytes, nFileSize)) { return S_OK; } else { return S_FALSE; } }
HRESULT COfficeUtils::IsFileExistInArchive(const std::wstring& _zipFile, const std::wstring& filePath) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring zipFile = CorrectPathW(_zipFile); #else std::wstring zipFile = _zipFile; #endif if( ZLibZipUtils::IsFileExistInArchive( zipFile.c_str(), filePath.c_str()) ) { return S_OK; } else { return S_FALSE; } }
HRESULT COfficeUtils::IsArchive(const std::wstring& _filename) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring filename = CorrectPathW(_filename); #else std::wstring filename = _filename; #endif if( ZLibZipUtils::IsArchive(filename.c_str()) ) { return S_OK; } else { return S_FALSE; } }
bool COfficeFileFormatChecker::isMS_OFFCRYPTOFormatFile (const std::wstring & _fileName, std::wstring & documentID) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring fileName = CorrectPathW(_fileName); #else std::wstring fileName = _fileName; #endif POLE::Storage storage(fileName.c_str()); if (storage.open()) { if ( isMS_OFFCRYPTOFormatFile(&storage, documentID) ) { nFileType = AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO; return true; } } return false; }
std::wstring COfficeFileFormatChecker::getDocumentID (const std::wstring & _fileName ) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring fileName = CorrectPathW(_fileName); #else std::wstring fileName = _fileName; #endif std::wstring documentID; POLE::Storage storage(fileName.c_str()); if (storage.open()) { if ( isMS_OFFCRYPTOFormatFile(&storage, documentID) ) { nFileType = AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO; } } else { if ( false == isOpenOfficeFormatFile(fileName, documentID)) { NSFile::CFileBinary file; if (!file.OpenFile(fileName)) return documentID; unsigned char* buffer = new unsigned char[4096]; //enaf !! if (!buffer){file.CloseFile();return documentID;} DWORD dwReadBytes = 0; file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes); file.CloseFile(); if (isPdfFormatFile(buffer, (int)dwReadBytes, documentID) ) { nFileType = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF; } } } sDocumentID = documentID; return documentID; }
bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & _fileName) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) std::wstring fileName = CorrectPathW(_fileName); #else std::wstring fileName = _fileName; #endif //приоритет как оказывается важен //Metamorphic Manual for windows 28415.doc POLE::Storage storage(fileName.c_str()); if (storage.open()) { if ( isDocFormatFile(&storage) ) { //nFileType внутри return true; } else if ( isXlsFormatFile(&storage) ) { nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS; return true; } else if ( isPptFormatFile(&storage) ) { #if defined FILE_FORMAT_CHECKER_WITH_MACRO COfficePPTFile pptFile; bMacroEnabled = true; long nResult = pptFile.OpenFile(fileName, L"", bMacroEnabled); if (nResult != S_OK) { return false; } pptFile.CloseFile(); #endif nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT; return true; } else if ( isMS_OFFCRYPTOFormatFile(&storage, sDocumentID) ) { nFileType = AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO; return true; } } COfficeUtils OfficeUtils(NULL); if (OfficeUtils.IsArchive(fileName) == S_OK) { if ( isOOXFormatFile(fileName) ) return true; else if ( isOpenOfficeFormatFile(fileName) ) return true; else if ( isOnlyOfficeFormatFile(fileName) ) return true; else if ( isXpsFile(fileName) ) return true; } //----------------------------------------------------------------------------------------------- // others { NSFile::CFileBinary file; if (!file.OpenFile(fileName)) return false; unsigned char* buffer = new unsigned char[4096]; //enaf !! if (!buffer){file.CloseFile();return false;} DWORD dwReadBytes = 0; file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes); int sizeRead = (int)dwReadBytes; if ( isRtfFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF; } else if ( isBinaryDoctFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_CANVAS_WORD; } else if ( isBinaryXlstFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET; } else if ( isBinaryPpttFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION; } else if (isPdfFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF; } else if (isDjvuFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU; } else if (isHtmlFormatFile(buffer,sizeRead, false)) { long fileSize = file.GetFileSize(); if (fileSize > MIN_SIZE_BUFFER) { file.SeekFile(fileSize - MIN_SIZE_BUFFER); file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes); int sizeRead = (int)dwReadBytes; } if (isHtmlFormatFile(buffer,sizeRead, true)) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; } } else if (isFB2FormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_FB2; } else if (isOpenOfficeFlatFormatFile(buffer,sizeRead) ) { //nFileType } else if (isDocFlatFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC_FLAT; // without compaund container } //------------------------------------------------------------------------------------------------ file.CloseFile(); if (buffer)delete []buffer; buffer = NULL; } if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN)return true; //------------------------------------------------------------------------------------------------ //// by Extension std::wstring::size_type nExtPos = fileName.rfind(L'.'); std::wstring sExt = L"unknown"; if (nExtPos != std::wstring::npos) sExt = fileName.substr(nExtPos); std::transform(sExt.begin(), sExt.end(), sExt.begin(), tolower); if (0 == sExt.compare(L".mht")) nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; else if (0 == sExt.compare(L".csv")) nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; else if (0 == sExt.compare(L".html") || 0 == sExt.compare(L".htm")) nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; else if (0 == sExt.compare(L".bin")) //base64 string nFileType = AVS_OFFICESTUDIO_FILE_CANVAS_PDF; else if (0 == sExt.compare(L".doct"))//случай архива с html viewer nFileType = AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY; else //if (0 == sExt.compare(L".txt") || 0 == sExt.compare(L".xml")) //volsciv.rtf -или любой другой nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN) return true; return false; }