/** * @brief Tell if user may use ".." and move to parents directory. * This function checks if current compare's parent folders should * be allowed to open. I.e. if current compare folders are: * - C:\Work\Project1 and * - C:\Work\Project2 * we check if C:\Work and C:\Work should be allowed to opened. * For regular folders we allow opening if both folders exist. * @param [out] leftParent Left parent folder to open. * @param [out] rightParent Right parent folder to open. * @return Info if opening parent folders should be enabled: * - No : upward RESTRICTED * - ParentIsRegularPath : upward ENABLED * - ParentIsTempPath : upward ENABLED */ CDirDoc::AllowUpwardDirectory::ReturnCode CDirDoc::AllowUpwardDirectory(String &leftParent, String &rightParent) { const String & left = GetLeftBasePath(); const String & right = GetRightBasePath(); // If we have temp context it means we are comparing archives if (IsArchiveFolders()) { LPCTSTR lname = PathFindFileName(left.c_str()); LPCTSTR rname = PathFindFileName(right.c_str()); String::size_type cchLeftRoot = m_pTempPathContext->m_strLeftRoot.length(); if (left.length() <= cchLeftRoot) { if (m_pTempPathContext->m_pParent) { leftParent = m_pTempPathContext->m_pParent->m_strLeftRoot; rightParent = m_pTempPathContext->m_pParent->m_strRightRoot; if (GetPairComparability(leftParent.c_str(), rightParent.c_str()) != IS_EXISTING_DIR) return AllowUpwardDirectory::Never; return AllowUpwardDirectory::ParentIsTempPath; } leftParent = m_pTempPathContext->m_strLeftDisplayRoot; rightParent = m_pTempPathContext->m_strRightDisplayRoot; if (!m_pCtxt->m_piFilterGlobal->includeFile(leftParent.c_str(), rightParent.c_str())) return AllowUpwardDirectory::Never; if (lstrcmpi(lname, _T("ORIGINAL")) == 0 && lstrcmpi(rname, _T("ALTERED")) == 0) { leftParent = paths_GetParentPath(leftParent.c_str()); rightParent = paths_GetParentPath(rightParent.c_str()); } lname = PathFindFileName(leftParent.c_str()); rname = PathFindFileName(rightParent.c_str()); if (lstrcmpi(lname, rname) == 0) { leftParent = paths_GetParentPath(leftParent.c_str()); rightParent = paths_GetParentPath(rightParent.c_str()); if (GetPairComparability(leftParent.c_str(), rightParent.c_str()) != IS_EXISTING_DIR) return AllowUpwardDirectory::Never; return AllowUpwardDirectory::ParentIsTempPath; } return AllowUpwardDirectory::No; } rname = lname; } // If regular parent folders exist, allow opening them leftParent = paths_GetParentPath(left.c_str()); rightParent = paths_GetParentPath(right.c_str()); if (GetPairComparability(leftParent.c_str(), rightParent.c_str()) != IS_EXISTING_DIR) return AllowUpwardDirectory::Never; return AllowUpwardDirectory::ParentIsRegularPath; }
/** * @brief Called when users selects plugin browse button. */ void COpenView::OnSelectUnpacker() { PATH_EXISTENCE pathsType; UpdateData(TRUE); int index; int nFiles = 0; for (index = 0; index < countof(m_strPath); index++) { if (index == 2 && m_strPath[index].empty()) break; m_files.SetSize(nFiles + 1); m_files[nFiles] = m_strPath[index]; nFiles++; } pathsType = GetPairComparability(m_files); if (pathsType != IS_EXISTING_FILE) return; // let the user select a handler CSelectUnpackerDlg dlg(m_files[0], this); PackingInfo infoUnpacker(PLUGIN_AUTO); dlg.SetInitialInfoHandler(&infoUnpacker); if (dlg.DoModal() == IDOK) { m_infoHandler = dlg.GetInfoHandler(); m_strUnpacker = m_infoHandler.pluginName; UpdateData(FALSE); } }
static UINT UpdateButtonStatesThread(LPVOID lpParam) { MSG msg; BOOL bRet; CoInitialize(NULL); CAssureScriptsForThread scriptsForRescan; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) break; if (msg.message != WM_USER + 2) continue; BOOL bButtonEnabled = TRUE; BOOL bInvalid[3] = {FALSE, FALSE, FALSE}; int iStatusMsgId = 0; int iUnpackerStatusMsgId = 0; UpdateButtonStatesThreadParams *pParams = reinterpret_cast<UpdateButtonStatesThreadParams *>(msg.wParam); PathContext paths = pParams->m_paths; HWND hWnd = pParams->m_hWnd; delete pParams; // Check if we have project file as left side path BOOL bProject = FALSE; String ext; paths_SplitFilename(paths[0], NULL, NULL, &ext); if (paths[1].empty() && string_compare_nocase(ext, ProjectFile::PROJECTFILE_EXT) == 0) bProject = TRUE; if (!bProject) { if (paths_DoesPathExist(paths[0], IsArchiveFile) == DOES_NOT_EXIST) bInvalid[0] = TRUE; if (paths_DoesPathExist(paths[1], IsArchiveFile) == DOES_NOT_EXIST) bInvalid[1] = TRUE; if (paths.GetSize() > 2 && paths_DoesPathExist(paths[2], IsArchiveFile) == DOES_NOT_EXIST) bInvalid[2] = TRUE; } // Enable buttons as appropriate if (GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS)) { PATH_EXISTENCE pathsType = DOES_NOT_EXIST; if (paths.GetSize() <= 2) { if (bInvalid[0] && bInvalid[1]) iStatusMsgId = IDS_OPEN_BOTHINVALID; else if (bInvalid[0]) iStatusMsgId = IDS_OPEN_LEFTINVALID; else if (bInvalid[1]) iStatusMsgId = IDS_OPEN_RIGHTINVALID; else if (!bInvalid[0] && !bInvalid[1]) { pathsType = GetPairComparability(paths, IsArchiveFile); if (pathsType == DOES_NOT_EXIST) iStatusMsgId = IDS_OPEN_MISMATCH; else iStatusMsgId = IDS_OPEN_FILESDIRS; } } else { if (bInvalid[0] && bInvalid[1] && bInvalid[2]) iStatusMsgId = IDS_OPEN_ALLINVALID; else if (!bInvalid[0] && bInvalid[1] && bInvalid[2]) iStatusMsgId = IDS_OPEN_MIDDLERIGHTINVALID; else if (bInvalid[0] && !bInvalid[1] && bInvalid[2]) iStatusMsgId = IDS_OPEN_LEFTRIGHTINVALID; else if (!bInvalid[0] && !bInvalid[1] && bInvalid[2]) iStatusMsgId = IDS_OPEN_RIGHTINVALID; else if (bInvalid[0] && bInvalid[1] && !bInvalid[2]) iStatusMsgId = IDS_OPEN_LEFTMIDDLEINVALID; else if (!bInvalid[0] && bInvalid[1] && !bInvalid[2]) iStatusMsgId = IDS_OPEN_MIDDLEINVALID; else if (bInvalid[0] && !bInvalid[1] && !bInvalid[2]) iStatusMsgId = IDS_OPEN_LEFTINVALID; else if (!bInvalid[0] && !bInvalid[1] && !bInvalid[2]) { pathsType = GetPairComparability(paths, IsArchiveFile); if (pathsType == DOES_NOT_EXIST) iStatusMsgId = IDS_OPEN_MISMATCH; else iStatusMsgId = IDS_OPEN_FILESDIRS; } } if (pathsType == IS_EXISTING_FILE || bProject) iUnpackerStatusMsgId = 0; //Empty field else iUnpackerStatusMsgId = IDS_OPEN_UNPACKERDISABLED; if (bProject) bButtonEnabled = TRUE; else bButtonEnabled = (pathsType != DOES_NOT_EXIST); } PostMessage(hWnd, WM_USER + 1, bButtonEnabled, MAKELPARAM(iStatusMsgId, iUnpackerStatusMsgId)); } CoUninitialize(); return 0; }
/** * @brief Called when dialog is closed with "OK". * * Checks that paths are valid and sets filters. */ void COpenView::OnOK() { int pathsType; // enum from PATH_EXISTENCE in paths.h const String filterPrefix = _("[F] "); UpdateData(TRUE); TrimPaths(); int index; int nFiles = 0; for (index = 0; index < countof(m_strPath); index++) { if (index == 2 && m_strPath[index].empty()) break; m_files.SetSize(nFiles + 1); m_files[nFiles] = m_strPath[index]; m_dwFlags[nFiles] &= ~FFILEOPEN_READONLY; m_dwFlags[nFiles] |= m_bReadOnly[index] ? FFILEOPEN_READONLY : 0; nFiles++; } // If left path is a project-file, load it String ext; paths_SplitFilename(m_strPath[0], NULL, NULL, &ext); if (m_strPath[1].empty() && string_compare_nocase(ext, ProjectFile::PROJECTFILE_EXT) == 0) LoadProjectFile(m_strPath[0]); pathsType = GetPairComparability(m_files, IsArchiveFile); if (pathsType == DOES_NOT_EXIST) { LangMessageBox(IDS_ERROR_INCOMPARABLE, MB_ICONSTOP); return; } for (index = 0; index < nFiles; index++) { // If user has edited path by hand, expand environment variables bool bExpand = false; if (string_compare_nocase(m_strBrowsePath[index], m_files[index]) != 0) bExpand = true; if (!paths_IsURLorCLSID(m_files[index])) { m_files[index] = paths_GetLongPath(m_files[index], bExpand); // Add trailing '\' for directories if its missing if (paths_DoesPathExist(m_files[index]) == IS_EXISTING_DIR) m_files[index] = paths_AddTrailingSlash(m_files[index]); m_strPath[index] = m_files[index]; } } UpdateData(FALSE); KillTimer(IDT_CHECKFILES); String filter(string_trim_ws(m_strExt)); // If prefix found from start.. if (filter.find(filterPrefix, 0) == 0) { // Remove prefix + space filter.erase(0, filterPrefix.length()); if (!theApp.m_pGlobalFileFilter->SetFilter(filter)) { // If filtername is not found use default *.* mask theApp.m_pGlobalFileFilter->SetFilter(_T("*.*")); filter = _T("*.*"); } GetOptionsMgr()->SaveOption(OPT_FILEFILTER_CURRENT, filter); } else { BOOL bFilterSet = theApp.m_pGlobalFileFilter->SetFilter(filter); if (!bFilterSet) m_strExt = theApp.m_pGlobalFileFilter->GetFilterNameOrMask(); GetOptionsMgr()->SaveOption(OPT_FILEFILTER_CURRENT, filter); } SaveComboboxStates(); GetOptionsMgr()->SaveOption(OPT_CMP_INCLUDE_SUBDIRS, m_bRecurse); LoadComboboxStates(); m_constraint.Persist(true, false); COpenDoc *pDoc = GetDocument(); pDoc->m_files = m_files; pDoc->m_bRecurse = m_bRecurse; pDoc->m_strExt = m_strExt; pDoc->m_strUnpacker = m_strUnpacker; pDoc->m_infoHandler = m_infoHandler; pDoc->m_dwFlags[0] = m_dwFlags[0]; pDoc->m_dwFlags[1] = m_dwFlags[1]; pDoc->m_dwFlags[2] = m_dwFlags[2]; if (GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK)) GetParentFrame()->PostMessage(WM_CLOSE); GetMainFrame()->DoFileOpen( &PathContext(pDoc->m_files), &std::vector<DWORD>(pDoc->m_dwFlags, pDoc->m_dwFlags + 3)[0], NULL, _T(""), !!pDoc->m_bRecurse, NULL, _T(""), &PackingInfo(pDoc->m_infoHandler)); }