diff --git a/Common/OfficeFileFormatChecker2.cpp b/Common/OfficeFileFormatChecker2.cpp index e921ff292b..6e157fd9f7 100644 --- a/Common/OfficeFileFormatChecker2.cpp +++ b/Common/OfficeFileFormatChecker2.cpp @@ -245,8 +245,14 @@ bool COfficeFileFormatChecker::isMS_OFFCRYPTOFormatFile (POLE::Storage * storage return true; return false; } -bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & fileName) +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()); diff --git a/DesktopEditor/common/Directory.h b/DesktopEditor/common/Directory.h index cdaeea37b1..c969f84c99 100644 --- a/DesktopEditor/common/Directory.h +++ b/DesktopEditor/common/Directory.h @@ -314,7 +314,8 @@ namespace NSDirectory static bool Exists(const std::wstring& strDirectory) { #if defined(_WIN32) || defined (_WIN64) - DWORD dwAttrib = ::GetFileAttributesW(strDirectory.c_str()); + std::wstring sDirectoryW = CorrectPathW(strDirectory); + DWORD dwAttrib = ::GetFileAttributesW(strDirectoryW.c_str()); return (dwAttrib != INVALID_FILE_ATTRIBUTES && 0 != (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); #elif __linux__ BYTE* pUtf8 = NULL; diff --git a/DesktopEditor/common/File.h b/DesktopEditor/common/File.h index 7cf654892e..181e72daf1 100644 --- a/DesktopEditor/common/File.h +++ b/DesktopEditor/common/File.h @@ -57,14 +57,17 @@ // local files: '\\?\' prefix // server files: '\\?\UNC\' prefix <== TODO! int nLen = GetFullPathNameW(path_str, 0, 0, 0); - wchar_t* pBuf = new wchar_t[(4 + nLen) * sizeof(wchar_t)]; + if (2 > nLen) + return path; - pBuf[0] = L'\\', pBuf[1] = L'\\', pBuf[2] = L'?', pBuf[3] = L'\\'; - GetFullPathNameW(path_str, nLen, pBuf + 4, NULL); + wchar_t* pBuf = new wchar_t[nLen * sizeof(wchar_t)]; + GetFullPathNameW(path_str, nLen, pBuf, NULL); + if (pBuf[0] == '\\' || pBuf[1] == '/') + return path; std::wstring retPath(pBuf); delete [] pBuf; - return retPath; + return L"\\\\?\\" + retPath; } #endif @@ -854,8 +857,9 @@ namespace NSFile static bool Exists(const std::wstring& strFileName) { #if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) + std::wstring sFileNameW = CorrectPathW(sFileName); FILE* pFile = NULL; - if ( 0 != _wfopen_s( &pFile, strFileName.c_str(), L"rb")) + if ( 0 != _wfopen_s( &pFile, sFileNameW.c_str(), L"rb")) return false; #else BYTE* pUtf8 = NULL; diff --git a/OfficeUtils/src/OfficeUtils.cpp b/OfficeUtils/src/OfficeUtils.cpp index ef91f5143d..2d01f5b333 100644 --- a/OfficeUtils/src/OfficeUtils.cpp +++ b/OfficeUtils/src/OfficeUtils.cpp @@ -39,8 +39,16 @@ COfficeUtils::COfficeUtils(OnProgressCallback* fCallback) m_fCallback = fCallback; } -HRESULT COfficeUtils::ExtractToDirectory(const std::wstring& zipFile, const std::wstring& unzipDir, wchar_t* password, SHORT extract_without_path) +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; @@ -52,8 +60,16 @@ HRESULT COfficeUtils::ExtractToDirectory(const std::wstring& zipFile, const std: } -HRESULT COfficeUtils::CompressFileOrDirectory(const std::wstring& name, const std::wstring& outputFile, bool bSorted, short level) +HRESULT COfficeUtils::CompressFileOrDirectory(const std::wstring& _name, const std::wstring& _outputFile, bool bSorted, short level) { +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64) + std::wstring 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)) { @@ -104,8 +120,14 @@ HRESULT COfficeUtils::Compress(BYTE* destBuf, ULONG* destSize, BYTE* sourceBuf, } } -HRESULT COfficeUtils::IsArchive(const std::wstring& filename) +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; @@ -116,8 +138,14 @@ HRESULT COfficeUtils::IsArchive(const std::wstring& filename) } } -HRESULT COfficeUtils::IsFileExistInArchive(const std::wstring& zipFile, const std::wstring& filePath) +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; @@ -128,8 +156,14 @@ HRESULT COfficeUtils::IsFileExistInArchive(const std::wstring& zipFile, const st } } -HRESULT COfficeUtils::LoadFileFromArchive(const std::wstring& zipFile, const std::wstring& filePath, BYTE** fileInBytes, ULONG& nFileSize) +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; @@ -140,20 +174,38 @@ HRESULT COfficeUtils::LoadFileFromArchive(const std::wstring& zipFile, const std } } -HRESULT COfficeUtils::ExtractFilesToMemory(const std::wstring& zipFile, const ExtractedFileCallback& data_receiver, void* pParam, bool* result) +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::CompressFilesFromMemory(const std::wstring& zipFile, const RequestFileCallback& data_source, void* pParam, SHORT compression_level, bool* result) +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::GetFilesSize(const std::wstring& zipFile, const std::wstring& searchPattern, ULONG& nCommpressed, ULONG& nUncommpressed) +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;