Пример #1
0
__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;
}
Пример #2
0
__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;
}
Пример #3
0
bool download(category cat, const char* name)
{
	int count = DownloadSearch(DL_ANY, cat, name);
	if (count<=0) {
		LOG_ERROR("Couldn't find %s",name);
		return false;
	}
	for (int i=0; i<count; i++) {
		DownloadAdd(i);
	}
	show_results(count);
	return true;
}
Пример #4
0
// 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");
}