void Curl_Register_predownload(void) { if (curl_mutex) Thread_LockMutex(curl_mutex); Curl_CommandWhenDone("cl_begindownloads"); Curl_CommandWhenError("cl_begindownloads"); if (curl_mutex) Thread_UnlockMutex(curl_mutex); }
/* ==================== Curl_Clear_forthismap Clears the "will disconnect on failure" flags. ==================== */ void Curl_Clear_forthismap(void) { downloadinfo *di; if(noclear) return; for(di = downloads; di; di = di->next) di->forthismap = false; Curl_CommandWhenError(NULL); Curl_CommandWhenDone(NULL); numdownloads_fail = 0; numdownloads_success = 0; numdownloads_added = 0; }
void Curl_Register_predownload(void) { Curl_CommandWhenDone("cl_begindownloads"); Curl_CommandWhenError("cl_begindownloads"); }
/* ==================== Curl_Curl_f implements the "curl" console command curl --info curl --cancel curl --cancel filename curl url For internal use: curl [--pak] [--forthismap] [--for filename filename...] url --pak: after downloading, load the package into the virtual file system --for filename...: only download of at least one of the named files is missing --forthismap: don't reconnect on failure curl --clear_autodownload clears the download success/failure counters curl --finish_autodownload if at least one download has been started, disconnect and drop to the menu once the last download completes successfully, reconnect to the current server ==================== */ void Curl_Curl_f(void) { double maxspeed = 0; int i; int end; qboolean pak = false; qboolean forthismap = false; const char *url; const char *name = 0; if(!curl_dll) { Con_Print("libcurl DLL not found, this command is inactive.\n"); return; } if(!cl_curl_enabled.integer) { Con_Print("curl support not enabled. Set cl_curl_enabled to 1 to enable.\n"); return; } if(Cmd_Argc() < 2) { Con_Print("usage:\ncurl --info, curl --cancel [filename], curl url\n"); return; } url = Cmd_Argv(Cmd_Argc() - 1); end = Cmd_Argc(); for(i = 1; i != end; ++i) { const char *a = Cmd_Argv(i); if(!strcmp(a, "--info")) { Curl_Info_f(); return; } else if(!strcmp(a, "--cancel")) { if(i == end - 1) // last argument Curl_CancelAll(); else { downloadinfo *di = Curl_Find(url); if(di) Curl_EndDownload(di, CURL_DOWNLOAD_ABORTED, CURLE_OK); else Con_Print("download not found\n"); } return; } else if(!strcmp(a, "--pak")) { pak = true; } else if(!strcmp(a, "--for")) // must be last option { for(i = i + 1; i != end - 1; ++i) { if(!FS_FileExists(Cmd_Argv(i))) goto needthefile; // why can't I have a "double break"? } // if we get here, we have all the files... return; } else if(!strcmp(a, "--forthismap")) { forthismap = true; } else if(!strcmp(a, "--as")) { if(i < end - 1) { ++i; name = Cmd_Argv(i); } } else if(!strcmp(a, "--clear_autodownload")) { // mark all running downloads as "not for this map", so if they // fail, it does not matter Curl_Clear_forthismap(); return; } else if(!strcmp(a, "--finish_autodownload")) { if(numdownloads_added) { char donecommand[256]; if(cls.netcon) { if(cl.loadbegun) // curling won't inhibit loading the map any more when at this stage, so bail out and force a reconnect { dpsnprintf(donecommand, sizeof(donecommand), "connect %s", cls.netcon->address); Curl_CommandWhenDone(donecommand); noclear = TRUE; CL_Disconnect(); noclear = FALSE; Curl_CheckCommandWhenDone(); } else Curl_Register_predownload(); } } return; } else if(!strncmp(a, "--maxspeed=", 11)) { maxspeed = atof(a + 11); } else if(*a == '-') { Con_Printf("curl: invalid option %s\n", a); // but we ignore the option } } needthefile: Curl_Begin_ToFile(url, maxspeed, name, pak, forthismap); }