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)) ...@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,shlxtmsi))
$(eval $(call gb_Library_use_external,shlxtmsi,boost_headers)) $(eval $(call gb_Library_use_external,shlxtmsi,boost_headers))
$(eval $(call gb_Library_add_defs,shlxtmsi,\ $(eval $(call gb_Library_add_defs,shlxtmsi,\
-DUNICODE \
-D_UNICODE \
-U_DLL \ -U_DLL \
)) ))
......
...@@ -17,90 +17,47 @@ ...@@ -17,90 +17,47 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #include <malloc.h>
#include <assert.h> #include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue> #include <queue>
#include <stdio.h> #include <stdio.h>
#include <systools/win32/uwinapi.h> #include <systools/win32/uwinapi.h>
#include <../tools/seterror.hxx> #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) extern "C" UINT __stdcall CheckInstallDirectory(MSIHANDLE handle)
{ {
std::_tstring sInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION")); std::wstring sInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION");
std::_tstring sOfficeHostnamePath = GetMsiProperty(handle, TEXT("OFFICEDIRHOSTNAME")); 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 // unsetting all properties
UnsetMsiProperty( handle, TEXT("DIRECTORY_NOT_EMPTY") ); UnsetMsiPropertyW( handle, L"DIRECTORY_NOT_EMPTY" );
// 1. Searching for file setup.ini // 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; WIN32_FIND_DATA data;
HANDLE hdl = FindFirstFile(sSetupIniPath.c_str(), &data); HANDLE hdl = FindFirstFileW(sSetupIniPath.c_str(), &data);
// std::_tstring mystr = "Searching for " + sSetupIniPath; // std::wstring mystr = L"Searching for " + sSetupIniPath;
// MessageBox(NULL, mystr.c_str(), "DEBUG", MB_OK); // MessageBoxW(NULL, mystr.c_str(), L"DEBUG", MB_OK);
if ( IsValidHandle(hdl) ) if ( IsValidHandle(hdl) )
{ {
// setup.ini found -> directory cannot be used for installation. // 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 ); SetMsiErrorCode( MSI_ERROR_DIRECTORY_NOT_EMPTY );
// std::_tstring notEmptyStr = "Directory is not empty. Please choose another installation directory."; // std::wstring notEmptyStr = L"Directory is not empty. Please choose another installation directory.";
// std::_tstring notEmptyTitle = "Directory not empty"; // std::wstring notEmptyTitle = L"Directory not empty";
// MessageBox(NULL, notEmptyStr.c_str(), notEmptyTitle.c_str(), MB_OK); // MessageBoxW(NULL, notEmptyStr.c_str(), notEmptyTitle.c_str(), MB_OK);
FindClose(hdl);
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
......
...@@ -17,87 +17,47 @@ ...@@ -17,87 +17,47 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #include <malloc.h>
#include <assert.h> #include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue> #include <queue>
#include <stdio.h> #include <stdio.h>
#include <strsafe.h> #include <strsafe.h>
#include <systools/win32/uwinapi.h> #include <systools/win32/uwinapi.h>
#ifdef DEBUG #ifdef DEBUG
inline void OutputDebugStringFormat( LPCSTR pFormat, ... ) inline void OutputDebugStringFormatW( PCWSTR pFormat, ... )
{ {
CHAR buffer[1024]; WCHAR buffer[1024];
va_list args; va_list args;
va_start( args, pFormat ); va_start( args, pFormat );
StringCchVPrintfA( buffer, sizeof(buffer), pFormat, args ); StringCchVPrintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), pFormat, args );
OutputDebugStringA( buffer ); OutputDebugStringW( buffer );
va_end(args); va_end(args);
} }
#else #else
static inline void OutputDebugStringFormat( LPCSTR, ... ) static inline void OutputDebugStringFormatW( PCWSTR, ... )
{ {
} }
#endif #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 ) extern "C" UINT __stdcall CheckPatchList( MSIHANDLE handle )
{ {
std::_tstring sPatchList = GetMsiProperty( handle, TEXT("PATCH") ); std::wstring sPatchList = GetMsiPropertyW( handle, L"PATCH" );
std::_tstring sRequiredPatch = GetMsiProperty( handle, TEXT("PREREQUIREDPATCH") ); 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 ( ( 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") ); SetMsiPropertyW( handle, L"IGNOREPREREQUIREDPATCH", L"1" );
OutputDebugStringFormat( "Set Property IgnorePrerequiredPatch!\n" ); OutputDebugStringFormatW( L"Set Property IgnorePrerequiredPatch!\n" );
} }
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
......
...@@ -17,50 +17,10 @@ ...@@ -17,50 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #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 ) 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 // 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 ) ...@@ -75,15 +35,15 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
// Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind // Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind
// the program files folder. // the program files folder.
std::_tstring sInstallLocation = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ); std::wstring sInstallLocation = GetMsiPropertyW( handle, L"INSTALLLOCATION" );
std::_tstring sOfficeDirHostname = GetMsiProperty( handle, TEXT("OFFICEDIRHOSTNAME_") ); std::wstring sOfficeDirHostname = GetMsiPropertyW( handle, L"OFFICEDIRHOSTNAME_" );
// If sInstallLocation ends with (contains) the string sOfficeDirHostname, // If sInstallLocation ends with (contains) the string sOfficeDirHostname,
// INSTALLLOCATION is good and nothing has to be done here. // INSTALLLOCATION is good and nothing has to be done here.
bool pathCompletionRequired = true; bool pathCompletionRequired = true;
if ( _tcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) ) if ( wcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) )
{ {
pathCompletionRequired = false; // nothing to do pathCompletionRequired = false; // nothing to do
} }
...@@ -93,49 +53,49 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle ) ...@@ -93,49 +53,49 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
if ( pathCompletionRequired ) if ( pathCompletionRequired )
{ {
std::_tstring sManufacturer = GetMsiProperty( handle, TEXT("Manufacturer") ); std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
std::_tstring sDefinedName = GetMsiProperty( handle, TEXT("DEFINEDPRODUCT") ); std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
std::_tstring sUpgradeCode = GetMsiProperty( handle, TEXT("UpgradeCode") ); std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
// sUpdateVersion can be "3.0", "3.1" or "3.2" // sUpdateVersion can be "3.0", "3.1" or "3.2"
std::_tstring sProductKey30 = "Software\\" + sManufacturer + "\\" + sDefinedName + std::wstring sProductKey30 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
"\\" + "3.0" + "\\" + sUpgradeCode; L"\\" L"3.0" L"\\" + sUpgradeCode;
std::_tstring sProductKey31 = "Software\\" + sManufacturer + "\\" + sDefinedName + std::wstring sProductKey31 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
"\\" + "3.1" + "\\" + sUpgradeCode; L"\\" L"3.1" L"\\" + sUpgradeCode;
std::_tstring sProductKey32 = "Software\\" + sManufacturer + "\\" + sDefinedName + std::wstring sProductKey32 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
"\\" + "3.2" + "\\" + sUpgradeCode; L"\\" L"3.2" L"\\" + sUpgradeCode;
bool oldVersionExists = false; 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; oldVersionExists = true;
RegCloseKey( hKey ); 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; oldVersionExists = true;
RegCloseKey( hKey ); 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; oldVersionExists = true;
RegCloseKey( hKey ); 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; oldVersionExists = true;
RegCloseKey( hKey ); 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; oldVersionExists = true;
RegCloseKey( hKey ); 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; oldVersionExists = true;
RegCloseKey( hKey ); RegCloseKey( hKey );
...@@ -146,7 +106,7 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle ) ...@@ -146,7 +106,7 @@ extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
// Adding the new path content sOfficeDirHostname // Adding the new path content sOfficeDirHostname
sInstallLocation = sInstallLocation + sOfficeDirHostname; sInstallLocation = sInstallLocation + sOfficeDirHostname;
// Setting the new property value // Setting the new property value
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstallLocation.c_str()); MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstallLocation.c_str());
} }
} }
......
...@@ -17,83 +17,43 @@ ...@@ -17,83 +17,43 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #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 ) extern "C" UINT __stdcall MigrateInstallPath( MSIHANDLE handle )
{ {
TCHAR szValue[8192]; WCHAR szValue[8192];
DWORD nValueSize = sizeof(szValue); DWORD nValueSize = sizeof(szValue); // yes, it is the number of bytes
HKEY hKey; HKEY hKey;
std::_tstring sInstDir; std::wstring sInstDir;
std::_tstring sManufacturer = GetMsiProperty( handle, TEXT("Manufacturer") ); std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
std::_tstring sDefinedName = GetMsiProperty( handle, TEXT("DEFINEDPRODUCT") ); std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
std::_tstring sUpdateVersion = GetMsiProperty( handle, TEXT("DEFINEDVERSION") ); std::wstring sUpdateVersion = GetMsiPropertyW( handle, L"DEFINEDVERSION" );
std::_tstring sUpgradeCode = GetMsiProperty( handle, TEXT("UpgradeCode") ); std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
std::_tstring sProductKey = "Software\\" + sManufacturer + "\\" + sDefinedName + std::wstring sProductKey = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
"\\" + sUpdateVersion + "\\" + sUpgradeCode; 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; sInstDir = szValue;
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstDir.c_str()); MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
// MessageBox( NULL, sInstDir.c_str(), "Found in HKEY_CURRENT_USER", MB_OK ); // MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_CURRENT_USER", MB_OK );
} }
RegCloseKey( hKey ); 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; sInstDir = szValue;
MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstDir.c_str()); MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
// MessageBox( NULL, sInstDir.c_str(), "Found in HKEY_LOCAL_MACHINE", MB_OK ); // MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_LOCAL_MACHINE", MB_OK );
} }
RegCloseKey( hKey ); 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 @@ ...@@ -17,41 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#define UNICODE #include "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 <malloc.h> #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. Called during installation to customize the start menu folder icon.
......
...@@ -17,25 +17,15 @@ ...@@ -17,25 +17,15 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * 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
#undef _UNICODE #undef _UNICODE
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #include <malloc.h>
#include <assert.h> #include <assert.h>
#include <tchar.h>
#include <string>
using namespace std; using namespace std;
namespace namespace
...@@ -109,55 +99,55 @@ namespace ...@@ -109,55 +99,55 @@ namespace
return convertedGuid; return convertedGuid;
} }
string GetMsiProperty(MSIHANDLE handle, const string& sProperty) string GetMsiPropertyA(MSIHANDLE handle, const string& sProperty)
{ {
string result; string result;
TCHAR szDummy[1] = TEXT(""); CHAR szDummy[1] = "";
DWORD nChars = 0; 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); DWORD nBytes = ++nChars * sizeof(CHAR);
LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes)); LPSTR buffer = reinterpret_cast<LPSTR>(_alloca(nBytes));
ZeroMemory( buffer, nBytes ); ZeroMemory( buffer, nBytes );
MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars); MsiGetPropertyA( handle, sProperty.c_str(), buffer, &nChars );
result = buffer; result = buffer;
} }
return result; 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( bool RegistryKeyHasUpgradeSubKey(
HKEY hRootKey, const string& regKey, const string& upgradeKey) HKEY hRootKey, const wstring& regKey, const string& upgradeKey)
{ {
HKEY hKey; HKEY hKey;
if (RegOpenKey(hRootKey, regKey.c_str(), &hKey) == ERROR_SUCCESS) if (RegOpenKeyW(hRootKey, regKey.c_str(), &hKey) == ERROR_SUCCESS)
{ {
DWORD nSubKeys; DWORD nSubKeys;
DWORD lLongestSubKey; DWORD lLongestSubKey;
if (RegQueryInfoKey( if (RegQueryInfoKeyA(
hKey, NULL, NULL, NULL, &nSubKeys, &lLongestSubKey, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 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++) 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)) if ((ret == ERROR_SUCCESS) && (buffer == upgradeKey))
return true; return true;
} }
...@@ -169,26 +159,26 @@ namespace ...@@ -169,26 +159,26 @@ namespace
extern "C" UINT __stdcall SetProductInstallMode(MSIHANDLE handle) 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)); 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( if (RegistryKeyHasUpgradeSubKey(
HKEY_CURRENT_USER, HKEY_CURRENT_USER,
TEXT("Software\\Microsoft\\Installer\\UpgradeCodes"), L"Software\\Microsoft\\Installer\\UpgradeCodes",
upgradeCode) && IsSetMsiProperty(handle, TEXT("ALLUSERS"))) upgradeCode) && IsSetMsiPropertyA(handle, "ALLUSERS"))
{ {
UnsetMsiProperty(handle, TEXT("ALLUSERS")); UnsetMsiPropertyA(handle, "ALLUSERS");
//MessageBox(NULL, "ALLUSERS removed", "DEBUG", MB_OK); // MessageBoxW(NULL, L"ALLUSERS removed", L"DEBUG", MB_OK);
} }
else if (RegistryKeyHasUpgradeSubKey( else if (RegistryKeyHasUpgradeSubKey(
HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE,
TEXT("Software\\Classes\\Installer\\UpgradeCodes"), L"Software\\Classes\\Installer\\UpgradeCodes",
upgradeCode) && !IsSetMsiProperty(handle, TEXT("ALLUSERS"))) upgradeCode) && !IsSetMsiPropertyA(handle, "ALLUSERS"))
{ {
SetMsiProperty(handle, TEXT("ALLUSERS")); SetMsiPropertyA(handle, "ALLUSERS");
//MessageBox(NULL, "ALLUSERS set", "DEBUG", MB_OK); // MessageBoxW(NULL, L"ALLUSERS set", L"DEBUG", MB_OK);
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
......
...@@ -17,27 +17,11 @@ ...@@ -17,27 +17,11 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifdef _MSC_VER #include "shlxtmsi.hxx"
#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 <malloc.h> #include <malloc.h>
#include <assert.h> #include <assert.h>
#ifdef UNICODE
#define _UNICODE
#define _tstring wstring
#else
#define _tstring string
#endif
#include <tchar.h>
#include <string>
#include <queue> #include <queue>
#include <stdio.h> #include <stdio.h>
#include <strsafe.h> #include <strsafe.h>
...@@ -45,61 +29,43 @@ ...@@ -45,61 +29,43 @@
#include <systools/win32/uwinapi.h> #include <systools/win32/uwinapi.h>
#include <../tools/seterror.hxx> #include <../tools/seterror.hxx>
static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty ) static BOOL RemoveCompleteDirectoryW(const std::wstring& rPath)
{
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)
{ {
bool bDirectoryRemoved = true; bool bDirectoryRemoved = true;
std::_tstring sPattern = rPath + TEXT("\\") + TEXT("*.*"); std::wstring sPattern = rPath + L"\\" + L"*.*";
WIN32_FIND_DATA aFindData; WIN32_FIND_DATA aFindData;
// Finding all content in rPath // Finding all content in rPath
HANDLE hFindContent = FindFirstFile( sPattern.c_str(), &aFindData ); HANDLE hFindContent = FindFirstFileW( sPattern.c_str(), &aFindData );
if ( hFindContent != INVALID_HANDLE_VALUE ) if ( hFindContent != INVALID_HANDLE_VALUE )
{ {
bool fNextFile = false; bool fNextFile = false;
std::_tstring sCurrentDir = TEXT("."); std::wstring sCurrentDir = L".";
std::_tstring sParentDir = TEXT(".."); std::wstring sParentDir = L"..";
do do
{ {
std::_tstring sFileName = aFindData.cFileName; std::wstring sFileName = aFindData.cFileName;
if (( strcmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) && if (( wcscmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) &&
( strcmp(sFileName.c_str(),sParentDir.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 ) if ( aFindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{ {
RemoveCompleteDirectory(sCompleteFileName); RemoveCompleteDirectoryW(sCompleteFileName);
} }
else else
{ {
DeleteFile( sCompleteFileName.c_str() ); DeleteFileW( sCompleteFileName.c_str() );
} }
} }
fNextFile = FindNextFile( hFindContent, &aFindData ); fNextFile = FindNextFileW( hFindContent, &aFindData );
} while ( fNextFile ); } while ( fNextFile );
...@@ -110,7 +76,7 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath) ...@@ -110,7 +76,7 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath)
// -> first removing content -> closing handle -> remove empty directory // -> first removing content -> closing handle -> remove empty directory
if( !( RemoveDirectory(rPath.c_str()) ) ) if( !( RemoveDirectoryW(rPath.c_str()) ) )
{ {
bDirectoryRemoved = false; bDirectoryRemoved = false;
} }
...@@ -121,19 +87,19 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath) ...@@ -121,19 +87,19 @@ static BOOL RemoveCompleteDirectory(const std::_tstring& rPath)
extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle ) 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::wstring sRenameSrc = sOfficeInstallPath + L"program";
std::_tstring sRenameDst = sOfficeInstallPath + TEXT("program_old"); 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 ) if ( !bSuccess )
{ {
TCHAR sAppend[2] = TEXT("0"); WCHAR sAppend[2] = L"0";
for ( int i = 0; i < 10; i++ ) for ( int i = 0; i < 10; i++ )
{ {
sRenameDst = sOfficeInstallPath + TEXT("program_old") + sAppend; sRenameDst = sOfficeInstallPath + L"program_old" + sAppend;
bSuccess = MoveFile( sRenameSrc.c_str(), sRenameDst.c_str() ); bSuccess = MoveFileW( sRenameSrc.c_str(), sRenameDst.c_str() );
if ( bSuccess ) if ( bSuccess )
break; break;
sAppend[0] += 1; sAppend[0] += 1;
...@@ -145,16 +111,16 @@ extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle ) ...@@ -145,16 +111,16 @@ extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle )
extern "C" UINT __stdcall RemovePrgFolder( MSIHANDLE handle ) extern "C" UINT __stdcall RemovePrgFolder( MSIHANDLE handle )
{ {
std::_tstring sOfficeInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION")); std::wstring sOfficeInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION");
std::_tstring sRemoveDir = sOfficeInstallPath + TEXT("program_old"); 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++ ) for ( int i = 0; i < 10; i++ )
{ {
sRemoveDir = sOfficeInstallPath + TEXT("program_old") + sAppend; sRemoveDir = sOfficeInstallPath + L"program_old" + sAppend;
RemoveCompleteDirectory( sRemoveDir ); RemoveCompleteDirectoryW( sRemoveDir );
sAppend[0] += 1; 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