X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=Src%2F7zCommon.cpp;h=123fda8ae40ce404492134e92985cfd75bbfbb03;hb=bfd5a8fc3dc5e53a53d0c2afd78b7a62e1e0d3ed;hp=97f14361164a00094e5db42ebf42cda04c8f291d;hpb=22591de01569e17fbfabc2e9cd729d4e28119085;p=winmerge-jp%2Fwinmerge-jp.git diff --git a/Src/7zCommon.cpp b/Src/7zCommon.cpp index 97f143611..123fda8ae 100644 --- a/Src/7zCommon.cpp +++ b/Src/7zCommon.cpp @@ -98,24 +98,19 @@ DATE: BY: DESCRIPTION: #include "stdafx.h" #include "7zCommon.h" #include -#include #include "OptionsDef.h" #include "OptionsMgr.h" -#include "Merge.h" // DirDocFilter theApp GetOptionsMgr() -#include "resource.h" #include "DirView.h" #include "DirDoc.h" #include "DirActions.h" //#include "ExternalArchiveFormat.h" -#include "version.h" +#include "VersionInfo.h" #include "paths.h" #include "Environment.h" #include "Merge7zFormatRegister.h" #ifdef _DEBUG #define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; #endif /** @@ -124,9 +119,9 @@ static char THIS_FILE[] = __FILE__; static __declspec(thread) Merge7z::Proxy m_Merge7z = { { 0, 0, DllBuild_Merge7z, }, - "Merge7z\\Merge7z%u%02u"DECORATE_U".dll", + "Merge7z\\Merge7z.dll", "Merge7z", - NULL + nullptr }; std::vector Merge7zFormatRegister::optionalFormats; @@ -144,17 +139,16 @@ bool IsArchiveFile(const String& pszFile) { try { Merge7z::Format *piHandler = ArchiveGuessFormat(pszFile); - if (piHandler) - return TRUE; + if (piHandler != nullptr) + return true; else - return FALSE; + return false; } catch (CException *e) { e->Delete(); - return FALSE; + return false; } - return FALSE; } /** @@ -165,22 +159,22 @@ bool IsArchiveFile(const String& pszFile) Merge7z::Format *ArchiveGuessFormat(const String& path) { if (GetOptionsMgr()->GetInt(OPT_ARCHIVE_ENABLE) == 0) - return NULL; - if (paths_IsDirectory(path)) - return NULL; + return nullptr; + if (paths::IsDirectory(path)) + return nullptr; String path2(path); // Map extensions through ExternalArchiveFormat.ini static TCHAR null[] = _T(""); static const TCHAR section[] = _T("extensions"); - String entry = paths_FindExtension(path); + String entry = paths::FindExtension(path); TCHAR value[20]; - static LPCTSTR filename = NULL; - if (filename == NULL) + static LPCTSTR filename = nullptr; + if (filename == nullptr) { TCHAR cPath[INTERNET_MAX_PATH_LENGTH]; - DWORD cchPath = SearchPath(NULL, _T("ExternalArchiveFormat.ini"), NULL, - INTERNET_MAX_PATH_LENGTH, cPath, NULL); - filename = cchPath && cchPath < INTERNET_MAX_PATH_LENGTH ? StrDup(cPath) : null; + DWORD cchPath = SearchPath(nullptr, _T("ExternalArchiveFormat.ini"), nullptr, + INTERNET_MAX_PATH_LENGTH, cPath, nullptr); + filename = cchPath && cchPath < INTERNET_MAX_PATH_LENGTH ? _tcsdup(cPath) : null; } if (*filename && GetPrivateProfileString(section, entry.c_str(), null, value, 20, filename) && @@ -210,14 +204,14 @@ Merge7z::Format *ArchiveGuessFormat(const String& path) try { Merge7z::Format *pFormat = m_Merge7z->GuessFormat(path2.c_str()); - if (!pFormat) + if (pFormat == nullptr) pFormat = Merge7zFormatRegister::GuessFormat(path2); return pFormat; } catch (...) { Merge7z::Format *pFormat = Merge7zFormatRegister::GuessFormat(path2); - if (pFormat) + if (pFormat != nullptr) return pFormat; throw; } @@ -255,18 +249,23 @@ CTempPathContext *CTempPathContext::DeleteHead() return pParent; } +void CTempPathContext::Swap(int idx1, int idx2) +{ + std::swap(m_strDisplayRoot[idx1], m_strDisplayRoot[idx2]); + std::swap(m_strRoot[idx1], m_strRoot[idx2]); + if (m_pParent != nullptr) + m_pParent->Swap(idx1, idx2); +} + /** * @brief Return installed or local version of 7-Zip. */ DWORD NTAPI VersionOf7z() { - TCHAR path[MAX_PATH]; - GetModuleFileName(0, path, sizeof path/sizeof*path); - PathRemoveFileSpec(path); - PathAppend(path, _T("Merge7z\\7z.dll")); + String path = paths::ConcatPath(env::GetProgPath(), _T("Merge7z\\7z.dll")); unsigned versionMS = 0; unsigned versionLS = 0; - CVersionInfo(path).GetFixedFileVersion(versionMS, versionLS); + CVersionInfo(path.c_str()).GetFixedFileVersion(versionMS, versionLS); return versionMS; } @@ -278,20 +277,18 @@ interface Merge7z *Merge7z::Proxy::operator->() // As long as the Merge7z*.DLL has not yet been loaded, Merge7z // [0] points to the name of the DLL (with placeholders for 7- // Zip major and minor version numbers). Once the DLL has been - // loaded successfully, Merge7z[0] is set to NULL, causing the + // loaded successfully, Merge7z[0] is set to nullptr, causing the // if to fail on subsequent calls. if (const char *format = Merge7z[0]) { // Merge7z has not yet been loaded - if (!GetOptionsMgr()->GetInt(OPT_ARCHIVE_ENABLE)) + if (GetOptionsMgr()->GetInt(OPT_ARCHIVE_ENABLE) == 0) throw new CResourceException(); if (DWORD ver = VersionOf7z()) { - char name[MAX_PATH]; - wsprintfA(name, format, UINT HIWORD(ver), UINT LOWORD(ver)); - Merge7z[0] = name; + Merge7z[0] = format; stub.Load(); } else @@ -392,7 +389,10 @@ UINT DirItemEnumerator::Open() { m_nIndex = -1; m_curFolderPrefix = m_rgFolderPrefix.begin(); - m_index = (m_nFlags & Right) != 0 ? 1 : 0; + if (m_pView->GetDocument()->m_nDirs < 3) + m_index = (m_nFlags & Right) != 0 ? 1 : 0; + else + m_index = ((m_nFlags & Right) != 0) ? 2 : ((m_nFlags & Middle) != 0 ? 1 : 0); size_t nrgFolderPrefix = m_rgFolderPrefix.size(); if (nrgFolderPrefix) { @@ -404,7 +404,7 @@ UINT DirItemEnumerator::Open() } return static_cast(( - m_nFlags & LVNI_SELECTED + (m_nFlags & LVNI_SELECTED) ? pView(m_pView)->GetSelectedCount() : pView(m_pView)->GetItemCount() ) * nrgFolderPrefix); @@ -436,7 +436,7 @@ const DIFFITEM &DirItemEnumerator::Next() * storage, along with the Envelope itself. The Envelope pointer is passed to * Merge7z as the return value of the function. It is not meant to be a success * indicator, so if no temporary storage is required, it is perfectly alright - * to return NULL. + * to return `nullptr`. */ Merge7z::Envelope *DirItemEnumerator::Enum(Item &item) { @@ -455,10 +455,10 @@ Merge7z::Envelope *DirItemEnumerator::Enum(Item &item) const String &sFilename = di.diffFileInfo[m_index].filename; const String &sSubdir = di.diffFileInfo[m_index].path; if (sSubdir.length()) - envelope->Name = paths_ConcatPath(sSubdir, sFilename); + envelope->Name = paths::ConcatPath(sSubdir, sFilename); else envelope->Name = sFilename; - envelope->FullPath = paths_ConcatPath( + envelope->FullPath = paths::ConcatPath( di.getFilepath(m_index, ctxt.GetNormalizedPath(m_index)), sFilename); @@ -471,7 +471,7 @@ Merge7z::Envelope *DirItemEnumerator::Enum(Item &item) { // Item is missing on right side PVOID &implied = m_rgImpliedFolders[m_index][di.diffFileInfo[1-m_index].path.get()]; - if (!implied) + if (implied == nullptr) { // Folder is not implied by some other file, and has // not been enumerated so far, so enumerate it now! @@ -509,7 +509,7 @@ bool DirItemEnumerator::MultiStepCompressArchive(LPCTSTR path) { DeleteFile(path); Merge7z::Format *piHandler = ArchiveGuessFormat(path); - if (piHandler) + if (piHandler != nullptr) { HWND hwndOwner = CWnd::GetSafeOwner()->GetSafeHwnd(); CString pathIntermediate; @@ -520,8 +520,8 @@ bool DirItemEnumerator::MultiStepCompressArchive(LPCTSTR path) bool bDone = MultiStepCompressArchive(pathIntermediate); if (bDone) { - piHandler->CompressArchive(hwndOwner, path, - &SingleItemEnumerator(path, pathIntermediate)); + SingleItemEnumerator tmpEnumerator(path, pathIntermediate); + piHandler->CompressArchive(hwndOwner, path, &tmpEnumerator); DeleteFile(pathIntermediate); } else @@ -539,11 +539,8 @@ bool DirItemEnumerator::MultiStepCompressArchive(LPCTSTR path) void DirItemEnumerator::CompressArchive(LPCTSTR path) { String strPath; - if (path == 0) + if (path == nullptr) { - // No path given, so prompt for path! - static const TCHAR _T_Merge7z[] = _T("Merge7z"); - static const TCHAR _T_FilterIndex[] = _T("FilterIndex"); // 7z311 can only write 7z, zip, and tar(.gz|.bz2) archives, so don't // offer other formats here! static const TCHAR _T_Filter[] @@ -582,7 +579,7 @@ void DirItemEnumerator::CompressArchive(LPCTSTR path) OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN, strFilter.c_str() ); - dlg.m_ofn.nFilterIndex = AfxGetApp()->GetProfileInt(_T_Merge7z, _T_FilterIndex, 1); + dlg.m_ofn.nFilterIndex = GetOptionsMgr()->GetInt(OPT_ARCHIVE_FILTER_INDEX); // Use extension from current filter as default extension: if (int i = dlg.m_ofn.nFilterIndex) { @@ -601,7 +598,7 @@ void DirItemEnumerator::CompressArchive(LPCTSTR path) { strPath = dlg.GetPathName(); path = strPath.c_str(); - AfxGetApp()->WriteProfileInt(_T_Merge7z, _T_FilterIndex, dlg.m_ofn.nFilterIndex); + GetOptionsMgr()->SaveOption(OPT_ARCHIVE_FILTER_INDEX, static_cast(dlg.m_ofn.nFilterIndex)); } } if (path && !MultiStepCompressArchive(path)) @@ -613,17 +610,18 @@ void DirItemEnumerator::CompressArchive(LPCTSTR path) DecompressResult DecompressArchive(HWND hWnd, const PathContext& files) { - DecompressResult res(files, NULL, IS_EXISTING_DIR); + DecompressResult res(files, nullptr, paths::IS_EXISTING_DIR); try { String path; USES_CONVERSION; // Handle archives using 7-zip Merge7z::Format *piHandler; - if (piHandler = ArchiveGuessFormat(res.files[0].c_str())) + piHandler = ArchiveGuessFormat(res.files[0]); + if (piHandler != nullptr) { res.pTempPathContext = new CTempPathContext; - path = env_GetTempChildPath(); + path = env::GetTempChildPath(); for (int index = 0; index < res.files.GetSize(); index++) res.pTempPathContext->m_strDisplayRoot[index] = res.files[index]; if (res.files.GetSize() == 2 && res.files[0] == res.files[1]) @@ -634,64 +632,70 @@ DecompressResult DecompressArchive(HWND hWnd, const PathContext& files) break; if (res.files[0].find(path) == 0) { - VERIFY(::DeleteFile(res.files[0].c_str()) || (LogErrorString(string_format(_T("DeleteFile(%s) failed"), res.files[0].c_str())), false)); + VERIFY(::DeleteFile(res.files[0].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[0].c_str())), false)); } BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[0].c_str()); res.files[0] = OLE2T(pTmp); SysFreeString(pTmp); res.files[0].insert(0, _T("\\")); res.files[0].insert(0, path); - } while (piHandler = ArchiveGuessFormat(res.files[0].c_str())); + piHandler = ArchiveGuessFormat(res.files[0]); + } while (piHandler != nullptr); res.files[0] = path; } - if (!res.files[1].empty() && (piHandler = ArchiveGuessFormat(res.files[1].c_str()))) + piHandler = res.files[1].empty() ? nullptr + : ArchiveGuessFormat(res.files[1]); + if (piHandler != nullptr) { - if (!res.pTempPathContext) + if (res.pTempPathContext == nullptr) { res.pTempPathContext = new CTempPathContext; for (int index = 0; index < res.files.GetSize(); index++) res.pTempPathContext->m_strDisplayRoot[index] = res.files[index]; } - path = env_GetTempChildPath(); + path = env::GetTempChildPath(); do { if (FAILED(piHandler->DeCompressArchive(hWnd, res.files[1].c_str(), path.c_str()))) break;; if (res.files[1].find(path) == 0) { - VERIFY(::DeleteFile(res.files[1].c_str()) || (LogErrorString(string_format(_T("DeleteFile(%s) failed"), res.files[1].c_str())), false)); + VERIFY(::DeleteFile(res.files[1].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[1].c_str())), false)); } BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[1].c_str()); res.files[1] = OLE2T(pTmp); SysFreeString(pTmp); res.files[1].insert(0, _T("\\")); res.files[1].insert(0, path); - } while (piHandler = ArchiveGuessFormat(res.files[1].c_str())); + piHandler = ArchiveGuessFormat(res.files[1]); + } while (piHandler != nullptr); res.files[1] = path; } - if (res.files.GetSize() > 2 && (piHandler = ArchiveGuessFormat(res.files[2].c_str()))) + piHandler = (res.files.GetSize() <= 2) ? nullptr : ArchiveGuessFormat(res.files[2]); + if (piHandler != nullptr) { - if (!res.pTempPathContext) + if (res.pTempPathContext == nullptr) { res.pTempPathContext = new CTempPathContext; for (int index = 0; index < res.files.GetSize(); index++) res.pTempPathContext->m_strDisplayRoot[index] = res.files[index]; } - path = env_GetTempChildPath(); + path = env::GetTempChildPath(); do { if (FAILED(piHandler->DeCompressArchive(hWnd, res.files[2].c_str(), path.c_str()))) break;; if (res.files[2].find(path) == 0) { - VERIFY(::DeleteFile(res.files[2].c_str()) || (LogErrorString(string_format(_T("DeleteFile(%s) failed"), res.files[2].c_str())), false)); + VERIFY(::DeleteFile(res.files[2].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[2].c_str())), false)); } BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[1].c_str()); res.files[2] = OLE2T(pTmp); SysFreeString(pTmp); res.files[2].insert(0, _T("\\")); res.files[2].insert(0, path); - } while (piHandler = ArchiveGuessFormat(res.files[2].c_str())); + piHandler = ArchiveGuessFormat(res.files[2]); + } while (piHandler != nullptr); res.files[2] = path; } if (res.files[1].empty())