Explorar o código

Extension can require specific PowerShell and Windows version

Source commit: c2a9d781f0027435e40c63b182e66fb12ecd8a9b
Martin Prikryl %!s(int64=9) %!d(string=hai) anos
pai
achega
153b2a1c82

+ 2 - 0
source/forms/Preferences.cpp

@@ -2423,6 +2423,8 @@ void __fastcall TPreferencesDialog::AddExtension()
           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 = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
+          Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
           Url = CampaignUrl(Url);
         }
 

+ 32 - 0
source/windows/Setup.cpp

@@ -41,6 +41,7 @@
 UnicodeString LastPathError;
 //---------------------------------------------------------------------------
 UnicodeString NetVersionStr;
+UnicodeString PowerShellVersionStr;
 //---------------------------------------------------------------------------
 // Display the error "err_msg".
 void err_out(LPCTSTR err_msg)
@@ -2136,3 +2137,34 @@ UnicodeString __fastcall GetNetVersionStr()
 
   return NetVersionStr;
 }
+//---------------------------------------------------------------------------
+UnicodeString __fastcall GetPowerShellVersionStr()
+{
+  if (PowerShellVersionStr.IsEmpty())
+  {
+    PowerShellVersionStr = 0; // not to retry on failure
+
+    std::unique_ptr<TRegistryStorage> Registry(new TRegistryStorage(L"SOFTWARE\\Microsoft\\PowerShell", 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 + L"\\PowerShellEngine", false, true))
+        {
+          UnicodeString VersionStr = Registry->ReadString(L"PowerShellVersion", L"");
+          if (!VersionStr.IsEmpty() && (CompareVersion(VersionStr, PowerShellVersionStr) > 0))
+          {
+            PowerShellVersionStr = VersionStr;
+          }
+
+          Registry->CloseSubKey();
+        }
+      }
+    }
+  }
+
+  return PowerShellVersionStr;
+}

+ 1 - 0
source/windows/Setup.h

@@ -34,5 +34,6 @@ UnicodeString __fastcall FirstUnshownTip();
 void __fastcall TipsUpdateStaticUsage();
 int __fastcall GetNetVersion();
 UnicodeString __fastcall GetNetVersionStr();
+UnicodeString __fastcall GetPowerShellVersionStr();
 //---------------------------------------------------------------------------
 #endif

+ 8 - 0
source/windows/WinConfiguration.cpp

@@ -2800,6 +2800,14 @@ void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines)
             {
               Failed = (CompareVersion(Value, GetNetVersionStr()) > 0);
             }
+            else if (Dependency == L"powershell")
+            {
+              Failed = (CompareVersion(Value, GetPowerShellVersionStr()) > 0);
+            }
+            else if (Dependency == L"windows")
+            {
+              Failed = (CompareVersion(Value, WindowsVersion()) > 0);
+            }
             else
             {
               Failed = true;