Ver código fonte

Windows XP does not have RegDeleteTreeW - Disabling /ComRegistration on this system

Source commit: 3e49228e0577b4f60a9eb6b25e7c7cc7f370f887
Martin Prikryl 6 anos atrás
pai
commit
270e53416e
3 arquivos alterados com 34 adições e 4 exclusões
  1. 8 3
      source/core/Common.cpp
  2. 1 0
      source/core/Common.h
  3. 25 1
      source/windows/Setup.cpp

+ 8 - 3
source/core/Common.cpp

@@ -1432,11 +1432,16 @@ bool __fastcall IsRealFile(const UnicodeString & FileName)
   return (FileName != THISDIRECTORY) && (FileName != PARENTDIRECTORY);
 }
 //---------------------------------------------------------------------------
+UnicodeString GetOSInfo()
+{
+  UnicodeString Result = WindowsVersionLong();
+  AddToList(Result, WindowsProductName(), L" - ");
+  return Result;
+}
+//---------------------------------------------------------------------------
 UnicodeString GetEnvironmentInfo()
 {
-  UnicodeString OS = WindowsVersionLong();
-  AddToList(OS, WindowsProductName(), L" - ");
-  UnicodeString Result = FORMAT(L"WinSCP %s (OS %s)", (Configuration->VersionStr, OS));
+  UnicodeString Result = FORMAT(L"WinSCP %s (OS %s)", (Configuration->VersionStr, GetOSInfo()));
   return Result;
 }
 //---------------------------------------------------------------------------

+ 1 - 0
source/core/Common.h

@@ -176,6 +176,7 @@ void __fastcall LoadScriptFromFile(UnicodeString FileName, TStrings * Lines);
 UnicodeString __fastcall StripEllipsis(const UnicodeString & S);
 UnicodeString __fastcall GetFileMimeType(const UnicodeString & FileName);
 bool __fastcall IsRealFile(const UnicodeString & FileName);
+UnicodeString GetOSInfo();
 UnicodeString GetEnvironmentInfo();
 //---------------------------------------------------------------------------
 struct TSearchRecSmart : public TSearchRec

+ 25 - 1
source/windows/Setup.cpp

@@ -2560,6 +2560,9 @@ bool DoUnregisterChoice(TConsole * Console)
   return (Console->Choice(L"U", -1, -1, -1, 0, 0, 0, UnicodeString()) == 1);
 }
 //---------------------------------------------------------------------------
+typedef HRESULT WINAPI (* RegDeleteTreeProc)(HKEY Key, LPCWSTR SubKey);
+static RegDeleteTreeProc ARegDeleteTree = NULL;
+//---------------------------------------------------------------------------
 void DoDeleteKey(TConsole * Console, TRegistry * Registry, const UnicodeString & Key, int Platform, bool & AnyDeleted, bool & AllDeleted)
 {
   UnicodeString ParentKey = ExtractFileDir(Key);
@@ -2567,7 +2570,14 @@ void DoDeleteKey(TConsole * Console, TRegistry * Registry, const UnicodeString &
   bool Result = Registry->OpenKey(ParentKey, false);
   if (Result)
   {
-    Result = (RegDeleteTreeW(Registry->CurrentKey, ChildKey.c_str()) == 0);
+    if (DebugAlwaysFalse(ARegDeleteTree == NULL))
+    {
+      Result = false;
+    }
+    else
+    {
+      Result = (ARegDeleteTree(Registry->CurrentKey, ChildKey.c_str()) == 0);
+    }
     Registry->CloseKey();
   }
 
@@ -2590,6 +2600,20 @@ int ComRegistration(TConsole * Console)
   int Result = RESULT_SUCCESS;
   try
   {
+    if (ARegDeleteTree == NULL)
+    {
+      HINSTANCE AdvapiLibrary = LoadLibrary(L"advapi32.dll");
+      if (DebugAlwaysTrue(AdvapiLibrary != NULL))
+      {
+        ARegDeleteTree = reinterpret_cast<RegDeleteTreeProc>(GetProcAddress(AdvapiLibrary, "RegDeleteTreeW"));
+      }
+    }
+
+    if (ARegDeleteTree == NULL)
+    {
+      throw Exception(FORMAT(L"Not supported on %s", (GetOSInfo())));
+    }
+
     Console->PrintLine(GetEnvironmentInfo());
     Console->PrintLine();