Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / shellextensions / startmenuicon.cxx
blobe1679dd9754dac9b66dc2cd3e0123c655de7fad0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #define _WIN32_WINDOWS 0x0410
31 #ifdef _MSC_VER
32 #pragma warning(push, 1) /* disable warnings within system headers */
33 #endif
34 #define WIN32_LEAN_AND_MEAN
35 #include <windows.h>
36 #include <msiquery.h>
37 #ifdef _MSC_VER
38 #pragma warning(pop)
39 #endif
41 #include <malloc.h>
43 #ifdef UNICODE
44 #define _UNICODE
45 #define _tstring wstring
46 #else
47 #define _tstring string
48 #endif
49 #include <tchar.h>
50 #include <string>
53 std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
55 std::_tstring result;
56 TCHAR szDummy[1] = TEXT("");
57 DWORD nChars = 0;
59 if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
61 DWORD nBytes = ++nChars * sizeof(TCHAR);
62 LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
63 ZeroMemory( buffer, nBytes );
64 MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
65 result = buffer;
68 return result;
72 Called during installation to customize the start menu folder icon.
73 See: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/custom.asp
75 extern "C" UINT __stdcall InstallStartmenuFolderIcon( MSIHANDLE handle )
77 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") );
78 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini");
79 std::_tstring sIconFile = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ) + TEXT("program\\soffice.exe");
81 OSVERSIONINFO osverinfo;
82 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
83 GetVersionEx( &osverinfo );
85 if (osverinfo.dwMajorVersion < 6 /* && osverinfo.dwMinorVersion */ )
87 WritePrivateProfileString(
88 TEXT(".ShellClassInfo"),
89 TEXT("IconFile"),
90 sIconFile.c_str(),
91 sDesktopFile.c_str() );
93 WritePrivateProfileString(
94 TEXT(".ShellClassInfo"),
95 TEXT("IconIndex"),
96 TEXT("0"),
97 sDesktopFile.c_str() );
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 // }
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() );
112 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_HIDDEN );
113 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_SYSTEM );
116 return ERROR_SUCCESS;
119 extern "C" UINT __stdcall DeinstallStartmenuFolderIcon(MSIHANDLE handle)
121 std::_tstring sOfficeMenuFolder = GetMsiProperty( handle, TEXT("OfficeMenuFolder") );
122 std::_tstring sDesktopFile = sOfficeMenuFolder + TEXT("Desktop.ini");
124 SetFileAttributes( sDesktopFile.c_str(), FILE_ATTRIBUTE_NORMAL );
125 DeleteFile( sDesktopFile.c_str() );
127 SetFileAttributes( sOfficeMenuFolder.c_str(), FILE_ATTRIBUTE_NORMAL );
129 return ERROR_SUCCESS;
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */