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