xXx2o1o

C++ Updater

Feb 16th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. void checkForUpdate() {
  2.     remove("crashes.delete");
  3.     HINTERNET hNet, hNetFile;
  4.  
  5.     hNet = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  6.     if(hNet == NULL)
  7.         return;
  8.  
  9.         hNetFile = InternetOpenUrlA(hNet, "https://raw.githubusercontent.com/Whitetigerswt/gtasa_crashfix/master/LatestVersion.txt", 0, 0, 0, 0);
  10.  
  11.     if(hNetFile == NULL)
  12.         return;
  13.  
  14.     char szLatestVersion[256];
  15.     DWORD dwBytesRead = 0;
  16.     do {
  17.         InternetReadFile(hNetFile, (LPVOID)szLatestVersion, 256, &dwBytesRead);
  18.     } while(dwBytesRead > 0);
  19.  
  20.     float version;
  21.     char* url = new char[200];
  22.     sscanf_s (szLatestVersion, "%f %s", &version, url);
  23.  
  24.     if(version > VERSION) {
  25.         DeleteUrlCacheEntry(url);
  26.  
  27.         char currentDir[MAX_PATH + 15];
  28.         GetCurrentDirectory( MAX_PATH, currentDir );
  29.  
  30.         strcat_s(currentDir, "\\crashes.delete_");
  31.  
  32.         DeleteFile(currentDir);
  33.  
  34.         HRESULT hr = URLDownloadToFile(NULL, url, currentDir, 0, NULL);
  35.  
  36.         if(SUCCEEDED(hr)) {
  37.             char currentMod[MAX_PATH + 15];
  38.             GetModuleFileName(g_hMod, currentMod, MAX_PATH+15);
  39.  
  40.             currentMod[strlen(currentMod)] = '\0';
  41.  
  42.             rename(currentMod, "crashes.delete");
  43.  
  44.             rename(currentDir, "crashes.asi");
  45.  
  46.             LoadLibrary("crashes.asi");
  47.             FreeLibraryAndExitThread(g_hMod, 0);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment