OSDN Git Service

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