Пример #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 {
		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;
}
Пример #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 {
		QueueDownloadStarted(ID);
		result = DownloadStart();
		LOG_L(L_DEBUG, "Download finished %s", filename.c_str());
	}
	DownloadShutdown();

	return result;
}
Пример #3
0
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;
}