/** * @brief Read paths and filter from project file. * Reads the given project file. After the file is read, found paths and * filter is updated to dialog GUI. Other possible settings found in the * project file are kept in memory and used later when loading paths * selected. * @param [in] path Path to the project file. * @return TRUE if the project file was successfully loaded, FALSE otherwise. */ BOOL COpenView::LoadProjectFile(const String &path) { String filterPrefix = _("[F] "); ProjectFile prj; if (!theApp.LoadProjectFile(path, prj)) return FALSE; bool recurse; prj.GetPaths(m_files, recurse); m_bRecurse = recurse; m_dwFlags[0] &= ~FFILEOPEN_READONLY; m_dwFlags[0] |= prj.GetLeftReadOnly() ? FFILEOPEN_READONLY : 0; if (m_files.GetSize() < 3) { m_dwFlags[1] &= ~FFILEOPEN_READONLY; m_dwFlags[1] |= prj.GetRightReadOnly() ? FFILEOPEN_READONLY : 0; } else { m_dwFlags[1] &= ~FFILEOPEN_READONLY; m_dwFlags[1] |= prj.GetMiddleReadOnly() ? FFILEOPEN_READONLY : 0; m_dwFlags[2] &= ~FFILEOPEN_READONLY; m_dwFlags[2] |= prj.GetRightReadOnly() ? FFILEOPEN_READONLY : 0; } if (prj.HasFilter()) { m_strExt = string_trim_ws(prj.GetFilter()); if (m_strExt[0] != '*') m_strExt.insert(0, filterPrefix); } return TRUE; }
/** * @brief Called when "Select..." button for filters is selected. */ void COpenView::OnSelectFilter() { String filterPrefix = _("[F] "); String curFilter; const BOOL bUseMask = theApp.m_pGlobalFileFilter->IsUsingMask(); GetDlgItemText(IDC_EXT_COMBO, curFilter); curFilter = string_trim_ws(curFilter); GetMainFrame()->SelectFilter(); String filterNameOrMask = theApp.m_pGlobalFileFilter->GetFilterNameOrMask(); if (theApp.m_pGlobalFileFilter->IsUsingMask()) { // If we had filter chosen and now has mask we can overwrite filter if (!bUseMask || curFilter[0] != '*') { SetDlgItemText(IDC_EXT_COMBO, filterNameOrMask); } } else { filterNameOrMask = filterPrefix + filterNameOrMask; SetDlgItemText(IDC_EXT_COMBO, filterNameOrMask); } }
/** * @brief Writes options values from UI to storage. */ void PropRegistry::WriteOptions() { GetOptionsMgr()->SaveOption(OPT_USE_RECYCLE_BIN, m_bUseRecycleBin == TRUE); String sExtEditor = string_trim_ws(m_strEditorPath); if (sExtEditor.empty()) sExtEditor = GetOptionsMgr()->GetDefault<String>(OPT_EXT_EDITOR_CMD); GetOptionsMgr()->SaveOption(OPT_EXT_EDITOR_CMD, sExtEditor); String sFilterPath = string_trim_ws(m_strUserFilterPath); GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, sFilterPath); bool useSysTemp = m_tempFolderType == 0; GetOptionsMgr()->SaveOption(OPT_USE_SYSTEM_TEMP_PATH, useSysTemp); String tempFolder = string_trim_ws(m_tempFolder); GetOptionsMgr()->SaveOption(OPT_CUSTOM_TEMP_PATH, tempFolder); }
/** * @brief Store all name:value strings from file into m_pCfgSettings */ bool CConfigLog::ParseSettings(const String & Filepath) { UniMemFile file; if (!file.Open(Filepath.c_str())) return false; String strline; bool lossy; while (file.ReadString(strline, &lossy)) { String::size_type colon = strline.find(_T(":")); if (colon > 0) { String name = strline.substr(0, colon); String value = strline.substr(colon + 1); name = string_trim_ws(name); value = string_trim_ws(value); m_pCfgSettings->Add(name.c_str(), value.c_str()); } } file.Close(); return true; }
/** * @brief Set filter. * * Simple-to-use function to select filter. This function determines * filter type so caller doesn't need to care about it. * * @param [in] filter File mask or filter name. * @return TRUE if given filter was set, FALSE if default filter was set. * @note If function returns FALSE, you should ask filter set with * GetFilterNameOrMask(). */ BOOL FileFilterHelper::SetFilter(const String &filter) { // If filter is empty string set default filter if (filter.empty()) { UseMask(TRUE); SetMask(_T("*.*")); SetFileFilterPath(_T("")); return FALSE; } // Remove leading and trailing whitespace characters from the string. String flt = string_trim_ws(filter); // Star means we have a file extension mask if (flt[0] == '*') { UseMask(TRUE); SetMask(flt.c_str()); SetFileFilterPath(_T("")); } else { CString path = GetFileFilterPath(flt.c_str()); if (!path.IsEmpty()) { UseMask(FALSE); SetFileFilterPath(path); } // If filter not found with given name, use default filter else { UseMask(TRUE); SetMask(_T("*.*")); SetFileFilterPath(_T("")); return FALSE; } } return TRUE; }
/** * @brief Removes whitespaces from left and right paths * @note Assumes UpdateData(TRUE) is called before this function. */ void COpenView::TrimPaths() { for (int index = 0; index < countof(m_strPath); index++) m_strPath[index] = string_trim_ws(m_strPath[index]); }
/** * @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)); }