BOOL fsUploadMgr::ZipFiles () { if (m_bZipFileCreated) return TRUE; Event (UMGRE_ZIP_FILES_START); char szTmpFile [MAX_PATH]; char szTmpPath [MAX_PATH]; GetTempPath (MAX_PATH, szTmpPath); GetTempFileName (szTmpPath, "tmp", 0, szTmpFile); m_strUploadFile = szTmpFile; zipFile zip = zipOpen (m_strUploadFile, 0); BOOL bOk = TRUE; m_strZipContentsDescHtml = "<ul>"; for (size_t i = 0; i < m_pkg.m_vPathes.size () && bOk && m_bNeedStop == false; i++) { LPCSTR psz = m_pkg.m_vPathes [i]; char szName [1000] = ""; fsGetFileName (psz, szName); if (GetFileAttributes (psz) & FILE_ATTRIBUTE_DIRECTORY) { AddItemToZipContentsDescHtml (szName, _UI64_MAX); m_strZipContentsDescHtml += "<ul>"; bOk = bOk && Zip_AddFolder (zip, psz, NULL, 1); m_strZipContentsDescHtml += "</ul>"; } else { bOk = bOk && Zip_AddFile (zip, psz, NULL); if (bOk) { WIN32_FILE_ATTRIBUTE_DATA wfad; GetFileAttributesEx (psz, GetFileExInfoStandard, &wfad); AddItemToZipContentsDescHtml (szName, ((UINT64)wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow); } } } m_strZipContentsDescHtml += "</ul>"; zipClose (zip, NULL); if (m_bNeedStop || bOk == FALSE) DeleteFile (m_strUploadFile); else m_bZipFileCreated = TRUE; if (m_bNeedStop == false) Event (bOk ? UMGRE_ZIP_FILES_DONE : UMGRE_ZIP_FILES_FAILED); return m_bZipFileCreated; }
fsString fsUploadMgr::get_UploadName() { if (m_pkg.is_shouldBeCompressed ()) { fsString str; str = m_pkg.m_strName; str += ".zip"; return str; } else { char sz [MAX_PATH]; fsGetFileName (m_pkg.m_vPathes [0], sz); return sz; } }
bool vms7zipArchive::Extract(LPCSTR pszArchive, LPCSTR pszOutFolder) { CInFileStream *fileSpec = new CInFileStream; CMyComPtr <IInStream> spFile = fileSpec; m_errExtract = AEE_GENERIC_ERROR; if (false == fileSpec->Open(pszArchive)) return false; CMyComPtr <IInArchive> spArc; vms7zipFormatDLL dll; if (false == Find7zipDLL (dll, pszArchive, true, spFile, spArc) && false == Find7zipDLL (dll, pszArchive, false, spFile, spArc)) return false; m_errExtract = AEE_NO_ERROR; char sz [MY_MAX_PATH]; fsGetFileName (pszArchive, sz); vms7zipArchiveExtractCallback aec (spArc, pszOutFolder, m_pAC, sz); HRESULT hr; if (FAILED (hr=spArc->Extract (NULL, (UInt32)-1, 0, &aec))) { spArc = NULL; m_errExtract = aec.is_AbortedByUser () ? AEE_ABORTED_BY_USER : AEE_GENERIC_ERROR; return false; } spArc = NULL; if (*aec.get_FurtherExtractFile () != 0) { bool b = Extract (aec.get_FurtherExtractFile (), pszOutFolder); DeleteFile (aec.get_FurtherExtractFile ()); return b; } return true; }
void vmsTpDownloadMgr::RenameFile(BOOL bFormat1) { int i = 1; DWORD dwResult; CHAR szFileWE [MY_MAX_PATH]; CString strFile; strcpy (szFileWE, m_info.strOutputPath + m_info.strFileName); LPSTR pszExt = strrchr (szFileWE, '.'); LPSTR pszDirEnd = strrchr (szFileWE, '\\'); if (pszExt != NULL && pszDirEnd > pszExt) pszExt = NULL; if (pszExt) *pszExt = 0; if (m_bRename_CheckIfRenamed) { int l = lstrlen (szFileWE); if (szFileWE [l-1] == ')') { LPSTR psz = szFileWE + l - 2; while (*psz && *psz >= '0' && *psz <= '9') psz--; if (*psz == '(') *psz = 0; } } do { if (pszExt) strFile.Format ("%s(%d).%s", szFileWE, i++, pszExt+1); else strFile.Format ("%s(%d)", szFileWE, i++); dwResult = GetFileAttributes (strFile); } while (dwResult != DWORD (-1)); char* szFileNameNew; fsnew (szFileNameNew, CHAR, strFile.GetLength () + 1); strcpy (szFileNameNew, strFile); HANDLE hFile = CreateFile (szFileNameNew, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) CloseHandle (hFile); CHAR szFileName [MY_MAX_PATH]; fsGetFileName (strFile, szFileName); CString strEv; if (bFormat1) strEv.Format ("%s \"%s\"", LS (L_FILEALREXISTSRENAMING), szFileName); else strEv.Format ("%s %s", LS (L_RENAMINGTO), szFileName); m_info.strFileName = szFileName; setDirty(); RaiseEvent (strEv, EDT_WARNING); RaiseEvent (DE_EXTERROR, DMEE_FILEUPDATED); }