浏览代码

.NET extension dependency

Source commit: d6b0067424413ad1549caab96fb8912ccd4e1cee
Martin Prikryl 9 年之前
父节点
当前提交
56a595dc47
共有 2 个文件被更改,包括 68 次插入4 次删除
  1. 5 4
      source/core/FileInfo.cpp
  2. 63 0
      source/windows/WinConfiguration.cpp

+ 5 - 4
source/core/FileInfo.cpp

@@ -5,6 +5,7 @@
 #include <Common.h>
 #include <Common.h>
 #include <Exceptions.h>
 #include <Exceptions.h>
 #include <Windows.hpp>
 #include <Windows.hpp>
+#include <Math.hpp>
 #include "FileInfo.h"
 #include "FileInfo.h"
 #include "FileBuffer.h"
 #include "FileBuffer.h"
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -270,9 +271,9 @@ int __fastcall CalculateCompoundVersion(int MajorVer,
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 int __fastcall StrToCompoundVersion(UnicodeString S)
 int __fastcall StrToCompoundVersion(UnicodeString S)
 {
 {
-  int MajorVer = StrToInt(CutToChar(S, L'.', false));
-  int MinorVer = StrToInt(CutToChar(S, L'.', false));
-  int Release = S.IsEmpty() ? 0 : StrToInt(CutToChar(S, L'.', false));
-  int Build = S.IsEmpty() ? 0 : StrToInt(CutToChar(S, L'.', false));
+  int MajorVer = Min(StrToInt(CutToChar(S, L'.', false)), 99);
+  int MinorVer = Min(StrToInt(CutToChar(S, L'.', false)), 99);
+  int Release = S.IsEmpty() ? 0 : Min(StrToInt(CutToChar(S, L'.', false)), 99);
+  int Build = S.IsEmpty() ? 0 : Min(StrToInt(CutToChar(S, L'.', false)), 9999);
   return CalculateCompoundVersion(MajorVer, MinorVer, Release, Build);
   return CalculateCompoundVersion(MajorVer, MinorVer, Release, Build);
 }
 }

+ 63 - 0
source/windows/WinConfiguration.cpp

@@ -2689,6 +2689,63 @@ void __fastcall TCustomCommandType::LoadExtension(const UnicodeString & Path)
   Command = ReplaceStr(Command, L"%EXTENSION_PATH%", 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)
 void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines)
 {
 {
   Params = ccLocal;
   Params = ccLocal;
@@ -2746,12 +2803,18 @@ void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines)
           {
           {
             UnicodeString DependencyVersion = Value;
             UnicodeString DependencyVersion = Value;
             UnicodeString Dependency = CutToChar(Value, L' ', true).LowerCase();
             UnicodeString Dependency = CutToChar(Value, L' ', true).LowerCase();
+            Value = Value.Trim();
             bool Failed = false;
             bool Failed = false;
             if (Dependency == L"winscp")
             if (Dependency == L"winscp")
             {
             {
               int Version = StrToCompoundVersion(Value);
               int Version = StrToCompoundVersion(Value);
               Failed = (Version > WinConfiguration->CompoundVersion);
               Failed = (Version > WinConfiguration->CompoundVersion);
             }
             }
+            else if (Dependency == L".net")
+            {
+              int Version = StrToCompoundVersion(Value);
+              Failed = (Version > GetNetVersion());
+            }
             else
             else
             {
             {
               Failed = true;
               Failed = true;