Kaydet (Commit) 7fe92c76 authored tarafından skswales's avatar skswales Kaydeden (comit) Michael Stahl

Work towards tdf#72606 EasyHack _tstring/TCHAR elimination

setup_native/source/win32/customactions/shellextensions in MSI Installer compiled as UNICODE

Functions suffixed with A/W (ANSI/Wide) as needed for clarity

Change-Id: I711f781b47c0efdb1e3d9bf995f7658dbb0e38d1
Reviewed-on: https://gerrit.libreoffice.org/25556Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst e0c8c5b7
......@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,shlxtmsi))
$(eval $(call gb_Library_use_external,shlxtmsi,boost_headers))
$(eval $(call gb_Library_add_defs,shlxtmsi,\
-DUNICODE \
-D_UNICODE \
-U_DLL \
))
......
......@@ -17,90 +17,47 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue>
#include <stdio.h>
#include <systools/win32/uwinapi.h>
#include <../tools/seterror.hxx>
static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
static void UnsetMsiProperty(MSIHANDLE handle, const std::_tstring& sProperty)
{
MsiSetProperty(handle, sProperty.c_str(), NULL);
}
static void SetMsiProperty(MSIHANDLE handle, const std::_tstring& sProperty, const std::_tstring&)
{
MsiSetProperty(handle, sProperty.c_str(), TEXT("1"));
}
extern "C" UINT __stdcall CheckInstallDirectory(MSIHANDLE handle)
{
std::_tstring sInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
std::_tstring sOfficeHostnamePath = GetMsiProperty(handle, TEXT("OFFICEDIRHOSTNAME"));
std::wstring sInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION");
std::wstring sOfficeHostnamePath = GetMsiPropertyW(handle, L"OFFICEDIRHOSTNAME");
// MessageBox(NULL, sInstallPath.c_str(), "DEBUG", MB_OK);
// MessageBoxW(NULL, sInstallPath.c_str(), L"DEBUG", MB_OK);
// unsetting all properties
UnsetMsiProperty( handle, TEXT("DIRECTORY_NOT_EMPTY") );
UnsetMsiPropertyW( handle, L"DIRECTORY_NOT_EMPTY" );
// 1. Searching for file setup.ini
std::_tstring sSetupIniPath = sInstallPath + sOfficeHostnamePath + TEXT("\\program\\setup.ini");
std::wstring sSetupIniPath = sInstallPath + sOfficeHostnamePath + L"\\program\\setup.ini";
WIN32_FIND_DATA data;
HANDLE hdl = FindFirstFile(sSetupIniPath.c_str(), &data);
HANDLE hdl = FindFirstFileW(sSetupIniPath.c_str(), &data);
// std::_tstring mystr = "Searching for " + sSetupIniPath;
// MessageBox(NULL, mystr.c_str(), "DEBUG", MB_OK);
// std::wstring mystr = L"Searching for " + sSetupIniPath;
// MessageBoxW(NULL, mystr.c_str(), L"DEBUG", MB_OK);
if ( IsValidHandle(hdl) )
{
// setup.ini found -> directory cannot be used for installation.
SetMsiProperty( handle, TEXT("DIRECTORY_NOT_EMPTY"), TEXT("1") );
SetMsiPropertyW( handle, L"DIRECTORY_NOT_EMPTY", L"1" );
SetMsiErrorCode( MSI_ERROR_DIRECTORY_NOT_EMPTY );
// std::_tstring notEmptyStr = "Directory is not empty. Please choose another installation directory.";
// std::_tstring notEmptyTitle = "Directory not empty";
// MessageBox(NULL, notEmptyStr.c_str(), notEmptyTitle.c_str(), MB_OK);
// std::wstring notEmptyStr = L"Directory is not empty. Please choose another installation directory.";
// std::wstring notEmptyTitle = L"Directory not empty";
// MessageBoxW(NULL, notEmptyStr.c_str(), notEmptyTitle.c_str(), MB_OK);
FindClose(hdl);
}
return ERROR_SUCCESS;
......
......@@ -17,87 +17,47 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue>
#include <stdio.h>
#include <strsafe.h>
#include <systools/win32/uwinapi.h>
#ifdef DEBUG
inline void OutputDebugStringFormat( LPCSTR pFormat, ... )
inline void OutputDebugStringFormatW( PCWSTR pFormat, ... )
{
CHAR buffer[1024];
WCHAR buffer[1024];
va_list args;
va_start( args, pFormat );
StringCchVPrintfA( buffer, sizeof(buffer), pFormat, args );
OutputDebugStringA( buffer );
StringCchVPrintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), pFormat, args );
OutputDebugStringW( buffer );
va_end(args);
}
#else
static inline void OutputDebugStringFormat( LPCSTR, ... )
static inline void OutputDebugStringFormatW( PCWSTR, ... )
{
}
#endif
static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
static void SetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
MsiSetProperty( handle, sProperty.c_str(), TEXT("1") );
}
extern "C" UINT __stdcall CheckPatchList( MSIHANDLE handle )
{
std::_tstring sPatchList = GetMsiProperty( handle, TEXT("PATCH") );
std::_tstring sRequiredPatch = GetMsiProperty( handle, TEXT("PREREQUIREDPATCH") );
std::wstring sPatchList = GetMsiPropertyW( handle, L"PATCH" );
std::wstring sRequiredPatch = GetMsiPropertyW( handle, L"PREREQUIREDPATCH" );
OutputDebugStringFormat( "CheckPatchList called with PATCH=%s and PRQ= %s\n", sPatchList.c_str(), sRequiredPatch.c_str() );
OutputDebugStringFormatW( L"CheckPatchList called with PATCH=%s and PRQ=%s\n", sPatchList.c_str(), sRequiredPatch.c_str() );
if ( ( sPatchList.length() != 0 ) && ( sRequiredPatch.length() != 0 ) )
{
if ( _tcsstr( sPatchList.c_str(), sRequiredPatch.c_str() ) )
if ( wcsstr( sPatchList.c_str(), sRequiredPatch.c_str() ) )
{
SetMsiProperty( handle, TEXT("IGNOREPREREQUIREDPATCH") );
OutputDebugStringFormat( "Set Property IgnorePrerequiredPatch!\n" );
SetMsiPropertyW( handle, L"IGNOREPREREQUIREDPATCH", L"1" );
OutputDebugStringFormatW( L"Set Property IgnorePrerequiredPatch!\n" );
}
}
return ERROR_SUCCESS;
......
......@@ -17,50 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
using namespace std;
namespace
{
std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
} // namespace
extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
{
// This CustomAction is necessary for updates from OOo 3.0, OOo 3.1 and OOo 3.2 to versions
......@@ -75,15 +35,15 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
// Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind
// the program files folder.
std::_tstring sInstallLocation = GetMsiProperty( handle, TEXT("INSTALLLOCATION") );
std::_tstring sOfficeDirHostname = GetMsiProperty( handle, TEXT("OFFICEDIRHOSTNAME_") );
std::wstring sInstallLocation = GetMsiPropertyW( handle, L"INSTALLLOCATION" );
std::wstring sOfficeDirHostname = GetMsiPropertyW( handle, L"OFFICEDIRHOSTNAME_" );
// If sInstallLocation ends with (contains) the string sOfficeDirHostname,
// INSTALLLOCATION is good and nothing has to be done here.
bool pathCompletionRequired = true;
if ( _tcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) )
if ( wcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) )
{
pathCompletionRequired = false; // nothing to do
}
......@@ -93,49 +53,49 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
if ( pathCompletionRequired )
{
std::_tstring sManufacturer = GetMsiProperty( handle, TEXT("Manufacturer") );
std::_tstring sDefinedName = GetMsiProperty( handle, TEXT("DEFINEDPRODUCT") );
std::_tstring sUpgradeCode = GetMsiProperty( handle, TEXT("UpgradeCode") );
std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
// sUpdateVersion can be "3.0", "3.1" or "3.2"
std::_tstring sProductKey30 = "Software\\" + sManufacturer + "\\" + sDefinedName +
"\\" + "3.0" + "\\" + sUpgradeCode;
std::wstring sProductKey30 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
L"\\" L"3.0" L"\\" + sUpgradeCode;
std::_tstring sProductKey31 = "Software\\" + sManufacturer + "\\" + sDefinedName +
"\\" + "3.1" + "\\" + sUpgradeCode;
std::wstring sProductKey31 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
L"\\" L"3.1" L"\\" + sUpgradeCode;
std::_tstring sProductKey32 = "Software\\" + sManufacturer + "\\" + sDefinedName +
"\\" + "3.2" + "\\" + sUpgradeCode;
std::wstring sProductKey32 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
L"\\" L"3.2" L"\\" + sUpgradeCode;
bool oldVersionExists = false;
if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey30.c_str(), &hKey ) )
if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey30.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey31.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey31.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey32.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey32.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey30.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey30.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey31.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey31.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey32.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey32.c_str(), &hKey ) )
{
oldVersionExists = true;
RegCloseKey( hKey );
......@@ -146,7 +106,7 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
// Adding the new path content sOfficeDirHostname
sInstallLocation = sInstallLocation + sOfficeDirHostname;
// Setting the new property value
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstallLocation.c_str());
MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstallLocation.c_str());
}
}
......
......@@ -17,83 +17,43 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
using namespace std;
namespace
{
std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
} // namespace
extern "C" UINT __stdcall MigrateInstallPath( MSIHANDLE handle )
{
TCHAR szValue[8192];
DWORD nValueSize = sizeof(szValue);
WCHAR szValue[8192];
DWORD nValueSize = sizeof(szValue); // yes, it is the number of bytes
HKEY hKey;
std::_tstring sInstDir;
std::wstring sInstDir;
std::_tstring sManufacturer = GetMsiProperty( handle, TEXT("Manufacturer") );
std::_tstring sDefinedName = GetMsiProperty( handle, TEXT("DEFINEDPRODUCT") );
std::_tstring sUpdateVersion = GetMsiProperty( handle, TEXT("DEFINEDVERSION") );
std::_tstring sUpgradeCode = GetMsiProperty( handle, TEXT("UpgradeCode") );
std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
std::wstring sUpdateVersion = GetMsiPropertyW( handle, L"DEFINEDVERSION" );
std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
std::_tstring sProductKey = "Software\\" + sManufacturer + "\\" + sDefinedName +
"\\" + sUpdateVersion + "\\" + sUpgradeCode;
std::wstring sProductKey = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
L"\\" + sUpdateVersion + L"\\" + sUpgradeCode;
if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) )
if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) )
{
if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
if ( ERROR_SUCCESS == RegQueryValueExW( hKey, L"INSTALLLOCATION", NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
{
sInstDir = szValue;
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstDir.c_str());
// MessageBox( NULL, sInstDir.c_str(), "Found in HKEY_CURRENT_USER", MB_OK );
MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
// MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_CURRENT_USER", MB_OK );
}
RegCloseKey( hKey );
}
else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) )
else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) )
{
if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
if ( ERROR_SUCCESS == RegQueryValueExW( hKey, L"INSTALLLOCATION", NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
{
sInstDir = szValue;
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstDir.c_str());
// MessageBox( NULL, sInstDir.c_str(), "Found in HKEY_LOCAL_MACHINE", MB_OK );
MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
// MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_LOCAL_MACHINE", MB_OK );
}
RegCloseKey( hKey );
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_SHELLEXTENSIONS_SHLXTMSI_HXX
#define INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_SHELLEXTENSIONS_SHLXTMSI_HXX
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _WIN32_WINNT_WINBLUE
#include <VersionHelpers.h>
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <string>
static inline std::wstring GetMsiPropertyW( MSIHANDLE handle, const std::wstring& sProperty )
{
std::wstring result;
WCHAR szDummy[1] = L"";
DWORD nChars = 0;
if ( MsiGetPropertyW( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(WCHAR);
PWSTR buffer = reinterpret_cast<PWSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetPropertyW( handle, sProperty.c_str(), buffer, &nChars );
result = buffer;
}
return result;
}
static inline void SetMsiPropertyW( MSIHANDLE handle, const std::wstring& sProperty, const std::wstring& sValue )
{
MsiSetPropertyW( handle, sProperty.c_str(), sValue.c_str() );
}
static inline void UnsetMsiPropertyW( MSIHANDLE handle, const std::wstring& sProperty )
{
MsiSetPropertyW( handle, sProperty.c_str(), NULL );
}
#endif // INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_SHELLEXTENSIONS_SHLXTMSI_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -17,41 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#define UNICODE
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _WIN32_WINNT_WINBLUE
#include <VersionHelpers.h>
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#include <string>
std::wstring GetMsiPropertyW( MSIHANDLE handle, const std::wstring& sProperty )
{
std::wstring result;
WCHAR szDummy[1] = L"";
DWORD nChars = 0;
if ( MsiGetPropertyW( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(WCHAR);
PWSTR buffer = reinterpret_cast<PWSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetPropertyW(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
/*
Called during installation to customize the start menu folder icon.
......
......@@ -17,25 +17,15 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// NB This file still makes use of largely ANSI MSI API calls
#undef UNICODE
#undef _UNICODE
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#include <assert.h>
#include <tchar.h>
#include <string>
using namespace std;
namespace
......@@ -109,55 +99,55 @@ namespace
return convertedGuid;
}
string GetMsiProperty(MSIHANDLE handle, const string& sProperty)
string GetMsiPropertyA(MSIHANDLE handle, const string& sProperty)
{
string result;
TCHAR szDummy[1] = TEXT("");
CHAR szDummy[1] = "";
DWORD nChars = 0;
if (MsiGetProperty(handle, sProperty.c_str(), szDummy, &nChars) == ERROR_MORE_DATA)
if (MsiGetPropertyA(handle, sProperty.c_str(), szDummy, &nChars) == ERROR_MORE_DATA)
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
DWORD nBytes = ++nChars * sizeof(CHAR);
LPSTR buffer = reinterpret_cast<LPSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
MsiGetPropertyA( handle, sProperty.c_str(), buffer, &nChars );
result = buffer;
}
return result;
}
inline bool IsSetMsiProperty(MSIHANDLE handle, const string& sProperty)
inline bool IsSetMsiPropertyA(MSIHANDLE handle, const string& sProperty)
{
return (GetMsiProperty(handle, sProperty).length() > 0);
return (GetMsiPropertyA(handle, sProperty).length() > 0);
}
inline void UnsetMsiProperty(MSIHANDLE handle, const string& sProperty)
inline void UnsetMsiPropertyA(MSIHANDLE handle, const string& sProperty)
{
MsiSetProperty(handle, sProperty.c_str(), NULL);
MsiSetPropertyA(handle, sProperty.c_str(), NULL);
}
inline void SetMsiProperty(MSIHANDLE handle, const string& sProperty)
inline void SetMsiPropertyA(MSIHANDLE handle, const string& sProperty)
{
MsiSetProperty(handle, sProperty.c_str(), TEXT("1"));
MsiSetPropertyA(handle, sProperty.c_str(), "1");
}
bool RegistryKeyHasUpgradeSubKey(
HKEY hRootKey, const string& regKey, const string& upgradeKey)
HKEY hRootKey, const wstring& regKey, const string& upgradeKey)
{
HKEY hKey;
if (RegOpenKey(hRootKey, regKey.c_str(), &hKey) == ERROR_SUCCESS)
if (RegOpenKeyW(hRootKey, regKey.c_str(), &hKey) == ERROR_SUCCESS)
{
DWORD nSubKeys;
DWORD lLongestSubKey;
if (RegQueryInfoKey(
if (RegQueryInfoKeyA(
hKey, NULL, NULL, NULL, &nSubKeys, &lLongestSubKey, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(lLongestSubKey + 1));
LPSTR buffer = reinterpret_cast<LPSTR>(_alloca(lLongestSubKey + 1));
for (DWORD i = 0; i < nSubKeys; i++)
{
LONG ret = RegEnumKey(hKey, i, buffer, lLongestSubKey + 1);
LONG ret = RegEnumKeyA(hKey, i, buffer, lLongestSubKey + 1);
if ((ret == ERROR_SUCCESS) && (buffer == upgradeKey))
return true;
}
......@@ -169,26 +159,26 @@ namespace
extern "C" UINT __stdcall SetProductInstallMode(MSIHANDLE handle)
{
string upgradeCode = GetMsiProperty(handle, TEXT("UpgradeCode"));
string upgradeCode = GetMsiPropertyA(handle, "UpgradeCode");
upgradeCode = ConvertGuid(string(upgradeCode.c_str() + 1, upgradeCode.length() - 2));
//MessageBox(NULL, upgradeCode.c_str(), TEXT("Debug"), MB_OK);
// MessageBoxA(NULL, upgradeCode.c_str(), "Debug", MB_OK);
if (RegistryKeyHasUpgradeSubKey(
HKEY_CURRENT_USER,
TEXT("Software\\Microsoft\\Installer\\UpgradeCodes"),
upgradeCode) && IsSetMsiProperty(handle, TEXT("ALLUSERS")))
L"Software\\Microsoft\\Installer\\UpgradeCodes",
upgradeCode) && IsSetMsiPropertyA(handle, "ALLUSERS"))
{
UnsetMsiProperty(handle, TEXT("ALLUSERS"));
//MessageBox(NULL, "ALLUSERS removed", "DEBUG", MB_OK);
UnsetMsiPropertyA(handle, "ALLUSERS");
// MessageBoxW(NULL, L"ALLUSERS removed", L"DEBUG", MB_OK);
}
else if (RegistryKeyHasUpgradeSubKey(
HKEY_LOCAL_MACHINE,
TEXT("Software\\Classes\\Installer\\UpgradeCodes"),
upgradeCode) && !IsSetMsiProperty(handle, TEXT("ALLUSERS")))
L"Software\\Classes\\Installer\\UpgradeCodes",
upgradeCode) && !IsSetMsiPropertyA(handle, "ALLUSERS"))
{
SetMsiProperty(handle, TEXT("ALLUSERS"));
//MessageBox(NULL, "ALLUSERS set", "DEBUG", MB_OK);
SetMsiPropertyA(handle, "ALLUSERS");
// MessageBoxW(NULL, L"ALLUSERS set", L"DEBUG", MB_OK);
}
return ERROR_SUCCESS;
}
......
......@@ -17,27 +17,11 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "shlxtmsi.hxx"
#include <malloc.h>
#include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue>
#include <stdio.h>
#include <strsafe.h>
......@@ -45,61 +29,43 @@
#include <systools/win32/uwinapi.h>
#include <../tools/seterror.hxx>
static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
{
std::_tstring result;
TCHAR szDummy[1] = TEXT("");
DWORD nChars = 0;
if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
{
DWORD nBytes = ++nChars * sizeof(TCHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
result = buffer;
}
return result;
}
static BOOL RemoveCompleteDirectory(const std::_tstring& rPath)
static BOOL RemoveCompleteDirectoryW(const std::wstring& rPath)
{
bool bDirectoryRemoved = true;
std::_tstring sPattern = rPath + TEXT("\\") + TEXT("*.*");
std::wstring sPattern = rPath + L"\\" + L"*.*";
WIN32_FIND_DATA aFindData;
// Finding all content in rPath
HANDLE hFindContent = FindFirstFile( sPattern.c_str(), &aFindData );
HANDLE hFindContent = FindFirstFileW( sPattern.c_str(), &aFindData );
if ( hFindContent != INVALID_HANDLE_VALUE )
{
bool fNextFile = false;
std::_tstring sCurrentDir = TEXT(".");
std::_tstring sParentDir = TEXT("..");
std::wstring sCurrentDir = L".";
std::wstring sParentDir = L"..";
do
{
std::_tstring sFileName = aFindData.cFileName;
std::wstring sFileName = aFindData.cFileName;
if (( strcmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) &&
( strcmp(sFileName.c_str(),sParentDir.c_str()) != 0 ))
if (( wcscmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) &&
( wcscmp(sFileName.c_str(),sParentDir.c_str()) != 0 ))
{
std::_tstring sCompleteFileName = rPath + TEXT("\\") + sFileName;
std::wstring sCompleteFileName = rPath + L"\\" + sFileName;
if ( aFindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
RemoveCompleteDirectory(sCompleteFileName);
RemoveCompleteDirectoryW(sCompleteFileName);
}
else
{
DeleteFile( sCompleteFileName.c_str() );
DeleteFileW( sCompleteFileName.c_str() );
}
}
fNextFile = FindNextFile( hFindContent, &aFindData );
fNextFile = FindNextFileW( hFindContent, &aFindData );
} while ( fNextFile );
......@@ -110,7 +76,7 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath)
// -> first removing content -> closing handle -> remove empty directory
if( !( RemoveDirectory(rPath.c_str()) ) )
if( !( RemoveDirectoryW(rPath.c_str()) ) )
{
bDirectoryRemoved = false;
}
......@@ -121,19 +87,19 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath)
extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle )
{
std::_tstring sOfficeInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
std::wstring sOfficeInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION");
std::_tstring sRenameSrc = sOfficeInstallPath + TEXT("program");
std::_tstring sRenameDst = sOfficeInstallPath + TEXT("program_old");
std::wstring sRenameSrc = sOfficeInstallPath + L"program";
std::wstring sRenameDst = sOfficeInstallPath + L"program_old";
bool bSuccess = MoveFile( sRenameSrc.c_str(), sRenameDst.c_str() );
bool bSuccess = MoveFileW( sRenameSrc.c_str(), sRenameDst.c_str() );
if ( !bSuccess )
{
TCHAR sAppend[2] = TEXT("0");
WCHAR sAppend[2] = L"0";
for ( int i = 0; i < 10; i++ )
{
sRenameDst = sOfficeInstallPath + TEXT("program_old") + sAppend;
bSuccess = MoveFile( sRenameSrc.c_str(), sRenameDst.c_str() );
sRenameDst = sOfficeInstallPath + L"program_old" + sAppend;
bSuccess = MoveFileW( sRenameSrc.c_str(), sRenameDst.c_str() );
if ( bSuccess )
break;
sAppend[0] += 1;
......@@ -145,16 +111,16 @@ extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle )
extern "C" UINT __stdcall RemovePrgFolder( MSIHANDLE handle )
{
std::_tstring sOfficeInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
std::_tstring sRemoveDir = sOfficeInstallPath + TEXT("program_old");
std::wstring sOfficeInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION");
std::wstring sRemoveDir = sOfficeInstallPath + L"program_old";
RemoveCompleteDirectory( sRemoveDir );
RemoveCompleteDirectoryW( sRemoveDir );
TCHAR sAppend[2] = TEXT("0");
WCHAR sAppend[2] = L"0";
for ( int i = 0; i < 10; i++ )
{
sRemoveDir = sOfficeInstallPath + TEXT("program_old") + sAppend;
RemoveCompleteDirectory( sRemoveDir );
sRemoveDir = sOfficeInstallPath + L"program_old" + sAppend;
RemoveCompleteDirectoryW( sRemoveDir );
sAppend[0] += 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment