Răsfoiți Sursa

Refresh download URL before automatic download, if it is more than 2 minutes old

Source commit: c20e43f923315f820df67344d469e106b690ecdc
Martin Prikryl 9 ani în urmă
părinte
comite
31eaff8e15
1 a modificat fișierele cu 24 adăugiri și 2 ștergeri
  1. 24 2
      source/windows/Setup.cpp

+ 24 - 2
source/windows/Setup.cpp

@@ -29,6 +29,7 @@
 #include <PuttyTools.h>
 #include <VCLCommon.h>
 #include <WebBrowserEx.hpp>
+#include <DateUtils.hpp>
 //---------------------------------------------------------------------------
 #define KEY _T("SYSTEM\\CurrentControlSet\\Control\\") \
             _T("Session Manager\\Environment")
@@ -1188,6 +1189,7 @@ private:
   std::unique_ptr<Exception> FException;
   std::unique_ptr<THttp> FHttp;
   TUpdatesConfiguration FUpdates;
+  UnicodeString FDownloadUrl;
 };
 //---------------------------------------------------------------------------
 __fastcall TUpdateDownloadThread::TUpdateDownloadThread(TProgressBar * ProgressBar) :
@@ -1207,12 +1209,32 @@ __fastcall TUpdateDownloadThread::~TUpdateDownloadThread()
 //---------------------------------------------------------------------------
 void __fastcall TUpdateDownloadThread::Execute()
 {
+  FDownloadUrl = FUpdates.Results.DownloadUrl;
+
+  // If the download URL is too old (> 2 minutes), get a new one.
+  // If anything goes wrong, just stick with the old one and let it fail.
+  if (FUpdates.LastCheck < IncMinute(Now(), -2))
+  {
+    try
+    {
+      TUpdatesConfiguration Updates2 = FUpdates;
+      QueryUpdates(Updates2);
+      if (!Updates2.Results.DownloadUrl.IsEmpty())
+      {
+        FDownloadUrl = Updates2.Results.DownloadUrl;
+      }
+    }
+    catch (...)
+    {
+    }
+  }
+
   try
   {
     try
     {
       FHttp.reset(CreateHttp(FUpdates));
-      FHttp->URL = FUpdates.Results.DownloadUrl;
+      FHttp->URL = FDownloadUrl;
       FHttp->OnDownload = HttpDownload;
       FHttp->Get();
     }
@@ -1264,7 +1286,7 @@ void __fastcall TUpdateDownloadThread::UpdateDownloaded()
     DownloadNotVerified();
   }
 
-  UnicodeString FileName = FUpdates.Results.DownloadUrl;
+  UnicodeString FileName = FDownloadUrl;
   int P = FileName.Pos(L"?");
   if (P > 0)
   {