bool CZipArchive::ExtractFile(WORD uIndex, LPCTSTR lpszPath, DWORD nBufSize) { if (!nBufSize) return false; CFileHeader header; GetFileInfo(header, uIndex); // to ensure that slash and oem conversions take place CString szFile = lpszPath; szFile.TrimRight(_T("\\")); szFile += _T("\\") + GetFileDirAndName(header.m_szFileName); // just in case in the archive there are file names with drives if (IsFileDirectory(uIndex)) { ForceDirectory(szFile); SetFileAttributes(szFile, header.m_uExternalAttr); } else { if (!OpenFile(uIndex)) return false; ForceDirectory(GetFilePath(szFile)); CFile f(szFile, CFile::modeWrite | CFile::modeCreate | CFile::shareDenyWrite); DWORD iRead; CAutoBuffer buf(nBufSize); do { iRead = ReadFile(buf, buf.GetSize()); if (iRead) f.Write(buf, iRead); } while (iRead == buf.GetSize()); CloseFile(f); } return true; }
void DocProvHelper::GeneratePlaceHolderPath(CStdString sFilePath) const { if( sFilePath.IsEmpty() ) /* TXTEX_IGNORE */ throw std::exception("GeneratePlaceHolderPath passed an empty string"); if( !ForceDirectory( sFilePath ) ) { /* TXTEX_IGNORE */ throw std::exception("GeneratePlaceHolderPath failed to create folder"); } }
bool CZipArchive::ForceDirectory(LPCTSTR lpDirectory) { ASSERT(lpDirectory); CString szDirectory = lpDirectory; szDirectory.TrimRight(_T("\\")); if ((GetFilePath(szDirectory) == szDirectory) || (FileExists(szDirectory) == -1)) return true; if (!ForceDirectory(GetFilePath(szDirectory))) return false; if (!CreateDirectory(szDirectory, NULL)) return false; return true; }
CStdString DocProvHelper::CreatePlaceHolderFile(const CStdString& sDocumentID) const { CStdString sPlaceHolderPath; CStdString sPlaceHolderFile; GetPlaceHolderPathAndName( sDocumentID, sPlaceHolderPath, sPlaceHolderFile ); /* TXTEX_IGNORE */ CStdString sPlaceFile = sPlaceHolderPath + _T("/") + sPlaceHolderFile; if( DoesPlaceHolderFileExist( sDocumentID ) ) return sPlaceFile; ForceDirectory(sPlaceHolderPath); HANDLE hFile = CreateFile( sPlaceFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if(hFile == INVALID_HANDLE_VALUE) /* TXTEX_IGNORE */ throw std::exception( "CreatePlaceHolderFile INVALID_HANDLE_VALUE" ); CloseHandle(hFile); return sPlaceFile; }
bool DocProvHelper::ForceDirectory(CStdString lpDirectory) const { ASSERT(lpDirectory); CStdString szDirectory = lpDirectory; /* TXTEX_IGNORE */ szDirectory.TrimRight(_T("\\")); /* TXTEX_IGNORE */ szDirectory.TrimRight(_T("/")); if( (GetFilePath(szDirectory) == szDirectory) || CGeneral::FileExists(szDirectory) ) return true; if (PathIsUNCFolderShare(szDirectory)) return true; // if it_T('s a share assume it exists - it')ll fail at the next level up if not if(!ForceDirectory(GetFilePath(szDirectory))) return false; if (!CreateDirectory(szDirectory, NULL)) return false; return true; }