00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00029
00030
00031 #include "stdafx.h"
00032 #include "Shareaza.h"
00033 #include "Settings.h"
00034 #include "ResultFilters.h"
00035
00036 CResultFilters::CResultFilters(void)
00037 {
00038 m_pFilters = NULL;
00039 m_nFilters = 0;
00040 m_nDefault = NONE;
00041 }
00042
00043 CResultFilters::~CResultFilters(void)
00044 {
00045 if ( m_pFilters )
00046 {
00047 for ( DWORD i = 0; i < m_nFilters; i++ )
00048 {
00049 delete m_pFilters[i];
00050 }
00051 }
00052
00053 delete [] ( m_pFilters );
00054 }
00055
00056 void CResultFilters::Serialize(CArchive & ar)
00057 {
00058 int nVersion = 1;
00059
00060 if ( ar.IsStoring() )
00061 {
00062 ar << nVersion;
00063
00064 ar.WriteCount(m_nFilters);
00065
00066 for (DWORD i = 0; i < m_nFilters; i++)
00067 {
00068 CFilterOptions* pFilter = m_pFilters[ i ];
00069 pFilter->Serialize( ar );
00070 }
00071
00072 ar << m_nDefault;
00073 }
00074 else
00075 {
00076 ar >> nVersion;
00077
00078 m_nFilters = ar.ReadCount();
00079
00080 m_pFilters = new CFilterOptions *[ m_nFilters ];
00081 ZeroMemory( m_pFilters, sizeof(CFilterOptions*) * m_nFilters );
00082
00083 for (DWORD i = 0; i < m_nFilters; i++)
00084 {
00085 CFilterOptions* pFilter = new CFilterOptions();
00086 m_pFilters[ i ] = pFilter;
00087 pFilter->Serialize( ar );
00088 }
00089
00090 ar >> m_nDefault;
00091 }
00092 }
00093
00094 void CResultFilters::Add(CFilterOptions *pOptions)
00095 {
00096 CFilterOptions **pFilters = new CFilterOptions * [m_nFilters + 1];
00097
00098 CopyMemory(pFilters, m_pFilters, sizeof(CFilterOptions *) * m_nFilters);
00099
00100 pFilters[m_nFilters++] = pOptions;
00101
00102 delete [] m_pFilters;
00103
00104 m_pFilters = pFilters;
00105 }
00106
00107
00108 int CResultFilters::Search(const CString& strName)
00109 {
00110 for ( DWORD index = 0; index < m_nFilters; index++ )
00111 {
00112 if ( strName.Compare( m_pFilters[index]->m_sName ) == 0 )
00113 {
00114 return index;
00115 }
00116 }
00117 return NONE;
00118 }
00119
00120 void CResultFilters::Remove(DWORD index)
00121 {
00122 if ( ( index >= 0 ) && ( index < m_nFilters ) )
00123 {
00124 delete m_pFilters[index];
00125 CopyMemory(&m_pFilters[index], &m_pFilters[index + 1], sizeof(CFilterOptions *) * (m_nFilters - index));
00126 m_nFilters--;
00127
00128 if ( index == m_nDefault ) m_nDefault = NONE;
00129 else if ( ( m_nDefault != NONE ) && ( index < m_nDefault ) ) m_nDefault--;
00130
00131 if ( m_nFilters == 0 ) m_nDefault = NONE;
00132 }
00133 }
00134
00135 void CResultFilters::Load()
00136 {
00137
00138 if ( m_pFilters )
00139 {
00140 for ( DWORD i = 0; i < m_nFilters; i++ )
00141 {
00142 delete m_pFilters[i];
00143 }
00144 }
00145 delete [] ( m_pFilters );
00146
00147 CString strFile;
00148 CFile f;
00149
00150 strFile.Format( _T("%s\\Data\\Filters.dat"), (LPCTSTR)Settings.General.UserPath );
00151
00152 if ( f.Open( strFile, CFile::modeRead ) )
00153 {
00154 CArchive ar( &f, CArchive::load );
00155 Serialize(ar);
00156 ar.Close();
00157 f.Close();
00158 }
00159 }
00160
00161 void CResultFilters::Save()
00162 {
00163 CString strFile;
00164 CFile f;
00165
00166 strFile.Format( _T("%s\\Data\\Filters.dat"), (LPCTSTR)Settings.General.UserPath );
00167
00168 if (f.Open(strFile, CFile::modeCreate | CFile::modeWrite))
00169 {
00170 CArchive ar( &f, CArchive::store );
00171 Serialize( ar );
00172 ar.Close();
00173 f.Close();
00174 }
00175 }
00177
00178
00179 CFilterOptions::CFilterOptions()
00180 {
00181 m_bFilterBusy = ( Settings.Search.FilterMask & ( 1 << 0 ) ) > 0;
00182 m_bFilterPush = ( Settings.Search.FilterMask & ( 1 << 1 ) ) > 0;
00183 m_bFilterUnstable = ( Settings.Search.FilterMask & ( 1 << 2 ) ) > 0;
00184 m_bFilterReject = ( Settings.Search.FilterMask & ( 1 << 3 ) ) > 0;
00185 m_bFilterLocal = ( Settings.Search.FilterMask & ( 1 << 4 ) ) > 0;
00186 m_bFilterBogus = ( Settings.Search.FilterMask & ( 1 << 5 ) ) > 0;
00187 m_bFilterDRM = ( Settings.Search.FilterMask & ( 1 << 6 ) ) > 0;
00188 m_bFilterAdult = ( Settings.Search.FilterMask & ( 1 << 7 ) ) > 0;
00189 m_nFilterMinSize = 1;
00190 m_nFilterMaxSize = 0;
00191 m_nFilterSources = 1;
00192 }
00193
00194 void CFilterOptions::Serialize(CArchive & ar)
00195 {
00196 if ( ar.IsStoring() )
00197 {
00198 ar << m_sName;
00199 ar << m_sFilter;
00200 ar << m_bFilterBusy;
00201 ar << m_bFilterPush;
00202 ar << m_bFilterUnstable;
00203 ar << m_bFilterReject;
00204 ar << m_bFilterLocal;
00205 ar << m_bFilterBogus;
00206 ar << m_nFilterMinSize;
00207 ar << m_nFilterMaxSize;
00208 ar << m_nFilterSources;
00209 }
00210 else
00211 {
00212 ar >> m_sName;
00213 ar >> m_sFilter;
00214 ar >> m_bFilterBusy;
00215 ar >> m_bFilterPush;
00216 ar >> m_bFilterUnstable;
00217 ar >> m_bFilterReject;
00218 ar >> m_bFilterLocal;
00219 ar >> m_bFilterBogus;
00220 ar >> m_nFilterMinSize;
00221 ar >> m_nFilterMaxSize;
00222 ar >> m_nFilterSources;
00223 }
00224 }