__FORCE_ALIGN_STACK__ int Download(int ID, const std::string& filename, DownloadEnum::Category cat) { currentDownloadID = ID; // FIXME: Progress is incorrectly updated when rapid is queried to check for existing packages. SetDownloadListener(UpdateProgress); LOG_L(L_DEBUG, "Going to download %s", filename.c_str()); DownloadInit(); const int count = DownloadSearch(cat, filename.c_str()); for (int i = 0; i < count; i++) { DownloadAdd(i); struct downloadInfo dl; if (DownloadGetInfo(i, dl)) { LOG_L(L_DEBUG, "Download info: %s %d", dl.filename, dl.cat); } } int result; LOG_L(L_DEBUG, "Download count: %d", count); // TODO: count will be 1 when archives already exist. We should instead return a different result with DownloadFailed/DownloadFinished? if (count == 0) { // there's nothing to download result = 2; QueueDownloadFailed(ID, result); } else { QueueDownloadStarted(ID); result = DownloadStart(); LOG_L(L_DEBUG, "Download finished %s", filename.c_str()); } DownloadShutdown(); return result; }
__FORCE_ALIGN_STACK__ int Download(int ID, const std::string& filename, DownloadEnum::Category cat) { currentDownloadID = ID; // FIXME: Progress is incorrectly updated when rapid is queried to check for existing packages. SetDownloadListener(UpdateProgress); LOG_L(L_DEBUG, "Going to download %s", filename.c_str()); DownloadInit(); const int count = DownloadSearch(cat, filename.c_str()); for (int i = 0; i < count; i++) { DownloadAdd(i); struct downloadInfo dl; if (DownloadGetInfo(i, dl)) { LOG_L(L_DEBUG, "Download info: %s %d", dl.filename, dl.cat); } } int result; LOG_L(L_DEBUG, "Download count: %d", count); // TODO: count will be 1 when archives already exist. We should instead return a different result with DownloadFailed/DownloadFinished? if (count == 0) { // there's nothing to download result = 2; QueueDownloadFailed(ID, result); } else { LOG_L(L_DEBUG, "Download finished %s", filename.c_str()); QueueDownloadStarted(ID); result = DownloadStart(); // TODO: This works but there are errors spammed as it's trying to clear timers in the main thread, which this is not: // Error: [Watchdog::ClearTimer(id)] Invalid thread 4 (_threadId=(nil)) archiveScanner->ScanAllDirs(); } DownloadShutdown(); return result; }
//--------------------------------------- /// 外部からダウンロードマネージャーでファイルをDLする /// /// @param [in] wParam DLStartItemのポインタ LRESULT CDownloadManager::OnStartDownload(UINT uMsg, WPARAM wParam, LPARAM lParam) { if (CDLControlOption::s_bUseDLManager == false) return E_FAIL; DLStartItem* pItem = (DLStartItem*)wParam; DownloadStart(pItem->strURL, pItem->strDLFolder, pItem->hWnd, pItem->dwOption); return S_OK; }
// TODO remove void UserInterface::onTest(Fl_Widget *w, void* d) { UserInterface* ui = static_cast<UserInterface*>(d); Model& m = ui->model_; //m.testThread(); //m.download("asda asdasd dsa", Model::DT_MAP); m.download("Red Comet", Model::DT_MAP); //m.download("aksdgh", Model::DT_GAME); #if 0 LOG(INFO)<< "DownloadSearch..."; int cnt = DownloadSearch(DL_ANY, CAT_MAP, "Red Comet"); LOG(INFO)<< "DownloadSearch cnt:"<<cnt; if (cnt == 1) { bool res; res = DownloadAdd(0); LOG(INFO)<< "DownloadAdd res:"<<res; res = DownloadStart(); LOG(INFO)<< "DownloadStart res:"<<res; } #endif // Sound::beep(); // ui->sound_->play(); // // m.getModAIs("Zero-K v1.0.3.8"); #if 0 auto maps = m.getMaps(); unsigned char const * data = m.getMapImage(maps[0], 0); assert(data); cimg_library::CImg<unsigned char> img(1024, 1024, 1, 3); { int const siz = 1024*1024; unsigned char * d = img; unsigned char * r = d; unsigned char * g = r+siz; unsigned char * b = g+siz; for (int i=0; i < 1024*1024*3; i+=3) { *r = data[i+0]; ++r; *g = data[i+1]; ++g; *b = data[i+2]; ++b; } } // cimg_library::CImg<unsigned char> img("in.png"); img.save_png("out.png", 3); // img.resize(128, 128, 1, 3); //, 6); img.resize_halfXY(); img.save_png("out2.png", 3); img.resize_halfXY(); img.save_png("out3.png", 3); img.resize_halfXY(); img.save_png("out4.png", 3); #endif // int width, height; // m.getMetalMap(maps[0], width, height); // m.getHeightMap(maps[0], width, height); // for (auto mapName : maps) // { // int width, height; // m.getMetalMapImage(mapName, width, height); // } // auto maps = m.getMaps(); // MapInfo mi = m.getMapInfo(maps[0]); // std::ofstream ofs("mapinfo.txt"); // std::cout << mi << std::endl; // ofs << mi; // ofs.close(); // std::ifstream ifs("mapinfo.txt"); // MapInfo mi2; // ifs >> mi2; // std::cout << mi << std::endl; // std::cout << (mi == mi2) << std::endl; // for (auto mapName : maps) // { // MapInfo mi = m.getMapInfo(mapName); // std::cout << mi; // } // write map image to png // // std::string const mapName = "Tabula-v4"; // std::pair<uchar const *, int> res = ui->model_.getMapImage(mapName, 0); // if (res.first) // { // uchar const * p = res.first; // png::image< png::rgb_pixel > image(1024, 1024); // for (std::size_t y = 0; y < 1024; ++y) // { // for (std::size_t x = 0; x < 1024; ++x) // { // image[y][x] = png::rgb_pixel(p[0], p[1], p[2]); // p += 3; // } // } // // image.write(mapName + ".png"); // } // ui->channelsWindow_->show(); // IControllerEvent & iControllerEvent = ui->model_; // iControllerEvent.message("SERVERMSG " // "line1 http://www.archlinux.org bla bla \n" // "line2 http://www.google.se\n" // "line3 bla bla ..." // ); // iControllerEvent.message("SERVERMSG "); // iControllerEvent.message("SAIDPRIVATE cavity hej hopp http://archlinux.org BBB"); // iControllerEvent.message("SAIDPRIVATE cavity hej hopp http://archlinux.org CCC"); // IChat * iChat = ui->tabs_; // iChat->openChannelChat("channel"); }
int main(int argc, char **argv) { show_version(); if (argc<2) show_help(argv[0]); DownloadInit(); bool res=true; while (true) { int option_index = 0; int c = getopt_long(argc, argv, "", long_options, &option_index); if (c == -1) break; switch (c) { case RAPID_DOWNLOAD: { download(CAT_GAME, optarg); break; } case RAPID_VALIDATE: { DownloadRapidValidate(); break; } case FILESYSTEM_DUMPSDP: { DownloadDumpSDP(optarg); break; } case FILESYSTEM_WRITEPATH: { DownloadSetConfig(CONFIG_FILESYSTEM_WRITEPATH, optarg); break; } case HTTP_SEARCH: { search(CAT_ANY, optarg); break; } case HTTP_DOWNLOAD: { if (!download(CAT_ANY, optarg)) res = false; break; } case DOWNLOAD_MAP: { if (!download(CAT_MAP, optarg)) { LOG_ERROR("No map found for %s",optarg); res=false; } break; } case DOWNLOAD_GAME: { if (!download(CAT_GAME, optarg)) { LOG_ERROR("No game found for %s",optarg); res=false; } break; } case SHOW_VERSION: show_version(); break; case DOWNLOAD_ENGINE: { char buf[1024]; snprintf(buf, sizeof(buf), "spring %s", optarg); if (!download(CAT_ENGINE, buf)) { LOG_ERROR("No engine version found for %s",optarg); res=false; } break; } case HELP: default: { show_help(argv[0]); break; } } } if (optind < argc) { while (optind < argc) { if (!download(CAT_ANY, argv[optind])) { LOG_ERROR("No file found for %s",argv[optind]); res=false; } optind++; } } DownloadStart(); DownloadShutdown(); if (res) return 0; return 1; }
//-------------------------------------------- /// DLが開始されるときに呼ばれる STDMETHODIMP CDownloadManager::Download( IMoniker* pmk, IBindCtx* pbc, DWORD dwBindVerb, LONG grfBINDF, BINDINFO* pBindInfo, LPCOLESTR pszHeaders, LPCOLESTR pszRedir, UINT uiCP ) { if (CDLControlOption::s_bUseDLManager == false) return E_FAIL; if (::GetKeyState(VK_MENU) < 0) return E_FAIL; // Altを押しているとデフォルトに任せる if (CDLOptions::bShowWindowOnDL) OnShowDLManager(0, 0, NULL); CCustomBindStatusCallBack* pCBSCB = _CreateCustomBindStatusCallBack(); IBindStatusCallback* pbscbPrev; HRESULT hr = ::RegisterBindStatusCallback(pbc, (IBindStatusCallback*)pCBSCB, &pbscbPrev, 0); if (FAILED(hr) && pbscbPrev) { hr = pbc->RevokeObjectParam(L"_BSCB_Holder_"); if (SUCCEEDED(hr)) { TRACEIN(_T("Download() : _BSCB_Holder_")); // 今度は成功する hr = ::RegisterBindStatusCallback(pbc, (IBindStatusCallback*)pCBSCB, NULL, 0); if (SUCCEEDED(hr)) { pCBSCB->SetReferer(s_strReferer); s_strReferer.Empty(); pCBSCB->SetBSCB(pbscbPrev); pCBSCB->SetBindCtx(pbc); } } } else { #if 0 //\\ 自前でやっちゃうとまずいっぽい // pbscbPrevがNULLだったときの場合 LPOLESTR strUrl; hr = pmk->GetDisplayName(pbc, NULL, &strUrl); if (SUCCEEDED(hr)) { DownloadStart(strUrl); ::CoTaskMemFree(strUrl); return S_OK; } #endif if (pszHeaders == nullptr) { TRACEIN(_T("Download() : Referer : %s"), (LPCTSTR)s_strReferer); pCBSCB->SetReferer(s_strReferer); s_strReferer.Empty(); IBindCtx* pBC; hr = ::CreateAsyncBindCtx(0, pCBSCB, NULL, &pBC); pbc = pBC; } } if (SUCCEEDED(hr)) { CComPtr<IStream> spStream; hr = pmk->BindToStorage(pbc, NULL, IID_IStream, (void**)&spStream); } else { delete pCBSCB; } return hr; }