OSDN Git Service

initial icon overlay support using the wingit lib
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / ContextMenu.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "ShellExt.h"\r
21 #include "ItemIDList.h"\r
22 #include "PreserveChdir.h"\r
23 #include "UnicodeUtils.h"\r
24 //#include "GitProperties.h"\r
25 #include "GitStatus.h"\r
26 #include "TGitPath.h"\r
27 \r
28 #define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])\r
29 #define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])\r
30 \r
31 int g_shellidlist=RegisterClipboardFormat(CFSTR_SHELLIDLIST);\r
32 \r
33 CShellExt::MenuInfo CShellExt::menuInfo[] =\r
34 {       \r
35         { ShellMenuClone,                                               MENUCLONE,                      IDI_CLONE,                              IDS_MENUCLONE,                  IDS_MENUDESCCHECKOUT,\r
36         ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
37 \r
38         { ShellMenuPull,                                                MENUPULL,                       IDI_PULL,                               IDS_MENUPULL,                   IDS_MENUPULL,\r
39         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
40 \r
41         { ShellMenuFetch,                                               MENUFETCH,                      IDI_PULL,                               IDS_MENUFETCH,                  IDS_MENUFETCH,\r
42         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
43 \r
44         { ShellMenuPush,                                                MENUPUSH,                       IDI_PUSH,                               IDS_MENUPUSH,                   IDS_MENUPULL,\r
45         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
46 \r
47 //      { ShellMenuCheckout,                                    MENUCHECKOUT,           IDI_CHECKOUT,                   IDS_MENUCHECKOUT,                       IDS_MENUDESCCHECKOUT,\r
48 //      ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
49 \r
50 //      { ShellMenuUpdate,                                              MENUUPDATE,                     IDI_UPDATE,                             IDS_MENUUPDATE,                         IDS_MENUDESCUPDATE,                             \r
51 //      ITEMIS_INSVN,   ITEMIS_ADDED, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
52 \r
53         { ShellMenuCommit,                                              MENUCOMMIT,                     IDI_COMMIT,                             IDS_MENUCOMMIT,                         IDS_MENUDESCCOMMIT,\r
54         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
55 \r
56         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
57 \r
58         { ShellMenuDiff,                                                MENUDIFF,                       IDI_DIFF,                               IDS_MENUDIFF,                           IDS_MENUDESCDIFF,\r
59         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },\r
60 \r
61         { ShellMenuPrevDiff,                                    MENUPREVDIFF,                   IDI_DIFF,                               IDS_MENUPREVDIFF,                       IDS_MENUDESCPREVDIFF,\r
62         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
63 \r
64 //      { ShellMenuUrlDiff,                                             MENUURLDIFF,            IDI_DIFF,                               IDS_MENUURLDIFF,                        IDS_MENUDESCURLDIFF,\r
65 //      ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
66 \r
67         { ShellMenuLog,                                                 MENULOG,                        IDI_LOG,                                IDS_MENULOG,                            IDS_MENUDESCLOG,\r
68         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },\r
69 \r
70 //      { ShellMenuRepoBrowse,                                  MENUREPOBROWSE,         IDI_REPOBROWSE,                 IDS_MENUREPOBROWSE,                     IDS_MENUDESCREPOBROWSE,\r
71 //      ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
72 \r
73         { ShellMenuShowChanged,                                 MENUSHOWCHANGED,        IDI_SHOWCHANGED,                IDS_MENUSHOWCHANGED,            IDS_MENUDESCSHOWCHANGED,\r
74         ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},\r
75 \r
76 //      { ShellMenuRevisionGraph,                               MENUREVISIONGRAPH,      IDI_REVISIONGRAPH,              IDS_MENUREVISIONGRAPH,          IDS_MENUDESCREVISIONGRAPH,\r
77 //      ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},\r
78 \r
79         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
80 \r
81         { ShellMenuConflictEditor,                              MENUCONFLICTEDITOR,     IDI_CONFLICT,                   IDS_MENUCONFLICT,                       IDS_MENUDESCCONFLICT,\r
82         ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
83 \r
84 //      { ShellMenuResolve,                                             MENURESOLVE,            IDI_RESOLVE,                    IDS_MENURESOLVE,                        IDS_MENUDESCRESOLVE,\r
85 //      ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },\r
86 \r
87 //      { ShellMenuUpdateExt,                                   MENUUPDATEEXT,          IDI_UPDATE,                             IDS_MENUUPDATEEXT,                      IDS_MENUDESCUPDATEEXT,\r
88 //      ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },\r
89 \r
90         { ShellMenuRename,                                              MENURENAME,                     IDI_RENAME,                             IDS_MENURENAME,                         IDS_MENUDESCRENAME,\r
91         ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },\r
92 \r
93         { ShellMenuRemove,                                              MENUREMOVE,                     IDI_DELETE,                             IDS_MENUREMOVE,                         IDS_MENUDESCREMOVE,\r
94         ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
95 \r
96         { ShellMenuRemoveKeep,                                  MENUREMOVE,                     IDI_DELETE,                             IDS_MENUREMOVEKEEP,                     IDS_MENUDESCREMOVEKEEP,\r
97         ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
98 \r
99         { ShellMenuRevert,                                              MENUREVERT,                     IDI_REVERT,                             IDS_MENUREVERT,                         IDS_MENUDESCREVERT,\r
100         ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },\r
101 \r
102         { ShellMenuRevert,                                              MENUREVERT,                     IDI_REVERT,                             IDS_MENUUNDOADD,                        IDS_MENUDESCUNDOADD,\r
103         ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },\r
104 \r
105         { ShellMenuDelUnversioned,                              MENUDELUNVERSIONED,     IDI_DELUNVERSIONED,             IDS_MENUDELUNVERSIONED,         IDS_MENUDESCDELUNVERSIONED,\r
106         ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
107 \r
108         { ShellMenuCleanup,                                             MENUCLEANUP,            IDI_CLEANUP,                    IDS_MENUCLEANUP,                        IDS_MENUDESCCLEANUP,\r
109         ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },\r
110 \r
111 //      { ShellMenuLock,                                                MENULOCK,                       IDI_LOCK,                               IDS_MENU_LOCK,                          IDS_MENUDESC_LOCK,\r
112 //      ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },\r
113 \r
114 //      { ShellMenuUnlock,                                              MENUUNLOCK,                     IDI_UNLOCK,                             IDS_MENU_UNLOCK,                        IDS_MENUDESC_UNLOCK,\r
115 //      ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },\r
116 \r
117 //      { ShellMenuUnlockForce,                                 MENUUNLOCK,                     IDI_UNLOCK,                             IDS_MENU_UNLOCKFORCE,           IDS_MENUDESC_UNLOCKFORCE,\r
118 //      ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
119 \r
120         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
121 \r
122 //      { ShellMenuCopy,                                                MENUCOPY,                       IDI_COPY,                               IDS_MENUBRANCH,                         IDS_MENUDESCCOPY,\r
123 //      ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
124 \r
125         { ShellMenuSwitch,                                              MENUSWITCH,                     IDI_SWITCH,                             IDS_MENUSWITCH,                         IDS_MENUDESCSWITCH,\r
126         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
127 \r
128         { ShellMenuMerge,                                               MENUMERGE,                      IDI_MERGE,                              IDS_MENUMERGE,                          IDS_MENUDESCMERGE,\r
129         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
130         { ShellMenuMergeAll,                                    MENUMERGEALL,           IDI_MERGE,                              IDS_MENUMERGEALL,                       IDS_MENUDESCMERGEALL,\r
131         ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
132 \r
133         { ShellMenuBranch,                                              MENUCOPY,                       IDI_COPY,                               IDS_MENUBRANCH,                         IDS_MENUDESCCOPY,\r
134         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
135         { ShellMenuTag,                                                 MENUTAG,                        IDI_TAG,                                IDS_MENUTAG,                            IDS_MENUDESCCOPY,\r
136         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
137 \r
138         { ShellMenuExport,                                              MENUEXPORT,                     IDI_EXPORT,                             IDS_MENUEXPORT,                         IDS_MENUDESCEXPORT,\r
139         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
140 \r
141 //      { ShellMenuRelocate,                                    MENURELOCATE,           IDI_RELOCATE,                   IDS_MENURELOCATE,                       IDS_MENUDESCRELOCATE,\r
142 //      ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
143 \r
144         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
145 \r
146         { ShellMenuCreateRepos,                                 MENUCREATEREPOS,        IDI_CREATEREPOS,                IDS_MENUCREATEREPOS,            IDS_MENUDESCCREATEREPOS,\r
147         ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
148 \r
149         { ShellMenuAdd,                                                 MENUADD,                        IDI_ADD,                                IDS_MENUADD,                            IDS_MENUDESCADD,\r
150         ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },\r
151 \r
152 //      { ShellMenuAddAsReplacement,                    MENUADD,                        IDI_ADD,                                IDS_MENUADDASREPLACEMENT,       IDS_MENUADDASREPLACEMENT,\r
153 //      ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
154 \r
155 //      { ShellMenuImport,                                              MENUIMPORT,                     IDI_IMPORT,                             IDS_MENUIMPORT,                         IDS_MENUDESCIMPORT,\r
156 //      ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },\r
157 \r
158         { ShellMenuBlame,                                               MENUBLAME,                      IDI_BLAME,                              IDS_MENUBLAME,                          IDS_MENUDESCBLAME,\r
159         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
160 \r
161         { ShellMenuIgnoreSub,                                   MENUIGNORE,                     IDI_IGNORE,                             IDS_MENUIGNORE,                         IDS_MENUDESCIGNORE,\r
162         ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },\r
163 \r
164         { ShellMenuUnIgnoreSub,                                 MENUIGNORE,                     IDI_IGNORE,                             IDS_MENUUNIGNORE,                       IDS_MENUDESCUNIGNORE,\r
165         ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },\r
166 \r
167         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
168 \r
169 //      { ShellMenuCherryPick,                                  MENUCHERRYPICK,         IDI_CREATEPATCH,                IDS_MENUCHERRYPICK,             IDS_MENUDESCCREATEPATCH,\r
170 //      ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
171 \r
172         { ShellMenuFormatPatch,                                 MENUFORMATPATCH,        IDI_CREATEPATCH,                IDS_MENUFORMATPATCH,            IDS_MENUDESCCREATEPATCH,\r
173         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
174 \r
175         { ShellMenuImportPatch,                                 MENUIMPORTPATCH,        IDI_PATCH,                              IDS_MENUIMPORTPATCH,            IDS_MENUDESCCREATEPATCH,\r
176         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
177 \r
178 \r
179         { ShellMenuCreatePatch,                                 MENUCREATEPATCH,        IDI_CREATEPATCH,                IDS_MENUCREATEPATCH,            IDS_MENUDESCCREATEPATCH,\r
180         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
181 \r
182         { ShellMenuApplyPatch,                                  MENUAPPLYPATCH,         IDI_PATCH,                              IDS_MENUAPPLYPATCH,                     IDS_MENUDESCAPPLYPATCH,\r
183         ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },\r
184 \r
185         { ShellMenuProperties,                                  MENUPROPERTIES,         IDI_PROPERTIES,                 IDS_MENUPROPERTIES,                     IDS_MENUDESCPROPERTIES,\r
186         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
187 \r
188         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
189 //      { ShellMenuClipPaste,                                   MENUCLIPPASTE,          IDI_CLIPPASTE,                  IDS_MENUCLIPPASTE,                      IDS_MENUDESCCLIPPASTE,\r
190 //      ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },\r
191 \r
192         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
193 \r
194         { ShellMenuSettings,                                    MENUSETTINGS,           IDI_SETTINGS,                   IDS_MENUSETTINGS,                       IDS_MENUDESCSETTINGS,\r
195         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
196         { ShellMenuHelp,                                                MENUHELP,                       IDI_HELP,                               IDS_MENUHELP,                           IDS_MENUDESCHELP,\r
197         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
198         { ShellMenuAbout,                                               MENUABOUT,                      IDI_ABOUT,                              IDS_MENUABOUT,                          IDS_MENUDESCABOUT,\r
199         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
200 \r
201         // the sub menus - they're not added like the the commands, therefore the menu ID is zero\r
202         // but they still need to be in here, because we use the icon and string information anyway.\r
203         { ShellSubMenu,                                                 NULL,                           IDI_APP,                                IDS_MENUSUBMENU,                        0,\r
204         0, 0, 0, 0, 0, 0, 0, 0 },\r
205         { ShellSubMenuFile,                                             NULL,                           IDI_MENUFILE,                   IDS_MENUSUBMENU,                        0,\r
206         0, 0, 0, 0, 0, 0, 0, 0 },\r
207         { ShellSubMenuFolder,                                   NULL,                           IDI_MENUFOLDER,                 IDS_MENUSUBMENU,                        0,\r
208         0, 0, 0, 0, 0, 0, 0, 0 },\r
209         { ShellSubMenuLink,                                             NULL,                           IDI_MENULINK,                   IDS_MENUSUBMENU,                        0,\r
210         0, 0, 0, 0, 0, 0, 0, 0 },\r
211         { ShellSubMenuMultiple,                                 NULL,                           IDI_MENUMULTIPLE,               IDS_MENUSUBMENU,                        0,\r
212         0, 0, 0, 0, 0, 0, 0, 0 },\r
213         // mark the last entry to tell the loop where to stop iterating over this array\r
214         { ShellMenuLastEntry,                                   0,                                      0,                                              0,                                                      0,\r
215         0, 0, 0, 0, 0, 0, 0, 0 },\r
216 };\r
217 \r
218 \r
219 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,\r
220                                    LPDATAOBJECT pDataObj,\r
221                                    HKEY /* hRegKey */)\r
222 {\r
223 \r
224         ATLTRACE("Shell :: Initialize\n");\r
225         PreserveChdir preserveChdir;\r
226         files_.clear();\r
227         folder_.erase();\r
228         uuidSource.erase();\r
229         uuidTarget.erase();\r
230         itemStates = 0;\r
231         itemStatesFolder = 0;\r
232         stdstring statuspath;\r
233         git_wc_status_kind fetchedstatus = git_wc_status_none;\r
234         // get selected files/folders\r
235         if (pDataObj)\r
236         {\r
237                 STGMEDIUM medium;\r
238                 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,\r
239                         (DVTARGETDEVICE FAR *)NULL, \r
240                         DVASPECT_CONTENT, \r
241                         -1, \r
242                         TYMED_HGLOBAL};\r
243                 HRESULT hres = pDataObj->GetData(&fmte, &medium);\r
244 \r
245                 if (SUCCEEDED(hres) && medium.hGlobal)\r
246                 {\r
247                         if (m_State == FileStateDropHandler)\r
248                         {\r
249 \r
250                                 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };\r
251                                 STGMEDIUM stg = { TYMED_HGLOBAL };\r
252                                 if ( FAILED( pDataObj->GetData ( &etc, &stg )))\r
253                                 {\r
254                                         ReleaseStgMedium ( &medium );\r
255                                         return E_INVALIDARG;\r
256                                 }\r
257 \r
258 \r
259                                 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);\r
260                                 if ( NULL == drop )\r
261                                 {\r
262                                         ReleaseStgMedium ( &stg );\r
263                                         ReleaseStgMedium ( &medium );\r
264                                         return E_INVALIDARG;\r
265                                 }\r
266 \r
267                                 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);\r
268                                 if (count == 1)\r
269                                         itemStates |= ITEMIS_ONLYONE;\r
270                                 for (int i = 0; i < count; i++)\r
271                                 {\r
272                                         // find the path length in chars\r
273                                         UINT len = DragQueryFile(drop, i, NULL, 0);\r
274                                         if (len == 0)\r
275                                                 continue;\r
276                                         TCHAR * szFileName = new TCHAR[len+1];\r
277                                         if (0 == DragQueryFile(drop, i, szFileName, len+1))\r
278                                         {\r
279                                                 delete [] szFileName;\r
280                                                 continue;\r
281                                         }\r
282                                         stdstring str = stdstring(szFileName);\r
283                                         delete [] szFileName;\r
284                                         if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))\r
285                                         {\r
286                                                 if (itemStates & ITEMIS_ONLYONE)\r
287                                                 {\r
288                                                         CTGitPath strpath;\r
289                                                         strpath.SetFromWin(str.c_str());\r
290                                                         itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;\r
291                                                         itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;\r
292                                                 }\r
293                                                 files_.push_back(str);\r
294                                                 if (i == 0)\r
295                                                 {\r
296                                                         //get the Subversion status of the item\r
297                                                         git_wc_status_kind status = git_wc_status_none;\r
298                                                         CTGitPath askedpath;\r
299                                                         askedpath.SetFromWin(str.c_str());\r
300                                                         try\r
301                                                         {\r
302                                                                 GitStatus stat;\r
303                                                                 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);\r
304                                                                 if (stat.status)\r
305                                                                 {\r
306                                                                         statuspath = str;\r
307                                                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
308                                                                         fetchedstatus = status;\r
309                                                                         //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
310                                                                         //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
311                                                                         //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
312                                                                         //{\r
313                                                                         //      itemStates |= ITEMIS_FOLDER;\r
314                                                                         //      if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
315                                                                         //              itemStates |= ITEMIS_FOLDERINGit;\r
316                                                                         //}\r
317                                                                         //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
318                                                                         //{\r
319                                                                         //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
320                                                                         //              itemStates |= ITEMIS_NEEDSLOCK;\r
321                                                                         //}\r
322                                                                         //if ((stat.status->entry)&&(stat.status->entry->uuid))\r
323                                                                         //      uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
324                                                                 }\r
325                                                                 else\r
326                                                                 {\r
327                                                                         // sometimes, git_client_status() returns with an error.\r
328                                                                         // in that case, we have to check if the working copy is versioned\r
329                                                                         // anyway to show the 'correct' context menu\r
330                                                                         if (askedpath.HasAdminDir())\r
331                                                                                 status = git_wc_status_normal;\r
332                                                                 }\r
333                                                         }\r
334                                                         catch ( ... )\r
335                                                         {\r
336                                                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
337                                                         }\r
338                                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
339                                                                 itemStates |= ITEMIS_INSVN;\r
340                                                         if (status == git_wc_status_ignored)\r
341                                                                 itemStates |= ITEMIS_IGNORED;\r
342                                                         if (status == git_wc_status_normal)\r
343                                                                 itemStates |= ITEMIS_NORMAL;\r
344                                                         if (status == git_wc_status_conflicted)\r
345                                                                 itemStates |= ITEMIS_CONFLICTED;\r
346                                                         if (status == git_wc_status_added)\r
347                                                                 itemStates |= ITEMIS_ADDED;\r
348                                                         if (status == git_wc_status_deleted)\r
349                                                                 itemStates |= ITEMIS_DELETED;\r
350                                                 }\r
351                                         }\r
352                                 } // for (int i = 0; i < count; i++)\r
353                                 GlobalUnlock ( drop );\r
354                                 ReleaseStgMedium ( &stg );\r
355 \r
356                         } // if (m_State == FileStateDropHandler) \r
357                         else\r
358                         {\r
359 \r
360                                 //Enumerate PIDLs which the user has selected\r
361                                 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);\r
362                                 ItemIDList parent( GetPIDLFolder (cida));\r
363 \r
364                                 int count = cida->cidl;\r
365                                 BOOL statfetched = FALSE;\r
366                                 for (int i = 0; i < count; ++i)\r
367                                 {\r
368                                         ItemIDList child (GetPIDLItem (cida, i), &parent);\r
369                                         stdstring str = child.toString();\r
370                                         if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))\r
371                                         {\r
372                                                 //check if our menu is requested for a subversion admin directory\r
373                                                 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))\r
374                                                         continue;\r
375 \r
376                                                 files_.push_back(str);\r
377                                                 CTGitPath strpath;\r
378                                                 strpath.SetFromWin(str.c_str());\r
379                                                 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;\r
380                                                 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;\r
381                                                 if (!statfetched)\r
382                                                 {\r
383                                                         //get the Subversion status of the item\r
384                                                         git_wc_status_kind status = git_wc_status_none;\r
385                                                         if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))\r
386                                                         {\r
387                                                                 if (strpath.HasAdminDir())\r
388                                                                         status = git_wc_status_normal;\r
389                                                         }\r
390                                                         else\r
391                                                         {\r
392                                                                 try\r
393                                                                 {\r
394                                                                         GitStatus stat;\r
395                                                                         if (strpath.HasAdminDir())\r
396                                                                                 stat.GetStatus(strpath, false, true, true);\r
397                                                                         statuspath = str;\r
398                                                                         if (stat.status)\r
399                                                                         {\r
400                                                                                 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
401                                                                                 fetchedstatus = status;\r
402                                                                                 //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
403                                                                                 //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
404                                                                                 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
405                                                                                 //{\r
406                                                                                 //      itemStates |= ITEMIS_FOLDER;\r
407                                                                                 //      if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
408                                                                                 //              itemStates |= ITEMIS_FOLDERINGit;\r
409                                                                                 //}\r
410                                                                                 //if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))\r
411                                                                                 //      itemStates |= ITEMIS_CONFLICTED;\r
412                                                                                 //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
413                                                                                 //{\r
414                                                                                 //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
415                                                                                 //              itemStates |= ITEMIS_NEEDSLOCK;\r
416                                                                                 //}\r
417                                                                                 //if ((stat.status->entry)&&(stat.status->entry->uuid))\r
418                                                                                 //      uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
419                                                                         }       \r
420                                                                         else\r
421                                                                         {\r
422                                                                                 // sometimes, git_client_status() returns with an error.\r
423                                                                                 // in that case, we have to check if the working copy is versioned\r
424                                                                                 // anyway to show the 'correct' context menu\r
425                                                                                 if (strpath.HasAdminDir())\r
426                                                                                 {\r
427                                                                                         status = git_wc_status_normal;\r
428                                                                                         fetchedstatus = status;\r
429                                                                                 }\r
430                                                                         }\r
431                                                                         statfetched = TRUE;\r
432                                                                 }\r
433                                                                 catch ( ... )\r
434                                                                 {\r
435                                                                         ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
436                                                                 }\r
437                                                         }\r
438                                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
439                                                                 itemStates |= ITEMIS_INSVN;\r
440                                                         if (status == git_wc_status_ignored)\r
441                                                         {\r
442                                                                 itemStates |= ITEMIS_IGNORED;\r
443                                                                 // the item is ignored. Get the svn:ignored properties so we can (maybe) later\r
444                                                                 // offer a 'remove from ignored list' entry\r
445 //                                                              GitProperties props(strpath.GetContainingDirectory(), false);\r
446 //                                                              ignoredprops.empty();\r
447 //                                                              for (int p=0; p<props.GetCount(); ++p)\r
448 //                                                              {\r
449 //                                                                      if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)\r
450 //                                                                      {\r
451 //                                                                              std::string st = props.GetItemValue(p);\r
452 //                                                                              ignoredprops = MultibyteToWide(st.c_str());\r
453 //                                                                              // remove all escape chars ('\\')\r
454 //                                                                              std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');\r
455 //                                                                              break;\r
456 //                                                                      }\r
457 //                                                              }\r
458                                                         }\r
459                                                         if (status == git_wc_status_normal)\r
460                                                                 itemStates |= ITEMIS_NORMAL;\r
461                                                         if (status == git_wc_status_conflicted)\r
462                                                                 itemStates |= ITEMIS_CONFLICTED;\r
463                                                         if (status == git_wc_status_added)\r
464                                                                 itemStates |= ITEMIS_ADDED;\r
465                                                         if (status == git_wc_status_deleted)\r
466                                                                 itemStates |= ITEMIS_DELETED;\r
467                                                 }\r
468                                         }\r
469                                 } // for (int i = 0; i < count; ++i)\r
470                                 ItemIDList child (GetPIDLItem (cida, 0), &parent);\r
471 //                              if (g_ShellCache.HasGitAdminDir(child.toString().c_str(), FALSE))\r
472 //                                      itemStates |= ITEMIS_INVERSIONEDFOLDER;\r
473                                 GlobalUnlock(medium.hGlobal);\r
474 \r
475                                 // if the item is a versioned folder, check if there's a patch file\r
476                                 // in the clipboard to be used in "Apply Patch"\r
477                                 UINT cFormatDiff = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));\r
478                                 if (cFormatDiff)\r
479                                 {\r
480                                         if (IsClipboardFormatAvailable(cFormatDiff)) \r
481                                                 itemStates |= ITEMIS_PATCHINCLIPBOARD;\r
482                                 }\r
483                                 if (IsClipboardFormatAvailable(CF_HDROP)) \r
484                                         itemStates |= ITEMIS_PATHINCLIPBOARD;\r
485 \r
486                         }\r
487 \r
488                         ReleaseStgMedium ( &medium );\r
489                         if (medium.pUnkForRelease)\r
490                         {\r
491                                 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;\r
492                                 relInterface->Release();\r
493                         }\r
494                 }\r
495         }\r
496 \r
497         // get folder background\r
498         if (pIDFolder)\r
499         {\r
500 \r
501                 ItemIDList list(pIDFolder);\r
502                 folder_ = list.toString();\r
503                 git_wc_status_kind status = git_wc_status_none;\r
504                 if (IsClipboardFormatAvailable(CF_HDROP)) \r
505                         itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;\r
506                 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))\r
507                 {\r
508                         CTGitPath askedpath;\r
509                         askedpath.SetFromWin(folder_.c_str());\r
510                         try\r
511                         {\r
512                                 GitStatus stat;\r
513                                 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);\r
514                                 if (stat.status)\r
515                                 {\r
516                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
517 //                                      if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
518 //                                              itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
519 //                                      if ((stat.status->entry)&&(stat.status->entry->present_props))\r
520 //                                      {\r
521 //                                              if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
522 //                                                      itemStatesFolder |= ITEMIS_NEEDSLOCK;\r
523 //                                      }\r
524 //                                      if ((stat.status->entry)&&(stat.status->entry->uuid))\r
525 //                                              uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
526                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
527                                                 itemStatesFolder |= ITEMIS_INSVN;\r
528                                         if (status == git_wc_status_normal)\r
529                                                 itemStatesFolder |= ITEMIS_NORMAL;\r
530                                         if (status == git_wc_status_conflicted)\r
531                                                 itemStatesFolder |= ITEMIS_CONFLICTED;\r
532                                         if (status == git_wc_status_added)\r
533                                                 itemStatesFolder |= ITEMIS_ADDED;\r
534                                         if (status == git_wc_status_deleted)\r
535                                                 itemStatesFolder |= ITEMIS_DELETED;\r
536                                 }\r
537                                 else\r
538                                 {\r
539                                         // sometimes, git_client_status() returns with an error.\r
540                                         // in that case, we have to check if the working copy is versioned\r
541                                         // anyway to show the 'correct' context menu\r
542                                         if (askedpath.HasAdminDir())\r
543                                                 status = git_wc_status_normal;\r
544                                 }\r
545                         }\r
546                         catch ( ... )\r
547                         {\r
548                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
549                         }\r
550                 }\r
551                 else\r
552                 {\r
553                         status = fetchedstatus;\r
554                 }\r
555                 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
556                 {\r
557                         itemStatesFolder |= ITEMIS_FOLDERINSVN;\r
558                 }\r
559                 if (status == git_wc_status_ignored)\r
560                         itemStatesFolder |= ITEMIS_IGNORED;\r
561                 itemStatesFolder |= ITEMIS_FOLDER;\r
562                 if (files_.size() == 0)\r
563                         itemStates |= ITEMIS_ONLYONE;\r
564                 if (m_State != FileStateDropHandler)\r
565                         itemStates |= itemStatesFolder;\r
566 \r
567         }\r
568         if (files_.size() == 2)\r
569                 itemStates |= ITEMIS_TWO;\r
570         if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))\r
571         {\r
572 \r
573                 itemStates |= ITEMIS_ONLYONE;\r
574                 if (m_State != FileStateDropHandler)\r
575                 {\r
576                         if (PathIsDirectory(files_.front().c_str()))\r
577                         {\r
578                                 folder_ = files_.front();\r
579                                 git_wc_status_kind status = git_wc_status_none;\r
580                                 if (folder_.compare(statuspath)!=0)\r
581                                 {\r
582                                         CTGitPath askedpath;\r
583                                         askedpath.SetFromWin(folder_.c_str());\r
584                                         try\r
585                                         {\r
586                                                 GitStatus stat;\r
587                                                 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);\r
588                                                 if (stat.status)\r
589                                                 {\r
590                                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
591 //                                                      if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
592 //                                                              itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
593 //                                                      if ((stat.status->entry)&&(stat.status->entry->present_props))\r
594 //                                                      {\r
595 //                                                              if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
596 //                                                                      itemStates |= ITEMIS_NEEDSLOCK;\r
597 //                                                      }\r
598 //                                                      if ((stat.status->entry)&&(stat.status->entry->uuid))\r
599 //                                                              uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
600                                                 }\r
601                                         }\r
602                                         catch ( ... )\r
603                                         {\r
604                                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
605                                         }\r
606                                 }\r
607                                 else\r
608                                 {\r
609                                         status = fetchedstatus;\r
610                                 }\r
611                                 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
612                                         itemStates |= ITEMIS_FOLDERINSVN;\r
613                                 if (status == git_wc_status_ignored)\r
614                                         itemStates |= ITEMIS_IGNORED;\r
615                                 itemStates |= ITEMIS_FOLDER;\r
616                                 if (status == git_wc_status_added)\r
617                                         itemStates |= ITEMIS_ADDED;\r
618                                 if (status == git_wc_status_deleted)\r
619                                         itemStates |= ITEMIS_DELETED;\r
620                         }\r
621                 }\r
622         \r
623         }\r
624         \r
625         return NOERROR;\r
626 }\r
627 \r
628 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)\r
629 {\r
630         TCHAR menutextbuffer[255] = {0};\r
631         TCHAR verbsbuffer[255] = {0};\r
632         MAKESTRING(stringid);\r
633 \r
634         if (istop)\r
635         {\r
636                 //menu entry for the top context menu, so append an "Git " before\r
637                 //the menu text to indicate where the entry comes from\r
638                 _tcscpy_s(menutextbuffer, 255, _T("Git "));\r
639         }\r
640         _tcscat_s(menutextbuffer, 255, stringtablebuffer);\r
641         if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
642         {\r
643                 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);\r
644                 if (fullver >= 0x500)\r
645                 {\r
646                         // on win2k, the context menu does not work properly if we use\r
647                         // icon bitmaps. At least the menu text is empty in the context menu\r
648                         // for folder backgrounds (seems like a win2k bug).\r
649                         HBITMAP bmp = IconToBitmap(icon); \r
650                         SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);\r
651                 }\r
652         }\r
653         else\r
654         {\r
655                 MENUITEMINFO menuiteminfo = {0};\r
656                 menuiteminfo.cbSize = sizeof(menuiteminfo);\r
657                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;\r
658                 menuiteminfo.fType = MFT_STRING;\r
659                 menuiteminfo.dwTypeData = menutextbuffer;\r
660                 if (icon)\r
661                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;\r
662                 menuiteminfo.wID = id;\r
663                 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);\r
664         }\r
665 \r
666         if (istop)\r
667         {\r
668                 //menu entry for the top context menu, so append an "Git " before\r
669                 //the menu text to indicate where the entry comes from\r
670                 _tcscpy_s(menutextbuffer, 255, _T("Git "));\r
671         }\r
672         LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));\r
673         _tcscat_s(menutextbuffer, 255, verbsbuffer);\r
674         stdstring verb = stdstring(menutextbuffer);\r
675         if (verb.find('&') != -1)\r
676         {\r
677                 verb.erase(verb.find('&'),1);\r
678         }\r
679         myVerbsMap[verb] = id - idCmdFirst;\r
680         myVerbsMap[verb] = id;\r
681         myVerbsIDMap[id - idCmdFirst] = verb;\r
682         myVerbsIDMap[id] = verb;\r
683         // We store the relative and absolute diameter\r
684         // (drawitem callback uses absolute, others relative)\r
685         myIDMap[id - idCmdFirst] = com;\r
686         myIDMap[id] = com;\r
687         if (!istop)\r
688                 mySubMenuMap[pos] = com;\r
689 }\r
690 \r
691 HBITMAP CShellExt::IconToBitmap(UINT uIcon)\r
692 {\r
693         std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);\r
694         if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)\r
695                 return bitmap_it->second;\r
696 \r
697         HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);\r
698         if (!hIcon)\r
699                 return NULL;\r
700 \r
701         RECT rect;\r
702 \r
703         rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);\r
704         rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);\r
705 \r
706         rect.left = rect.top = 0;\r
707 \r
708         HWND desktop = ::GetDesktopWindow();\r
709         if (desktop == NULL)\r
710         {\r
711                 DestroyIcon(hIcon);\r
712                 return NULL;\r
713         }\r
714 \r
715         HDC screen_dev = ::GetDC(desktop);\r
716         if (screen_dev == NULL)\r
717         {\r
718                 DestroyIcon(hIcon);\r
719                 return NULL;\r
720         }\r
721 \r
722         // Create a compatible DC\r
723         HDC dst_hdc = ::CreateCompatibleDC(screen_dev);\r
724         if (dst_hdc == NULL)\r
725         {\r
726                 DestroyIcon(hIcon);\r
727                 ::ReleaseDC(desktop, screen_dev); \r
728                 return NULL;\r
729         }\r
730 \r
731         // Create a new bitmap of icon size\r
732         HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);\r
733         if (bmp == NULL)\r
734         {\r
735                 DestroyIcon(hIcon);\r
736                 ::DeleteDC(dst_hdc);\r
737                 ::ReleaseDC(desktop, screen_dev); \r
738                 return NULL;\r
739         }\r
740 \r
741         // Select it into the compatible DC\r
742         HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);\r
743         if (old_dst_bmp == NULL)\r
744         {\r
745                 DestroyIcon(hIcon);\r
746                 return NULL;\r
747         }\r
748 \r
749         // Fill the background of the compatible DC with the white color\r
750         // that is taken by menu routines as transparent\r
751         ::SetBkColor(dst_hdc, RGB(255, 255, 255));\r
752         ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);\r
753 \r
754         // Draw the icon into the compatible DC\r
755         ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);\r
756 \r
757         // Restore settings\r
758         ::SelectObject(dst_hdc, old_dst_bmp);\r
759         ::DeleteDC(dst_hdc);\r
760         ::ReleaseDC(desktop, screen_dev); \r
761         DestroyIcon(hIcon);\r
762         if (bmp)\r
763                 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));\r
764         return bmp;\r
765 }\r
766 \r
767 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)\r
768 {\r
769         bool bRet = true;\r
770         tempfile = stdstring();\r
771         //write all selected files and paths to a temporary file\r
772         //for TortoiseProc.exe to read out again.\r
773         DWORD written = 0;\r
774         DWORD pathlength = GetTempPath(0, NULL);\r
775         TCHAR * path = new TCHAR[pathlength+1];\r
776         TCHAR * tempFile = new TCHAR[pathlength + 100];\r
777         GetTempPath (pathlength+1, path);\r
778         GetTempFileName (path, _T("svn"), 0, tempFile);\r
779         tempfile = stdstring(tempFile);\r
780 \r
781         HANDLE file = ::CreateFile (tempFile,\r
782                 GENERIC_WRITE, \r
783                 FILE_SHARE_READ, \r
784                 0, \r
785                 CREATE_ALWAYS, \r
786                 FILE_ATTRIBUTE_TEMPORARY,\r
787                 0);\r
788 \r
789         delete [] path;\r
790         delete [] tempFile;\r
791         if (file == INVALID_HANDLE_VALUE)\r
792                 return false;\r
793 \r
794         if (!IsClipboardFormatAvailable(CF_HDROP))\r
795                 return false;\r
796         if (!OpenClipboard(NULL))\r
797                 return false;\r
798 \r
799         stdstring sClipboardText;\r
800         HGLOBAL hglb = GetClipboardData(CF_HDROP);\r
801         HDROP hDrop = (HDROP)GlobalLock(hglb);\r
802         if(hDrop != NULL)\r
803         {\r
804                 TCHAR szFileName[MAX_PATH];\r
805                 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); \r
806                 for(UINT i = 0; i < cFiles; ++i)\r
807                 {\r
808                         DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));\r
809                         stdstring filename = szFileName;\r
810                         ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);\r
811                         ::WriteFile (file, _T("\n"), 2, &written, 0);\r
812                 }\r
813                 GlobalUnlock(hDrop);\r
814         }\r
815         else bRet = false;\r
816         GlobalUnlock(hglb);\r
817 \r
818         CloseClipboard();\r
819         ::CloseHandle(file);\r
820 \r
821         return bRet;\r
822 }\r
823 \r
824 stdstring CShellExt::WriteFileListToTempFile()\r
825 {\r
826         //write all selected files and paths to a temporary file\r
827         //for TortoiseProc.exe to read out again.\r
828         DWORD pathlength = GetTempPath(0, NULL);\r
829         TCHAR * path = new TCHAR[pathlength+1];\r
830         TCHAR * tempFile = new TCHAR[pathlength + 100];\r
831         GetTempPath (pathlength+1, path);\r
832         GetTempFileName (path, _T("svn"), 0, tempFile);\r
833         stdstring retFilePath = stdstring(tempFile);\r
834         \r
835         HANDLE file = ::CreateFile (tempFile,\r
836                                                                 GENERIC_WRITE, \r
837                                                                 FILE_SHARE_READ, \r
838                                                                 0, \r
839                                                                 CREATE_ALWAYS, \r
840                                                                 FILE_ATTRIBUTE_TEMPORARY,\r
841                                                                 0);\r
842 \r
843         delete [] path;\r
844         delete [] tempFile;\r
845         if (file == INVALID_HANDLE_VALUE)\r
846                 return stdstring();\r
847                 \r
848         DWORD written = 0;\r
849         if (files_.empty())\r
850         {\r
851                 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);\r
852                 ::WriteFile (file, _T("\n"), 2, &written, 0);\r
853         }\r
854 \r
855         for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)\r
856         {\r
857                 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);\r
858                 ::WriteFile (file, _T("\n"), 2, &written, 0);\r
859         }\r
860         ::CloseHandle(file);\r
861         return retFilePath;\r
862 }\r
863 \r
864 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)\r
865 {\r
866         PreserveChdir preserveChdir;\r
867         LoadLangDll();\r
868 \r
869         if ((uFlags & CMF_DEFAULTONLY)!=0)\r
870                 return NOERROR;                                 //we don't change the default action\r
871 \r
872         if ((files_.size() == 0)||(folder_.size() == 0))\r
873                 return NOERROR;\r
874 \r
875         if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))\r
876                 return NOERROR;\r
877 \r
878         bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();\r
879 \r
880         //the drop handler only has eight commands, but not all are visible at the same time:\r
881         //if the source file(s) are under version control then those files can be moved\r
882         //to the new location or they can be moved with a rename, \r
883         //if they are unversioned then they can be added to the working copy\r
884         //if they are versioned, they also can be exported to an unversioned location\r
885         UINT idCmd = idCmdFirst;\r
886 \r
887         // Git move here\r
888         // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added\r
889         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))\r
890                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);\r
891 \r
892         // Git move and rename here\r
893         // available if source is a single, versioned but not added item, target is versioned, source and target from same repository or target folder is added\r
894         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))\r
895                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);\r
896 \r
897         // Git copy here\r
898         // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added\r
899         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))\r
900                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);\r
901 \r
902         // Git copy and rename here, source and target from same repository\r
903         // available if source is a single, versioned but not added item, target is versioned or target folder is added\r
904         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))\r
905                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);\r
906 \r
907         // Git add here\r
908         // available if target is versioned and source is either unversioned or from another repository\r
909         if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))\r
910                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);\r
911 \r
912         // Git export here\r
913         // available if source is versioned and a folder\r
914         if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))\r
915                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);\r
916 \r
917         // Git export all here\r
918         // available if source is versioned and a folder\r
919         if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))\r
920                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);\r
921 \r
922         // apply patch\r
923         // available if source is a patchfile\r
924         if (itemStates & ITEMIS_PATCHFILE)\r
925                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);\r
926 \r
927         // separator\r
928         if (idCmd != idCmdFirst)\r
929                 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); \r
930 \r
931         return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));\r
932 }\r
933 \r
934 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,\r
935                                          UINT indexMenu,\r
936                                          UINT idCmdFirst,\r
937                                          UINT /*idCmdLast*/,\r
938                                          UINT uFlags)\r
939 {\r
940         ATLTRACE("Shell :: QueryContextMenu\n");\r
941         PreserveChdir preserveChdir;\r
942         \r
943         //first check if our drop handler is called\r
944         //and then (if true) provide the context menu for the\r
945         //drop handler\r
946         if (m_State == FileStateDropHandler)\r
947         {\r
948                 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);\r
949         }\r
950 \r
951         if ((uFlags & CMF_DEFAULTONLY)!=0)\r
952                 return NOERROR;                                 //we don't change the default action\r
953 \r
954         if ((files_.size() == 0)&&(folder_.size() == 0))\r
955                 return NOERROR;\r
956 \r
957         if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))\r
958                 return NOERROR;\r
959 \r
960         int csidlarray[] = \r
961         {\r
962                 CSIDL_BITBUCKET,\r
963                 CSIDL_CDBURN_AREA,\r
964                 CSIDL_COMMON_FAVORITES,\r
965                 CSIDL_COMMON_STARTMENU,\r
966                 CSIDL_COMPUTERSNEARME,\r
967                 CSIDL_CONNECTIONS,\r
968                 CSIDL_CONTROLS,\r
969                 CSIDL_COOKIES,\r
970                 CSIDL_FAVORITES,\r
971                 CSIDL_FONTS,\r
972                 CSIDL_HISTORY,\r
973                 CSIDL_INTERNET,\r
974                 CSIDL_INTERNET_CACHE,\r
975                 CSIDL_NETHOOD,\r
976                 CSIDL_NETWORK,\r
977                 CSIDL_PRINTERS,\r
978                 CSIDL_PRINTHOOD,\r
979                 CSIDL_RECENT,\r
980                 CSIDL_SENDTO,\r
981                 CSIDL_STARTMENU,\r
982                 0\r
983         };\r
984         if (IsIllegalFolder(folder_, csidlarray))\r
985                 return NOERROR;\r
986 \r
987         if (folder_.empty())\r
988         {\r
989                 // folder is empty, but maybe files are selected\r
990                 if (files_.size() == 0)\r
991                         return NOERROR; // nothing selected - we don't have a menu to show\r
992                 // check whether a selected entry is an UID - those are namespace extensions\r
993                 // which we can't handle\r
994                 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)\r
995                 {\r
996                         if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)\r
997                                 return NOERROR;\r
998                 }\r
999         }\r
1000 \r
1001         //check if our menu is requested for a subversion admin directory\r
1002         if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))\r
1003                 return NOERROR;\r
1004 \r
1005         if (uFlags & CMF_EXTENDEDVERBS)\r
1006                 itemStates |= ITEMIS_EXTENDED;\r
1007 \r
1008         const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);\r
1009         if ( bShortcut && (files_.size()==1))\r
1010         {\r
1011                 // Don't show the context menu for a link if the\r
1012                 // destination is not part of a working copy.\r
1013                 // It would only show the standard menu items\r
1014                 // which are already shown for the lnk-file.\r
1015                 CString path = files_.front().c_str();\r
1016                 if ( !g_GitAdminDir.HasAdminDir(path) )\r
1017                 {\r
1018                         return NOERROR;\r
1019                 }\r
1020         }\r
1021 \r
1022         //check if we already added our menu entry for a folder.\r
1023         //we check that by iterating through all menu entries and check if \r
1024         //the dwItemData member points to our global ID string. That string is set\r
1025         //by our shell extension when the folder menu is inserted.\r
1026         TCHAR menubuf[MAX_PATH];\r
1027         int count = GetMenuItemCount(hMenu);\r
1028         for (int i=0; i<count; ++i)\r
1029         {\r
1030                 MENUITEMINFO miif;\r
1031                 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));\r
1032                 miif.cbSize = sizeof(MENUITEMINFO);\r
1033                 miif.fMask = MIIM_DATA;\r
1034                 miif.dwTypeData = menubuf;\r
1035                 miif.cch = sizeof(menubuf)/sizeof(TCHAR);\r
1036                 GetMenuItemInfo(hMenu, i, TRUE, &miif);\r
1037                 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)\r
1038                         return NOERROR;\r
1039         }\r
1040 \r
1041         LoadLangDll();\r
1042         UINT idCmd = idCmdFirst;\r
1043 \r
1044         //create the sub menu\r
1045         HMENU subMenu = CreateMenu();\r
1046         int indexSubMenu = 0;\r
1047 \r
1048         unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();\r
1049         unsigned __int64 menumask = g_ShellCache.GetMenuMask();\r
1050 \r
1051         int menuIndex = 0;\r
1052         bool bAddSeparator = false;\r
1053         bool bMenuEntryAdded = false;\r
1054         // insert separator at start\r
1055         InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
1056         bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));\r
1057         if (fullver <= 0x0500)\r
1058                 bShowIcons = false;\r
1059         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
1060         {\r
1061                 if (menuInfo[menuIndex].command == ShellSeparator)\r
1062                 {\r
1063                         // we don't add a separator immediately. Because there might not be\r
1064                         // another 'normal' menu entry after we insert a separator.\r
1065                         // we simply set a flag here, indicating that before the next\r
1066                         // 'normal' menu entry, a separator should be added.\r
1067                         bAddSeparator = true;\r
1068                 }\r
1069                 else\r
1070                 {\r
1071                         // check the conditions whether to show the menu entry or not\r
1072                         bool bInsertMenu = false;\r
1073 \r
1074                         if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)\r
1075                         {\r
1076                                 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)\r
1077                                         &&\r
1078                                         ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))\r
1079                                         bInsertMenu = true;\r
1080                         }\r
1081                         else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))\r
1082                                 bInsertMenu = true;\r
1083                         else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))\r
1084                                 bInsertMenu = true;\r
1085 \r
1086                         if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)\r
1087                         {\r
1088                                 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)\r
1089                                         &&\r
1090                                         ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))\r
1091                                         bInsertMenu = true;\r
1092                         }\r
1093                         else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))\r
1094                                 bInsertMenu = true;\r
1095                         else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))\r
1096                                 bInsertMenu = true;\r
1097 \r
1098                         if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)\r
1099                         {\r
1100                                 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)\r
1101                                         &&\r
1102                                         ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))\r
1103                                         bInsertMenu = true;\r
1104                         }\r
1105                         else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))\r
1106                                 bInsertMenu = true;\r
1107                         else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))\r
1108                                 bInsertMenu = true;\r
1109 \r
1110                         if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)\r
1111                         {\r
1112                                 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)\r
1113                                         &&\r
1114                                         ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))\r
1115                                         bInsertMenu = true;\r
1116                         }\r
1117                         else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))\r
1118                                 bInsertMenu = true;\r
1119                         else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))\r
1120                                 bInsertMenu = true;\r
1121 \r
1122                         if (menuInfo[menuIndex].menuID & (~menumask))\r
1123                         {\r
1124                                 if (bInsertMenu)\r
1125                                 {\r
1126                                         // insert a separator\r
1127                                         if ((bMenuEntryAdded)&&(bAddSeparator))\r
1128                                         {\r
1129                                                 bAddSeparator = false;\r
1130                                                 bMenuEntryAdded = false;\r
1131                                                 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); \r
1132                                                 idCmd++;\r
1133                                         }\r
1134                                         \r
1135                                         // handle special cases (sub menus)\r
1136                                         if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))\r
1137                                         {\r
1138                                                 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);\r
1139                                                 bMenuEntryAdded = true;\r
1140                                         }\r
1141                                         else\r
1142                                         {\r
1143                                                 // the 'get lock' command is special\r
1144                                                 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);\r
1145                                                 if (menuInfo[menuIndex].command == ShellMenuLock)\r
1146                                                 {\r
1147                                                         if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())\r
1148                                                                 bIsTop = true;\r
1149                                                 }\r
1150                                                 // insert the menu entry\r
1151                                                 InsertGitMenu(  bIsTop,\r
1152                                                                                 bIsTop ? hMenu : subMenu,\r
1153                                                                                 bIsTop ? indexMenu++ : indexSubMenu++,\r
1154                                                                                 idCmd++,\r
1155                                                                                 menuInfo[menuIndex].menuTextID,\r
1156                                                                                 bShowIcons ? menuInfo[menuIndex].iconID : 0,\r
1157                                                                                 idCmdFirst,\r
1158                                                                                 menuInfo[menuIndex].command,\r
1159                                                                                 uFlags);\r
1160                                                 if (!bIsTop)\r
1161                                                         bMenuEntryAdded = true;\r
1162                                         }\r
1163                                 }\r
1164                         }\r
1165                 }\r
1166                 menuIndex++;\r
1167         }\r
1168 \r
1169         //add sub menu to main context menu\r
1170         //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.\r
1171         //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.\r
1172         MAKESTRING(IDS_MENUSUBMENU);\r
1173         MENUITEMINFO menuiteminfo;\r
1174         SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
1175         menuiteminfo.cbSize = sizeof(menuiteminfo);\r
1176         menuiteminfo.fType = MFT_STRING;\r
1177         menuiteminfo.dwTypeData = stringtablebuffer;\r
1178 \r
1179         UINT uIcon = bShowIcons ? IDI_APP : 0;\r
1180         if (folder_.size())\r
1181         {\r
1182                 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;\r
1183                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;\r
1184                 myIDMap[idCmd] = ShellSubMenuFolder;\r
1185                 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;\r
1186         }\r
1187         else if (!bShortcut && (files_.size()==1))\r
1188         {\r
1189                 uIcon = bShowIcons ? IDI_MENUFILE : 0;\r
1190                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;\r
1191                 myIDMap[idCmd] = ShellSubMenuFile;\r
1192         }\r
1193         else if (bShortcut && (files_.size()==1))\r
1194         {\r
1195                 uIcon = bShowIcons ? IDI_MENULINK : 0;\r
1196                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;\r
1197                 myIDMap[idCmd] = ShellSubMenuLink;\r
1198         }\r
1199         else if (files_.size() > 1)\r
1200         {\r
1201                 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;\r
1202                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;\r
1203                 myIDMap[idCmd] = ShellSubMenuMultiple;\r
1204         }\r
1205         else\r
1206         {\r
1207                 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;\r
1208                 myIDMap[idCmd] = ShellSubMenu;\r
1209         }\r
1210         HBITMAP bmp = NULL;\r
1211         if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
1212         {\r
1213                 bmp = IconToBitmap(uIcon);\r
1214                 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;\r
1215         }\r
1216         else\r
1217         {\r
1218                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
1219                 if (bShowIcons)\r
1220                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;\r
1221         }\r
1222         menuiteminfo.hbmpChecked = bmp;\r
1223         menuiteminfo.hbmpUnchecked = bmp;\r
1224         menuiteminfo.hSubMenu = subMenu;\r
1225         menuiteminfo.wID = idCmd++;\r
1226         InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);\r
1227 \r
1228         //separator after\r
1229         InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
1230 \r
1231         //return number of menu items added\r
1232         return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));\r
1233 }\r
1234 \r
1235 \r
1236 // This is called when you invoke a command on the menu:\r
1237 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)\r
1238 {\r
1239         PreserveChdir preserveChdir;\r
1240         HRESULT hr = E_INVALIDARG;\r
1241         if (lpcmi == NULL)\r
1242                 return hr;\r
1243 \r
1244         std::string command;\r
1245         std::string parent;\r
1246         std::string file;\r
1247 \r
1248         if ((files_.size() > 0)||(folder_.size() > 0))\r
1249         {\r
1250                 UINT idCmd = LOWORD(lpcmi->lpVerb);\r
1251 \r
1252                 if (HIWORD(lpcmi->lpVerb))\r
1253                 {\r
1254                         stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));\r
1255                         std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);\r
1256                         if (verb_it != myVerbsMap.end() && verb_it->first == verb)\r
1257                                 idCmd = verb_it->second;\r
1258                         else\r
1259                                 return hr;\r
1260                 }\r
1261 \r
1262                 // See if we have a handler interface for this id\r
1263                 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);\r
1264                 if (id_it != myIDMap.end() && id_it->first == idCmd)\r
1265                 {\r
1266                         STARTUPINFO startup;\r
1267                         PROCESS_INFORMATION process;\r
1268                         memset(&startup, 0, sizeof(startup));\r
1269                         startup.cb = sizeof(startup);\r
1270                         memset(&process, 0, sizeof(process));\r
1271                         CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);\r
1272                         CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);\r
1273 \r
1274                         //TortoiseProc expects a command line of the form:\r
1275                         //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile\r
1276                         // or\r
1277                         //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>\r
1278                         //\r
1279                         //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)\r
1280                         //* pathfile is a path to a temporary file which contains a list of file paths\r
1281                         stdstring svnCmd = _T(" /command:");\r
1282                         stdstring tempfile;\r
1283                         switch (id_it->second)\r
1284                         {\r
1285                                 //#region case\r
1286                         case ShellMenuCheckout:\r
1287                                 svnCmd += _T("checkout /path:\"");\r
1288                                 svnCmd += folder_;\r
1289                                 svnCmd += _T("\"");\r
1290                                 break;\r
1291                         case ShellMenuUpdate:\r
1292                                 tempfile = WriteFileListToTempFile();\r
1293                                 svnCmd += _T("update /pathfile:\"");\r
1294                                 svnCmd += tempfile;\r
1295                                 svnCmd += _T("\"");\r
1296                                 svnCmd += _T(" /deletepathfile");\r
1297                                 break;\r
1298                         case ShellMenuUpdateExt:\r
1299                                 tempfile = WriteFileListToTempFile();\r
1300                                 svnCmd += _T("update /pathfile:\"");\r
1301                                 svnCmd += tempfile;\r
1302                                 svnCmd += _T("\"");\r
1303                                 svnCmd += _T(" /deletepathfile");\r
1304                                 svnCmd += _T(" /rev");\r
1305                                 break;\r
1306                         case ShellMenuCommit:\r
1307                                 tempfile = WriteFileListToTempFile();\r
1308                                 svnCmd += _T("commit /pathfile:\"");\r
1309                                 svnCmd += tempfile;\r
1310                                 svnCmd += _T("\"");\r
1311                                 svnCmd += _T(" /deletepathfile");\r
1312                                 break;\r
1313                         case ShellMenuAdd:\r
1314                         case ShellMenuAddAsReplacement:\r
1315                                 tempfile = WriteFileListToTempFile();\r
1316                                 svnCmd += _T("add /pathfile:\"");\r
1317                                 svnCmd += tempfile;\r
1318                                 svnCmd += _T("\"");\r
1319                                 svnCmd += _T(" /deletepathfile");\r
1320                                 break;\r
1321                         case ShellMenuIgnore:\r
1322                                 tempfile = WriteFileListToTempFile();\r
1323                                 svnCmd += _T("ignore /pathfile:\"");\r
1324                                 svnCmd += tempfile;\r
1325                                 svnCmd += _T("\"");\r
1326                                 svnCmd += _T(" /deletepathfile");\r
1327                                 break;\r
1328                         case ShellMenuIgnoreCaseSensitive:\r
1329                                 tempfile = WriteFileListToTempFile();\r
1330                                 svnCmd += _T("ignore /pathfile:\"");\r
1331                                 svnCmd += tempfile;\r
1332                                 svnCmd += _T("\"");\r
1333                                 svnCmd += _T(" /deletepathfile");\r
1334                                 svnCmd += _T(" /onlymask");\r
1335                                 break;\r
1336                         case ShellMenuUnIgnore:\r
1337                                 tempfile = WriteFileListToTempFile();\r
1338                                 svnCmd += _T("unignore /pathfile:\"");\r
1339                                 svnCmd += tempfile;\r
1340                                 svnCmd += _T("\"");\r
1341                                 svnCmd += _T(" /deletepathfile");\r
1342                                 break;\r
1343                         case ShellMenuUnIgnoreCaseSensitive:\r
1344                                 tempfile = WriteFileListToTempFile();\r
1345                                 svnCmd += _T("unignore /pathfile:\"");\r
1346                                 svnCmd += tempfile;\r
1347                                 svnCmd += _T("\"");\r
1348                                 svnCmd += _T(" /deletepathfile");\r
1349                                 svnCmd += _T(" /onlymask");\r
1350                                 break;\r
1351                         case ShellMenuRevert:\r
1352                                 tempfile = WriteFileListToTempFile();\r
1353                                 svnCmd += _T("revert /pathfile:\"");\r
1354                                 svnCmd += tempfile;\r
1355                                 svnCmd += _T("\"");\r
1356                                 svnCmd += _T(" /deletepathfile");\r
1357                                 break;\r
1358                         case ShellMenuDelUnversioned:\r
1359                                 svnCmd += _T("delunversioned /path:\"");\r
1360                                 svnCmd += folder_;\r
1361                                 svnCmd += _T("\"");\r
1362                                 break;\r
1363                         case ShellMenuCleanup:\r
1364                                 tempfile = WriteFileListToTempFile();\r
1365                                 svnCmd += _T("cleanup /pathfile:\"");\r
1366                                 svnCmd += tempfile;\r
1367                                 svnCmd += _T("\"");\r
1368                                 svnCmd += _T(" /deletepathfile");\r
1369                                 break;\r
1370                         case ShellMenuResolve:\r
1371                                 tempfile = WriteFileListToTempFile();\r
1372                                 svnCmd += _T("resolve /pathfile:\"");\r
1373                                 svnCmd += tempfile;\r
1374                                 svnCmd += _T("\"");\r
1375                                 svnCmd += _T(" /deletepathfile");\r
1376                                 break;\r
1377                         case ShellMenuSwitch:\r
1378                                 svnCmd += _T("switch /path:\"");\r
1379                                 if (files_.size() > 0)\r
1380                                         svnCmd += files_.front();\r
1381                                 else\r
1382                                         svnCmd += folder_;\r
1383                                 svnCmd += _T("\"");\r
1384                                 break;\r
1385                         case ShellMenuImport:\r
1386                                 svnCmd += _T("import /path:\"");\r
1387                                 svnCmd += folder_;\r
1388                                 svnCmd += _T("\"");\r
1389                                 break;\r
1390                         case ShellMenuExport:\r
1391                                 svnCmd += _T("export /path:\"");\r
1392                                 svnCmd += folder_;\r
1393                                 svnCmd += _T("\"");\r
1394                                 break;\r
1395                         case ShellMenuAbout:\r
1396                                 svnCmd += _T("about");\r
1397                                 break;\r
1398                         case ShellMenuCreateRepos:\r
1399                                 svnCmd += _T("repocreate /path:\"");\r
1400                                 svnCmd += folder_;\r
1401                                 svnCmd += _T("\"");\r
1402                                 break;\r
1403                         case ShellMenuMerge:\r
1404                                 svnCmd += _T("merge /path:\"");\r
1405                                 if (files_.size() > 0)\r
1406                                         svnCmd += files_.front();\r
1407                                 else\r
1408                                         svnCmd += folder_;\r
1409                                 svnCmd += _T("\"");\r
1410                                 break;\r
1411                         case ShellMenuMergeAll:\r
1412                                 svnCmd += _T("mergeall /path:\"");\r
1413                                 if (files_.size() > 0)\r
1414                                         svnCmd += files_.front();\r
1415                                 else\r
1416                                         svnCmd += folder_;\r
1417                                 svnCmd += _T("\"");\r
1418                                 break;\r
1419                         case ShellMenuCopy:\r
1420                                 svnCmd += _T("copy /path:\"");\r
1421                                 if (files_.size() > 0)\r
1422                                         svnCmd += files_.front();\r
1423                                 else\r
1424                                         svnCmd += folder_;\r
1425                                 svnCmd += _T("\"");\r
1426                                 break;\r
1427                         case ShellMenuSettings:\r
1428                                 svnCmd += _T("settings");\r
1429                                 break;\r
1430                         case ShellMenuHelp:\r
1431                                 svnCmd += _T("help");\r
1432                                 break;\r
1433                         case ShellMenuRename:\r
1434                                 svnCmd += _T("rename /path:\"");\r
1435                                 if (files_.size() > 0)\r
1436                                         svnCmd += files_.front();\r
1437                                 else\r
1438                                         svnCmd += folder_;\r
1439                                 svnCmd += _T("\"");\r
1440                                 break;\r
1441                         case ShellMenuRemove:\r
1442                                 tempfile = WriteFileListToTempFile();\r
1443                                 svnCmd += _T("remove /pathfile:\"");\r
1444                                 svnCmd += tempfile;\r
1445                                 svnCmd += _T("\"");\r
1446                                 svnCmd += _T(" /deletepathfile");\r
1447                                 break;\r
1448                         case ShellMenuRemoveKeep:\r
1449                                 tempfile = WriteFileListToTempFile();\r
1450                                 svnCmd += _T("remove /pathfile:\"");\r
1451                                 svnCmd += tempfile;\r
1452                                 svnCmd += _T("\"");\r
1453                                 svnCmd += _T(" /deletepathfile");\r
1454                                 svnCmd += _T(" /keep");\r
1455                                 break;\r
1456                         case ShellMenuDiff:\r
1457                                 svnCmd += _T("diff /path:\"");\r
1458                                 if (files_.size() == 1)\r
1459                                         svnCmd += files_.front();\r
1460                                 else if (files_.size() == 2)\r
1461                                 {\r
1462                                         std::vector<stdstring>::iterator I = files_.begin();\r
1463                                         svnCmd += *I;\r
1464                                         I++;\r
1465                                         svnCmd += _T("\" /path2:\"");\r
1466                                         svnCmd += *I;\r
1467                                 }\r
1468                                 else\r
1469                                         svnCmd += folder_;\r
1470                                 svnCmd += _T("\"");\r
1471                                 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)\r
1472                                         svnCmd += _T(" /alternative");\r
1473                                 break;\r
1474                         case ShellMenuPrevDiff:\r
1475                                 svnCmd += _T("prevdiff /path:\"");\r
1476                                 if (files_.size() == 1)\r
1477                                         svnCmd += files_.front();\r
1478                                 else\r
1479                                         svnCmd += folder_;\r
1480                                 svnCmd += _T("\"");\r
1481                                 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)\r
1482                                         svnCmd += _T(" /alternative");\r
1483                                 break;\r
1484                         case ShellMenuUrlDiff:\r
1485                                 svnCmd += _T("urldiff /path:\"");\r
1486                                 if (files_.size() == 1)\r
1487                                         svnCmd += files_.front();\r
1488                                 else\r
1489                                         svnCmd += folder_;\r
1490                                 svnCmd += _T("\"");\r
1491                                 break;\r
1492                         case ShellMenuDropCopyAdd:\r
1493                                 tempfile = WriteFileListToTempFile();\r
1494                                 svnCmd += _T("dropcopyadd /pathfile:\"");\r
1495                                 svnCmd += tempfile;\r
1496                                 svnCmd += _T("\"");\r
1497                                 svnCmd += _T(" /deletepathfile");\r
1498                                 svnCmd += _T(" /droptarget:\"");\r
1499                                 svnCmd += folder_;\r
1500                                 svnCmd += _T("\"";)\r
1501                                         break;\r
1502                         case ShellMenuDropCopy:\r
1503                                 tempfile = WriteFileListToTempFile();\r
1504                                 svnCmd += _T("dropcopy /pathfile:\"");\r
1505                                 svnCmd += tempfile;\r
1506                                 svnCmd += _T("\"");\r
1507                                 svnCmd += _T(" /deletepathfile");\r
1508                                 svnCmd += _T(" /droptarget:\"");\r
1509                                 svnCmd += folder_;\r
1510                                 svnCmd += _T("\"";)\r
1511                                         break;\r
1512                         case ShellMenuDropCopyRename:\r
1513                                 tempfile = WriteFileListToTempFile();\r
1514                                 svnCmd += _T("dropcopy /pathfile:\"");\r
1515                                 svnCmd += tempfile;\r
1516                                 svnCmd += _T("\"");\r
1517                                 svnCmd += _T(" /deletepathfile");\r
1518                                 svnCmd += _T(" /droptarget:\"");\r
1519                                 svnCmd += folder_;\r
1520                                 svnCmd += _T("\" /rename";)\r
1521                                         break;\r
1522                         case ShellMenuDropMove:\r
1523                                 tempfile = WriteFileListToTempFile();\r
1524                                 svnCmd += _T("dropmove /pathfile:\"");\r
1525                                 svnCmd += tempfile;\r
1526                                 svnCmd += _T("\"");\r
1527                                 svnCmd += _T(" /deletepathfile");\r
1528                                 svnCmd += _T(" /droptarget:\"");\r
1529                                 svnCmd += folder_;\r
1530                                 svnCmd += _T("\"");\r
1531                                 break;\r
1532                         case ShellMenuDropMoveRename:\r
1533                                 tempfile = WriteFileListToTempFile();\r
1534                                 svnCmd += _T("dropmove /pathfile:\"");\r
1535                                 svnCmd += tempfile;\r
1536                                 svnCmd += _T("\"");\r
1537                                 svnCmd += _T(" /deletepathfile");\r
1538                                 svnCmd += _T(" /droptarget:\"");\r
1539                                 svnCmd += folder_;\r
1540                                 svnCmd += _T("\" /rename";)\r
1541                                 break;\r
1542                         case ShellMenuDropExport:\r
1543                                 tempfile = WriteFileListToTempFile();\r
1544                                 svnCmd += _T("dropexport /pathfile:\"");\r
1545                                 svnCmd += tempfile;\r
1546                                 svnCmd += _T("\"");\r
1547                                 svnCmd += _T(" /deletepathfile");\r
1548                                 svnCmd += _T(" /droptarget:\"");\r
1549                                 svnCmd += folder_;\r
1550                                 svnCmd += _T("\"");\r
1551                                 break;\r
1552                         case ShellMenuDropExportExtended:\r
1553                                 tempfile = WriteFileListToTempFile();\r
1554                                 svnCmd += _T("dropexport /pathfile:\"");\r
1555                                 svnCmd += tempfile;\r
1556                                 svnCmd += _T("\"");\r
1557                                 svnCmd += _T(" /deletepathfile");\r
1558                                 svnCmd += _T(" /droptarget:\"");\r
1559                                 svnCmd += folder_;\r
1560                                 svnCmd += _T("\"");\r
1561                                 svnCmd += _T(" /extended");\r
1562                                 break;\r
1563                         case ShellMenuLog:\r
1564                                 svnCmd += _T("log /path:\"");\r
1565                                 if (files_.size() > 0)\r
1566                                         svnCmd += files_.front();\r
1567                                 else\r
1568                                         svnCmd += folder_;\r
1569                                 svnCmd += _T("\"");\r
1570                                 break;\r
1571                         case ShellMenuConflictEditor:\r
1572                                 svnCmd += _T("conflicteditor /path:\"");\r
1573                                 if (files_.size() > 0)\r
1574                                         svnCmd += files_.front();\r
1575                                 else\r
1576                                         svnCmd += folder_;\r
1577                                 svnCmd += _T("\"");\r
1578                                 break;\r
1579                         case ShellMenuRelocate:\r
1580                                 svnCmd += _T("relocate /path:\"");\r
1581                                 if (files_.size() > 0)\r
1582                                         svnCmd += files_.front();\r
1583                                 else\r
1584                                         svnCmd += folder_;\r
1585                                 svnCmd += _T("\"");\r
1586                                 break;\r
1587                         case ShellMenuShowChanged:\r
1588                                 if (files_.size() > 1)\r
1589                 {\r
1590                                     tempfile = WriteFileListToTempFile();\r
1591                                     svnCmd += _T("repostatus /pathfile:\"");\r
1592                                     svnCmd += tempfile;\r
1593                                 svnCmd += _T("\"");\r
1594                                 svnCmd += _T(" /deletepathfile");\r
1595                 }\r
1596                 else\r
1597                 {\r
1598                     svnCmd += _T("repostatus /path:\"");\r
1599                                     if (files_.size() > 0)\r
1600                                             svnCmd += files_.front();\r
1601                                     else\r
1602                                             svnCmd += folder_;\r
1603                                 svnCmd += _T("\"");\r
1604                 }\r
1605                                 break;\r
1606                         case ShellMenuRepoBrowse:\r
1607                                 svnCmd += _T("repobrowser /path:\"");\r
1608                                 if (files_.size() > 0)\r
1609                                         svnCmd += files_.front();\r
1610                                 else\r
1611                                         svnCmd += folder_;\r
1612                                 svnCmd += _T("\"");\r
1613                                 break;\r
1614                         case ShellMenuBlame:\r
1615                                 svnCmd += _T("blame /path:\"");\r
1616                                 if (files_.size() > 0)\r
1617                                         svnCmd += files_.front();\r
1618                                 else\r
1619                                         svnCmd += folder_;\r
1620                                 svnCmd += _T("\"");\r
1621                                 break;\r
1622                         case ShellMenuCreatePatch:\r
1623                                 tempfile = WriteFileListToTempFile();\r
1624                                 svnCmd += _T("createpatch /pathfile:\"");\r
1625                                 svnCmd += tempfile;\r
1626                                 svnCmd += _T("\"");\r
1627                                 svnCmd += _T(" /deletepathfile");\r
1628                                 break;\r
1629                         case ShellMenuApplyPatch:\r
1630                                 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))\r
1631                                 {\r
1632                                         // if there's a patch file in the clipboard, we save it\r
1633                                         // to a temporary file and tell TortoiseMerge to use that one\r
1634                                         UINT cFormat = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));\r
1635                                         if ((cFormat)&&(OpenClipboard(NULL)))\r
1636                                         { \r
1637                                                 HGLOBAL hglb = GetClipboardData(cFormat); \r
1638                                                 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb); \r
1639 \r
1640                                                 DWORD len = GetTempPath(0, NULL);\r
1641                                                 TCHAR * path = new TCHAR[len+1];\r
1642                                                 TCHAR * tempF = new TCHAR[len+100];\r
1643                                                 GetTempPath (len+1, path);\r
1644                                                 GetTempFileName (path, TEXT("svn"), 0, tempF);\r
1645                                                 std::wstring sTempFile = std::wstring(tempF);\r
1646                                                 delete [] path;\r
1647                                                 delete [] tempF;\r
1648 \r
1649                                                 FILE * outFile;\r
1650                                                 size_t patchlen = strlen(lpstr);\r
1651                                                 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));\r
1652                                                 if(outFile)\r
1653                                                 {\r
1654                                                         size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);\r
1655                                                         if (size == patchlen)\r
1656                                                         {\r
1657                                                                 itemStates |= ITEMIS_PATCHFILE;\r
1658                                                                 files_.clear();\r
1659                                                                 files_.push_back(sTempFile);\r
1660                                                         }\r
1661                                                         fclose(outFile);\r
1662                                                 }\r
1663                                                 GlobalUnlock(hglb); \r
1664                                                 CloseClipboard(); \r
1665                                         } \r
1666                                 }\r
1667                                 if (itemStates & ITEMIS_PATCHFILE)\r
1668                                 {\r
1669                                         svnCmd = _T(" /diff:\"");\r
1670                                         if (files_.size() > 0)\r
1671                                         {\r
1672                                                 svnCmd += files_.front();\r
1673                                                 if (itemStatesFolder & ITEMIS_FOLDERINSVN)\r
1674                                                 {\r
1675                                                         svnCmd += _T("\" /patchpath:\"");\r
1676                                                         svnCmd += folder_;\r
1677                                                 }\r
1678                                         }\r
1679                                         else\r
1680                                                 svnCmd += folder_;\r
1681                                         if (itemStates & ITEMIS_INVERSIONEDFOLDER)\r
1682                                                 svnCmd += _T("\" /wc");\r
1683                                         else\r
1684                                                 svnCmd += _T("\"");\r
1685                                 }\r
1686                                 else\r
1687                                 {\r
1688                                         svnCmd = _T(" /patchpath:\"");\r
1689                                         if (files_.size() > 0)\r
1690                                                 svnCmd += files_.front();\r
1691                                         else\r
1692                                                 svnCmd += folder_;\r
1693                                         svnCmd += _T("\"");\r
1694                                 }\r
1695                                 myIDMap.clear();\r
1696                                 myVerbsIDMap.clear();\r
1697                                 myVerbsMap.clear();\r
1698                                 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)\r
1699                                 {\r
1700                                         LPVOID lpMsgBuf;\r
1701                                         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
1702                                                 FORMAT_MESSAGE_FROM_SYSTEM | \r
1703                                                 FORMAT_MESSAGE_IGNORE_INSERTS,\r
1704                                                 NULL,\r
1705                                                 GetLastError(),\r
1706                                                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\r
1707                                                 (LPTSTR) &lpMsgBuf,\r
1708                                                 0,\r
1709                                                 NULL \r
1710                                                 );\r
1711                                         MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );\r
1712                                         LocalFree( lpMsgBuf );\r
1713                                 }\r
1714                                 CloseHandle(process.hThread);\r
1715                                 CloseHandle(process.hProcess);\r
1716                                 return NOERROR;\r
1717                                 break;\r
1718                         case ShellMenuRevisionGraph:\r
1719                                 svnCmd += _T("revisiongraph /path:\"");\r
1720                                 if (files_.size() > 0)\r
1721                                         svnCmd += files_.front();\r
1722                                 else\r
1723                                         svnCmd += folder_;\r
1724                                 svnCmd += _T("\"");\r
1725                                 break;\r
1726                         case ShellMenuLock:\r
1727                                 tempfile = WriteFileListToTempFile();\r
1728                                 svnCmd += _T("lock /pathfile:\"");\r
1729                                 svnCmd += tempfile;\r
1730                                 svnCmd += _T("\"");\r
1731                                 svnCmd += _T(" /deletepathfile");\r
1732                                 break;\r
1733                         case ShellMenuUnlock:\r
1734                                 tempfile = WriteFileListToTempFile();\r
1735                                 svnCmd += _T("unlock /pathfile:\"");\r
1736                                 svnCmd += tempfile;\r
1737                                 svnCmd += _T("\"");\r
1738                                 svnCmd += _T(" /deletepathfile");\r
1739                                 break;\r
1740                         case ShellMenuUnlockForce:\r
1741                                 tempfile = WriteFileListToTempFile();\r
1742                                 svnCmd += _T("unlock /pathfile:\"");\r
1743                                 svnCmd += tempfile;\r
1744                                 svnCmd += _T("\"");\r
1745                                 svnCmd += _T(" /deletepathfile");\r
1746                                 svnCmd += _T(" /force");\r
1747                                 break;\r
1748                         case ShellMenuProperties:\r
1749                                 tempfile = WriteFileListToTempFile();\r
1750                                 svnCmd += _T("properties /pathfile:\"");\r
1751                                 svnCmd += tempfile;\r
1752                                 svnCmd += _T("\"");\r
1753                                 svnCmd += _T(" /deletepathfile");\r
1754                                 break;\r
1755                         case ShellMenuClipPaste:\r
1756                                 if (WriteClipboardPathsToTempFile(tempfile))\r
1757                                 {\r
1758                                         bool bCopy = true;\r
1759                                         UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));\r
1760                                         if (cPrefDropFormat)\r
1761                                         {\r
1762                                                 if (OpenClipboard(lpcmi->hwnd))\r
1763                                                 {\r
1764                                                         HGLOBAL hglb = GetClipboardData(cPrefDropFormat);\r
1765                                                         if (hglb)\r
1766                                                         {\r
1767                                                                 DWORD* effect = (DWORD*) GlobalLock(hglb);\r
1768                                                                 if (*effect == DROPEFFECT_MOVE)\r
1769                                                                         bCopy = false;\r
1770                                                                 GlobalUnlock(hglb);\r
1771                                                         }\r
1772                                                         CloseClipboard();\r
1773                                                 }\r
1774                                         }\r
1775 \r
1776                                         if (bCopy)\r
1777                                                 svnCmd += _T("pastecopy /pathfile:\"");\r
1778                                         else\r
1779                                                 svnCmd += _T("pastemove /pathfile:\"");\r
1780                                         svnCmd += tempfile;\r
1781                                         svnCmd += _T("\"");\r
1782                                         svnCmd += _T(" /deletepathfile");\r
1783                                         svnCmd += _T(" /droptarget:\"");\r
1784                                         svnCmd += folder_;\r
1785                                         svnCmd += _T("\"");\r
1786                                 }\r
1787                                 else return NOERROR;\r
1788                                 break;\r
1789                         case ShellMenuClone:\r
1790                                 svnCmd += _T("clone /path:\"");\r
1791                                 svnCmd += folder_;\r
1792                                 svnCmd += _T("\"");\r
1793                                 break;\r
1794                         case ShellMenuPull:\r
1795                                 svnCmd += _T("pull /path:\"");\r
1796                                 if (files_.size() > 0)\r
1797                                         svnCmd += files_.front();\r
1798                                 else\r
1799                                         svnCmd += folder_;\r
1800                                 svnCmd += _T("\"");\r
1801                                 break;\r
1802                         case ShellMenuPush:\r
1803                                 svnCmd += _T("push /path:\"");\r
1804                                 if (files_.size() > 0)\r
1805                                         svnCmd += files_.front();\r
1806                                 else\r
1807                                         svnCmd += folder_;\r
1808                                 svnCmd += _T("\"");\r
1809                                 break;\r
1810                         case ShellMenuBranch:\r
1811                                 svnCmd += _T("branch /path:\"");\r
1812                                 if (files_.size() > 0)\r
1813                                         svnCmd += files_.front();\r
1814                                 else\r
1815                                         svnCmd += folder_;\r
1816                                 svnCmd += _T("\"");\r
1817                                 break;\r
1818                         \r
1819                         case ShellMenuTag:\r
1820                                 svnCmd += _T("tag /path:\"");\r
1821                                 if (files_.size() > 0)\r
1822                                         svnCmd += files_.front();\r
1823                                 else\r
1824                                         svnCmd += folder_;\r
1825                                 svnCmd += _T("\"");\r
1826                                 break;\r
1827 \r
1828                         case ShellMenuFormatPatch:\r
1829                                 svnCmd += _T("formatpatch /path:\"");\r
1830                                 if (files_.size() > 0)\r
1831                                         svnCmd += files_.front();\r
1832                                 else\r
1833                                         svnCmd += folder_;\r
1834                                 svnCmd += _T("\"");\r
1835                                 break;\r
1836 \r
1837                         case ShellMenuImportPatch:\r
1838                                 svnCmd += _T("importpatch /path:\"");\r
1839                                 if (files_.size() > 0)\r
1840                                         svnCmd += files_.front();\r
1841                                 else\r
1842                                         svnCmd += folder_;\r
1843                                 svnCmd += _T("\"");\r
1844                                 break;\r
1845 \r
1846                         case ShellMenuCherryPick:\r
1847                                 svnCmd += _T("cherrypick /path:\"");\r
1848                                 if (files_.size() > 0)\r
1849                                         svnCmd += files_.front();\r
1850                                 else\r
1851                                         svnCmd += folder_;\r
1852                                 svnCmd += _T("\"");\r
1853                                 break;\r
1854                         case ShellMenuFetch:\r
1855                                 svnCmd += _T("fetch /path:\"");\r
1856                                 if (files_.size() > 0)\r
1857                                         svnCmd += files_.front();\r
1858                                 else\r
1859                                         svnCmd += folder_;\r
1860                                 svnCmd += _T("\"");\r
1861                                 break;\r
1862 \r
1863                         default:\r
1864                                 break;\r
1865                                 //#endregion\r
1866                         } // switch (id_it->second) \r
1867                         svnCmd += _T(" /hwnd:");\r
1868                         TCHAR buf[30];\r
1869                         _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);\r
1870                         svnCmd += buf;\r
1871                         myIDMap.clear();\r
1872                         myVerbsIDMap.clear();\r
1873                         myVerbsMap.clear();\r
1874                         if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)\r
1875                         {\r
1876                                 LPVOID lpMsgBuf;\r
1877                                 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
1878                                         FORMAT_MESSAGE_FROM_SYSTEM | \r
1879                                         FORMAT_MESSAGE_IGNORE_INSERTS,\r
1880                                         NULL,\r
1881                                         GetLastError(),\r
1882                                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\r
1883                                         (LPTSTR) &lpMsgBuf,\r
1884                                         0,\r
1885                                         NULL \r
1886                                         );\r
1887                                 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );\r
1888                                 LocalFree( lpMsgBuf );\r
1889                         }\r
1890                         CloseHandle(process.hThread);\r
1891                         CloseHandle(process.hProcess);\r
1892                         hr = NOERROR;\r
1893                 } // if (id_it != myIDMap.end() && id_it->first == idCmd) \r
1894         } // if ((files_.size() > 0)||(folder_.size() > 0)) \r
1895         return hr;\r
1896 \r
1897 }\r
1898 \r
1899 // This is for the status bar and things like that:\r
1900 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,\r
1901                                          UINT uFlags,\r
1902                                          UINT FAR * /*reserved*/,\r
1903                                          LPSTR pszName,\r
1904                                          UINT cchMax)\r
1905 {\r
1906         PreserveChdir preserveChdir;\r
1907         //do we know the id?\r
1908         std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);\r
1909         if (id_it == myIDMap.end() || id_it->first != idCmd)\r
1910         {\r
1911                 return E_INVALIDARG;            //no, we don't\r
1912         }\r
1913 \r
1914         LoadLangDll();\r
1915         HRESULT hr = E_INVALIDARG;\r
1916 \r
1917         MAKESTRING(IDS_MENUDESCDEFAULT);\r
1918         int menuIndex = 0;\r
1919         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
1920         {\r
1921                 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)\r
1922                 {\r
1923                         MAKESTRING(menuInfo[menuIndex].menuDescID);\r
1924                         break;\r
1925                 }\r
1926                 menuIndex++;\r
1927         }\r
1928 \r
1929         const TCHAR * desc = stringtablebuffer;\r
1930         switch(uFlags)\r
1931         {\r
1932         case GCS_HELPTEXTA:\r
1933                 {\r
1934                         std::string help = WideToMultibyte(desc);\r
1935                         lstrcpynA(pszName, help.c_str(), cchMax);\r
1936                         hr = S_OK;\r
1937                         break; \r
1938                 }\r
1939         case GCS_HELPTEXTW: \r
1940                 {\r
1941                         wide_string help = desc;\r
1942                         lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax); \r
1943                         hr = S_OK;\r
1944                         break; \r
1945                 }\r
1946         case GCS_VERBA:\r
1947                 {\r
1948                         std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);\r
1949                         if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)\r
1950                         {\r
1951                                 std::string help = WideToMultibyte(verb_id_it->second);\r
1952                                 lstrcpynA(pszName, help.c_str(), cchMax);\r
1953                                 hr = S_OK;\r
1954                         }\r
1955                 }\r
1956                 break;\r
1957         case GCS_VERBW:\r
1958                 {\r
1959                         std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);\r
1960                         if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)\r
1961                         {\r
1962                                 wide_string help = verb_id_it->second;\r
1963                                 ATLTRACE("verb : %ws\n", help.c_str());\r
1964                                 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax); \r
1965                                 hr = S_OK;\r
1966                         }\r
1967                 }\r
1968                 break;\r
1969         }\r
1970         return hr;\r
1971 }\r
1972 \r
1973 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1974 {\r
1975         LRESULT res;\r
1976         return HandleMenuMsg2(uMsg, wParam, lParam, &res);\r
1977 }\r
1978 \r
1979 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)\r
1980 {\r
1981         PreserveChdir preserveChdir;\r
1982 \r
1983         LRESULT res;\r
1984         if (pResult == NULL)\r
1985                 pResult = &res;\r
1986         *pResult = FALSE;\r
1987 \r
1988         LoadLangDll();\r
1989         switch (uMsg)\r
1990         {\r
1991         case WM_MEASUREITEM:\r
1992                 {\r
1993                         MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;\r
1994                         if (lpmis==NULL)\r
1995                                 break;\r
1996                         lpmis->itemWidth += 2;\r
1997                         if (lpmis->itemHeight < 16)\r
1998                                 lpmis->itemHeight = 16;\r
1999                         *pResult = TRUE;\r
2000                 }\r
2001                 break;\r
2002         case WM_DRAWITEM:\r
2003                 {\r
2004                         LPCTSTR resource;\r
2005                         DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;\r
2006                         if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))\r
2007                                 return S_OK;            //not for a menu\r
2008                         resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);\r
2009                         if (resource == NULL)\r
2010                                 return S_OK;\r
2011                         HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);\r
2012                         if (hIcon == NULL)\r
2013                                 return S_OK;\r
2014                         DrawIconEx(lpdis->hDC,\r
2015                                 lpdis->rcItem.left - 16,\r
2016                                 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,\r
2017                                 hIcon, 16, 16,\r
2018                                 0, NULL, DI_NORMAL);\r
2019                         DestroyIcon(hIcon);\r
2020                         *pResult = TRUE;\r
2021                 }\r
2022                 break;\r
2023         case WM_MENUCHAR:\r
2024                 {\r
2025                         LPCTSTR resource;\r
2026                         TCHAR *szItem;\r
2027                         if (HIWORD(wParam) != MF_POPUP)\r
2028                                 return NOERROR;\r
2029                         int nChar = LOWORD(wParam);\r
2030                         if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))\r
2031                                 nChar = tolower(nChar);\r
2032                         // we have the char the user pressed, now search that char in all our\r
2033                         // menu items\r
2034                         std::vector<int> accmenus;\r
2035                         for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)\r
2036                         {\r
2037                                 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);\r
2038                                 if (resource == NULL)\r
2039                                         continue;\r
2040                                 szItem = stringtablebuffer;\r
2041                                 TCHAR * amp = _tcschr(szItem, '&');\r
2042                                 if (amp == NULL)\r
2043                                         continue;\r
2044                                 amp++;\r
2045                                 int ampChar = LOWORD(*amp);\r
2046                                 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))\r
2047                                         ampChar = tolower(ampChar);\r
2048                                 if (ampChar == nChar)\r
2049                                 {\r
2050                                         // yep, we found a menu which has the pressed key\r
2051                                         // as an accelerator. Add that menu to the list to\r
2052                                         // process later.\r
2053                                         accmenus.push_back(It->first);\r
2054                                 }\r
2055                         }\r
2056                         if (accmenus.size() == 0)\r
2057                         {\r
2058                                 // no menu with that accelerator key.\r
2059                                 *pResult = MAKELONG(0, MNC_IGNORE);\r
2060                                 return NOERROR;\r
2061                         }\r
2062                         if (accmenus.size() == 1)\r
2063                         {\r
2064                                 // Only one menu with that accelerator key. We're lucky!\r
2065                                 // So just execute that menu entry.\r
2066                                 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);\r
2067                                 return NOERROR;\r
2068                         }\r
2069                         if (accmenus.size() > 1)\r
2070                         {\r
2071                                 // we have more than one menu item with this accelerator key!\r
2072                                 MENUITEMINFO mif;\r
2073                                 mif.cbSize = sizeof(MENUITEMINFO);\r
2074                                 mif.fMask = MIIM_STATE;\r
2075                                 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)\r
2076                                 {\r
2077                                         GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);\r
2078                                         if (mif.fState == MFS_HILITE)\r
2079                                         {\r
2080                                                 // this is the selected item, so select the next one\r
2081                                                 ++it;\r
2082                                                 if (it == accmenus.end())\r
2083                                                         *pResult = MAKELONG(accmenus[0], MNC_SELECT);\r
2084                                                 else\r
2085                                                         *pResult = MAKELONG(*it, MNC_SELECT);\r
2086                                                 return NOERROR;\r
2087                                         }\r
2088                                 }\r
2089                                 *pResult = MAKELONG(accmenus[0], MNC_SELECT);\r
2090                         }\r
2091                 }\r
2092                 break;\r
2093         default:\r
2094                 return NOERROR;\r
2095         }\r
2096 \r
2097         return NOERROR;\r
2098 }\r
2099 \r
2100 LPCTSTR CShellExt::GetMenuTextFromResource(int id)\r
2101 {\r
2102         TCHAR textbuf[255];\r
2103         LPCTSTR resource = NULL;\r
2104         unsigned __int64 layout = g_ShellCache.GetMenuLayout();\r
2105         space = 6;\r
2106 \r
2107         int menuIndex = 0;\r
2108         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
2109         {\r
2110                 if (menuInfo[menuIndex].command == id)\r
2111                 {\r
2112                         MAKESTRING(menuInfo[menuIndex].menuTextID);\r
2113                         resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);\r
2114                         switch (id)\r
2115                         {\r
2116                         case ShellMenuLock:\r
2117                                 // menu lock is special because it can be set to the top\r
2118                                 // with a separate option in the registry\r
2119                                 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;\r
2120                                 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))\r
2121                                 {\r
2122                                         _tcscpy_s(textbuf, 255, _T("Git "));\r
2123                                         _tcscat_s(textbuf, 255, stringtablebuffer);\r
2124                                         _tcscpy_s(stringtablebuffer, 255, textbuf);\r
2125                                 }\r
2126                                 break;\r
2127                                 // the sub menu entries are special because they're *always* on the top level menu\r
2128                         case ShellSubMenuMultiple:\r
2129                         case ShellSubMenuLink:\r
2130                         case ShellSubMenuFolder:\r
2131                         case ShellSubMenuFile:\r
2132                         case ShellSubMenu:\r
2133                                 space = 0;\r
2134                                 break;\r
2135                         default:\r
2136                                 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;\r
2137                                 if (layout & (menuInfo[menuIndex].menuID)) \r
2138                                 {\r
2139                                         _tcscpy_s(textbuf, 255, _T("Git "));\r
2140                                         _tcscat_s(textbuf, 255, stringtablebuffer);\r
2141                                         _tcscpy_s(stringtablebuffer, 255, textbuf);\r
2142                                 }\r
2143                                 break;\r
2144                         }\r
2145                         return resource;\r
2146                 }\r
2147                 menuIndex++;\r
2148         }\r
2149         return NULL;\r
2150 }\r
2151 \r
2152 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)\r
2153 {\r
2154         int i=0;\r
2155         TCHAR buf[MAX_PATH];    //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!\r
2156         LPITEMIDLIST pidl = NULL;\r
2157         while (cslidarray[i])\r
2158         {\r
2159                 ++i;\r
2160                 pidl = NULL;\r
2161                 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)\r
2162                         continue;\r
2163                 if (!SHGetPathFromIDList(pidl, buf))\r
2164                 {\r
2165                         // not a file system path, definitely illegal for our use\r
2166                         CoTaskMemFree(pidl);\r
2167                         continue;\r
2168                 }\r
2169                 CoTaskMemFree(pidl);\r
2170                 if (_tcslen(buf)==0)\r
2171                         continue;\r
2172                 if (_tcscmp(buf, folder.c_str())==0)\r
2173                         return true;\r
2174         }\r
2175         return false;\r
2176 }\r
2177 \r
2178 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)\r
2179 {\r
2180         HMENU ignoresubmenu = NULL;\r
2181         int indexignoresub = 0;\r
2182         bool bShowIgnoreMenu = false;\r
2183         TCHAR maskbuf[MAX_PATH];                // MAX_PATH is ok, since this only holds a filename\r
2184         TCHAR ignorepath[MAX_PATH];             // MAX_PATH is ok, since this only holds a filename\r
2185         if (files_.size() == 0)\r
2186                 return;\r
2187         UINT icon = bShowIcons ? IDI_IGNORE : 0;\r
2188 \r
2189         std::vector<stdstring>::iterator I = files_.begin();\r
2190         if (_tcsrchr(I->c_str(), '\\'))\r
2191                 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);\r
2192         else\r
2193                 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());\r
2194         if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))\r
2195         {\r
2196                 // check if the item name is ignored or the mask\r
2197                 size_t p = 0;\r
2198                 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )\r
2199                 {\r
2200                         if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))\r
2201                                 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )\r
2202                         {\r
2203                                 break;\r
2204                         }\r
2205                         p++;\r
2206                 }\r
2207                 if (p!=-1)\r
2208                 {\r
2209                         ignoresubmenu = CreateMenu();\r
2210                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2211                         stdstring verb = stdstring(ignorepath);\r
2212                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2213                         myVerbsMap[verb] = idCmd;\r
2214                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2215                         myVerbsIDMap[idCmd] = verb;\r
2216                         myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;\r
2217                         myIDMap[idCmd++] = ShellMenuUnIgnore;\r
2218                         bShowIgnoreMenu = true;\r
2219                 }\r
2220                 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));\r
2221                 if (_tcsrchr(ignorepath, '.'))\r
2222                 {\r
2223                         _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));\r
2224                         p = ignoredprops.find(maskbuf);\r
2225                         if ((p!=-1) &&\r
2226                                 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))\r
2227                         {\r
2228                                 if (ignoresubmenu==NULL)\r
2229                                         ignoresubmenu = CreateMenu();\r
2230 \r
2231                                 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);\r
2232                                 stdstring verb = stdstring(maskbuf);\r
2233                                 myVerbsMap[verb] = idCmd - idCmdFirst;\r
2234                                 myVerbsMap[verb] = idCmd;\r
2235                                 myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2236                                 myVerbsIDMap[idCmd] = verb;\r
2237                                 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;\r
2238                                 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;\r
2239                                 bShowIgnoreMenu = true;\r
2240                         }\r
2241                 }\r
2242         }\r
2243         else if ((itemStates & ITEMIS_IGNORED) == 0)\r
2244         {\r
2245                 bShowIgnoreMenu = true;\r
2246                 ignoresubmenu = CreateMenu();\r
2247                 if (itemStates & ITEMIS_ONLYONE)\r
2248                 {\r
2249                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2250                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;\r
2251                         myIDMap[idCmd++] = ShellMenuIgnore;\r
2252 \r
2253                         _tcscpy_s(maskbuf, MAX_PATH, _T("*"));\r
2254                         if (_tcsrchr(ignorepath, '.'))\r
2255                         {\r
2256                                 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));\r
2257                                 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);\r
2258                                 stdstring verb = stdstring(maskbuf);\r
2259                                 myVerbsMap[verb] = idCmd - idCmdFirst;\r
2260                                 myVerbsMap[verb] = idCmd;\r
2261                                 myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2262                                 myVerbsIDMap[idCmd] = verb;\r
2263                                 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;\r
2264                                 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;\r
2265                         }\r
2266                 }\r
2267                 else\r
2268                 {\r
2269                         MAKESTRING(IDS_MENUIGNOREMULTIPLE);\r
2270                         _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());\r
2271                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2272                         stdstring verb = stdstring(ignorepath);\r
2273                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2274                         myVerbsMap[verb] = idCmd;\r
2275                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2276                         myVerbsIDMap[idCmd] = verb;\r
2277                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;\r
2278                         myIDMap[idCmd++] = ShellMenuIgnore;\r
2279 \r
2280                         MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);\r
2281                         _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());\r
2282                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2283                         verb = stdstring(ignorepath);\r
2284                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2285                         myVerbsMap[verb] = idCmd;\r
2286                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2287                         myVerbsIDMap[idCmd] = verb;\r
2288                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;\r
2289                         myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;\r
2290                 }\r
2291         }\r
2292 \r
2293         if (bShowIgnoreMenu)\r
2294         {\r
2295                 MENUITEMINFO menuiteminfo;\r
2296                 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
2297                 menuiteminfo.cbSize = sizeof(menuiteminfo);\r
2298                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
2299                 menuiteminfo.fType = MFT_STRING;\r
2300                 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);\r
2301                 if (icon)\r
2302                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;\r
2303                 menuiteminfo.hbmpChecked = bmp;\r
2304                 menuiteminfo.hbmpUnchecked = bmp;\r
2305                 menuiteminfo.hSubMenu = ignoresubmenu;\r
2306                 menuiteminfo.wID = idCmd;\r
2307                 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));\r
2308                 if (itemStates & ITEMIS_IGNORED)\r
2309                         GetMenuTextFromResource(ShellMenuUnIgnoreSub);\r
2310                 else\r
2311                         GetMenuTextFromResource(ShellMenuIgnoreSub);\r
2312                 menuiteminfo.dwTypeData = stringtablebuffer;\r
2313                 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);\r
2314 \r
2315                 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);\r
2316                 if (itemStates & ITEMIS_IGNORED)\r
2317                 {\r
2318                         myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;\r
2319                         myIDMap[idCmd++] = ShellMenuUnIgnoreSub;\r
2320                 }\r
2321                 else\r
2322                 {\r
2323                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;\r
2324                         myIDMap[idCmd++] = ShellMenuIgnoreSub;\r
2325                 }\r
2326         }\r
2327 }\r
2328 \r
2329 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)\r
2330 {\r
2331         std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);\r
2332         if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)\r
2333                 return bitmap_it->second;\r
2334 \r
2335         HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);\r
2336         if (!hIcon)\r
2337                 return NULL;\r
2338 \r
2339         if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)\r
2340                 return NULL;\r
2341 \r
2342         SIZE sizIcon;\r
2343         sizIcon.cx = GetSystemMetrics(SM_CXSMICON);\r
2344         sizIcon.cy = GetSystemMetrics(SM_CYSMICON);\r
2345 \r
2346         RECT rcIcon;\r
2347         SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);\r
2348         HBITMAP hBmp = NULL;\r
2349 \r
2350         HDC hdcDest = CreateCompatibleDC(NULL);\r
2351         if (hdcDest)\r
2352         {\r
2353                 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))\r
2354                 {\r
2355                         HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);\r
2356                         if (hbmpOld)\r
2357                         {\r
2358                                 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };\r
2359                                 BP_PAINTPARAMS paintParams = {0};\r
2360                                 paintParams.cbSize = sizeof(paintParams);\r
2361                                 paintParams.dwFlags = BPPF_ERASE;\r
2362                                 paintParams.pBlendFunction = &bfAlpha;\r
2363 \r
2364                                 HDC hdcBuffer;\r
2365                                 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);\r
2366                                 if (hPaintBuffer)\r
2367                                 {\r
2368                                         if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))\r
2369                                         {\r
2370                                                 // If icon did not have an alpha channel we need to convert buffer to PARGB\r
2371                                                 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);\r
2372                                         }\r
2373 \r
2374                                         // This will write the buffer contents to the destination bitmap\r
2375                                         pfnEndBufferedPaint(hPaintBuffer, TRUE);\r
2376                                 }\r
2377 \r
2378                                 SelectObject(hdcDest, hbmpOld);\r
2379                         }\r
2380                 }\r
2381 \r
2382                 DeleteDC(hdcDest);\r
2383         }\r
2384 \r
2385         DestroyIcon(hIcon);\r
2386 \r
2387         if(hBmp)\r
2388                 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));\r
2389         return hBmp;\r
2390 }\r
2391 \r
2392 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)\r
2393 {\r
2394         *phBmp = NULL;\r
2395 \r
2396         BITMAPINFO bmi;\r
2397         ZeroMemory(&bmi, sizeof(bmi));\r
2398         bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\r
2399         bmi.bmiHeader.biPlanes = 1;\r
2400         bmi.bmiHeader.biCompression = BI_RGB;\r
2401 \r
2402         bmi.bmiHeader.biWidth = psize->cx;\r
2403         bmi.bmiHeader.biHeight = psize->cy;\r
2404         bmi.bmiHeader.biBitCount = 32;\r
2405 \r
2406         HDC hdcUsed = hdc ? hdc : GetDC(NULL);\r
2407         if (hdcUsed)\r
2408         {\r
2409                 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);\r