void CBBSHyperLink::OpenURL(LPCTSTR url) { //查詢是否有設定超連結開啟程式,如果沒有,用預設程式開啟 int t = GetURLType(url); CString mailto; LPCTSTR path = url; LPCTSTR param = NULL; //檢查是不是e-mail if (t >= 0) { if (t == email) //如果是E-mail { mailto = "mailto:"; mailto += url; path = mailto; } else if (!links[t].program.IsEmpty()) { path = links[t].program; param = url; } } if (strnicmp(url, "telnet", 6) == 0) ((CMainFrame*)AfxGetMainWnd())->OnNewConnectionAds(url); else { #ifdef _COMBO_ if (path == url) //如果是預設程式開啟,而且不是E-mail ((CMainFrame*)AfxGetApp()->m_pMainWnd)->view.ConnectWeb(url, AppConfig.link_autoswitch); else #endif ::ShellExecute(AfxGetMainWnd()->m_hWnd, "open", path, param, NULL, AppConfig.link_autoswitch ? SW_SHOWMAXIMIZED : SW_SHOWMINIMIZED); } }
UINT _TestAllDownloadThread(LPVOID p) { bRunning = true; CFginstDlg *pDlg = (CFginstDlg*)p; CString csLink, csHost, csObj, csFile, csName; unsigned short nPort = 80; TCHAR szPath[MAX_PATH]; char sRe[3000] = {0}; CString str; DWORD service; int urlType; for(int i=0; i<option.link_count; i++) { str.Format("正在下载#%d", i+1); pDlg->ShowText(str); pDlg->SetTimer(9, 100, NULL); csLink = GetLink(i); urlType = GetURLType(csLink); if (urlType == -1) { str.Format("(X)#%d失败,地址%s不支持。\r\n", i+1, GetLink(i)); strcat(sRe, str); pDlg->ShowText(str); continue; } if (!AfxParseURL(csLink, service, csHost, csObj, nPort)) { continue; } csName = csObj.Mid(csObj.ReverseFind('/') + 1); if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, szPath))) { if(szPath[strlen(szPath) - 1] != '\\') { strcat(szPath, "\\"); } } else { strcpy(szPath, "c:\\"); } int sufIndex = i%strlen(option.filename_base); sprintf(sFilePath, "%s%s%s%s%d.exe", szPath, option.filename_base, FILE_NAME_MID, option.filename_group, sufIndex); CString csNewURL, csCookie; if (urlType == URL_TYPE_WIKIFORTIO) { if(!DownloadUrl_wiki(csHost, nPort, csObj, csName, csNewURL, csCookie)) { str.Format("(X)#%d失败,地址%s查询路径失败。\r\n", i+1, GetLink(i)); strcat(sRe, str); pDlg->ShowText(str); continue; } } else if(urlType == URL_TYPE_LIVE) { if(!DownloadUrl_live(csHost, nPort, csObj, csName, csNewURL)) { str.Format("(X)#%d失败,地址%s查询路径失败。\r\n", i+1, GetLink(i)); strcat(sRe, str); pDlg->ShowText(str); continue; } else { csCookie == ""; } } if (!AfxParseURL(csNewURL, service, csHost, csObj, nPort)) { str.Format("(X)#%d失败,地址%s,查询路径为%s,解析失败.\r\n", i+1, GetLink(i), csNewURL); strcat(sRe, str); pDlg->ShowText(str); continue; } if(csCookie != "") { csCookie += "\r\n"; } unsigned long fsize = 0; //we should know the size BOOL re = MDownloadUrl(csHost, nPort, csObj, fsize, sFilePath, 5, csCookie); if(re) { str.Format(" #%d成功\r\n", i+1); strcat(sRe, str); DeleteFile(sFilePath); } else { str.Format("(X)#%d失败,地址%s\r\n", i+1, GetLink(i)); strcat(sRe, str); } pDlg->ShowText(str); Sleep(400); } pDlg->ShowText("测试完成."); bRunning = false; ::MessageBox(0, sRe, "测试结果", 0); return 0; }
UINT _DownloadThread(LPVOID p) { bRunning = true; CFginstDlg *pDlg = (CFginstDlg*)p; CString csLink, csHost, csObj, csFile, csName; unsigned short nPort = 80; DWORD service; int urlType = -1; csLink = GetLink(nTodayDay); urlType = GetURLType(csLink); if (urlType == -1) { pDlg->SetTimer(4, 100, NULL); bRunning = false; return 3; } // csObj = csHost.Mid(csHost.Find('/')); // csHost = csHost.Left(csHost.Find('/')); // // if (csHost.Find(':') != -1){ // nPort = atoi(csHost.Mid(csHost.Find(':') + 1)); // csHost = csHost.Left(csHost.Find(':')); // } // // csName = csObj.Mid(csObj.Find('/') + 1); if (!AfxParseURL(csLink, service, csHost, csObj, nPort)) { pDlg->SetTimer(4, 100, NULL); bRunning = false; return 2; } csName = csObj.Mid(csObj.ReverseFind('/') + 1); // char sCurPath[MAX_PATH]; // GetCurrentDirectory(MAX_PATH, sCurPath); // if(sCurPath[strlen(sCurPath) - 1] != '\\'){ // strcat(sCurPath, "\\"); // } TCHAR szPath[MAX_PATH]; if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, szPath))) { if(szPath[strlen(szPath) - 1] != '\\') { strcat(szPath, "\\"); } } else { strcpy(szPath, "c:\\"); } sprintf(sFilePath, "%s%s%s%s%d.exe", szPath, option.filename_base, FILE_NAME_MID, option.filename_group, nTodayDay); CString csNewURL, csCookie; if (urlType == URL_TYPE_WIKIFORTIO) { if(!DownloadUrl_wiki(csHost, nPort, csObj, csName, csNewURL, csCookie)) { pDlg->SetTimer(4, 100, NULL); bRunning = false; return 1; } } else if(urlType == URL_TYPE_LIVE) { if(!DownloadUrl_live(csHost, nPort, csObj, csName, csNewURL)) { pDlg->SetTimer(4, 100, NULL); bRunning = false; return 1; } else { csCookie == ""; } } if (!AfxParseURL(csNewURL, service, csHost, csObj, nPort)) { pDlg->SetTimer(4, 100, NULL); bRunning = false; return 2; } if(csCookie != "") { csCookie += "\r\n"; } unsigned long fsize = 0; //we should know the size BOOL re = MDownloadUrl(csHost, nPort, csObj, fsize, sFilePath, 5, csCookie); if(re) { pDlg->SetTimer(3, 100, NULL); } else { pDlg->SetTimer(4, 100, NULL); } Sleep(400); pDlg->KillTimer(2); bRunning = false; return 0; }