20#define WIN32_LEAN_AND_MEAN
81 va_start(
args, pFormat );
82 StringCchVPrintfW( buffer,
sizeof(buffer)/
sizeof(*buffer), pFormat,
args );
83 OutputDebugStringW( buffer );
96 LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
98 if ( ERROR_SUCCESS == lResult )
100 WCHAR szBuffer[1024];
101 DWORD nSize =
sizeof( szBuffer );
103 lResult = RegQueryValueExW( hKey, L
"",
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(szBuffer), &nSize );
104 if ( ERROR_SUCCESS == lResult && nSize > 0 )
106 szBuffer[nSize/
sizeof(*szBuffer)] = L
'\0';
109 if ( wcsncmp( szBuffer, L
"WordPad.Document.1", 18 ) == 0 )
113 else if ( wcsncmp( szBuffer, L
"LibreOffice.", 12 ) == 0 )
117 else if ( wcsncmp( szBuffer, L
"lostub.", 7 ) == 0 )
135static bool GetMsiPropW( MSIHANDLE handle, LPCWSTR name, std::wstring& value )
138 LPWSTR dummy =
const_cast<LPWSTR
>(L
"");
139 if (MsiGetPropertyW(handle,
name, dummy, &sz) == ERROR_MORE_DATA)
142 DWORD nbytes = sz *
sizeof(WCHAR);
143 LPWSTR buff =
static_cast<LPWSTR
>(_alloca(nbytes));
144 ZeroMemory(buff, nbytes);
145 MsiGetPropertyW(handle,
name, buff, &sz);
156 return (val == L
"1");
161 WCHAR sPropName[256];
162 StringCchCopyW( sPropName, 256, L
"REGISTER_" );
164 CharUpperBuffW( sPropName+9, 4 );
167 MsiSetPropertyW( handle, sPropName, L
"1" );
170 MsiSetPropertyW( handle, sPropName, L
"0" );
178 LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0,
179 KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey );
181 if ( ERROR_SUCCESS == lResult )
183 WCHAR szBuffer[1024];
184 DWORD nSize =
sizeof( szBuffer );
186 lResult = RegQueryValueExW( hKey, L
"",
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(szBuffer), &nSize );
187 if ( ERROR_SUCCESS == lResult )
189 szBuffer[nSize/
sizeof(*szBuffer)] = L
'\0';
192 if ( wcsncmp( szBuffer, L
"LibreOffice.", 12 ) != 0 )
195 RegSetValueExW( hKey, L
"LOBackupAssociation", 0,
196 REG_SZ,
reinterpret_cast<LPBYTE
>(szBuffer), nSize );
199 HKEY hKey2 =
nullptr;
200 lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, szBuffer, 0,
201 KEY_QUERY_VALUE, &hKey2 );
202 if ( ERROR_SUCCESS == lResult )
204 nSize =
sizeof( szBuffer );
205 lResult = RegQueryValueExW( hKey2, L
"",
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(szBuffer), &nSize );
206 if ( ERROR_SUCCESS == lResult )
208 RegSetValueExW( hKey, L
"LOBackupAssociationDeref", 0,
209 REG_SZ,
reinterpret_cast<LPBYTE
>(szBuffer), nSize );
211 RegCloseKey( hKey2 );
260extern "C" __declspec(dllexport) UINT __stdcall LookForRegisteredExtensions( MSIHANDLE handle )
264 INSTALLSTATE current_state;
265 INSTALLSTATE future_state;
267 bool bWriterEnabled =
false;
268 bool bCalcEnabled =
false;
269 bool bImpressEnabled =
false;
270 bool bDrawEnabled =
false;
271 bool bRegisterNone =
IsSetMsiPropW( handle, L
"REGISTER_NO_MSO_TYPES" );
273 if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L
"gm_p_Wrt", ¤t_state, &future_state ) ) &&
274 ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) )
275 bWriterEnabled =
true;
277 OutputDebugStringFormatW( L
"LookForRegisteredExtensions: Install state Writer is [%d], will be [%d]", current_state, future_state );
278 if ( bWriterEnabled )
283 if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L
"gm_p_Calc", ¤t_state, &future_state ) ) &&
284 ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) )
287 OutputDebugStringFormatW( L
"LookForRegisteredExtensions: Install state Calc is [%d], will be [%d]", current_state, future_state );
293 if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L
"gm_p_Impress", ¤t_state, &future_state ) ) &&
294 ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) )
295 bImpressEnabled =
true;
297 OutputDebugStringFormatW( L
"LookForRegisteredExtensions: Install state Impress is [%d], will be [%d]", current_state, future_state );
298 if ( bImpressEnabled )
303 if ( ( ERROR_SUCCESS == MsiGetFeatureStateW( handle, L
"gm_p_Draw", ¤t_state, &future_state ) ) &&
304 ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) )
307 OutputDebugStringFormatW( L
"LookForRegisteredExtensions: Install state Draw is [%d], will be [%d]", current_state, future_state );
308 if ( bImpressEnabled )
313 MsiSetPropertyW( handle, L
"SELECT_WORD", L
"" );
314 MsiSetPropertyW( handle, L
"SELECT_EXCEL", L
"" );
315 MsiSetPropertyW( handle, L
"SELECT_POWERPOINT", L
"" );
316 MsiSetPropertyW( handle, L
"SELECT_VISIO", L
"" );
318 if ( ! bRegisterNone )
322 if ( bWriterEnabled )
323 MsiSetPropertyW( handle, L
"SELECT_WORD", L
"1" );
325 MsiSetPropertyW( handle, L
"SELECT_EXCEL", L
"1" );
326 if ( bImpressEnabled )
327 MsiSetPropertyW( handle, L
"SELECT_POWERPOINT", L
"1" );
329 MsiSetPropertyW( handle, L
"SELECT_VISIO", L
"1" );
335 MsiSetPropertyW( handle, L
"SELECT_WORD", L
"1" );
340 MsiSetPropertyW( handle, L
"SELECT_EXCEL", L
"1" );
345 MsiSetPropertyW( handle, L
"SELECT_POWERPOINT", L
"1" );
350 MsiSetPropertyW( handle, L
"SELECT_VISIO", L
"1" );
356 MsiSetPropertyW( handle, L
"FILETYPEDIALOGUSED", L
"1" );
358 return ERROR_SUCCESS;
361extern "C" __declspec(dllexport) UINT __stdcall RegisterSomeExtensions( MSIHANDLE handle )
368 MsiSetFeatureStateW( handle, L
"gm_p_Wrt_MSO_Reg", INSTALLSTATE_LOCAL );
374 MsiSetFeatureStateW( handle, L
"gm_p_Wrt_MSO_Reg", INSTALLSTATE_ABSENT );
380 MsiSetFeatureStateW( handle, L
"gm_p_Calc_MSO_Reg", INSTALLSTATE_LOCAL );
386 MsiSetFeatureStateW( handle, L
"gm_p_Calc_MSO_Reg", INSTALLSTATE_ABSENT );
392 MsiSetFeatureStateW( handle, L
"gm_p_Impress_MSO_Reg", INSTALLSTATE_LOCAL );
398 MsiSetFeatureStateW( handle, L
"gm_p_Impress_MSO_Reg", INSTALLSTATE_ABSENT );
404 MsiSetFeatureStateW( handle, L
"gm_p_Draw_MSO_Reg", INSTALLSTATE_LOCAL );
410 MsiSetFeatureStateW( handle, L
"gm_p_Draw_MSO_Reg", INSTALLSTATE_ABSENT );
412 return ERROR_SUCCESS;
415extern "C" __declspec(dllexport) UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle )
420 return ERROR_SUCCESS;
425 bool bRegisterAll =
IsSetMsiPropW( handle, L
"REGISTER_ALL_MSO_TYPES" );
430 return ERROR_SUCCESS;
432 else if ( bRegisterAll )
450 return ERROR_SUCCESS;
456 LONG lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, lpSubKey, 0,
457 KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey );
459 if ( ERROR_SUCCESS == lResult )
461 WCHAR szBuffer[1024];
462 DWORD nSize =
sizeof( szBuffer );
464 lResult = RegQueryValueExW( hKey, L
"LOBackupAssociation",
nullptr,
nullptr,
465 reinterpret_cast<LPBYTE
>(szBuffer), &nSize );
466 if ( ERROR_SUCCESS == lResult )
468 szBuffer[nSize/
sizeof(*szBuffer)] = L
'\0';
469 HKEY hKey2 =
nullptr;
470 lResult = RegOpenKeyExW( HKEY_CLASSES_ROOT, szBuffer, 0,
471 KEY_QUERY_VALUE, &hKey2 );
472 if ( ERROR_SUCCESS == lResult )
474 WCHAR szBuffer2[1024];
475 DWORD nSize2 =
sizeof( szBuffer2 );
477 lResult = RegQueryValueExW( hKey2, L
"",
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(szBuffer2), &nSize2 );
478 if ( ERROR_SUCCESS == lResult )
480 WCHAR szBuffer3[1024];
481 DWORD nSize3 =
sizeof( szBuffer3 );
484 lResult = RegQueryValueExW( hKey, L
"LOBackupAssociationDeref",
nullptr,
nullptr,
485 reinterpret_cast<LPBYTE
>(szBuffer3), &nSize3 );
486 if ( ERROR_SUCCESS == lResult )
488 if ( nSize2 == nSize3 && wcsncmp (szBuffer2, szBuffer3, nSize2/
sizeof(*szBuffer2)) == 0)
491 RegSetValueExW( hKey, L
"", 0, REG_SZ,
reinterpret_cast<LPBYTE
>(szBuffer), nSize );
495 RegCloseKey( hKey2 );
497 RegDeleteValueW( hKey, L
"LOBackupAssociation" );
499 RegDeleteValueW( hKey, L
"LOBackupAssociationDeref" );
504extern "C" __declspec(dllexport) UINT __stdcall RestoreRegAllMSDoc( MSIHANDLE )
516 return ERROR_SUCCESS;
static void registerSomeExtensions(MSIHANDLE handle, const int nStart, const int nEnd, bool bRegister)
static bool GetMsiPropW(MSIHANDLE handle, LPCWSTR name, std::wstring &value)
static bool checkSomeExtensionInRegistry(const int nStart, const int nEnd)
static void restoreOldRegistration(LPCWSTR lpSubKey)
static bool IsSetMsiPropW(MSIHANDLE handle, LPCWSTR name)
static void registerForExtension(MSIHANDLE handle, const int nIndex, bool bRegister)
static const WCHAR * g_Extensions[]
static void registerForExtensions(MSIHANDLE handle, bool bRegisterAll)
__declspec(dllexport) UINT __stdcall LookForRegisteredExtensions(MSIHANDLE handle)
static void saveOldRegistration(LPCWSTR lpSubKey)
const int POWERPOINT_START
void OutputDebugStringFormatW(LPCWSTR pFormat,...)
static bool CheckExtensionInRegistry(LPCWSTR lpSubKey)