BOOL TFindDlg::EventUser(UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_FINDDLG_DELAY) { FilterHost(); return TRUE; } return FALSE; }
void ConnectionManager::ReportHosts(vector<GnutellaHost> &hosts) { int i,j; vector<GnutellaHost> filtered_host_cache; // Filter the host cache with the people we are already connected to for(i=0;i<(int)hosts.size();i++) { // Check with all of the mods with the hosts that they are reporting as being currently connected to bool found=false; found=FilterHost(hosts[i].Host().c_str()); if(!found) { for(j=0;j<(int)v_mods.size();j++) { if(v_mods[j]->IsConnected(hosts[i].IP())) { found=true; break; } } } if(!found) { filtered_host_cache.push_back(hosts[i]); } } // Add these hosts to the host cache for(i=0;i<(int)filtered_host_cache.size();i++) { // Check to see if they are already in the hosts vector bool found=false; for(j=(int)v_host_cache.size()-1;j>=0;j--) { if(filtered_host_cache[i]==v_host_cache[j]) { found=true; break; } } if(!found) { v_host_cache.push_back(filtered_host_cache[i]); } } }
BOOL TFindDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hWndCtl) { switch (wID) { case IDOK: int cnt; GetDlgItemTextU8(FIND_COMBO, cfg->FindStr[0], MAX_NAMEBUF); cfg->FindAll = SendDlgItemMessage(ALLFIND_CHECK, BM_GETCHECK, 0, 0); if (sendDlg->FindHost(cfg->FindStr[0])) { for (cnt=1; cnt < cfg->FindMax; cnt++) { if (stricmp(cfg->FindStr[cnt], cfg->FindStr[0]) == 0) break; } memmove(cfg->FindStr[2], cfg->FindStr[1], (cnt == cfg->FindMax ? cnt-2 : cnt-1) * MAX_NAMEBUF); memcpy(cfg->FindStr[1], cfg->FindStr[0], MAX_NAMEBUF); DWORD start, end; // エディット部の選択状態の保存 SendDlgItemMessage(FIND_COMBO, CB_GETEDITSEL, (WPARAM)&start, (LPARAM)&end); // CB_RESETCONTENT でエディット部がクリア // なお、DELETESTRING でも edit 同名stringの場合、同じくクリアされる SendDlgItemMessage(FIND_COMBO, CB_RESETCONTENT, 0, 0); for (cnt=1; cnt < cfg->FindMax && cfg->FindStr[cnt][0]; cnt++) { Wstr find_w(cfg->FindStr[cnt], BY_UTF8); SendDlgItemMessageW(FIND_COMBO, CB_INSERTSTRING, cnt-1, (LPARAM)find_w.Buf()); } SetDlgItemTextU8(FIND_COMBO, cfg->FindStr[0]); SendDlgItemMessage(FIND_COMBO, CB_SETEDITSEL, 0, MAKELPARAM(start, end)); } cfg->WriteRegistry(CFG_FINDHIST); return TRUE; case IDCANCEL: case CLOSE_BUTTON: sendDlg->FilterHost(""); EndDialog(FALSE); return TRUE; case FIND_COMBO: if (wNotifyCode == CBN_EDITCHANGE) { FilterHost(); } else if (wNotifyCode == CBN_SELCHANGE) { PostMessage(WM_FINDDLG_DELAY, 0, 0); } return TRUE; } return FALSE; }
void ConnectionManager::ReadInHostCache() { UINT i; // If there is a hosts.dat file, read it into the hosts cache CFile file; if(file.Open("C:\\syncher\\src\\GnutellaHostCache\\hosts.dat",CFile::modeRead|CFile::typeBinary|CFile::shareDenyNone)==TRUE) { // Create a buffer in memory to read in the hosts cache file unsigned int buf_len=(UINT)file.GetLength(); char *buf=new char[buf_len]; file.Read(buf,buf_len); // read in the file file.Close(); char *ptr=buf; // Read in the number of hosts in the hosts.dat file unsigned int num_hosts=*((unsigned int *)ptr); ptr+=sizeof(unsigned int); // Copy the hosts from the buffer for(i=0;i<num_hosts;i++) { GnutellaHost host; host.IP(*((unsigned int *)ptr)); ptr+=sizeof(unsigned int); host.Port(*((unsigned int *)ptr)); ptr+=sizeof(unsigned int); if(FilterHost(host.Host().c_str())==false) v_host_cache.push_back(host); } delete [] buf; } }