Updated Tortoise.pot
[TortoiseGit.git] / src / Utils / TaskbarUUID.cpp
blobd1640280c7c51f5e67816f6954f4b0d026f63c8a
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.
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"
28 #include <atlbase.h>
30 #define APPID (_T("TGIT.TGIT.1"))
33 void SetTaskIDPerUUID()
35 typedef HRESULT STDAPICALLTYPE SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID);
36 CAutoLibrary hShell = AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
37 if (hShell)
39 SetCurrentProcessExplicitAppUserModelIDFN *pfnSetCurrentProcessExplicitAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDFN*)GetProcAddress(hShell, "SetCurrentProcessExplicitAppUserModelID");
40 if (pfnSetCurrentProcessExplicitAppUserModelID)
42 std::wstring id = GetTaskIDPerUUID();
43 pfnSetCurrentProcessExplicitAppUserModelID(id.c_str());
48 std::wstring GetTaskIDPerUUID(LPCTSTR uuid /*= NULL */)
50 CRegStdDWORD r = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 0);
51 std::wstring id = APPID;
52 if ((r < 2)||(r == 3))
54 wchar_t buf[MAX_PATH] = {0};
55 GetModuleFileName(NULL, buf, MAX_PATH);
56 std::wstring n = buf;
57 n = n.substr(n.find_last_of('\\'));
58 id += n;
61 if (r)
63 if (uuid)
65 id += uuid;
67 else
69 CCmdLineParser parser(GetCommandLine());
70 if (parser.HasVal(L"groupuuid"))
72 id += parser.GetVal(L"groupuuid");
76 return id;
79 #ifdef _MFC_VER
80 extern CString g_sGroupingUUID;
81 #endif
83 void SetUUIDOverlayIcon( HWND hWnd )
85 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 0))
87 if (CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepoOverlay"), FALSE))
89 std::wstring uuid;
90 #ifdef _MFC_VER
91 uuid = g_sGroupingUUID;
92 #else
93 CCmdLineParser parser(GetCommandLine());
94 if (parser.HasVal(L"groupuuid"))
95 uuid = parser.GetVal(L"groupuuid");
96 #endif
97 if (!uuid.empty())
99 ITaskbarList3 * pTaskbarInterface = NULL;
100 HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, reinterpret_cast<void**> (&(pTaskbarInterface)));
102 if (SUCCEEDED(hr))
104 int foundUUIDIndex = 0;
107 wchar_t buf[MAX_PATH];
108 swprintf_s(buf, _countof(buf), L"%s%d", L"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\", foundUUIDIndex);
109 CRegStdString r = CRegStdString(buf);
110 std::wstring sr = r;
111 if (sr.empty() || (sr.compare(uuid)==0))
113 r = uuid;
114 break;
116 foundUUIDIndex++;
117 } while (foundUUIDIndex < 20);
118 if (foundUUIDIndex >= 20)
120 CRegStdString r = CRegStdString(L"Software\\TortoiseGit\\LastUsedUUIDsForGrouping\\1");
121 r.removeKey();
124 DWORD colors[6] = {0x80FF0000, 0x80FFFF00, 0x8000FF00, 0x800000FF, 0x80000000, 0x8000FFFF};
126 // AND mask - monochrome - determines which pixels get drawn
127 BYTE AND[32];
128 for( int i=0; i<32; i++ )
130 AND[i] = 0xFF;
133 // XOR mask - 32bpp ARGB - determines the pixel values
134 DWORD XOR[256];
135 for( int i=0; i<256; i++ )
137 XOR[i] = colors[foundUUIDIndex % 6];
140 HICON icon = ::CreateIcon(NULL,16,16,1,32,AND,(BYTE*)XOR);
141 pTaskbarInterface->SetOverlayIcon(hWnd, icon, uuid.c_str());
142 pTaskbarInterface->Release();
143 DestroyIcon(icon);