1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/nsis/Contrib/ApplicationID/Set.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,219 @@ 1.4 +/* 1.5 + * Module : Set.cpp 1.6 + * Purpose: NSIS Plug-in for setting shortcut ApplicationID property 1.7 + * Created: 27/12/2009 1.8 + * Original code Copyright (c) 2009 Mike Anchor. 1.9 + */ 1.10 + 1.11 +/* 1.12 + * Additional Mozilla contributions: 1.13 + * Unicode support 1.14 + * Jump list deletion on uninstall 1.15 + * Pinned item removal on uninstall 1.16 + * contrib: <jmathies@mozilla.com> 1.17 + */ 1.18 + 1.19 +#define INITGUID 1.20 + 1.21 +#include <windows.h> 1.22 +#include <shlobj.h> 1.23 +#include <propvarutil.h> 1.24 +#include <propkey.h> 1.25 +#include <stdio.h> 1.26 + 1.27 +#pragma comment (lib, "shlwapi.lib") 1.28 + 1.29 +#define MAX_STRLEN 1024 1.30 + 1.31 +typedef struct _stack_t { 1.32 + struct _stack_t *next; 1.33 + TCHAR text[MAX_PATH]; 1.34 +} stack_t; 1.35 + 1.36 +stack_t **g_stacktop; 1.37 +unsigned int g_stringsize; 1.38 +TCHAR *g_variables; 1.39 + 1.40 +// Indicates that an application supports dual desktop and immersive modes. In Windows 8, this property is only applicable for web browsers. 1.41 +DEFINE_PROPERTYKEY(PKEY_AppUserModel_IsDualMode, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 11); 1.42 + 1.43 +int popstring(TCHAR *str, int len); 1.44 +void pushstring(const TCHAR *str, int len); 1.45 + 1.46 +extern "C" void __declspec(dllexport) Set(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) 1.47 +{ 1.48 + g_stringsize = string_size; 1.49 + g_stacktop = stacktop; 1.50 + g_variables = variables; 1.51 + 1.52 + { 1.53 + IPropertyStore *m_pps = NULL; 1.54 + WCHAR wszPath[MAX_PATH]; 1.55 + WCHAR wszAppID[MAX_PATH]; 1.56 + TCHAR szPath[MAX_PATH]; 1.57 + TCHAR szAppID[MAX_PATH]; 1.58 + TCHAR szDualMode[MAX_PATH]; 1.59 + bool success = false; 1.60 + 1.61 + ZeroMemory(wszPath, sizeof(wszPath)); 1.62 + ZeroMemory(wszAppID, sizeof(wszAppID)); 1.63 + ZeroMemory(szPath, sizeof(szPath)); 1.64 + ZeroMemory(szAppID, sizeof(szAppID)); 1.65 + ZeroMemory(szDualMode, sizeof(szDualMode)); 1.66 + 1.67 + popstring(szPath, MAX_PATH); 1.68 + popstring(szAppID, MAX_PATH); 1.69 + bool dualMode = (popstring(szDualMode, MAX_PATH) == 0); // optional 1.70 +#if !defined(UNICODE) 1.71 + MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH); 1.72 + MultiByteToWideChar(CP_ACP, 0, szAppID, -1, wszAppID, MAX_PATH); 1.73 + if (dualMode && stricmp(szDualMode, "true") != 0) { 1.74 + dualMode = false; 1.75 + } 1.76 +#else 1.77 + wcscpy_s(wszPath, szPath); 1.78 + wcscpy_s(wszAppID, szAppID); 1.79 + if (dualMode && _wcsicmp(szDualMode, L"true") != 0) { 1.80 + dualMode = false; 1.81 + } 1.82 +#endif 1.83 + 1.84 + CoInitialize(NULL); 1.85 + 1.86 + if (SUCCEEDED(SHGetPropertyStoreFromParsingName(wszPath, NULL, GPS_READWRITE, IID_PPV_ARGS(&m_pps)))) 1.87 + { 1.88 + PROPVARIANT propvar; 1.89 + if (SUCCEEDED(InitPropVariantFromString(wszAppID, &propvar))) { 1.90 + if (SUCCEEDED(m_pps->SetValue(PKEY_AppUserModel_ID, propvar))) { 1.91 + if (dualMode) { 1.92 + InitPropVariantFromBoolean(true, &propvar); 1.93 + m_pps->SetValue(PKEY_AppUserModel_IsDualMode, propvar); 1.94 + } 1.95 + if (SUCCEEDED(m_pps->Commit())) { 1.96 + success = true; 1.97 + } 1.98 + } 1.99 + } 1.100 + } 1.101 + if (m_pps != NULL) 1.102 + m_pps->Release(); 1.103 + 1.104 + CoUninitialize(); 1.105 + 1.106 + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); 1.107 + } 1.108 +} 1.109 + 1.110 +extern "C" void __declspec(dllexport) UninstallJumpLists(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) 1.111 +{ 1.112 + g_stringsize = string_size; 1.113 + g_stacktop = stacktop; 1.114 + g_variables = variables; 1.115 + 1.116 + ICustomDestinationList *m_cdl = NULL; 1.117 + WCHAR wszAppID[MAX_PATH]; 1.118 + TCHAR szAppID[MAX_PATH]; 1.119 + bool success = false; 1.120 + 1.121 + ZeroMemory(wszAppID, sizeof(wszAppID)); 1.122 + ZeroMemory(szAppID, sizeof(szAppID)); 1.123 + 1.124 + popstring(szAppID, MAX_PATH); 1.125 + 1.126 +#if !defined(UNICODE) 1.127 + MultiByteToWideChar(CP_ACP, 0, szAppID, -1, wszAppID, MAX_PATH); 1.128 +#else 1.129 + wcscpy_s(wszAppID, szAppID); 1.130 +#endif 1.131 + 1.132 + CoInitialize(NULL); 1.133 + 1.134 + CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, 1.135 + IID_ICustomDestinationList, (void**)&m_cdl); 1.136 + 1.137 + if (m_cdl) { 1.138 + if (SUCCEEDED(m_cdl->DeleteList(wszAppID))) { 1.139 + success = true; 1.140 + } 1.141 + } 1.142 + 1.143 + if (m_cdl) 1.144 + m_cdl->Release(); 1.145 + 1.146 + CoUninitialize(); 1.147 + 1.148 + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); 1.149 +} 1.150 + 1.151 +extern "C" void __declspec(dllexport) UninstallPinnedItem(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) 1.152 +{ 1.153 + g_stringsize = string_size; 1.154 + g_stacktop = stacktop; 1.155 + g_variables = variables; 1.156 + 1.157 + IShellItem *pItem = NULL; 1.158 + IStartMenuPinnedList *pPinnedList = NULL; 1.159 + WCHAR wszPath[MAX_PATH]; 1.160 + TCHAR szPath[MAX_PATH]; 1.161 + bool success = false; 1.162 + 1.163 + ZeroMemory(wszPath, sizeof(wszPath)); 1.164 + ZeroMemory(szPath, sizeof(szPath)); 1.165 + 1.166 + popstring(szPath, MAX_PATH); 1.167 + 1.168 +#if !defined(UNICODE) 1.169 + MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH); 1.170 +#else 1.171 + wcscpy_s(wszPath, szPath); 1.172 +#endif 1.173 + 1.174 + CoInitialize(NULL); 1.175 + 1.176 + HRESULT hr; 1.177 + hr = SHCreateItemFromParsingName(wszPath, NULL, IID_PPV_ARGS(&pItem)); 1.178 + 1.179 + if (SUCCEEDED(hr)) { 1.180 + 1.181 + hr = CoCreateInstance(CLSID_StartMenuPin, 1.182 + NULL, 1.183 + CLSCTX_INPROC_SERVER, 1.184 + IID_PPV_ARGS(&pPinnedList)); 1.185 + 1.186 + if (SUCCEEDED(hr)) { 1.187 + hr = pPinnedList->RemoveFromList(pItem); 1.188 + pPinnedList->Release(); 1.189 + success = true; 1.190 + } 1.191 + 1.192 + pItem->Release(); 1.193 + } 1.194 + 1.195 + CoUninitialize(); 1.196 + 1.197 + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); 1.198 +} 1.199 + 1.200 +//Function: Removes the element from the top of the NSIS stack and puts it in the buffer 1.201 +int popstring(TCHAR *str, int len) 1.202 +{ 1.203 + stack_t *th; 1.204 + if (!g_stacktop || !*g_stacktop) return 1; 1.205 + th=(*g_stacktop); 1.206 + lstrcpyn(str,th->text, len); 1.207 + *g_stacktop=th->next; 1.208 + GlobalFree((HGLOBAL)th); 1.209 + return 0; 1.210 +} 1.211 + 1.212 +//Function: Adds an element to the top of the NSIS stack 1.213 +void pushstring(const TCHAR *str, int len) 1.214 +{ 1.215 + stack_t *th; 1.216 + 1.217 + if (!g_stacktop) return; 1.218 + th=(stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + len); 1.219 + lstrcpyn(th->text, str, len); 1.220 + th->next=*g_stacktop; 1.221 + *g_stacktop=th; 1.222 +}