Fixed issue #1351: Add Hotkey to deselect all files on commit
[TortoiseGit.git] / src / Utils / TaskbarUUID.cpp
blob75604b35494191e6418b869e0d9df461f79eeae2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "StdAfx.h"
21 #include "TaskbarUUID.h"
22 #include "registry.h"
23 #include "CmdLineParser.h"
25 #include <Shobjidl.h>
26 #include "Win7.h"
27 #include "SmartHandle.h"
29 #define APPID (_T("TGIT.TGIT.1"))
32 void SetTaskIDPerUUID()
34 typedef HRESULT STDAPICALLTYPE SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID);
35 CAutoLibrary hShell = ::LoadLibrary(_T("shell32.dll"));
36 if (hShell)
38 SetCurrentProcessExplicitAppUserModelIDFN *pfnSetCurrentProcessExplicitAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDFN*)GetProcAddress(hShell, "SetCurrentProcessExplicitAppUserModelID");
39 if (pfnSetCurrentProcessExplicitAppUserModelID)
41 std::wstring id = GetTaskIDPerUUID();
42 pfnSetCurrentProcessExplicitAppUserModelID(id.c_str());
47 std::wstring GetTaskIDPerUUID(LPCTSTR uuid /*= NULL */)
49 CRegStdDWORD r = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 0);
50 std::wstring id = APPID;
51 if ((r < 2)||(r == 3))
53 wchar_t buf[MAX_PATH] = {0};
54 GetModuleFileName(NULL, buf, MAX_PATH);
55 std::wstring n = buf;
56 n = n.substr(n.find_last_of('\\'));
57 id += n;
60 if (r)
62 if (uuid)
64 id += uuid;
66 else
68 CCmdLineParser parser(GetCommandLine());
69 if (parser.HasVal(L"groupuuid"))
71 id += parser.GetVal(L"groupuuid");
75 return id;
78 #ifdef _MFC_VER
79 extern CString g_sGroupingUUID;
80 #endif
82 void SetUUIDOverlayIcon( HWND hWnd )
84 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 0))
86 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepoOverlay"), FALSE))
88 std::wstring uuid;
89 #ifdef _MFC_VER
90 uuid = g_sGroupingUUID;
91 #else
92 CCmdLineParser parser(GetCommandLine());
93 if (parser.HasVal(L"groupuuid"))
94 uuid = parser.GetVal(L"groupuuid");
95 #endif
96 if (!uuid.empty())
98 ITaskbarList3 * pTaskbarInterface = NULL;
99 HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, reinterpret_cast<void**> (&(pTaskbarInterface)));
101 if (SUCCEEDED(hr))
103 int foundUUIDIndex = 0;
106 wchar_t buf[MAX_PATH];
107 swprintf_s(buf, _countof(buf), L"%s%d", L"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\", foundUUIDIndex);
108 CRegStdString r = CRegStdString(buf);
109 std::wstring sr = r;
110 if (sr.empty() || (sr.compare(uuid)==0))
112 r = uuid;
113 break;
115 foundUUIDIndex++;
116 } while (foundUUIDIndex < 20);
117 if (foundUUIDIndex >= 20)
119 CRegStdString r = CRegStdString(L"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\1");
120 r.removeKey();
123 DWORD colors[6] = {0x80FF0000, 0x80FFFF00, 0x8000FF00, 0x800000FF, 0x80000000, 0x8000FFFF};
125 // AND mask - monochrome - determines which pixels get drawn
126 BYTE AND[32];
127 for( int i=0; i<32; i++ )
129 AND[i] = 0xFF;
132 // XOR mask - 32bpp ARGB - determines the pixel values
133 DWORD XOR[256];
134 for( int i=0; i<256; i++ )
136 XOR[i] = colors[foundUUIDIndex % 6];
139 HICON icon = ::CreateIcon(NULL,16,16,1,32,AND,(BYTE*)XOR);
140 pTaskbarInterface->SetOverlayIcon(hWnd, icon, uuid.c_str());
141 pTaskbarInterface->Release();
142 DestroyIcon(icon);