1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2012 - 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.
21 #include "TaskbarUUID.h"
23 #include "CmdLineParser.h"
27 #include "SmartHandle.h"
30 #define APPID (_T("TGIT.TGIT.1"))
32 void SetTaskIDPerUUID()
34 typedef HRESULT STDAPICALLTYPE
SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID
);
35 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
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"), 3);
50 std::wstring id
= APPID
;
51 if ((r
< 2)||(r
== 3))
53 wchar_t buf
[MAX_PATH
] = {0};
54 GetModuleFileName(NULL
, buf
, MAX_PATH
);
56 n
= n
.substr(n
.find_last_of('\\'));
68 CCmdLineParser
parser(GetCommandLine());
69 if (parser
.HasVal(L
"groupuuid"))
71 id
+= parser
.GetVal(L
"groupuuid");
79 extern CString g_sGroupingUUID
;
82 void SetUUIDOverlayIcon( HWND hWnd
)
84 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3))
86 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepoOverlay"), TRUE
))
90 uuid
= g_sGroupingUUID
;
92 CCmdLineParser
parser(GetCommandLine());
93 if (parser
.HasVal(L
"groupuuid"))
94 uuid
= parser
.GetVal(L
"groupuuid");
98 ITaskbarList3
* pTaskbarInterface
= NULL
;
99 HRESULT hr
= CoCreateInstance(CLSID_TaskbarList
, NULL
, CLSCTX_INPROC_SERVER
, IID_ITaskbarList3
, reinterpret_cast<void**> (&(pTaskbarInterface
)));
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
);
110 if (sr
.empty() || (sr
.compare(uuid
)==0))
116 } while (foundUUIDIndex
< 20);
117 if (foundUUIDIndex
>= 20)
119 CRegStdString r
= CRegStdString(L
"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\1");
123 DWORD colors
[6] = {0x80FF0000, 0x80FFFF00, 0x8000FF00, 0x800000FF, 0x80000000, 0x8000FFFF};
125 // AND mask - monochrome - determines which pixels get drawn
127 for( int i
=0; i
<32; i
++ )
132 // XOR mask - 32bpp ARGB - determines the pixel values
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();