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

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/25153Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 163dcad7
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
$(eval $(call gb_StaticLibrary_StaticLibrary,quickstarter)) $(eval $(call gb_StaticLibrary_StaticLibrary,quickstarter))
$(eval $(call gb_StaticLibrary_add_defs,quickstarter,\ $(eval $(call gb_StaticLibrary_add_defs,quickstarter,\
-DUNICODE \
-D_UNICODE \
-U_DLL \ -U_DLL \
)) ))
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "quickstarter.hxx" #include "quickstarter.hxx"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */ #pragma warning(push, 1) /* disable warnings within system headers */
#endif #endif
...@@ -25,66 +26,67 @@ ...@@ -25,66 +26,67 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#include <malloc.h> #include <malloc.h>
std::string GetOfficeInstallationPath(MSIHANDLE handle) std::wstring GetOfficeInstallationPathW(MSIHANDLE handle)
{ {
std::string progpath; std::wstring progpath;
DWORD sz = 0; DWORD sz = 0;
LPTSTR dummy = const_cast<LPTSTR>(TEXT("")); PWSTR dummy = const_cast<PWSTR>(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' sz++; // space for the final '\0'
DWORD nbytes = sz * sizeof(TCHAR); DWORD nbytes = sz * sizeof(WCHAR);
LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); PWSTR buff = reinterpret_cast<PWSTR>(_alloca(nbytes));
ZeroMemory(buff, nbytes); ZeroMemory(buff, nbytes);
MsiGetProperty(handle, TEXT("INSTALLLOCATION"), buff, &sz); MsiGetPropertyW(handle, L"INSTALLLOCATION", buff, &sz);
progpath = buff; progpath = buff;
} }
return progpath; return progpath;
} }
std::string GetOfficeProductName(MSIHANDLE handle) std::wstring GetOfficeProductNameW(MSIHANDLE handle)
{ {
std::string productname; std::wstring productname;
DWORD sz = 0; DWORD sz = 0;
LPTSTR dummy = const_cast<LPTSTR>(TEXT("")); PWSTR dummy = const_cast<PWSTR>(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' sz++; // space for the final '\0'
DWORD nbytes = sz * sizeof(TCHAR); DWORD nbytes = sz * sizeof(WCHAR);
LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); PWSTR buff = reinterpret_cast<PWSTR>(_alloca(nbytes));
ZeroMemory(buff, nbytes); ZeroMemory(buff, nbytes);
MsiGetProperty(handle, TEXT("ProductName"), buff, &sz); MsiGetPropertyW(handle, L"ProductName", buff, &sz);
productname = buff; productname = buff;
} }
return productname; return productname;
} }
std::string GetQuickstarterLinkName(MSIHANDLE handle) std::wstring GetQuickstarterLinkNameW(MSIHANDLE handle)
{ {
std::string quickstarterlinkname; std::wstring quickstarterlinkname;
DWORD sz = 0; DWORD sz = 0;
LPTSTR dummy = const_cast<LPTSTR>(TEXT("")); PWSTR dummy = const_cast<PWSTR>(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' sz++; // space for the final '\0'
DWORD nbytes = sz * sizeof(TCHAR); DWORD nbytes = sz * sizeof(WCHAR);
LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); PWSTR buff = reinterpret_cast<PWSTR>(_alloca(nbytes));
ZeroMemory(buff, nbytes); ZeroMemory(buff, nbytes);
MsiGetProperty(handle, TEXT("Quickstarterlinkname"), buff, &sz); MsiGetPropertyW(handle, L"Quickstarterlinkname", buff, &sz);
quickstarterlinkname = buff; 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' sz++; // space for the final '\0'
DWORD nbytes = sz * sizeof(TCHAR); DWORD nbytes = sz * sizeof(WCHAR);
LPTSTR buff = reinterpret_cast<LPTSTR>(_alloca(nbytes)); PWSTR buff = reinterpret_cast<PWSTR>(_alloca(nbytes));
ZeroMemory(buff, nbytes); ZeroMemory(buff, nbytes);
MsiGetProperty(handle, TEXT("ProductName"), buff, &sz); MsiGetPropertyW(handle, L"ProductName", buff, &sz);
quickstarterlinkname = buff; quickstarterlinkname = buff;
} }
return quickstarterlinkname; return quickstarterlinkname;
...@@ -95,18 +97,18 @@ inline bool IsValidHandle( HANDLE handle ) ...@@ -95,18 +97,18 @@ inline bool IsValidHandle( HANDLE handle )
return NULL != handle && INVALID_HANDLE_VALUE != 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; static FN_PROC lpProc = NULL;
if ( !lpProc ) if ( !lpProc )
{ {
HMODULE hLibrary = LoadLibrary("PSAPI.DLL"); HMODULE hLibrary = LoadLibraryW(L"PSAPI.DLL");
if ( hLibrary ) if ( hLibrary )
lpProc = reinterpret_cast< FN_PROC >(GetProcAddress( hLibrary, "GetModuleFileNameExA" )); lpProc = reinterpret_cast< FN_PROC >(GetProcAddress( hLibrary, "GetModuleFileNameExW" ));
} }
if ( lpProc ) if ( lpProc )
...@@ -116,17 +118,17 @@ static DWORD WINAPI _GetModuleFileNameExA( HANDLE hProcess, HMODULE hModule, LPS ...@@ -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 ); HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId );
if ( IsValidHandle( hProcess ) ) 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; sImagePath = szPathBuffer;
CloseHandle( hProcess ); CloseHandle( hProcess );
......
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
#include <string> #include <string>
std::string GetOfficeInstallationPath(MSIHANDLE handle); std::wstring GetOfficeInstallationPathW(MSIHANDLE handle);
std::string GetOfficeProductName(MSIHANDLE handle); std::wstring GetOfficeProductNameW(MSIHANDLE handle);
std::string GetQuickstarterLinkName(MSIHANDLE handle); std::wstring GetQuickstarterLinkNameW(MSIHANDLE handle);
std::string GetProcessImagePath( DWORD dwProcessId ); std::wstring GetProcessImagePathW(DWORD dwProcessId);
#endif // INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_QUICKSTARTER_QUICKSTARTER_HXX #endif // INCLUDED_SETUP_NATIVE_SOURCE_WIN32_CUSTOMACTIONS_QUICKSTARTER_QUICKSTARTER_HXX
......
...@@ -17,35 +17,30 @@ ...@@ -17,35 +17,30 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "quickstarter.hxx"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */ #pragma warning(push, 1) /* disable warnings within system headers */
#pragma warning(disable: 4917) #pragma warning(disable: 4917)
#endif #endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h> #include <shlobj.h>
#include <msiquery.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#include <string>
#include "quickstarter.hxx"
extern "C" UINT __stdcall RemoveQuickstarterLink( MSIHANDLE hMSI ) 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 += L"\\";
sQuickstartLinkPath += GetQuickstarterLinkName( hMSI ); sQuickstartLinkPath += GetQuickstarterLinkNameW( hMSI );
sQuickstartLinkPath += ".lnk"; sQuickstartLinkPath += L".lnk";
DeleteFileA( sQuickstartLinkPath.c_str() ); DeleteFileW( sQuickstartLinkPath.c_str() );
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "quickstarter.hxx" #include "quickstarter.hxx"
#include <systools/win32/qswin32.h> #include <systools/win32/qswin32.h>
static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam ) static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
...@@ -25,7 +26,7 @@ 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 ); MSIHANDLE hMSI = static_cast< MSIHANDLE >( lParam );
CHAR szClassName[sizeof(QUICKSTART_CLASSNAMEA) + 1]; 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 ) ) if ( nCharsCopied && !_stricmp( QUICKSTART_CLASSNAMEA, szClassName ) )
{ {
...@@ -33,10 +34,10 @@ static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam ) ...@@ -33,10 +34,10 @@ static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) ) if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) )
{ {
std::string sImagePath = GetProcessImagePath( dwProcessId ); std::wstring sImagePath = GetProcessImagePathW( dwProcessId );
std::string sOfficeImageDir = GetOfficeInstallationPath( hMSI ) + "program\\"; 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 ); UINT uMsgShutdownQuickstart = RegisterWindowMessageA( SHUTDOWN_QUICKSTART_MESSAGEA );
......
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