BOOL CIPFilterDlg::OnInitDialog() { CResizableDialog::OnInitDialog(); InitWindowStyles(this); AddAnchor(IDC_IPFILTER, TOP_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_TOTAL_IPFILTER_LABEL, BOTTOM_LEFT); AddAnchor(IDC_TOTAL_IPFILTER, BOTTOM_LEFT); AddAnchor(IDC_TOTAL_IPS_LABEL, BOTTOM_LEFT); AddAnchor(IDC_TOTAL_IPS, BOTTOM_LEFT); AddAnchor(IDC_COPY, BOTTOM_RIGHT); AddAnchor(IDC_REMOVE, BOTTOM_RIGHT); AddAnchor(IDC_APPEND, BOTTOM_RIGHT); AddAnchor(IDC_SAVE, BOTTOM_RIGHT); AddAnchor(IDOK, BOTTOM_RIGHT); EnableSaveRestore(PREF_INI_SECTION); ASSERT( m_ipfilter.GetStyle() & LVS_OWNERDATA ); m_ipfilter.SendMessage(CCM_SETUNICODEFORMAT, TRUE); m_ipfilter.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); m_ipfilter.EnableHdrCtrlSortBitmaps(); m_ipfilter.ReadColumnStats(ARRSIZE(_aColumns), _aColumns); m_ipfilter.CreateColumns(ARRSIZE(_aColumns), _aColumns); m_ipfilter.InitColumnOrders(ARRSIZE(_aColumns), _aColumns); m_ipfilter.UpdateSortColumn(ARRSIZE(_aColumns), _aColumns); SetIcon(m_icoDlg = theApp.LoadIcon(_T("IPFilter")), FALSE); InitIPFilters(); m_pMenuIPFilter = new CMenu(); if (m_pMenuIPFilter->CreatePopupMenu()) { m_pMenuIPFilter->AppendMenu(MF_ENABLED | MF_STRING, MP_COPYSELECTED, GetResString(IDS_COPY)); m_pMenuIPFilter->AppendMenu(MF_ENABLED | MF_STRING, MP_REMOVE, GetResString(IDS_REMOVE)); m_pMenuIPFilter->AppendMenu(MF_SEPARATOR); m_pMenuIPFilter->AppendMenu(MF_ENABLED | MF_STRING, MP_SELECTALL, GetResString(IDS_SELECTALL)); m_pMenuIPFilter->AppendMenu(MF_SEPARATOR); m_pMenuIPFilter->AppendMenu(MF_ENABLED | MF_STRING, MP_FIND, GetResString(IDS_FIND)); } m_ipfilter.m_pMenu = m_pMenuIPFilter; m_ipfilter.m_pParent = this; // localize SetWindowText(GetResString(IDS_IPFILTER)); SetDlgItemText(IDC_STATICIPLABEL,GetResString(IDS_IP_RULES)); SetDlgItemText(IDC_TOTAL_IPFILTER_LABEL,GetResString(IDS_TOTAL_IPFILTER_LABEL)); SetDlgItemText(IDC_TOTAL_IPS_LABEL,GetResString(IDS_TOTAL_IPS_LABEL)); SetDlgItemText(IDC_COPY,GetResString(IDS_COPY)); SetDlgItemText(IDC_REMOVE,GetResString(IDS_DELETESELECTED)); SetDlgItemText(IDC_APPEND,GetResString(IDS_APPEND)); SetDlgItemText(IDC_SAVE,GetResString(IDS_SAVE)); SetDlgItemText(IDOK,GetResString(IDS_FD_CLOSE)); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CIPFilterDlg::OnBnClickedAppend() { CString strFilePath; // Do NOT localize that string if (DialogBrowseFile(strFilePath, _T("All IP Filter Files (*ipfilter.dat;*ip.prefix;*.p2b;*.p2p;*.p2p.txt;*.zip;*.gz;*.rar)|*ipfilter.dat;*ip.prefix;*.p2b;*.p2p;*.p2p.txt;*.zip;*.gz;*.rar|eMule IP Filter Files (*ipfilter.dat;*ip.prefix)|*ipfilter.dat;*ip.prefix|Peer Guardian Files (*.p2b;*.p2p;*.p2p.txt)|*.p2b;*.p2p;*.p2p.txt|Text Files (*.txt)|*.txt|ZIP Files (*.zip;*.gz)|*.zip;*.gz|RAR Files (*.rar)|*.rar|All Files (*.*)|*.*||"))) { CWaitCursor curWait; TCHAR szExt[_MAX_EXT]; _tsplitpath(strFilePath, NULL, NULL, NULL, szExt); _tcslwr(szExt); bool bIsArchiveFile = _tcscmp(szExt, _T(".zip"))==0 || _tcscmp(szExt, _T(".rar"))==0 || _tcscmp(szExt, _T(".gz"))==0; bool bExtractedArchive = false; CString strTempUnzipFilePath; if (_tcscmp(szExt, _T(".zip")) == 0) { CZIPFile zip; if (zip.Open(strFilePath)) { CZIPFile::File* zfile = zip.GetFile(_T("guarding.p2p")); if (zfile == NULL) zfile = zip.GetFile(_T("ipfilter.dat")); if (zfile) { _tmakepathlimit(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetMuleDirectory(EMULE_CONFIGDIR), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); if (zfile->Extract(strTempUnzipFilePath)) { strFilePath = strTempUnzipFilePath; bExtractedArchive = true; } else { CString strError; strError.Format(_T("Failed to extract IP filter file from ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } } else { CString strError; strError.Format(_T("Failed to find IP filter file \"guarding.p2p\" or \"ipfilter.dat\" in ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } zip.Close(); } else { CString strError; strError.Format(_T("Failed to open file \"%s\".\r\n\r\nInvalid file format?"), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } } else if (_tcscmp(szExt, _T(".rar")) == 0) { CRARFile rar; if (rar.Open(strFilePath)) { CString strFile; if (rar.GetNextFile(strFile) && (strFile.CompareNoCase(_T("ipfilter.dat")) == 0 || strFile.CompareNoCase(_T("guarding.p2p")) == 0)) { _tmakepathlimit(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetMuleDirectory(EMULE_CONFIGDIR), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); if (rar.Extract(strTempUnzipFilePath)) { strFilePath = strTempUnzipFilePath; bExtractedArchive = true; } else { CString strError; strError.Format(_T("Failed to extract IP filter file from RAR file \"%s\"."), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } } else { CString strError; strError.Format(_T("Failed to find IP filter file \"guarding.p2p\" or \"ipfilter.dat\" in RAR file \"%s\"."), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } rar.Close(); } else { CString strError; strError.Format(_T("Failed to open file \"%s\".\r\n\r\nInvalid file format?\r\n\r\nDownload latest version of UNRAR.DLL from http://www.rarlab.com and copy UNRAR.DLL into eMule installation folder."), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } } else if (_tcscmp(szExt, _T(".gz")) == 0) { CGZIPFile gz; if (gz.Open(strFilePath)) { _tmakepathlimit(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetMuleDirectory(EMULE_CONFIGDIR), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); // add filename and extension of uncompressed file to temporary file CString strUncompressedFileName = gz.GetUncompressedFileName(); if (!strUncompressedFileName.IsEmpty()) { strTempUnzipFilePath += _T('.'); strTempUnzipFilePath += strUncompressedFileName; } if (gz.Extract(strTempUnzipFilePath)) { strFilePath = strTempUnzipFilePath; bExtractedArchive = true; } gz.Close(); } else { CString strError; strError.Format(_T("Failed to open file \"%s\".\r\n\r\nInvalid file format?"), strFilePath); AfxMessageBox(strError, MB_ICONERROR); } } if ((!bIsArchiveFile || bExtractedArchive) && theApp.ipfilter->AddFromFile(strFilePath, true)) { if (thePrefs.GetFilterServerByIP()) theApp.emuledlg->serverwnd->serverlistctrl.RemoveAllFilteredServers(); InitIPFilters(); m_ipfilter.Update(-1); } if (!strTempUnzipFilePath.IsEmpty()) VERIFY( _tremove(strTempUnzipFilePath) == 0); } }
void CIPFilterDlg::OnBnClickedAppend() { CString strFilePath; if (DialogBrowseFile(strFilePath, GetResString(IDS_IPFILTERFILES))) { CWaitCursor curWait; CString strTempUnzipFilePath; CZIPFile zip; if (zip.Open(strFilePath)) { CZIPFile::File* zfile = zip.GetFile(_T("guarding.p2p")); if (zfile) { _tmakepath(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); if (zfile->Extract(strTempUnzipFilePath)) strFilePath = strTempUnzipFilePath; else { CString strError; strError.Format(_T("Failed to extract IP filter file \"guarding.p2p\" from ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError); } } else { CString strError; strError.Format(_T("Failed to find IP filter file \"guarding.p2p\" in ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError); } zip.Close(); } else { CGZIPFile gz; if (gz.Open(strFilePath)) { _tmakepath(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); // add filename and extension of uncompressed file to temporary file CString strUncompressedFileName = gz.GetUncompressedFileName(); if (!strUncompressedFileName.IsEmpty()) { strTempUnzipFilePath += _T('.'); strTempUnzipFilePath += strUncompressedFileName; } if (gz.Extract(strTempUnzipFilePath)) strFilePath = strTempUnzipFilePath; } gz.Close(); } if (theApp.ipfilter->AddFromFile(strFilePath, true)) { InitIPFilters(); m_ipfilter.Update(-1); } if (!strTempUnzipFilePath.IsEmpty()) _tremove(strTempUnzipFilePath); } }