From 669b05cf97735bf0b0d45662e724160830465816 Mon Sep 17 00:00:00 2001
From: Andras Timar <atimar@suse.com>
Date: Wed, 20 Jun 2012 21:07:29 +0200
Subject: [PATCH] fdo#51270 fix RemoveExtensions custom action

FINDPRODUCT property was not available to this deferred custom action.
Not to mention that registry keys are also deleted at his stage of uninstallation.
The proper solution is to set the installation directory with a type 51 custom action,
and pass it to RemoveExtensions custom action via CustomActionData property.

Change-Id: I0ac18b3a0b19ff1a87bcf580fad9c7fdadb26f76
---
 .../windows/msi_templates/AdminExe.idt             |    2 +-
 .../windows/msi_templates/CustomAc.idt             |    3 +-
 .../windows/msi_templates/InstallE.idt             |    3 +-
 .../shellextensions/registerextensions.cxx         |   44 ++++----------------
 4 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/instsetoo_native/inc_openoffice/windows/msi_templates/AdminExe.idt b/instsetoo_native/inc_openoffice/windows/msi_templates/AdminExe.idt
index 18b3ca4..2dd9e91 100644
--- a/instsetoo_native/inc_openoffice/windows/msi_templates/AdminExe.idt
+++ b/instsetoo_native/inc_openoffice/windows/msi_templates/AdminExe.idt
@@ -11,4 +11,4 @@ InstallFinalize		400
 InstallInitialize		250
 InstallValidate		200
 ScheduleReboot	ISSCHEDULEREBOOT	375
-SetInstalllocation		390
+SetInstallLocation1		390
diff --git a/instsetoo_native/inc_openoffice/windows/msi_templates/CustomAc.idt b/instsetoo_native/inc_openoffice/windows/msi_templates/CustomAc.idt
index 913bfe7..938ba05 100644
--- a/instsetoo_native/inc_openoffice/windows/msi_templates/CustomAc.idt
+++ b/instsetoo_native/inc_openoffice/windows/msi_templates/CustomAc.idt
@@ -122,7 +122,8 @@ setAllUsersProfile2K	51	ALLUSERSPROFILE	[%ALLUSERSPROFILE]
 SetAllUsersProfileNT	51	ALLUSERSPROFILE	[%SystemRoot]\Profiles\All Users
 setUserProfileNT	51	USERPROFILE	[%USERPROFILE]
 SetARPInstallLocation	51	ARPINSTALLLOCATION	[INSTALLLOCATION]
-SetInstalllocation	51	RegisterExtensions	[INSTALLLOCATION]
+SetInstallLocation1	51	RegisterExtensions	[INSTALLLOCATION]
+SetInstallLocation2	51	RemoveExtensions	[INSTALLLOCATION]
 NewProductFound	19		OOO_CUSTOMACTION_1
 SameProductFound	19		OOO_CUSTOMACTION_2
 SetLanguageSelected	51	LANG_SELECTED	1
diff --git a/instsetoo_native/inc_openoffice/windows/msi_templates/InstallE.idt b/instsetoo_native/inc_openoffice/windows/msi_templates/InstallE.idt
index 81c1e9a..473b0f8 100644
--- a/instsetoo_native/inc_openoffice/windows/msi_templates/InstallE.idt
+++ b/instsetoo_native/inc_openoffice/windows/msi_templates/InstallE.idt
@@ -172,7 +172,8 @@ ScheduleReboot	ISSCHEDULEREBOOT	3125
 SelfRegModules		2850
 SelfUnregModules		1100
 SetARPInstallLocation		990
-SetInstalllocation		3140
+SetInstallLocation1		3140
+SetInstallLocation2		3141
 SetODBCFolders		550
 StartServices	VersionNT	2800
 StopServices	VersionNT	950
diff --git a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
index 1e30c46..0fbe4e1 100644
--- a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
+++ b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
@@ -211,44 +211,16 @@ extern "C" UINT __stdcall RegisterExtensions(MSIHANDLE handle)
 
 extern "C" UINT __stdcall RemoveExtensions(MSIHANDLE handle)
 {
-    std::_tstring mystr;
-
-    // Finding the product with the help of the propery FINDPRODUCT,
-    // that contains a Windows Registry key, that points to the install location.
-
-    TCHAR szValue[8192];
-    DWORD nValueSize = sizeof(szValue);
-    HKEY  hKey;
-    std::_tstring sInstDir;
-
-    std::_tstring sProductKey = GetMsiProperty( handle, TEXT("FINDPRODUCT") );
-
-    if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER,  sProductKey.c_str(), &hKey ) )
-    {
-        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
-        {
-            sInstDir = szValue;
-        }
-        RegCloseKey( hKey );
-    }
-    else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE,  sProductKey.c_str(), &hKey ) )
-    {
-        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
-        {
-            sInstDir = szValue;
-        }
-        RegCloseKey( hKey );
-    }
-    else
-    {
-        return ERROR_SUCCESS;
-    }
-
-    // Removing complete directory "Basis\prereg\bundled"
+    std::_tstring sInstDir = GetMsiProperty( handle, TEXT("CustomActionData") );
 
-    std::_tstring sCacheDir = sInstDir + TEXT("share\\prereg\\bundled");
+    // Removing complete directory "share\prereg\bundled"
+    RemoveCompleteDirectory( sInstDir + TEXT("share\\prereg\\bundled") );
 
-    RemoveCompleteDirectory( sCacheDir );
+    // At this point we need to take care about removing upper directories,
+    // because we are after InstallFinalize. We remove only empty directories.
+    RemoveDirectory( (sInstDir + TEXT("share\\prereg")).c_str() );
+    RemoveDirectory( (sInstDir + TEXT("share")).c_str() );
+    RemoveDirectory( sInstDir.c_str() );
 
     return ERROR_SUCCESS;
 }
-- 
1.7.5.1

