diff options
Diffstat (limited to 'setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx')
-rw-r--r-- | setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx | 305 |
1 files changed, 153 insertions, 152 deletions
diff --git a/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx b/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx index c6434e35106e..efcfb0dd705d 100644 --- a/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx +++ b/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx @@ -31,40 +31,40 @@ #include <string> #include <strsafe.h> -static const CHAR* g_Extensions[] = +static const WCHAR* g_Extensions[] = { - ".doc", // Microsoft Word Text [0] - ".dot", // Microsoft Word Template - ".wps", // Kingsoft Writer Document - ".wpt", // Kingsoft Writer Template - ".rtf", // rtf text - ".docx", // Office Word 2007 XML document - ".docm", // Office Word 2007 XML macro-enabled document - ".dotx", // Office Word 2007 XML template - ".dotm", // Office Word 2007 XML macro-enabled template - ".xlw", // Microsoft Excel - ".xls", // Microsoft Excel - ".xlt", // Microsoft Excel Template - ".xlsx", // Office Excel 2007 XML workbook - ".xlsm", // Office Excel 2007 XML macro-enabled workbook - ".xltx", // Office Excel 2007 XML template - ".xltm", // Office Excel 2007 XML macro-enabled template - ".xlsb", // Office Excel 2007 binary workbook (BIFF12) - ".iqy", // Microsoft Excel Web Query File - ".et", // Kingsoft Spreadsheet - ".ett", // Kingsoft SpreadSheet Template - ".ppt", // Microsoft Powerpoint - ".pps", // Microsoft Powerpoint - ".pot", // Microsoft Powerpoint Template - ".pptx", // Office PowerPoint 2007 XML presentation - ".pptm", // Office PowerPoint 2007 macro-enabled XML presentation - ".potx", // Office PowerPoint 2007 XML template - ".potm", // Office PowerPoint 2007 macro-enabled XML template - ".ppsx", // Office PowerPoint 2007 XML show - ".dps", // Kingsoft Presentation - ".dpt", // Kingsoft Presentation Template - ".vsd", // Visio 2000/XP/2003 document - ".vst", // Visio 2000/XP/2003 template + L".doc", // Microsoft Word Text [0] + L".dot", // Microsoft Word Template + L".wps", // Kingsoft Writer Document + L".wpt", // Kingsoft Writer Template + L".rtf", // rtf text + L".docx", // Office Word 2007 XML document + L".docm", // Office Word 2007 XML macro-enabled document + L".dotx", // Office Word 2007 XML template + L".dotm", // Office Word 2007 XML macro-enabled template + L".xlw", // Microsoft Excel + L".xls", // Microsoft Excel + L".xlt", // Microsoft Excel Template + L".xlsx", // Office Excel 2007 XML workbook + L".xlsm", // Office Excel 2007 XML macro-enabled workbook + L".xltx", // Office Excel 2007 XML template + L".xltm", // Office Excel 2007 XML macro-enabled template + L".xlsb", // Office Excel 2007 binary workbook (BIFF12) + L".iqy", // Microsoft Excel Web Query File + L".et", // Kingsoft Spreadsheet + L".ett", // Kingsoft SpreadSheet Template + L".ppt", // Microsoft Powerpoint + L".pps", // Microsoft Powerpoint + L".pot", // Microsoft Powerpoint Template + L".pptx", // Office PowerPoint 2007 XML presentation + L".pptm", // Office PowerPoint 2007 macro-enabled XML presentation + L".potx", // Office PowerPoint 2007 XML template + L".potm", // Office PowerPoint 2007 macro-enabled XML template + L".ppsx", // Office PowerPoint 2007 XML show + L".dps", // Kingsoft Presentation + L".dpt", // Kingsoft Presentation Template + L".vsd", // Visio 2000/XP/2003 document + L".vst", // Visio 2000/XP/2003 template nullptr }; @@ -79,48 +79,48 @@ static const int VISIO_END = 32; // ".ppsm", // Office PowerPoint 2007 macro-enabled XML show #ifdef DEBUG -inline void OutputDebugStringFormatA( LPCSTR pFormat, ... ) +inline void OutputDebugStringFormatW( LPCWSTR 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), pFormat, args ); + OutputDebugStringW( buffer ); va_end(args); } #else -static inline void OutputDebugStringFormatA( LPCSTR, ... ) +static inline void OutputDebugStringFormatW( LPCWSTR, ... ) { } #endif -static BOOL CheckExtensionInRegistry( LPCSTR lpSubKey ) +static BOOL CheckExtensionInRegistry( LPCWSTR lpSubKey ) { BOOL bRet = false; HKEY hKey = nullptr; - LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE, &hKey ); + LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE, &hKey ); if ( ERROR_SUCCESS == lResult ) { - CHAR szBuffer[1024]; - DWORD nSize = sizeof( szBuffer ); + WCHAR szBuffer[1024]; + DWORD nSize = sizeof( szBuffer ); - lResult = RegQueryValueExA( hKey, "", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); + lResult = RegQueryValueExW( hKey, L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); if ( ERROR_SUCCESS == lResult && nSize > 0 ) { - szBuffer[nSize] = '\0'; - OutputDebugStringFormatA( "Found value [%s] for key [%s].\n", szBuffer, lpSubKey ); + szBuffer[nSize/sizeof(*szBuffer)] = L'\0'; + OutputDebugStringFormatW( L"Found value [%s] for key [%s].\n", szBuffer, lpSubKey ); - if ( strncmp( szBuffer, "WordPad.Document.1", 18 ) == 0 ) + if ( wcsncmp( szBuffer, L"WordPad.Document.1", 18 ) == 0 ) { // We will replace registration for WordPad (alas, on XP only) FIXME bRet = true; } - else if ( strncmp( szBuffer, "LibreOffice.", 12 ) == 0 ) + else if ( wcsncmp( szBuffer, L"LibreOffice.", 12 ) == 0 ) { // We will replace registration for our own types, too bRet = true; } - else if ( strncmp( szBuffer, "lostub.", 7 ) == 0 ) + else if ( wcsncmp( szBuffer, L"lostub.", 7 ) == 0 ) { // We will replace registration for lostub, too bRet = true; } @@ -138,80 +138,80 @@ static BOOL CheckExtensionInRegistry( LPCSTR lpSubKey ) return bRet; } -bool GetMsiPropA( MSIHANDLE handle, LPCSTR name, /*out*/std::string& value ) +bool GetMsiPropW( MSIHANDLE handle, LPCWSTR name, /*out*/std::wstring& value ) { DWORD sz = 0; - LPSTR dummy = const_cast<LPSTR>(""); - if (MsiGetPropertyA(handle, name, dummy, &sz) == ERROR_MORE_DATA) + LPWSTR dummy = const_cast<LPWSTR>(L""); + if (MsiGetPropertyW(handle, name, dummy, &sz) == ERROR_MORE_DATA) { sz++; - DWORD nbytes = sz * sizeof(CHAR); - LPSTR buff = static_cast<LPSTR>(_alloca(nbytes)); + DWORD nbytes = sz * sizeof(WCHAR); + LPWSTR buff = static_cast<LPWSTR>(_alloca(nbytes)); ZeroMemory(buff, nbytes); - MsiGetPropertyA(handle, name, buff, &sz); + MsiGetPropertyW(handle, name, buff, &sz); value = buff; return true; } return false; } -bool IsSetMsiPropA( MSIHANDLE handle, LPCSTR name ) +bool IsSetMsiPropW( MSIHANDLE handle, LPCWSTR name ) { - std::string val; - GetMsiPropA( handle, name, val ); - return (val == "1"); + std::wstring val; + GetMsiPropW( handle, name, val ); + return (val == L"1"); } static void registerForExtension( MSIHANDLE handle, const int nIndex, bool bRegister ) { - CHAR sPropName[256]; - StringCchCopyA( sPropName, 256, "REGISTER_" ); - StringCchCatA( sPropName, 256, (g_Extensions[nIndex])+1 ); - CharUpperBuffA( sPropName+9, 4 ); + WCHAR sPropName[256]; + StringCchCopyW( sPropName, 256, L"REGISTER_" ); + StringCchCatW( sPropName, 256, (g_Extensions[nIndex])+1 ); + CharUpperBuffW( sPropName+9, 4 ); if ( bRegister ) { - MsiSetPropertyA( handle, sPropName, "1" ); - OutputDebugStringFormatA( "Set MSI property %s.\n", sPropName ); + MsiSetPropertyW( handle, sPropName, L"1" ); + OutputDebugStringFormatW( L"Set MSI property %s.\n", sPropName ); } else { - MsiSetPropertyA( handle, sPropName, "0" ); - OutputDebugStringFormatA( "Unset MSI property %s.\n", sPropName ); + MsiSetPropertyW( handle, sPropName, L"0" ); + OutputDebugStringFormatW( L"Unset MSI property %s.\n", sPropName ); } } -static void saveOldRegistration( LPCSTR lpSubKey ) +static void saveOldRegistration( LPCWSTR lpSubKey ) { HKEY hKey = nullptr; - LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0, + LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey ); if ( ERROR_SUCCESS == lResult ) { - CHAR szBuffer[1024]; + WCHAR szBuffer[1024]; DWORD nSize = sizeof( szBuffer ); - lResult = RegQueryValueExA( hKey, "", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); + lResult = RegQueryValueExW( hKey, L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); if ( ERROR_SUCCESS == lResult ) { - szBuffer[nSize] = '\0'; + szBuffer[nSize/sizeof(*szBuffer)] = L'\0'; // No need to save associations for our own types - if ( strncmp( szBuffer, "LibreOffice.", 12 ) != 0 ) + if ( wcsncmp( szBuffer, L"LibreOffice.", 12 ) != 0 ) { // Save the old association - RegSetValueExA( hKey, "LOBackupAssociation", 0, + RegSetValueExW( hKey, L"LOBackupAssociation", 0, REG_SZ, reinterpret_cast<LPBYTE>(szBuffer), nSize ); // Also save what the old association means, just so we can try to verify // if/when restoring it that the old application still exists HKEY hKey2 = nullptr; - lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, szBuffer, 0, + lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, szBuffer, 0, KEY_QUERY_VALUE, &hKey2 ); if ( ERROR_SUCCESS == lResult ) { nSize = sizeof( szBuffer ); - lResult = RegQueryValueExA( hKey2, "", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); + lResult = RegQueryValueExW( hKey2, L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); if ( ERROR_SUCCESS == lResult ) { - RegSetValueExA( hKey, "LOBackupAssociationDeref", 0, + RegSetValueExW( hKey, L"LOBackupAssociationDeref", 0, REG_SZ, reinterpret_cast<LPBYTE>(szBuffer), nSize ); } RegCloseKey( hKey2 ); @@ -246,7 +246,7 @@ static bool checkSomeExtensionInRegistry( const int nStart, const int nEnd ) bFound = ! CheckExtensionInRegistry( g_Extensions[nIndex] ); if ( bFound ) - OutputDebugStringFormatA( "Found registration for [%s].\n", g_Extensions[nIndex] ); + OutputDebugStringFormatW( L"Found registration for [%s].\n", g_Extensions[nIndex] ); ++nIndex; } @@ -265,7 +265,7 @@ static void registerSomeExtensions( MSIHANDLE handle, const int nStart, const in extern "C" UINT __stdcall LookForRegisteredExtensions( MSIHANDLE handle ) { - OutputDebugStringFormatA( "LookForRegisteredExtensions: " ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: " ); INSTALLSTATE current_state; INSTALLSTATE future_state; @@ -274,181 +274,181 @@ extern "C" UINT __stdcall LookForRegisteredExtensions( MSIHANDLE handle ) bool bCalcEnabled = false; bool bImpressEnabled = false; bool bDrawEnabled = false; - bool bRegisterNone = IsSetMsiPropA( handle, "REGISTER_NO_MSO_TYPES" ); + bool bRegisterNone = IsSetMsiPropW( handle, L"REGISTER_NO_MSO_TYPES" ); if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L"gm_p_Wrt", ¤t_state, &future_state ) ) && ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) bWriterEnabled = true; - OutputDebugStringFormatA( "LookForRegisteredExtensions: Install state Writer is [%d], will be [%d]", current_state, future_state ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Install state Writer is [%d], will be [%d]", current_state, future_state ); if ( bWriterEnabled ) - OutputDebugStringFormatA( "LookForRegisteredExtensions: Writer is enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Writer is enabled" ); else - OutputDebugStringFormatA( "LookForRegisteredExtensions: Writer is NOT enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Writer is NOT enabled" ); if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L"gm_p_Calc", ¤t_state, &future_state ) ) && ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) bCalcEnabled = true; - OutputDebugStringFormatA( "LookForRegisteredExtensions: Install state Calc is [%d], will be [%d]", current_state, future_state ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Install state Calc is [%d], will be [%d]", current_state, future_state ); if ( bCalcEnabled ) - OutputDebugStringFormatA( "LookForRegisteredExtensions: Calc is enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Calc is enabled" ); else - OutputDebugStringFormatA( "LookForRegisteredExtensions: Calc is NOT enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Calc is NOT enabled" ); if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L"gm_p_Impress", ¤t_state, &future_state ) ) && ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) bImpressEnabled = true; - OutputDebugStringFormatA( "LookForRegisteredExtensions: Install state Impress is [%d], will be [%d]", current_state, future_state ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Install state Impress is [%d], will be [%d]", current_state, future_state ); if ( bImpressEnabled ) - OutputDebugStringFormatA( "LookForRegisteredExtensions: Impress is enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Impress is enabled" ); else - OutputDebugStringFormatA( "LookForRegisteredExtensions: Impress is NOT enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Impress is NOT enabled" ); if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L"gm_p_Draw", ¤t_state, &future_state ) ) && ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) bDrawEnabled = true; - OutputDebugStringFormatA( "LookForRegisteredExtensions: Install state Draw is [%d], will be [%d]", current_state, future_state ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Install state Draw is [%d], will be [%d]", current_state, future_state ); if ( bImpressEnabled ) - OutputDebugStringFormatA( "LookForRegisteredExtensions: Draw is enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Draw is enabled" ); else - OutputDebugStringFormatA( "LookForRegisteredExtensions: Draw is NOT enabled" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Draw is NOT enabled" ); - MsiSetPropertyA( handle, "SELECT_WORD", "" ); - MsiSetPropertyA( handle, "SELECT_EXCEL", "" ); - MsiSetPropertyA( handle, "SELECT_POWERPOINT", "" ); - MsiSetPropertyA( handle, "SELECT_VISIO", "" ); + MsiSetPropertyW( handle, L"SELECT_WORD", L"" ); + MsiSetPropertyW( handle, L"SELECT_EXCEL", L"" ); + MsiSetPropertyW( handle, L"SELECT_POWERPOINT", L"" ); + MsiSetPropertyW( handle, L"SELECT_VISIO", L"" ); if ( ! bRegisterNone ) { - if ( IsSetMsiPropA( handle, "REGISTER_ALL_MSO_TYPES" ) ) + if ( IsSetMsiPropW( handle, L"REGISTER_ALL_MSO_TYPES" ) ) { if ( bWriterEnabled ) - MsiSetPropertyA( handle, "SELECT_WORD", "1" ); + MsiSetPropertyW( handle, L"SELECT_WORD", L"1" ); if ( bCalcEnabled ) - MsiSetPropertyA( handle, "SELECT_EXCEL", "1" ); + MsiSetPropertyW( handle, L"SELECT_EXCEL", L"1" ); if ( bImpressEnabled ) - MsiSetPropertyA( handle, "SELECT_POWERPOINT", "1" ); + MsiSetPropertyW( handle, L"SELECT_POWERPOINT", L"1" ); if ( bDrawEnabled ) - MsiSetPropertyA( handle, "SELECT_VISIO", "1" ); + MsiSetPropertyW( handle, L"SELECT_VISIO", L"1" ); } else { if ( bWriterEnabled && ! checkSomeExtensionInRegistry( WORD_START, EXCEL_START ) ) { - MsiSetPropertyA( handle, "SELECT_WORD", "1" ); - OutputDebugStringFormatA( "LookForRegisteredExtensions: Register for Microsoft Word" ); + MsiSetPropertyW( handle, L"SELECT_WORD", L"1" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Register for Microsoft Word" ); } if ( bCalcEnabled && ! checkSomeExtensionInRegistry( EXCEL_START, POWERPOINT_START ) ) { - MsiSetPropertyA( handle, "SELECT_EXCEL", "1" ); - OutputDebugStringFormatA( "LookForRegisteredExtensions: Register for Microsoft Excel" ); + MsiSetPropertyW( handle, L"SELECT_EXCEL", L"1" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Register for Microsoft Excel" ); } if ( bImpressEnabled && ! checkSomeExtensionInRegistry( POWERPOINT_START, VISIO_START ) ) { - MsiSetPropertyA( handle, "SELECT_POWERPOINT", "1" ); - OutputDebugStringFormatA( "LookForRegisteredExtensions: Register for Microsoft PowerPoint" ); + MsiSetPropertyW( handle, L"SELECT_POWERPOINT", L"1" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Register for Microsoft PowerPoint" ); } if ( bImpressEnabled && ! checkSomeExtensionInRegistry( VISIO_START, VISIO_END ) ) { - MsiSetPropertyA( handle, "SELECT_VISIO", "1" ); - OutputDebugStringFormatA( "LookForRegisteredExtensions: Register for Microsoft Visio" ); + MsiSetPropertyW( handle, L"SELECT_VISIO", L"1" ); + OutputDebugStringFormatW( L"LookForRegisteredExtensions: Register for Microsoft Visio" ); } } } - MsiSetPropertyA( handle, "FILETYPEDIALOGUSED", "1" ); + MsiSetPropertyW( handle, L"FILETYPEDIALOGUSED", L"1" ); return ERROR_SUCCESS; } extern "C" UINT __stdcall RegisterSomeExtensions( MSIHANDLE handle ) { - OutputDebugStringFormatA( "RegisterSomeExtensions: " ); + OutputDebugStringFormatW( L"RegisterSomeExtensions: " ); - if ( IsSetMsiPropA( handle, "SELECT_WORD" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_WORD" ) ) { registerSomeExtensions( handle, WORD_START, EXCEL_START, true ); - MsiSetFeatureState( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_LOCAL ); - OutputDebugStringFormatA( "RegisterSomeExtensions: Register for Microsoft Word" ); + MsiSetFeatureStateW( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_LOCAL ); + OutputDebugStringFormatW( L"RegisterSomeExtensions: Register for Microsoft Word" ); } else { registerSomeExtensions( handle, WORD_START, EXCEL_START, false ); - MsiSetFeatureState( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_ABSENT ); + MsiSetFeatureStateW( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_ABSENT ); } - if ( IsSetMsiPropA( handle, "SELECT_EXCEL" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_EXCEL" ) ) { registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, true ); - MsiSetFeatureState( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_LOCAL ); - OutputDebugStringFormatA( "RegisterSomeExtensions: Register for Microsoft Excel" ); + MsiSetFeatureStateW( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_LOCAL ); + OutputDebugStringFormatW( L"RegisterSomeExtensions: Register for Microsoft Excel" ); } else { registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, false ); - MsiSetFeatureState( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_ABSENT ); + MsiSetFeatureStateW( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_ABSENT ); } - if ( IsSetMsiPropA( handle, "SELECT_POWERPOINT" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_POWERPOINT" ) ) { registerSomeExtensions( handle, POWERPOINT_START, VISIO_START, true ); - MsiSetFeatureState( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_LOCAL ); - OutputDebugStringFormatA( "RegisterSomeExtensions: Register for Microsoft PowerPoint" ); + MsiSetFeatureStateW( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_LOCAL ); + OutputDebugStringFormatW( L"RegisterSomeExtensions: Register for Microsoft PowerPoint" ); } else { registerSomeExtensions( handle, POWERPOINT_START, VISIO_START, false ); - MsiSetFeatureState( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_ABSENT ); + MsiSetFeatureStateW( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_ABSENT ); } - if ( IsSetMsiPropA( handle, "SELECT_VISIO" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_VISIO" ) ) { registerSomeExtensions( handle, VISIO_START, VISIO_END, true ); - MsiSetFeatureState( handle, L"gm_p_Draw_MSO_Reg", INSTALLSTATE_LOCAL ); - OutputDebugStringFormatA( "RegisterSomeExtensions: Register for Microsoft Visio" ); + MsiSetFeatureStateW( handle, L"gm_p_Draw_MSO_Reg", INSTALLSTATE_LOCAL ); + OutputDebugStringFormatW( L"RegisterSomeExtensions: Register for Microsoft Visio" ); } else { registerSomeExtensions( handle, VISIO_START, VISIO_END, false ); - MsiSetFeatureState( handle, L"gm_p_Draw_MSO_Reg", INSTALLSTATE_ABSENT ); + MsiSetFeatureStateW( handle, L"gm_p_Draw_MSO_Reg", INSTALLSTATE_ABSENT ); } return ERROR_SUCCESS; } extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle ) { - if ( IsSetMsiPropA( handle, "FILETYPEDIALOGUSED" ) ) + if ( IsSetMsiPropW( handle, L"FILETYPEDIALOGUSED" ) ) { - OutputDebugStringFormatA( "FindRegisteredExtensions: FILETYPEDIALOGUSED!" ); + OutputDebugStringFormatW( L"FindRegisteredExtensions: FILETYPEDIALOGUSED!" ); return ERROR_SUCCESS; } - OutputDebugStringFormatA( "FindRegisteredExtensions:" ); + OutputDebugStringFormatW( L"FindRegisteredExtensions:" ); - bool bRegisterAll = IsSetMsiPropA( handle, "REGISTER_ALL_MSO_TYPES" ); + bool bRegisterAll = IsSetMsiPropW( handle, L"REGISTER_ALL_MSO_TYPES" ); - if ( IsSetMsiPropA( handle, "REGISTER_NO_MSO_TYPES" ) ) + if ( IsSetMsiPropW( handle, L"REGISTER_NO_MSO_TYPES" ) ) { - OutputDebugStringFormatA( "FindRegisteredExtensions: Register none!" ); + OutputDebugStringFormatW( L"FindRegisteredExtensions: Register none!" ); return ERROR_SUCCESS; } else if ( bRegisterAll ) - OutputDebugStringFormatA( "FindRegisteredExtensions: Force all on" ); + OutputDebugStringFormatW( L"FindRegisteredExtensions: Force all on" ); else - OutputDebugStringFormatA( "FindRegisteredExtensions: " ); + OutputDebugStringFormatW( L"FindRegisteredExtensions: " ); // setting the msi properties SELECT_* will force registering for all corresponding // file types - if ( IsSetMsiPropA( handle, "SELECT_WORD" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_WORD" ) ) registerSomeExtensions( handle, WORD_START, EXCEL_START, true ); - if ( IsSetMsiPropA( handle, "SELECT_EXCEL" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_EXCEL" ) ) registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, true ); - if ( IsSetMsiPropA( handle, "SELECT_POWERPOINT" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_POWERPOINT" ) ) registerSomeExtensions( handle, POWERPOINT_START, VISIO_START, true ); - if ( IsSetMsiPropA( handle, "SELECT_VISIO" ) ) + if ( IsSetMsiPropW( handle, L"SELECT_VISIO" ) ) registerSomeExtensions( handle, VISIO_START, VISIO_END, true ); registerForExtensions( handle, bRegisterAll ); @@ -456,59 +456,60 @@ extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle ) return ERROR_SUCCESS; } -static void restoreOldRegistration( LPCSTR lpSubKey ) +static void restoreOldRegistration( LPCWSTR lpSubKey ) { HKEY hKey = nullptr; - LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0, + LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey ); if ( ERROR_SUCCESS == lResult ) { - CHAR szBuffer[1024]; + WCHAR szBuffer[1024]; DWORD nSize = sizeof( szBuffer ); - lResult = RegQueryValueExA( hKey, "LOBackupAssociation", nullptr, nullptr, + lResult = RegQueryValueExW( hKey, L"LOBackupAssociation", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer), &nSize ); if ( ERROR_SUCCESS == lResult ) { + szBuffer[nSize/sizeof(*szBuffer)] = L'\0'; HKEY hKey2 = nullptr; - lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, szBuffer, 0, + lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, szBuffer, 0, KEY_QUERY_VALUE, &hKey2 ); if ( ERROR_SUCCESS == lResult ) { - CHAR szBuffer2[1024]; + WCHAR szBuffer2[1024]; DWORD nSize2 = sizeof( szBuffer2 ); - lResult = RegQueryValueExA( hKey2, "", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer2), &nSize2 ); + lResult = RegQueryValueExW( hKey2, L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer2), &nSize2 ); if ( ERROR_SUCCESS == lResult ) { - CHAR szBuffer3[1024]; + WCHAR szBuffer3[1024]; DWORD nSize3 = sizeof( szBuffer3 ); // Try to verify that the old association is OK to restore - lResult = RegQueryValueExA( hKey, "LOBackupAssociationDeref", nullptr, nullptr, + lResult = RegQueryValueExW( hKey, L"LOBackupAssociationDeref", nullptr, nullptr, reinterpret_cast<LPBYTE>(szBuffer3), &nSize3 ); if ( ERROR_SUCCESS == lResult ) { - if ( nSize2 == nSize3 && strcmp (szBuffer2, szBuffer3) == 0) + if ( nSize2 == nSize3 && wcsncmp (szBuffer2, szBuffer3, nSize2/sizeof(*szBuffer2)) == 0) { // Yep. So restore it - RegSetValueExA( hKey, "", 0, REG_SZ, reinterpret_cast<LPBYTE>(szBuffer), nSize ); + RegSetValueExW( hKey, L"", 0, REG_SZ, reinterpret_cast<LPBYTE>(szBuffer), nSize ); } } } RegCloseKey( hKey2 ); } - RegDeleteValueA( hKey, "LOBackupAssociation" ); + RegDeleteValueW( hKey, L"LOBackupAssociation" ); } - RegDeleteValueA( hKey, "LOBackupAssociationDeref" ); + RegDeleteValueW( hKey, L"LOBackupAssociationDeref" ); RegCloseKey( hKey ); } } extern "C" UINT __stdcall RestoreRegAllMSDoc( MSIHANDLE /*handle*/ ) { - OutputDebugStringFormatA( "RestoreRegAllMSDoc\n" ); + OutputDebugStringFormatW( L"RestoreRegAllMSDoc\n" ); int nIndex = 0; while ( g_Extensions[nIndex] != nullptr ) |