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"
26 #include "SmartHandle.h"
29 #define APPID (_T("TGIT.TGIT.1"))
31 void SetTaskIDPerUUID()
33 typedef HRESULT STDAPICALLTYPE
SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID
);
34 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
37 SetCurrentProcessExplicitAppUserModelIDFN
*pfnSetCurrentProcessExplicitAppUserModelID
= (SetCurrentProcessExplicitAppUserModelIDFN
*)GetProcAddress(hShell
, "SetCurrentProcessExplicitAppUserModelID");
38 if (pfnSetCurrentProcessExplicitAppUserModelID
)
40 std::wstring id
= GetTaskIDPerUUID();
41 pfnSetCurrentProcessExplicitAppUserModelID(id
.c_str());
46 std::wstring
GetTaskIDPerUUID(LPCTSTR uuid
/*= NULL */)
48 CRegStdDWORD r
= CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
49 std::wstring id
= APPID
;
50 if ((r
< 2)||(r
== 3))
52 wchar_t buf
[MAX_PATH
] = {0};
53 GetModuleFileName(NULL
, buf
, MAX_PATH
);
55 n
= n
.substr(n
.find_last_of('\\'));
67 CCmdLineParser
parser(GetCommandLine());
68 if (parser
.HasVal(L
"groupuuid"))
70 id
+= parser
.GetVal(L
"groupuuid");
78 extern CString g_sGroupingUUID
;
81 void SetUUIDOverlayIcon( HWND hWnd
)
83 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3))
85 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepoOverlay"), TRUE
))
89 uuid
= g_sGroupingUUID
;
91 CCmdLineParser
parser(GetCommandLine());
92 if (parser
.HasVal(L
"groupuuid"))
93 uuid
= parser
.GetVal(L
"groupuuid");
97 ITaskbarList3
* pTaskbarInterface
= NULL
;
98 HRESULT hr
= CoCreateInstance(CLSID_TaskbarList
, NULL
, CLSCTX_INPROC_SERVER
, IID_ITaskbarList3
, reinterpret_cast<void**> (&(pTaskbarInterface
)));
102 int foundUUIDIndex
= 0;
105 wchar_t buf
[MAX_PATH
];
106 swprintf_s(buf
, _countof(buf
), L
"%s%d", L
"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\", foundUUIDIndex
);
107 CRegStdString r
= CRegStdString(buf
);
109 if (sr
.empty() || (sr
.compare(uuid
)==0))
115 } while (foundUUIDIndex
< 20);
116 if (foundUUIDIndex
>= 20)
118 CRegStdString r
= CRegStdString(L
"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\1");
122 DWORD colors
[6] = {0x80FF0000, 0x80FFFF00, 0x8000FF00, 0x800000FF, 0x80000000, 0x8000FFFF};
124 // AND mask - monochrome - determines which pixels get drawn
126 for( int i
=0; i
<32; i
++ )
131 // XOR mask - 32bpp ARGB - determines the pixel values
133 for( int i
=0; i
<256; i
++ )
135 XOR
[i
] = colors
[foundUUIDIndex
% 6];
138 HICON icon
= ::CreateIcon(NULL
,16,16,1,32,AND
,(BYTE
*)XOR
);
139 pTaskbarInterface
->SetOverlayIcon(hWnd
, icon
, uuid
.c_str());
140 pTaskbarInterface
->Release();