Beispiel #1
0
bool CFilterManager::CompileRegexes()
{
	for (auto & filter : m_globalFilters) {
		CompileRegexes(filter);
	}
	return true;
}
Beispiel #2
0
void CFilterDialog::OnOK(wxCommandEvent& event)
{
	m_globalFilters = m_filters;
	CompileRegexes();
	m_globalFilterSets = m_filterSets;
	m_globalCurrentFilterSet = m_currentFilterSet;

	SaveFilters();
	EndModal(wxID_OK);
}
Beispiel #3
0
void CFilterDialog::OnEdit(wxCommandEvent& event)
{
	CFilterEditDialog dlg;
	if (!dlg.Create(this, m_filters, m_filterSets))
		return;

	if (dlg.ShowModal() != wxID_OK)
		return;

	m_filters = dlg.GetFilters();
	m_filterSets = dlg.GetFilterSets();
	CompileRegexes();

	DisplayFilters();
}
Beispiel #4
0
void CFilterDialog::OnOkOrApply(wxCommandEvent& event)
{
	m_globalFilters = m_filters;
	CompileRegexes();
	m_globalFilterSets = m_filterSets;
	m_globalCurrentFilterSet = m_currentFilterSet;

	SaveFilters();

	CContextManager::Get()->NotifyAllHandlers(STATECHANGE_APPLYFILTER);

	if (event.GetId() == wxID_OK) {
		EndModal(wxID_OK);
	}
}
Beispiel #5
0
CFilterManager::CFilterManager()
{
	m_currentFilterSet = 0;
	LoadFilters();
	CompileRegexes();

	if (m_globalFilterSets.empty())
	{
		CFilterSet set;
		set.local.resize(m_filters.size(), false);
		set.remote.resize(m_filters.size(), false);

		m_globalFilterSets.push_back(set);
		m_filterSets.push_back(set);
	}
}
Beispiel #6
0
void CFilterManager::LoadFilters()
{
	if (m_loaded)
		return;

	m_loaded = true;

	CInterProcessMutex mutex(MUTEX_FILTERS);

	wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml"));
	if (!file.FileExists())
	{
		wxFileName defaults(wxGetApp().GetResourceDir(), _T("defaultfilters.xml"));
		if (defaults.FileExists())
		{
			TiXmlElement* pDocument = GetXmlFile(defaults);
			if (pDocument)
			{
				SaveXmlFile(file, pDocument);
				delete pDocument->GetDocument();
			}
		}
	}

	CXmlFile xml(file);
	TiXmlElement* pDocument = xml.Load();
	if (!pDocument)
	{
		wxString msg = xml.GetError() + _T("\n\n") + _("Any changes made to the filters will not be saved.");
		wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);

		return;
	}

	TiXmlElement *pFilters = pDocument->FirstChildElement("Filters");

	if (!pFilters)
		return;

	TiXmlElement *pFilter = pFilters->FirstChildElement("Filter");
	while (pFilter)
	{
		CFilter filter;
		filter.name = GetTextElement(pFilter, "Name");
		if (filter.name == _T(""))
		{
			pFilter = pFilter->NextSiblingElement("Filter");
			continue;
		}

		filter.filterFiles = GetTextElement(pFilter, "ApplyToFiles") == _T("1");
		filter.filterDirs = GetTextElement(pFilter, "ApplyToDirs") == _T("1");

		wxString type = GetTextElement(pFilter, "MatchType");
		if (type == _T("Any"))
			filter.matchType = CFilter::any;
		else if (type == _T("None"))
			filter.matchType = CFilter::none;
		else
			filter.matchType = CFilter::all;
		filter.matchCase = GetTextElement(pFilter, "MatchCase") == _T("1");

		TiXmlElement *pConditions = pFilter->FirstChildElement("Conditions");
		if (!pConditions)
		{
			pFilter = pFilter->NextSiblingElement("Filter");
			continue;
		}

		TiXmlElement *pCondition = pConditions->FirstChildElement("Condition");
		while (pCondition)
		{
			CFilterCondition condition;
			int type = GetTextElementInt(pCondition, "Type", 0);
			switch (type)
			{
			case 0:
				condition.type = filter_name;
				break;
			case 1:
				condition.type = filter_size;
				break;
			case 2:
				condition.type = filter_attributes;
				break;
			case 3:
				condition.type = filter_permissions;
				break;
			case 4:
				condition.type = filter_path;
				break;
			default:
				pCondition = pCondition->NextSiblingElement("Condition");
				continue;
			}
			condition.condition = GetTextElementInt(pCondition, "Condition", 0);
			condition.strValue = GetTextElement(pCondition, "Value");
			condition.matchCase = filter.matchCase;
			if (condition.strValue == _T(""))
			{
				pCondition = pCondition->NextSiblingElement("Condition");
				continue;
			}

			// TODO: 64bit filesize
			if (condition.type == filter_size)
			{
				unsigned long tmp;
				condition.strValue.ToULong(&tmp);
				condition.value = tmp;
			}
			else if (condition.type == filter_attributes || condition.type == filter_permissions)
			{
				if (condition.strValue == _T("0"))
					condition.value = 0;
				else
					condition.value = 1;
			}

			filter.filters.push_back(condition);

			pCondition = pCondition->NextSiblingElement("Condition");
		}

		if (!filter.filters.empty())
			m_globalFilters.push_back(filter);

		pFilter = pFilter->NextSiblingElement("Filter");
	}

	CompileRegexes();

	TiXmlElement* pSets = pDocument->FirstChildElement("Sets");
	if (!pSets)
		return;

	for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set"))
	{
		CFilterSet set;
		TiXmlElement* pItem = pSet->FirstChildElement("Item");
		while (pItem)
		{
			wxString local = GetTextElement(pItem, "Local");
			wxString remote = GetTextElement(pItem, "Remote");
			set.local.push_back(local == _T("1") ? true : false);
			set.remote.push_back(remote == _T("1") ? true : false);

			pItem = pItem->NextSiblingElement("Item");
		}

		if (!m_globalFilterSets.empty())
		{
			set.name = GetTextElement(pSet, "Name");
			if (set.name == _T(""))
				continue;
		}

		if (set.local.size() == m_globalFilters.size())
			m_globalFilterSets.push_back(set);
	}

	wxString attribute = GetTextAttribute(pSets, "Current");
	unsigned long value;
	if (attribute.ToULong(&value))
	{
		if (value < m_globalFilterSets.size())
			m_globalCurrentFilterSet = value;
	}
}
Beispiel #7
0
bool CFilterManager::CompileRegexes()
{
	for (unsigned int i = 0; i < m_globalFilters.size(); i++)
		CompileRegexes(m_globalFilters[i]);
	return true;
}
Beispiel #8
0
void CFilterManager::LoadFilters()
{
	if (m_loaded)
		return;

	m_loaded = true;

	CInterProcessMutex mutex(MUTEX_FILTERS);

	wxString file(wxGetApp().GetSettingsFile(_T("filters")));
	if (CLocalFileSystem::GetSize(file) < 1) {
		file = wxGetApp().GetResourceDir().GetPath() + _T("defaultfilters.xml");
	}

	CXmlFile xml(file);
	TiXmlElement* pDocument = xml.Load();
	if (!pDocument) {
		wxString msg = xml.GetError() + _T("\n\n") + _("Any changes made to the filters will not be saved.");
		wxMessageBoxEx(msg, _("Error loading xml file"), wxICON_ERROR);

		return;
	}

	TiXmlElement *pFilters = pDocument->FirstChildElement("Filters");

	if (!pFilters)
		return;

	TiXmlElement *pFilter = pFilters->FirstChildElement("Filter");
	while (pFilter) {
		CFilter filter;

		bool loaded = LoadFilter(pFilter, filter);

		if (loaded && !filter.name.empty() && !filter.filters.empty())
			m_globalFilters.push_back(filter);

		pFilter = pFilter->NextSiblingElement("Filter");
	}

	CompileRegexes();

	TiXmlElement* pSets = pDocument->FirstChildElement("Sets");
	if (!pSets)
		return;

	for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set")) {
		CFilterSet set;
		TiXmlElement* pItem = pSet->FirstChildElement("Item");
		while (pItem) {
			wxString local = GetTextElement(pItem, "Local");
			wxString remote = GetTextElement(pItem, "Remote");
			set.local.push_back(local == _T("1") ? true : false);
			set.remote.push_back(remote == _T("1") ? true : false);

			pItem = pItem->NextSiblingElement("Item");
		}

		if (!m_globalFilterSets.empty()) {
			set.name = GetTextElement(pSet, "Name");
			if (set.name.empty())
				continue;
		}

		if (set.local.size() == m_globalFilters.size())
			m_globalFilterSets.push_back(set);
	}

	wxString attribute = GetTextAttribute(pSets, "Current");
	unsigned long value;
	if (attribute.ToULong(&value)) {
		if (value < m_globalFilterSets.size())
			m_globalCurrentFilterSet = value;
	}
}