1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #define _WIN32_WINDOWS 0x0410 25 26 #ifdef _MSC_VER 27 #pragma warning(push, 1) /* disable warnings within system headers */ 28 #endif 29 #define WIN32_LEAN_AND_MEAN 30 #include <windows.h> 31 #include <msiquery.h> 32 #ifdef _MSC_VER 33 #pragma warning(pop) 34 #endif 35 36 #include <malloc.h> 37 38 #ifdef UNICODE 39 #define _UNICODE 40 #define _tstring wstring 41 #else 42 #define _tstring string 43 #endif 44 #include <tchar.h> 45 #include <string> 46 47 48 std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty ) 49 { 50 std::_tstring result; 51 TCHAR szDummy[1] = TEXT(""); 52 DWORD nChars = 0; 53 54 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA ) 55 { 56 DWORD nBytes = ++nChars * sizeof(TCHAR); 57 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes)); 58 ZeroMemory( buffer, nBytes ); 59 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars); 60 result = buffer; 61 } 62 63 return result; 64 } 65 66 /* 67 Called during installation to customize the start menu folder icon. 68 See: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/custom.asp 69 */ 70 extern "C" UINT __stdcall InstallStartmenuFolderIcon( MSIHANDLE handle ) 71 { 72 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") ); 73 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini"); 74 75 // MessageBox(NULL, sDesktopFile.c_str(), TEXT("OfficeMenuFolder"), MB_OK | MB_ICONINFORMATION); 76 77 std::_tstring sIconFile = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ) + TEXT("program\\soffice.exe"); 78 79 OSVERSIONINFO osverinfo; 80 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 81 GetVersionEx( &osverinfo ); 82 83 if (osverinfo.dwMajorVersion < 6 /* && osverinfo.dwMinorVersion */ ) 84 { 85 // This icon (18) is a Windows folder until XP Version (number is 0 based) 86 WritePrivateProfileString( 87 TEXT(".ShellClassInfo"), 88 TEXT("IconFile"), 89 sIconFile.c_str(), 90 sDesktopFile.c_str() ); 91 92 // FYI: in tool 'ResHack' this icon can be found on position '19' (number is 1 based) 93 WritePrivateProfileString( 94 TEXT(".ShellClassInfo"), 95 TEXT("IconIndex"), 96 TEXT("18"), 97 sDesktopFile.c_str() ); 98 } 99 // else 100 // { 101 // // at the moment there exists no Vista Icon, so we use the default folder icon. 102 // // add the icon into desktop/util/verinfo.rc 103 // } 104 105 // The value '0' is to avoid a message like "You Are Deleting a System Folder" warning when deleting or moving the folder. 106 WritePrivateProfileString( 107 TEXT(".ShellClassInfo"), 108 TEXT("ConfirmFileOp"), 109 TEXT("0"), 110 sDesktopFile.c_str() ); 111 112 /* 113 WritePrivateProfileString( 114 TEXT(".ShellClassInfo"), 115 TEXT("InfoTip"), 116 TEXT("StarOffice Productivity Suite"), 117 sDesktopFile.c_str() ); 118 */ 119 120 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_HIDDEN ); 121 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_SYSTEM ); 122 123 124 return ERROR_SUCCESS; 125 } 126 127 extern "C" UINT __stdcall DeinstallStartmenuFolderIcon(MSIHANDLE handle) 128 { 129 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") ); 130 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini"); 131 132 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_NORMAL ); 133 DeleteFile( sDesktopFile.c_str() ); 134 135 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_NORMAL ); 136 137 return ERROR_SUCCESS; 138 } 139