Procházet zdrojové kódy

Sending .NET framework version to the server when downloading extension + Comparing the .NET version number component by component (=handling build number correctly)

Source commit: 1efdd21aff848849eb4ac41196e0ec0bdf17d267
Martin Prikryl před 9 roky
rodič
revize
961d7c152c

+ 12 - 0
source/core/FileInfo.cpp

@@ -277,3 +277,15 @@ int __fastcall StrToCompoundVersion(UnicodeString S)
   int Build = S.IsEmpty() ? 0 : Min(StrToInt(CutToChar(S, L'.', false)), 9999);
   return CalculateCompoundVersion(MajorVer, MinorVer, Release, Build);
 }
+//---------------------------------------------------------------------------
+int __fastcall CompareVersion(UnicodeString V1, UnicodeString V2)
+{
+  int Result = 0;
+  while ((Result == 0) && (!V1.IsEmpty() || !V2.IsEmpty()))
+  {
+    int C1 = StrToIntDef(CutToChar(V1, L'.', false), 0);
+    int C2 = StrToIntDef(CutToChar(V2, L'.', false), 0);
+    Result = CompareValue(C1, C2);
+  }
+  return Result;
+}

+ 2 - 0
source/core/FileInfo.h

@@ -33,4 +33,6 @@ int __fastcall CalculateCompoundVersion(int MajorVer,
 
 int __fastcall StrToCompoundVersion(UnicodeString S);
 
+int __fastcall CompareVersion(UnicodeString V1, UnicodeString V2);
+
 #endif // FileInfoH

+ 4 - 1
source/forms/Preferences.cpp

@@ -2420,7 +2420,10 @@ void __fastcall TPreferencesDialog::AddExtension()
         bool WinSCPURL = IsWinSCPUrl(Url);
         if (WinSCPURL)
         {
-          Url = CampaignUrl(ProgramUrl(Url));
+          Url = ProgramUrl(Url);
+          // The EncodeUrlString should not be necessary, but as we get the value from regitry, let's be safe
+          Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
+          Url = CampaignUrl(Url);
         }
 
         TOperationVisualizer Visualizer;

+ 49 - 0
source/windows/Setup.cpp

@@ -40,6 +40,8 @@
 /* Command line options. */
 UnicodeString LastPathError;
 //---------------------------------------------------------------------------
+UnicodeString NetVersionStr;
+//---------------------------------------------------------------------------
 // Display the error "err_msg".
 void err_out(LPCTSTR err_msg)
 {
@@ -2087,3 +2089,50 @@ void __fastcall TipsUpdateStaticUsage()
   std::unique_ptr<TStringList> TipsSeen(TextToTipList(WinConfiguration->TipsSeen));
   Configuration->Usage->Set(L"TipsSeen", TipsSeen->Count);
 }
+//---------------------------------------------------------------------------
+static void ReadNetVersion(TRegistryStorage * Registry)
+{
+  UnicodeString VersionStr = Registry->ReadString(L"Version", L"");
+  if (CompareVersion(VersionStr, NetVersionStr) > 0)
+  {
+    NetVersionStr = VersionStr;
+  }
+}
+//---------------------------------------------------------------------------
+UnicodeString __fastcall GetNetVersionStr()
+{
+  if (NetVersionStr.IsEmpty())
+  {
+    NetVersionStr = L"0"; // not to retry on failure
+
+    std::unique_ptr<TRegistryStorage> Registry(new TRegistryStorage(L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP", HKEY_LOCAL_MACHINE));
+    if (Registry->OpenRootKey(false))
+    {
+      std::unique_ptr<TStringList> Keys(new TStringList());
+      Registry->GetSubKeyNames(Keys.get());
+      for (int Index = 0; Index < Keys->Count; Index++)
+      {
+        UnicodeString Key = Keys->Strings[Index];
+        if (Registry->OpenSubKey(Key, false))
+        {
+          ReadNetVersion(Registry.get());
+
+          if (Registry->OpenSubKey(L"Full", false))
+          {
+            ReadNetVersion(Registry.get());
+            Registry->CloseSubKey();
+          }
+          if (Registry->OpenSubKey(L"Client", false))
+          {
+            ReadNetVersion(Registry.get());
+            Registry->CloseSubKey();
+          }
+
+          Registry->CloseSubKey();
+        }
+      }
+    }
+  }
+
+  return NetVersionStr;
+}

+ 2 - 0
source/windows/Setup.h

@@ -32,5 +32,7 @@ void __fastcall AutoShowNewTip();
 void __fastcall ShowTips();
 UnicodeString __fastcall FirstUnshownTip();
 void __fastcall TipsUpdateStaticUsage();
+int __fastcall GetNetVersion();
+UnicodeString __fastcall GetNetVersionStr();
 //---------------------------------------------------------------------------
 #endif

+ 1 - 59
source/windows/WinConfiguration.cpp

@@ -2731,63 +2731,6 @@ void __fastcall TCustomCommandType::LoadExtension(const UnicodeString & Path)
   Command = ReplaceStr(Command, L"%EXTENSION_PATH%", Path);
 }
 //---------------------------------------------------------------------------
-int NetVersion = -1;
-//---------------------------------------------------------------------------
-static void ReadNetVersion(TRegistryStorage * Registry)
-{
-  try
-  {
-    UnicodeString VersionStr = Registry->ReadString(L"Version", L"");
-    if (!VersionStr.IsEmpty())
-    {
-      int Version = StrToCompoundVersion(VersionStr);
-      NetVersion = Max(NetVersion, Version);
-    }
-  }
-  catch (...)
-  {
-    // StrToCompoundVersion throws if there's no dot or the components are not numbers
-  }
-}
-//---------------------------------------------------------------------------
-static int GetNetVersion()
-{
-  if (NetVersion < 0)
-  {
-    NetVersion = 0; // not to retry on failure
-
-    std::unique_ptr<TRegistryStorage> Registry(new TRegistryStorage(L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP", HKEY_LOCAL_MACHINE));
-    if (Registry->OpenRootKey(false))
-    {
-      std::unique_ptr<TStringList> Keys(new TStringList());
-      Registry->GetSubKeyNames(Keys.get());
-      for (int Index = 0; Index < Keys->Count; Index++)
-      {
-        UnicodeString Key = Keys->Strings[Index];
-        if (Registry->OpenSubKey(Key, false))
-        {
-          ReadNetVersion(Registry.get());
-
-          if (Registry->OpenSubKey(L"Full", false))
-          {
-            ReadNetVersion(Registry.get());
-            Registry->CloseSubKey();
-          }
-          if (Registry->OpenSubKey(L"Client", false))
-          {
-            ReadNetVersion(Registry.get());
-            Registry->CloseSubKey();
-          }
-
-          Registry->CloseSubKey();
-        }
-      }
-    }
-  }
-
-  return NetVersion;
-}
-//---------------------------------------------------------------------------
 void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines)
 {
   Params = ccLocal;
@@ -2855,8 +2798,7 @@ void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines)
             }
             else if (Dependency == L".net")
             {
-              int Version = StrToCompoundVersion(Value);
-              Failed = (Version > GetNetVersion());
+              Failed = (CompareVersion(Value, GetNetVersionStr()) > 0);
             }
             else
             {