C++ - VCRedist downloader


SUBMITTED BY: Guest

DATE: Dec. 6, 2014, 4:07 p.m.

FORMAT: C++

SIZE: 4.7 kB

HITS: 7051

  1. //To be compiled using VS 2013
  2. #pragma warning(disable:4996)
  3. #include <iostream>
  4. #include <string>
  5. #include <ctime>
  6. #include <conio.h>
  7. #include <curl/curl.h>
  8. using namespace std;
  9. size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
  10. {
  11. size_t written = fwrite(ptr, size, nmemb, stream);
  12. return written;
  13. }
  14. void initDirs()
  15. {
  16. }
  17. void downloadFile(const char* url, const char* outfilename)
  18. {
  19. CURL *curl;
  20. FILE *fp;
  21. CURLcode res;
  22. curl = curl_easy_init();
  23. if (curl) {
  24. fp = fopen(outfilename, "wb");
  25. curl_easy_setopt(curl, CURLOPT_URL, url);
  26. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
  27. curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
  28. res = curl_easy_perform(curl);
  29. curl_easy_cleanup(curl);
  30. fclose(fp);
  31. }
  32. }
  33. int main()
  34. {
  35. system("if not exist %appdata%\\VCRedistDownloader mkdir %appdata%\\VCRedistDownloader");
  36. const char* appdataPath = getenv("appdata");
  37. string appdataPaths = appdataPath;
  38. string fullAppdataPath = appdataPaths + "\\VCRedistDownloader\\";
  39. string fullAppdataPath1 = fullAppdataPath + "vcredist_x86_2005.exe";
  40. string fullAppdataPath2 = fullAppdataPath + "vcredist_x64_2005.exe";
  41. string fullAppdataPath3 = fullAppdataPath + "vcredist_x86_2008.exe";
  42. string fullAppdataPath4 = fullAppdataPath + "vcredist_x64_2008.exe";
  43. string fullAppdataPath5 = fullAppdataPath + "vcredist_x86_2010.exe";
  44. string fullAppdataPath6 = fullAppdataPath + "vcredist_x64_2010.exe";
  45. string fullAppdataPath7 = fullAppdataPath + "vcredist_x86_2012.exe";
  46. string fullAppdataPath8 = fullAppdataPath + "vcredist_x64_2012.exe";
  47. string fullAppdataPath9 = fullAppdataPath + "vcredist_x86_2013.exe";
  48. string fullAppdataPath10 = fullAppdataPath + "vcredist_x64_2013.exe";
  49. string filesURL1 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x86_2005.exe";
  50. string filesURL2 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x64_2005.exe";
  51. string filesURL3 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x86_2008.exe";
  52. string filesURL4 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x64_2008.exe";
  53. string filesURL5 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x86_2010.exe";
  54. string filesURL6 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x64_2010.exe";
  55. string filesURL7 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x86_2012.exe";
  56. string filesURL8 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x64_2012.exe";
  57. string filesURL9 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x86_2013.exe";
  58. string filesURL10 = "http://hehehemlsharp.cba.pl/vcredist/vcredist_x64_2013.exe";
  59. clock_t timer1 = clock();
  60. cout << "Pobieranie Visual C++ Redistributable 2005 x86... ";
  61. downloadFile(filesURL1.c_str(), fullAppdataPath1.c_str());
  62. cout << "gotowe." << endl;
  63. cout << "Pobieranie Visual C++ Redistributable 2005 x64... ";
  64. downloadFile(filesURL2.c_str(), fullAppdataPath2.c_str());
  65. cout << "gotowe." << endl;
  66. cout << "Pobieranie Visual C++ Redistributable 2008 x86... ";
  67. downloadFile(filesURL3.c_str(), fullAppdataPath3.c_str());
  68. cout << "gotowe." << endl;
  69. cout << "Pobieranie Visual C++ Redistributable 2008 x64... ";
  70. downloadFile(filesURL4.c_str(), fullAppdataPath4.c_str());
  71. cout << "gotowe." << endl;
  72. cout << "Pobieranie Visual C++ Redistributable 2010 x86... ";
  73. downloadFile(filesURL5.c_str(), fullAppdataPath5.c_str());
  74. cout << "gotowe." << endl;
  75. cout << "Pobieranie Visual C++ Redistributable 2010 x64... ";
  76. downloadFile(filesURL6.c_str(), fullAppdataPath6.c_str());
  77. cout << "gotowe." << endl;
  78. cout << "Pobieranie Visual C++ Redistributable 2012 x86... ";
  79. downloadFile(filesURL7.c_str(), fullAppdataPath7.c_str());
  80. cout << "gotowe." << endl;
  81. cout << "Pobieranie Visual C++ Redistributable 2012 x64... ";
  82. downloadFile(filesURL8.c_str(), fullAppdataPath8.c_str());
  83. cout << "gotowe." << endl;
  84. cout << "Pobieranie Visual C++ Redistributable 2013 x86... ";
  85. downloadFile(filesURL9.c_str(), fullAppdataPath9.c_str());
  86. cout << "gotowe." << endl;
  87. cout << "Pobieranie Visual C++ Redistributable 2013 x64... ";
  88. downloadFile(filesURL10.c_str(), fullAppdataPath10.c_str());
  89. cout << "gotowe." << endl;
  90. clock_t timer2 = clock();
  91. double timeElapsed = ((double)timer2 - (double)timer1) / CLOCKS_PER_SEC;
  92. cout << "Wszystkie pliki zostaly pobrane. Zajelo to " << timeElapsed << " sekund.";
  93. system("explorer %appdata%\\VCRedistDownloader");
  94. _getch();
  95. return 0;
  96. }

comments powered by Disqus