int main(int argc, char *argv[]) { _debugOutput("Starting...\n"); //httpDownload("http://ftpclubic1.clubic.com/temp-clubic-rx270/logiciel/exstora_exstora_1.2_francais_22607.exe"); // string file = httpDownload("http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"); // string file = httpDownload("http://localhost/jinstall-1_4_2-windows-i586.cab"); // string file = httpDownload("http://127.0.0.1/test.msi"); // string file = httpDownload("http://travel.state.gov/passport/forms/forms_847.html"); // string file = httpDownload("http://java.sun.com/products/plugin/autodl/jinstall-1_3_0_05-win.cab"); string file = httpDownload("ftp://ftp.free.fr/pub/freeplayer/Freeplayer-Win32-20050905.zip"); //string file= httpDownload("http://downloads.sourceforge.net/filezilla/FileZilla_2_2_31_setup.exe?use_mirror=osdn"); printf("Downloaded: %s\n", file.c_str()); exit(0); }
string doDownload(string url, string &outParams) { string firstPrioRedirect = FileUtils::getExecutablePath() + "autodownload.redirect"; if (FileUtils::fileExists(firstPrioRedirect)) { url = "file:\\" + firstPrioRedirect; } string file; const string &FILE_PREFIX("file:"); if (StringUtils::startsWith(url, FILE_PREFIX)) { file = FileUtils::getRelOrAbsFile(url.substr(FILE_PREFIX.size())); } else { DEBUG("autodownload: Now downloading " + url); file = httpDownload(url, MSG_DOWNLOADING_JAVA, MSG_DOWNLOADING_JAVA_WAIT, _silent); printf("autodownload: GOT FILE[%s]\n", file.c_str()); } if (StringUtils::endsWith(file, "autodownload.redirect")){ DEBUG("autodownloadinfo: detected."); string adUrl = ""; FILE *f = fopen(file.c_str(), "r"); if (f) { const string &URL_KEY("url="); const string &PARAMS_KEY("params="); char line[1024]; outParams = ""; int lines = 0; while (fgets(line, MAX_LINE, f)) { if (lines++ > 20) { break; // had strange situation with endless loop } string linee = StringUtils::rtrim(line); if (StringUtils::startsWith(linee, URL_KEY)) { adUrl = linee.substr(URL_KEY.size()); } else if (StringUtils::startsWith(linee, PARAMS_KEY)) { outParams = linee.substr(PARAMS_KEY.size()); } if (!adUrl.empty() && !outParams.empty()) { break; } } fclose(f); } else { DEBUG("autodownloadinfo: file not found: " + file); } DEBUG("autodownloadinfo: url=" + adUrl + ", params=" + outParams); if (!adUrl.empty()) { if (StringUtils::startsWith(adUrl, FILE_PREFIX)) { adUrl = adUrl.substr(FILE_PREFIX.size()); file = FileUtils::getRelOrAbsFile(adUrl); } else { DEBUG("autodownloadinfo: Now downloading " + adUrl); file = httpDownload(adUrl, MSG_DOWNLOADING_JAVA, MSG_DOWNLOADING_JAVA_WAIT, _silent); printf("autodownloadinfo: GOT FILE[%s]\n", file.c_str()); } } } return file; }