Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / shellextensions / startmenuicon.cxx
blob50ca3f040d1ae12e4dd1dc3997036da549377655
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: startmenuicon.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #define _WIN32_WINDOWS 0x0410
33 #ifdef _MSC_VER
34 #pragma warning(push, 1) /* disable warnings within system headers */
35 #endif
36 #define WIN32_LEAN_AND_MEAN
37 #include <windows.h>
38 #include <msiquery.h>
39 #ifdef _MSC_VER
40 #pragma warning(pop)
41 #endif
43 #include <malloc.h>
45 #ifdef UNICODE
46 #define _UNICODE
47 #define _tstring wstring
48 #else
49 #define _tstring string
50 #endif
51 #include <tchar.h>
52 #include <string>
55 std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
57 std::_tstring result;
58 TCHAR szDummy[1] = TEXT("");
59 DWORD nChars = 0;
61 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
63 DWORD nBytes = ++nChars * sizeof(TCHAR);
64 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
65 ZeroMemory( buffer, nBytes );
66 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
67 result = buffer;
70 return result;
74 Called during installation to customize the start menu folder icon.
75 See: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/custom.asp
77 extern "C" UINT __stdcall InstallStartmenuFolderIcon( MSIHANDLE handle )
79 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") );
80 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini");
82 // MessageBox(NULL, sDesktopFile.c_str(), TEXT("OfficeMenuFolder"), MB_OK | MB_ICONINFORMATION);
84 std::_tstring sIconFile = GetMsiProperty( handle, TEXT("OFFICEINSTALLLOCATION") ) + TEXT("program\\soffice.exe");
86 OSVERSIONINFO osverinfo;
87 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
88 GetVersionEx( &osverinfo );
90 if (osverinfo.dwMajorVersion < 6 /* && osverinfo.dwMinorVersion */ )
92 // This icon (18) is a Windows folder until XP Version (number is 0 based)
93 WritePrivateProfileString(
94 TEXT(".ShellClassInfo"),
95 TEXT("IconFile"),
96 sIconFile.c_str(),
97 sDesktopFile.c_str() );
99 // FYI: in tool 'ResHack' this icon can be found on position '19' (number is 1 based)
100 WritePrivateProfileString(
101 TEXT(".ShellClassInfo"),
102 TEXT("IconIndex"),
103 TEXT("18"),
104 sDesktopFile.c_str() );
106 // else
107 // {
108 // // at the moment there exists no Vista Icon, so we use the default folder icon.
109 // // add the icon into desktop/util/verinfo.rc
110 // }
112 // The value '0' is to avoid a message like "You Are Deleting a System Folder" warning when deleting or moving the folder.
113 WritePrivateProfileString(
114 TEXT(".ShellClassInfo"),
115 TEXT("ConfirmFileOp"),
116 TEXT("0"),
117 sDesktopFile.c_str() );
120 WritePrivateProfileString(
121 TEXT(".ShellClassInfo"),
122 TEXT("InfoTip"),
123 TEXT("StarOffice Productivity Suite"),
124 sDesktopFile.c_str() );
127 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_HIDDEN );
128 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_SYSTEM );
131 return ERROR_SUCCESS;
134 extern "C" UINT __stdcall DeinstallStartmenuFolderIcon(MSIHANDLE handle)
136 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") );
137 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini");
139 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_NORMAL );
140 DeleteFile( sDesktopFile.c_str() );
142 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_NORMAL );
144 return ERROR_SUCCESS;