From 074bd09ee6f3113792b60ee721aabb731c5d7ace Mon Sep 17 00:00:00 2001 From: skswales Date: Thu, 19 May 2016 11:12:15 +0100 Subject: Work towards tdf#72606 EasyHack _tstring/TCHAR elimination Quickstarter removal code in MSI Installer compiled as UNICODE Functions suffixed with A/W (ANSI/Wide) as needed for clarity Change-Id: I50aa27a753542fc0ddf002f385de78ba106b17ab Reviewed-on: https://gerrit.libreoffice.org/25153 Tested-by: Jenkins Reviewed-by: Michael Stahl --- setup_native/StaticLibrary_quickstarter.mk | 2 + .../customactions/quickstarter/quickstarter.cxx | 68 +++++++++++----------- .../customactions/quickstarter/quickstarter.hxx | 8 +-- .../quickstarter/remove_quickstart_link.cxx | 23 +++----- .../quickstarter/shutdown_quickstart.cxx | 9 +-- 5 files changed, 55 insertions(+), 55 deletions(-) (limited to 'setup_native') diff --git a/setup_native/StaticLibrary_quickstarter.mk b/setup_native/StaticLibrary_quickstarter.mk index 0517a7511016..cc18d6a74a48 100644 --- a/setup_native/StaticLibrary_quickstarter.mk +++ b/setup_native/StaticLibrary_quickstarter.mk @@ -10,6 +10,8 @@ $(eval $(call gb_StaticLibrary_StaticLibrary,quickstarter)) $(eval $(call gb_StaticLibrary_add_defs,quickstarter,\ + -DUNICODE \ + -D_UNICODE \ -U_DLL \ )) diff --git a/setup_native/source/win32/customactions/quickstarter/quickstarter.cxx b/setup_native/source/win32/customactions/quickstarter/quickstarter.cxx index dccae732e3b2..8c919d617c16 100644 --- a/setup_native/source/win32/customactions/quickstarter/quickstarter.cxx +++ b/setup_native/source/win32/customactions/quickstarter/quickstarter.cxx @@ -18,6 +18,7 @@ */ #include "quickstarter.hxx" + #ifdef _MSC_VER #pragma warning(push, 1) /* disable warnings within system headers */ #endif @@ -25,66 +26,67 @@ #ifdef _MSC_VER #pragma warning(pop) #endif + #include -std::string GetOfficeInstallationPath(MSIHANDLE handle) +std::wstring GetOfficeInstallationPathW(MSIHANDLE handle) { - std::string progpath; + std::wstring progpath; DWORD sz = 0; - LPTSTR dummy = const_cast(TEXT("")); + PWSTR dummy = const_cast(L""); - if (MsiGetProperty(handle, TEXT("INSTALLLOCATION"), dummy, &sz) == ERROR_MORE_DATA) + if (MsiGetPropertyW(handle, L"INSTALLLOCATION", dummy, &sz) == ERROR_MORE_DATA) { sz++; // space for the final '\0' - DWORD nbytes = sz * sizeof(TCHAR); - LPTSTR buff = reinterpret_cast(_alloca(nbytes)); + DWORD nbytes = sz * sizeof(WCHAR); + PWSTR buff = reinterpret_cast(_alloca(nbytes)); ZeroMemory(buff, nbytes); - MsiGetProperty(handle, TEXT("INSTALLLOCATION"), buff, &sz); + MsiGetPropertyW(handle, L"INSTALLLOCATION", buff, &sz); progpath = buff; } return progpath; } -std::string GetOfficeProductName(MSIHANDLE handle) +std::wstring GetOfficeProductNameW(MSIHANDLE handle) { - std::string productname; + std::wstring productname; DWORD sz = 0; - LPTSTR dummy = const_cast(TEXT("")); + PWSTR dummy = const_cast(L""); - if (MsiGetProperty(handle, TEXT("ProductName"), dummy, &sz) == ERROR_MORE_DATA) + if (MsiGetPropertyW(handle, L"ProductName", dummy, &sz) == ERROR_MORE_DATA) { sz++; // space for the final '\0' - DWORD nbytes = sz * sizeof(TCHAR); - LPTSTR buff = reinterpret_cast(_alloca(nbytes)); + DWORD nbytes = sz * sizeof(WCHAR); + PWSTR buff = reinterpret_cast(_alloca(nbytes)); ZeroMemory(buff, nbytes); - MsiGetProperty(handle, TEXT("ProductName"), buff, &sz); + MsiGetPropertyW(handle, L"ProductName", buff, &sz); productname = buff; } return productname; } -std::string GetQuickstarterLinkName(MSIHANDLE handle) +std::wstring GetQuickstarterLinkNameW(MSIHANDLE handle) { - std::string quickstarterlinkname; + std::wstring quickstarterlinkname; DWORD sz = 0; - LPTSTR dummy = const_cast(TEXT("")); + PWSTR dummy = const_cast(L""); - if (MsiGetProperty(handle, TEXT("Quickstarterlinkname"), dummy, &sz) == ERROR_MORE_DATA) + if (MsiGetPropertyW(handle, L"Quickstarterlinkname", dummy, &sz) == ERROR_MORE_DATA) { sz++; // space for the final '\0' - DWORD nbytes = sz * sizeof(TCHAR); - LPTSTR buff = reinterpret_cast(_alloca(nbytes)); + DWORD nbytes = sz * sizeof(WCHAR); + PWSTR buff = reinterpret_cast(_alloca(nbytes)); ZeroMemory(buff, nbytes); - MsiGetProperty(handle, TEXT("Quickstarterlinkname"), buff, &sz); + MsiGetPropertyW(handle, L"Quickstarterlinkname", buff, &sz); quickstarterlinkname = buff; } - else if (MsiGetProperty(handle, TEXT("ProductName"), dummy, &sz) == ERROR_MORE_DATA) + else if (MsiGetPropertyW(handle, L"ProductName", dummy, &sz) == ERROR_MORE_DATA) { sz++; // space for the final '\0' - DWORD nbytes = sz * sizeof(TCHAR); - LPTSTR buff = reinterpret_cast(_alloca(nbytes)); + DWORD nbytes = sz * sizeof(WCHAR); + PWSTR buff = reinterpret_cast(_alloca(nbytes)); ZeroMemory(buff, nbytes); - MsiGetProperty(handle, TEXT("ProductName"), buff, &sz); + MsiGetPropertyW(handle, L"ProductName", buff, &sz); quickstarterlinkname = buff; } return quickstarterlinkname; @@ -95,18 +97,18 @@ inline bool IsValidHandle( HANDLE handle ) return NULL != handle && INVALID_HANDLE_VALUE != handle; } -static DWORD WINAPI _GetModuleFileNameExA( HANDLE hProcess, HMODULE hModule, LPSTR lpFileName, DWORD nSize ) +static DWORD WINAPI _GetModuleFileNameExW( HANDLE hProcess, HMODULE hModule, PWSTR lpFileName, DWORD nSize ) { - typedef DWORD (WINAPI *FN_PROC)( HANDLE hProcess, HMODULE hModule, LPSTR lpFileName, DWORD nSize ); + typedef DWORD (WINAPI *FN_PROC)( HANDLE hProcess, HMODULE hModule, LPWSTR lpFileName, DWORD nSize ); static FN_PROC lpProc = NULL; if ( !lpProc ) { - HMODULE hLibrary = LoadLibrary("PSAPI.DLL"); + HMODULE hLibrary = LoadLibraryW(L"PSAPI.DLL"); if ( hLibrary ) - lpProc = reinterpret_cast< FN_PROC >(GetProcAddress( hLibrary, "GetModuleFileNameExA" )); + lpProc = reinterpret_cast< FN_PROC >(GetProcAddress( hLibrary, "GetModuleFileNameExW" )); } if ( lpProc ) @@ -116,17 +118,17 @@ static DWORD WINAPI _GetModuleFileNameExA( HANDLE hProcess, HMODULE hModule, LPS } -std::string GetProcessImagePath( DWORD dwProcessId ) +std::wstring GetProcessImagePathW( DWORD dwProcessId ) { - std::string sImagePath; + std::wstring sImagePath; HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId ); if ( IsValidHandle( hProcess ) ) { - CHAR szPathBuffer[MAX_PATH] = ""; + WCHAR szPathBuffer[MAX_PATH] = L""; - if ( _GetModuleFileNameExA( hProcess, NULL, szPathBuffer, sizeof(szPathBuffer) ) ) + if ( _GetModuleFileNameExW( hProcess, NULL, szPathBuffer, sizeof(szPathBuffer)/sizeof(szPathBuffer[0]) ) ) sImagePath = szPathBuffer; CloseHandle( hProcess ); diff --git a/setup_native/source/win32/customactions/quickstarter/quickstarter.hxx b/setup_native/source/win32/customactions/quickstarter/quickstarter.hxx index b7fb07c3197f..664cff4c0a22 100644 --- a/setup_native/source/win32/customactions/quickstarter/quickstarter.hxx +++ b/setup_native/source/win32/customactions/quickstarter/quickstarter.hxx @@ -32,10 +32,10 @@ #include -std::string GetOfficeInstallationPath(MSIHANDLE handle); -std::string GetOfficeProductName(MSIHANDLE handle); -std::string GetQuickstarterLinkName(MSIHANDLE handle); -std::string GetProcessImagePath( DWORD dwProcessId ); +std::wstring GetOfficeInstallationPathW(MSIHANDLE handle); +std::wstring GetOfficeProductNameW(MSIHANDLE handle); +std::wstring GetQuickstarterLinkNameW(MSIHANDLE handle); +std::wstring GetProcessImagePathW(DWORD dwProcessId); #endif // INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_QUICKSTARTER_QUICKSTARTER_HXX diff --git a/setup_native/source/win32/customactions/quickstarter/remove_quickstart_link.cxx b/setup_native/source/win32/customactions/quickstarter/remove_quickstart_link.cxx index bbd4f02009fd..5939a0b4145b 100644 --- a/setup_native/source/win32/customactions/quickstarter/remove_quickstart_link.cxx +++ b/setup_native/source/win32/customactions/quickstarter/remove_quickstart_link.cxx @@ -17,35 +17,30 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "quickstarter.hxx" + #ifdef _MSC_VER #pragma warning(push, 1) /* disable warnings within system headers */ #pragma warning(disable: 4917) #endif -#define WIN32_LEAN_AND_MEAN -#include #include -#include #ifdef _MSC_VER #pragma warning(pop) #endif -#include -#include "quickstarter.hxx" - - extern "C" UINT __stdcall RemoveQuickstarterLink( MSIHANDLE hMSI ) { - CHAR szStartupPath[MAX_PATH]; + WCHAR szStartupPath[MAX_PATH]; - if ( SHGetSpecialFolderPathA( NULL, szStartupPath, CSIDL_STARTUP, FALSE ) ) + if ( SHGetSpecialFolderPathW( NULL, szStartupPath, CSIDL_STARTUP, FALSE ) ) { - std::string sQuickstartLinkPath = szStartupPath; + std::wstring sQuickstartLinkPath = szStartupPath; - sQuickstartLinkPath += "\\"; - sQuickstartLinkPath += GetQuickstarterLinkName( hMSI ); - sQuickstartLinkPath += ".lnk"; + sQuickstartLinkPath += L"\\"; + sQuickstartLinkPath += GetQuickstarterLinkNameW( hMSI ); + sQuickstartLinkPath += L".lnk"; - DeleteFileA( sQuickstartLinkPath.c_str() ); + DeleteFileW( sQuickstartLinkPath.c_str() ); } return ERROR_SUCCESS; diff --git a/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx b/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx index 22732480bd53..7a841bdbe221 100644 --- a/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx +++ b/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx @@ -18,6 +18,7 @@ */ #include "quickstarter.hxx" + #include static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam ) @@ -25,7 +26,7 @@ static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam ) MSIHANDLE hMSI = static_cast< MSIHANDLE >( lParam ); CHAR szClassName[sizeof(QUICKSTART_CLASSNAMEA) + 1]; - int nCharsCopied = GetClassName( hWnd, szClassName, sizeof( szClassName ) ); + int nCharsCopied = GetClassNameA( hWnd, szClassName, sizeof( szClassName ) ); if ( nCharsCopied && !_stricmp( QUICKSTART_CLASSNAMEA, szClassName ) ) { @@ -33,10 +34,10 @@ static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam ) if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) ) { - std::string sImagePath = GetProcessImagePath( dwProcessId ); - std::string sOfficeImageDir = GetOfficeInstallationPath( hMSI ) + "program\\"; + std::wstring sImagePath = GetProcessImagePathW( dwProcessId ); + std::wstring sOfficeImageDir = GetOfficeInstallationPathW( hMSI ) + L"program\\"; - if ( !_strnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) ) + if ( !_wcsnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) ) { UINT uMsgShutdownQuickstart = RegisterWindowMessageA( SHUTDOWN_QUICKSTART_MESSAGEA ); -- cgit