Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: reimplement COM objects using ATL

Changeset 2f829ff70272

Parent d001f17422b2

by David Golub

Changes to 23 files · Browse files at 2f829ff70272 Showing diff from parent d001f17422b2 Diff from another changeset...

1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
 
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
 
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
 
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
 
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
 
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
 
721
722
723
724
725
726
727
728
 
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
 
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
 
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
 
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
 
976
977
978
979
980
981
982
983
984
985
 
986
987
988
989
990
1
2
3
4
5
6
7
8
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
 
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
 
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
 
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
 
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
 
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
 
720
721
722
723
724
725
726
727
 
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
 
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
 
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
 
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
 
975
976
 
 
 
 
 
977
978
 
 
979
980
 
981
 
 
 #include "stdafx.h" +#include "THgShell_h.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "Thgstatus.h"  #include "Winstat.h"  #include "InitStatus.h"  #include "SysInfo.h" -#include "ShellExt.h"  #include "RegistryConfig.h"  #include "TortoiseIconBitmap.h"  #include "ThgVersion.h"    #include "Msi.h"    #include "CShellExtCMenu.h"    // According to http://msdn.microsoft.com/en-us/library/bb776094%28VS.85%29.aspx  // the help texts for the commands should be reasonably short (under 40 characters)    static const MenuDescription CMenuMenuDescList[] =  {   {"commit", L"Commit...",   L"Commit changes in repository",   "menucommit.ico", 0},   {"init", L"Create Repository Here",   L"Create a new repository",   "menucreaterepos.ico", 0},   {"clone", L"Clone...",   L"Create clone here from source",   "menuclone.ico", 0},   {"shelve", L"Shelve Changes",   L"Shelve or unshelve file changes",   "shelve.ico", 0},   {"status", L"View File Status",   L"Repository status & changes",   "menushowchanged.ico", 0},   {"add", L"Add Files...",   L"Add files to version control",   "menuadd.ico", 0},   {"revert", L"Revert Files...",   L"Revert file changes",   "menurevert.ico", 0},   {"remove", L"Remove Files...",   L"Remove files from version control",   "menudelete.ico", 0},   {"rename", L"Rename File...",   L"Rename file or directory",   "general.ico", 0},   {"workbench", L"Workbench",   L"View change history of repository",   "menulog.ico", 0},   {"log", L"Revision History",   L"View change history of selected files",   "menulog.ico", 0},   {"synch", L"Synchronize",   L"Synchronize with remote repository",   "menusynch.ico", 0},   {"serve", L"Web Server",   L"Start web server for this repository",   "proxy.ico", 0},   {"update", L"Update...",   L"Update working directory",   "menucheckout.ico", 0},   {"thgstatus", L"Update Icons",   L"Update icons for this repository",   "refresh_overlays.ico", 0},   {"userconf", L"Global Settings",   L"Configure user wide settings",   "settings_user.ico", 0},   {"repoconf", L"Repository Settings",   L"Configure repository settings",   "settings_repo.ico", 0},   {"about", L"About TortoiseHg",   L"Show About Dialog",   "menuabout.ico", 0},   {"annotate", L"Annotate Files",   L"Changeset information per file line",   "menublame.ico", 0},   {"vdiff", L"Visual Diff",   L"View changes using GUI diff tool",   "TortoiseMerge.ico", 0},   {"hgignore", L"Edit Ignore Filter",   L"Edit repository ignore filter",   "ignore.ico", 0},   {"guess", L"Guess Renames",   L"Detect renames and copies",   "detect_rename.ico", 0},   {"grep", L"Search History",   L"Search file revisions for patterns",   "menurepobrowse.ico", 0},   {"forget", L"Forget Files...",   L"Remove files from version control",   "menudelete.ico", 0},   {"shellconf", L"Explorer Extension Settings",   L"Configure Explorer extension",   "settings_repo.ico", 0},     /* Add new items here */     // template   //{"", L"", L"", ".ico", 0},  };    static const char* const RepoNoFilesMenu =   "commit status shelve vdiff sep"   " add revert rename forget remove sep"   " workbench update grep sep"   " synch serve clone init thgstatus sep"   " hgignore guess sep"   " shellconf repoconf userconf sep"   " about"  ;    static const char* const RepoFilesMenu =   "commit status vdiff sep"   " add revert rename forget remove sep"   " log annotate sep"   " about"  ;    static const char* const NoRepoMenu =   "clone init shellconf userconf thgstatus sep"   " workbench sep"   " about"  ;     -void CShellExtCMenu::AddMenuList(UINT idCmd, const std::string& name) +void CShellExtCMenuBase::AddMenuList(UINT idCmd, const std::string& name)  {   TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name);   myMenuIdMap[idCmd] = myDescMap[name];  }      void GetCMenuTranslation(   const std::string& lang,   const std::string& name,   std::wstring& menuText,   std::wstring& helpText  )  {   std::wstring subkey = L"Software\\TortoiseHg\\CMenu\\";   subkey += MultibyteToWide(lang);   subkey += L"\\";   subkey += MultibyteToWide(name);     TDEBUG_TRACEW(L"GetCMenuTranslation: " << subkey);     HKEY hkey = 0;   LONG rv = RegOpenKeyExW(   HKEY_CURRENT_USER, subkey.c_str(), 0, KEY_READ, &hkey);     if (rv == ERROR_SUCCESS && hkey)   {   GetRegSZValueW(hkey, L"menuText", menuText);   GetRegSZValueW(hkey, L"helpText", helpText);   }   else   {   TDEBUG_TRACEW(   L"GetCMenuTranslation: RegOpenKeyExW(\""   << subkey << "\") failed"   );   }     if (hkey)   RegCloseKey(hkey);  }   -void CShellExtCMenu::InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz) +void CShellExtCMenuBase::InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz)  {   if (myDescMap.empty())   {   std::string lang;   GetRegistryConfig("CMenuLang", lang);     for (std::size_t i = 0; i < sz; i++)   {   MenuDescription md = menuDescs[i];     if (md.name.empty())   {   TDEBUG_TRACE("**** InitMenuMaps: ignoring entry with empty name");   break;   }     TDEBUG_TRACE("InitMenuMaps: adding " << md.name);     // Look for translation of menu and help text   if (!lang.empty())   GetCMenuTranslation(lang, md.name, md.menuText, md.helpText);     myDescMap[md.name] = md;   }     }     myMenuIdMap.clear();  }      void InsertMenuItemWithIcon1(   HMENU hMenu, UINT indexMenu, UINT idCmd,   const std::wstring& menuText, const std::string& iconName)  {   // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING   // from Win2K onward)   MENUITEMINFOW mi;   memset(&mi, 0, sizeof(mi));   mi.cbSize = sizeof(mi);   mi.fMask = MIIM_ID | MIIM_STRING;   mi.dwTypeData = const_cast<wchar_t*>(menuText.c_str());   mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;     if (SysInfo::Instance().IsVistaOrLater())   {   HBITMAP hBmp = GetTortoiseIconBitmap(iconName);   if (hBmp)   {   mi.fMask |= MIIM_BITMAP;   mi.hbmpItem = hBmp;   }   else   {   TDEBUG_TRACE(" ***** InsertMenuItemWithIcon1: can't find " + iconName);   }   }   else   {   HICON h = GetTortoiseIcon(iconName);   if (h)   {   mi.fMask |= MIIM_BITMAP | MIIM_DATA;   mi.dwItemData = (ULONG_PTR) h;   mi.hbmpItem = HBMMENU_CALLBACK;   }   else   {   TDEBUG_TRACE(" ***** InsertMenuItemWithIcon1: can't find " + iconName);   }   }   InsertMenuItemW(hMenu, indexMenu, TRUE, &mi);     TDEBUG_TRACEW(   L"InsertMenuItemWithIcon1(\"" << menuText << L"\") finished");  }      void InsertSubMenuItemWithIcon2(   HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd,   const std::wstring& menuText, const std::string& iconName)  {   // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING   // from Win2K onward)   MENUITEMINFOW mi;   memset(&mi, 0, sizeof(mi));   mi.cbSize = sizeof(mi);   mi.fMask = MIIM_SUBMENU | MIIM_ID | MIIM_STRING;   mi.dwTypeData = const_cast<wchar_t*>(menuText.c_str());   mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;   mi.hSubMenu = hSubMenu;     if (SysInfo::Instance().IsVistaOrLater())   {   HBITMAP hBmp = GetTortoiseIconBitmap(iconName);   if (hBmp)   {   mi.fMask |= MIIM_BITMAP;   mi.hbmpItem = hBmp;   }   else   {   TDEBUG_TRACE(" ***** InsertSubMenuItemWithIcon2: can't find " + iconName);   }   }   else   {   HICON h = GetTortoiseIcon(iconName);   if (h)   {   mi.fMask |= MIIM_BITMAP | MIIM_DATA;   mi.dwItemData = (ULONG_PTR) h;   mi.hbmpItem = HBMMENU_CALLBACK;   }   else   {   TDEBUG_TRACE(" ***** InsertSubMenuItemWithIcon2: can't find " + iconName);   }   }     InsertMenuItemW(hMenu, indexMenu, TRUE, &mi);     TDEBUG_TRACEW(   L"InsertMenuItemWithIcon2(\"" << menuText << L"\") finished");  }     -void CShellExtCMenu::InsertMenuItemByName( +void CShellExtCMenuBase::InsertMenuItemByName(   HMENU hMenu, const std::string& name, UINT indexMenu,   UINT idCmd, UINT idCmdFirst, const std::wstring& prefix)  {   MenuDescriptionMap::iterator iter = myDescMap.find(name);   if (iter == myDescMap.end())   {   TDEBUG_TRACE("***** InsertMenuItemByName: can't find menu info for " << name);   return;   }       MenuDescription md = iter->second;   AddMenuList(idCmd - idCmdFirst, name);   InsertMenuItemWithIcon1(   hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);  }      const std::wstring TortoiseHgMenuEntryString = L"TortoiseHg";    int HasTortoiseMenu(HMENU hMenu, bool& hasmenu)  // returns -1 on error, 0 otherwise  {   hasmenu = false;     const int count = ::GetMenuItemCount(hMenu);   if (count == -1)   {   TDEBUG_TRACE("***** HasTortoiseMenu: GetMenuItemCount returned -1");   return -1;   }     MENUITEMINFOW mii;   for (int i = 0; i < count; ++i)   {   memset(&mii, 0, sizeof(MENUITEMINFOW));   mii.cbSize = sizeof(MENUITEMINFOW);     // first GetMenuItemInfoW call: get size of menu item string   mii.fMask = MIIM_STRING;   BOOL res = ::GetMenuItemInfoW(hMenu, i, true, &mii);   if (res == 0) {   TDEBUG_TRACE("HasTortoiseMenu: "   << "first GetMenuItemInfo returned 0");   continue;   }     if (mii.dwTypeData != MFT_STRING)   {   // not a string   continue;   }     // allocate buffer for the string   std::vector<wchar_t> text(mii.cch + 1);     // second GetMenuItemInfoW call: get string into buffer   mii.dwTypeData = &text[0];   ++mii.cch; // size of buffer is one more than length of string   res = ::GetMenuItemInfoW(hMenu, i, true, &mii);   if (res == 0) {   TDEBUG_TRACE("HasTortoiseMenu: "   << "second GetMenuItemInfo returned 0");   continue;   }     const std::wstring menuitemtext(&text[0]);   //TDEBUG_TRACEW(L"HasTortoiseMenu: "   // << L"menuitemtext is '" << menuitemtext << L"'");     if (menuitemtext == TortoiseHgMenuEntryString)   {   TDEBUG_TRACE("HasTortoiseMenu: FOUND TortoiseHg menu entry");   hasmenu = true;   return 0;   }   }     TDEBUG_TRACE("HasTortoiseMenu: TortoiseHg menu entry NOT found");   return 0;  }    void -CShellExtCMenu::TweakMenuForVista(HMENU hMenu) +CShellExtCMenuBase::TweakMenuForVista(HMENU hMenu)  {   if (!SysInfo::Instance().IsVistaOrLater())   return;     MENUINFO MenuInfo = {};   MenuInfo.cbSize = sizeof(MenuInfo);   MenuInfo.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;   MenuInfo.dwStyle = MNS_CHECKORBMP;     SetMenuInfo(hMenu, &MenuInfo);  }    #define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i)))    // IContextMenu  STDMETHODIMP -CShellExtCMenu::QueryContextMenu( +CShellExtCMenuBase::QueryContextMenu(   HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)  {   TDEBUG_TRACE("CShellExtCMenu::QueryContextMenu");     UINT idCmd = idCmdFirst;   BOOL bAppendItems = TRUE;     if ((uFlags & 0x000F) == CMF_NORMAL)   bAppendItems = TRUE;   else if (uFlags & CMF_VERBSONLY)   bAppendItems = TRUE;   else if (uFlags & CMF_EXPLORE)   bAppendItems = TRUE;   else   bAppendItems = FALSE;     if (!bAppendItems)   return S_OK;     bool hasthgmenu = false;   if (HasTortoiseMenu(hMenu, hasthgmenu) == 0 && hasthgmenu)   {   TDEBUG_TRACE("CShellExtCMenu::QueryContextMenu: "   << "TortoiseHg menu entry already in menu -> skipping");   return S_OK;   }     InitMenuMaps(CMenuMenuDescList, sizeof(CMenuMenuDescList) / sizeof(MenuDescription));     typedef std::vector<std::string> entriesT;   typedef entriesT::const_iterator entriesIter;     std::string promoted_string = "commit,workbench"; // default value if key not found   GetRegistryConfig("PromotedItems", promoted_string);     entriesT promoted;   Tokenize(promoted_string, promoted, ",");     // Select menu to show   bool fileMenu = !myFiles.empty();   bool isHgrepo = false;   std::string cwd;   if (!myFolder.empty())   {   cwd = myFolder;   }   else if (fileMenu)   {   cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]);   }     if (!cwd.empty())   {   // check if target directory is a Mercurial repository   std::string root = GetHgRepoRoot(cwd);   isHgrepo = !root.empty();   if (myFiles.size() == 1 && root == myFiles[0])   {   fileMenu = false;   myFolder = cwd;   myFiles.clear();   }   }     if ((uFlags & CMF_EXTENDEDVERBS) == 0)   {   // shift key is not down   if (!isHgrepo)   {   // we are not inside a repo   std::string cval;   if (GetRegistryConfig("HideMenuOutsideRepo", cval) != 0 && cval == "1")   {   return S_OK; // don't show thg cmenu entries   }   }   }     TDEBUG_TRACE(   "CShellExtCMenu::QueryContextMenu: isHgrepo = "   << isHgrepo << ", fileMenu = " << fileMenu   );     /* We have three menu types: files-selected, no-files-selected, no-repo */   const char* entries_string = 0;   if (isHgrepo)   if (fileMenu)   entries_string = RepoFilesMenu;   else   entries_string = RepoNoFilesMenu;   else   entries_string = NoRepoMenu;     // start building TortoiseHg menus and submenus   InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);     entriesT entries;   Tokenize(entries_string, entries, " ");     for (entriesIter i = entries.begin(); i != entries.end(); i++)   {   std::string name = *i;   if (contains(promoted, name))   {   InsertMenuItemByName(   hMenu, name, indexMenu++,   idCmd++, idCmdFirst, L"Hg "   );   }   }     const HMENU hSubMenu = CreatePopupMenu();   if (hSubMenu)   {   UINT indexSubMenu = 0;   bool isSeparator = true;   for (entriesIter i = entries.begin(); i != entries.end(); i++)   {   std::string name = *i;   if (name == "sep")   {   if (!isSeparator)   {   InsertMenu(   hSubMenu, indexSubMenu++,   MF_SEPARATOR | MF_BYPOSITION, 0, NULL   );   isSeparator = true;   }   }   else   {   if (!contains(promoted, name))   {   InsertMenuItemByName(   hSubMenu, name,   indexSubMenu++, idCmd++, idCmdFirst, L""   );   isSeparator = false;   }   }   }   if (isSeparator && indexSubMenu > 0)   RemoveMenu(hSubMenu, indexSubMenu - 1, MF_BYPOSITION);     TweakMenuForVista(hSubMenu);     }     TDEBUG_TRACE(" CShellExtCMenu::QueryContextMenu: adding main THG menu");   InsertSubMenuItemWithIcon2(hMenu, hSubMenu, indexMenu++, idCmd++,   TortoiseHgMenuEntryString, "hg.ico");     InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);     InitStatus::check();     TweakMenuForVista(hMenu);     return ResultFromShort(idCmd - idCmdFirst);  }      STDMETHODIMP -CShellExtCMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) +CShellExtCMenuBase::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)  {   TDEBUG_TRACE("CShellExtCMenu::InvokeCommand");     HRESULT hr = E_INVALIDARG;   if (!HIWORD(lpcmi->lpVerb))   {   UINT idCmd = LOWORD(lpcmi->lpVerb);   TDEBUG_TRACE("CShellExtCMenu::InvokeCommand: idCmd = " << idCmd);   MenuIdCmdMap::iterator iter = myMenuIdMap.find(idCmd);   if (iter != myMenuIdMap.end())   {   RunDialog(iter->second.name);   hr = S_OK;   }   else   {   TDEBUG_TRACE(   "***** CShellExtCMenu::InvokeCommand: action not found for idCmd "   << idCmd   );   }   }   return hr;  }      STDMETHODIMP -CShellExtCMenu::GetCommandString( +CShellExtCMenuBase::GetCommandString(   UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved,   LPSTR pszName, UINT cchMax)  {   // see http://msdn.microsoft.com/en-us/library/bb776094%28VS.85%29.aspx     HRESULT res = S_FALSE;     const char* psz = "";   const wchar_t* pszw = 0;     std::string sflags = "?";   switch (uFlags)   {   case GCS_HELPTEXTW:   sflags = "GCS_HELPTEXTW"; break;   case GCS_HELPTEXTA:   sflags = "GCS_HELPTEXTA"; break;   case GCS_VALIDATEW:   sflags = "GCS_VALIDATEW"; break;   case GCS_VALIDATEA:   sflags = "GCS_VALIDATEA"; break;   case GCS_VERBW:   sflags = "GCS_VERBW"; break;   case GCS_VERBA:   sflags = "GCS_VERBA"; break;   }     TDEBUG_TRACE(   "CShellExtCMenu::GetCommandString: idCmd = " << idCmd   << ", uFlags = " << uFlags << " (" << sflags << ")"   << ", cchMax = " << cchMax   );     MenuIdCmdMap::iterator iter = myMenuIdMap.find(static_cast<UINT>(idCmd));   if (iter == myMenuIdMap.end())   {   TDEBUG_TRACE("***** CShellExtCMenu::GetCommandString: idCmd not found");   }   else   {   TDEBUG_TRACE(   "CShellExtCMenu::GetCommandString: name = \"" << iter->second.name << "\"");     if (uFlags == GCS_HELPTEXTW)   {   pszw = iter->second.helpText.c_str();   res = S_OK;     size_t size = iter->second.helpText.size();   if (size >= 40)   {   TDEBUG_TRACE(   "***** CShellExtCMenu::GetCommandString: warning:"   << " length of help text is " << size   << ", which is not reasonably short (<40)");   }   }   else if (uFlags == GCS_HELPTEXTA)   {   // we don't provide ansi help texts   psz = "";   res = S_OK;   }   else if (uFlags == GCS_VERBW || uFlags == GCS_VERBA)   {  #if 0   psz = iter->second.name.c_str();  #else   // bugfix: don't provide verbs ("rename" conflicted with rename of explorer)   psz = "";  #endif   res = S_OK;   }   else if (uFlags == GCS_VALIDATEW || uFlags == GCS_VALIDATEA)   {   res = S_OK;   }   }     if (cchMax < 1)   {   TDEBUG_TRACE("CShellExtCMenu::GetCommandString: cchMax = "   << cchMax << " (is <1)");   return res;   }     size_t size = 0;     if (uFlags & GCS_UNICODE)   {   wchar_t* const dest = reinterpret_cast<wchar_t*>(pszName);   std::wstring wpsz = MultibyteToWide(psz);   const wchar_t* const src = pszw ? pszw : wpsz.c_str();     wcsncpy_s(dest, cchMax, src, cchMax-1);   *(dest + cchMax-1) = 0;     size = wcslen(src);     TDEBUG_TRACEW(L"CShellExtCMenu::GetCommandString: res = " << int(res)   << L", pszName (wide) = \"" << dest << L"\"");   }   else   {   strncpy_s(pszName, cchMax, psz, cchMax-1);   *(pszName + cchMax-1) = 0;     size = strlen(psz);     TDEBUG_TRACE("CShellExtCMenu::GetCommandString: res = " << int(res)   << ", pszName = \"" << psz << "\"");   }     if (size > cchMax-1)   {   TDEBUG_TRACE(   "***** CShellExtCMenu::GetCommandString: string was truncated: size = "   << size << ", cchMax = " << cchMax);   }     return res;  }      STDMETHODIMP -CShellExtCMenu::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) +CShellExtCMenuBase::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)  {   LRESULT res;   return HandleMenuMsg2(uMsg, wParam, lParam, &res);  }      STDMETHODIMP -CShellExtCMenu::HandleMenuMsg2( +CShellExtCMenuBase::HandleMenuMsg2(   UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)  {   // A great tutorial on owner drawn menus in shell extension can be found   // here: http://www.codeproject.com/shell/shellextguide7.asp     LRESULT res;   if (!pResult)   pResult = &res;   *pResult = FALSE;     switch (uMsg)   {   case WM_MEASUREITEM:   {   MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;   if (lpmis==NULL)   break;   lpmis->itemWidth += 2;   if(lpmis->itemHeight < 16)   lpmis->itemHeight = 16;   *pResult = TRUE;   }   break;     case WM_DRAWITEM:   {   DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;   if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData)   break; //not for a menu   DrawIconEx(   lpdis->hDC,   lpdis->rcItem.left - 16,   lpdis->rcItem.top   + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,   (HICON) lpdis->itemData, 16, 16,   0, 0, DI_NORMAL   );   *pResult = TRUE;   }   break;     default:   return S_OK;   }     return S_OK;  }     -void CShellExtCMenu::RunDialog(const std::string &cmd) +void CShellExtCMenuBase::RunDialog(const std::string &cmd)  {   std::string dir = GetTHgProgRoot();   if (dir.empty())   {   TDEBUG_TRACE("RunDialog: THG root is empty");   return;   }   std::string hgcmd = dir + "\\thgw.exe";     WIN32_FIND_DATAA data;   HANDLE hfind = FindFirstFileA(hgcmd.c_str(), &data);   if (hfind == INVALID_HANDLE_VALUE)   {   hgcmd = dir + "\\hgtk.exe";   hfind = FindFirstFileA(hgcmd.c_str(), &data);   if (hfind == INVALID_HANDLE_VALUE)   hgcmd = dir + "\\thg.cmd";   else   FindClose(hfind);   }   else   FindClose(hfind);     hgcmd = Quote(hgcmd) + " --nofork " + cmd;     std::string cwd;   if (!myFolder.empty())   {   cwd = myFolder;   }   else if (!myFiles.empty())   {   cwd = IsDirectory(myFiles[0]) ? myFiles[0] : DirName(myFiles[0]);   }   else   {   TDEBUG_TRACE("***** RunDialog: can't get cwd");   return;   }     if (cmd == "thgstatus")   {   if (Thgstatus::remove(cwd) != 0)   {   std::string p = dir + "\\TortoiseHgOverlayServer.exe";   LaunchCommand(Quote(p), dir);   }   InitStatus::check();   return;   }     if (!myFiles.empty())   {   const std::string tempfile = GetTemporaryFile();   if (tempfile.empty())   {   TDEBUG_TRACE("***** RunDialog: error: GetTemporaryFile returned empty string");   return;   }     TDEBUG_TRACE("RunDialog: temp file = " << tempfile);   HANDLE tempfileHandle = CreateFileA(   tempfile.c_str(), GENERIC_WRITE,   FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0   );     if (tempfileHandle == INVALID_HANDLE_VALUE)   {   TDEBUG_TRACE("***** RunDialog: error: failed to create file " << tempfile);   return;   }     typedef std::vector<std::string>::size_type ST;   for (ST i = 0; i < myFiles.size(); i++)   {   DWORD dwWritten;   TDEBUG_TRACE("RunDialog: temp file adding " << myFiles[i]);   WriteFile(   tempfileHandle, myFiles[i].c_str(),   static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0   );   WriteFile(tempfileHandle, "\n", 1, &dwWritten, 0);   }   CloseHandle(tempfileHandle);   hgcmd += " --listfile " + Quote(tempfile);   }     LaunchCommand(hgcmd, cwd);   InitStatus::check();  }   -void CShellExtCMenu::PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj) +void CShellExtCMenuBase::PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj)  {   TDEBUG_TRACE("CShellExtCMenu::Initialize");     // get installed MSI product id (for debugging purposes for now)  #ifdef _M_X64   const char* shellexid = "{D5D1E532-CDAD-4FFD-9695-757B8A29B4BA}";  #else   const char* shellexid = "{728E8840-5878-4EA7-918F-281C2697ABB1}";  #endif   std::vector<char> product_id(50, 0);   UINT msires = ::MsiGetProductCodeA(shellexid, &product_id[0]);   TDEBUG_TRACE("MSI shellexid: " << shellexid);   TDEBUG_TRACE("MSI msires: " << msires);   TDEBUG_TRACE("MSI installed product id: " << &product_id[0]);     DWORD busize = 300;   std::vector<char> buf(busize, 0);   msires = ::MsiGetProductInfoA(   &product_id[0], INSTALLPROPERTY_INSTALLLOCATION, &buf[0], &busize);   if (msires == ERROR_SUCCESS)   {   TDEBUG_TRACE("MSI install location: " << &buf[0]);   }   else   {   TDEBUG_TRACE("MSI install location: error " << msires);   }     TDEBUG_TRACEW(   L"---- TortoiseHg shell extension version "   << ThgVersion::get() << L"----"   );     TDEBUG_TRACE(" pIDFolder: " << pIDFolder);   TDEBUG_TRACE(" pDataObj: " << pDataObj);  }   -STDMETHODIMP CShellExtCMenu::Initialize( +STDMETHODIMP CShellExtCMenuBase::Initialize(   LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey)  {   TCHAR name[MAX_PATH+1];     PrintDebugHeader(pIDFolder, pDataObj);     myFolder.clear();   myFiles.clear();     if (pDataObj)   {   FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };   STGMEDIUM stg = { TYMED_HGLOBAL };   if (SUCCEEDED(pDataObj->GetData(&fmt, &stg)) && stg.hGlobal)   {   HDROP hDrop = (HDROP) GlobalLock(stg.hGlobal);     if (hDrop)   {   UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);   TDEBUG_TRACE(" hDrop uNumFiles = " << uNumFiles);   for (UINT i = 0; i < uNumFiles; ++i) {   if (DragQueryFile(hDrop, i, name, MAX_PATH) > 0)   {   TDEBUG_TRACE(" DragQueryFile [" << i << "] = " << name);   myFiles.push_back(name);   }   }   }   else   {   TDEBUG_TRACE(" hDrop is NULL ");   }     GlobalUnlock(stg.hGlobal);   if (stg.pUnkForRelease)   {   IUnknown* relInterface = (IUnknown*) stg.pUnkForRelease;   relInterface->Release();   }   }   else   {   TDEBUG_TRACE(" pDataObj->GetData failed");   }   }     // if a directory background   if (pIDFolder)   {   SHGetPathFromIDList(pIDFolder, name);   TDEBUG_TRACE(" Folder " << name);   myFolder = name;   }     // disable context menu if neither the folder nor the files   // have been found   if (myFolder.empty() && myFiles.empty()) {   TDEBUG_TRACE(" shell extension not available on this object");   return E_FAIL;   } else {   return S_OK;   }  }     -CShellExtCMenu::CShellExtCMenu(const char dummy) +CShellExtCMenuBase::CShellExtCMenuBase()  { - CShellExt::IncDllRef(); - ADDIFACE(IShellExtInit); - ADDIFACE(IContextMenu); - ADDIFACE(IContextMenu2); - ADDIFACE(IContextMenu3);  }   - -CShellExtCMenu::~CShellExtCMenu() +CShellExtCMenu::CShellExtCMenu()  { - CShellExt::DecDllRef();  } - -IMPLEMENT_UNKNOWN(CShellExtCMenu)
 
5
6
7
8
9
10
11
12
 
21
22
23
24
 
 
 
 
25
26
27
28
29
30
31
 
42
43
44
45
46
 
47
48
 
 
 
 
 
 
49
50
51
 
64
65
66
 
 
 
 
 
 
 
 
 
67
68
 
5
6
7
 
 
8
9
10
 
19
20
21
 
22
23
24
25
26
 
27
 
28
29
30
 
41
42
43
 
 
44
45
 
46
47
48
49
50
51
52
53
54
 
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@@ -5,8 +5,6 @@
 #include <string>  #include <map>   -#include "SimpleUnknown.h" -  struct MenuDescription  {   std::string name; @@ -21,11 +19,12 @@
 typedef std::map<UINT, MenuDescription> MenuIdCmdMap;     -class CShellExtCMenu: public CSimpleUnknown, IContextMenu3, IShellExtInit +class CShellExtCMenuBase : + public CComObjectRootEx<CComMultiThreadModel>, + public IContextMenu3, + public IShellExtInit  { -  protected: - ULONG m_cRef;   std::vector<std::string> myFiles;   std::string myFolder;   MenuDescriptionMap myDescMap; @@ -42,10 +41,14 @@
  void AddMenuList(UINT idCmd, const std::string& name);    public: - explicit CShellExtCMenu(const char dummy); - ~CShellExtCMenu(); + CShellExtCMenuBase();   - DECLARE_UNKNOWN() + BEGIN_COM_MAP(CShellExtCMenuBase) + COM_INTERFACE_ENTRY(IContextMenu) + COM_INTERFACE_ENTRY(IContextMenu2) + COM_INTERFACE_ENTRY(IContextMenu3) + COM_INTERFACE_ENTRY(IShellExtInit) + END_COM_MAP()     // IContextMenu3   STDMETHOD(QueryContextMenu)( @@ -64,5 +67,14 @@
  LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);  };   +class CShellExtCMenu : + public CShellExtCMenuBase, + public CComCoClass<CShellExtCMenu, &CLSID_TortoiseHgCmenu> +{ +public: + CShellExtCMenu(); + + DECLARE_REGISTRY_RESOURCE(IDR_CMENU) +};    #endif
Change 1 of 1 Show Entire File win32/​shellext/​CShellExtCMenu.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {46605027-5B8C-4DCE-BFE0-051B7972D64C} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
 
1
 
2
3
4
 
77
78
79
80
 
81
82
83
 
163
164
165
166
167
 
168
169
170
 
1
2
3
4
5
 
78
79
80
 
81
82
83
84
 
164
165
166
 
 
167
168
169
170
@@ -1,4 +1,5 @@
 #include "stdafx.h" +#include "THgShell_h.h"  #include "TortoiseUtils.h"    #include "CShellExtDnd.h" @@ -77,7 +78,7 @@
  //Append the current directory as the dest   myFiles.push_back(myFolder);   } - CShellExtCMenu::RunDialog(cmd); + CShellExtCMenuBase::RunDialog(cmd);  }     @@ -163,8 +164,7 @@
 }     -CShellExtDnd::CShellExtDnd(const char dummy) : - CShellExtCMenu(dummy) +CShellExtDnd::CShellExtDnd()  {  }  
 
4
5
6
7
8
 
 
 
9
10
11
12
13
14
15
 
16
17
 
 
18
19
20
 
4
5
6
 
 
7
8
9
10
11
12
13
14
15
 
16
17
18
19
20
21
22
23
@@ -4,17 +4,20 @@
 #include "CShellExtCMenu.h"     -//CShellExtCMenu implements IContextMenu3, IShellExtInit -class CShellExtDnd: public CShellExtCMenu +// CShellExtCMenuBase implements IContextMenu3, IShellExtInit +class CShellExtDnd : public CShellExtCMenuBase, + public CComCoClass<CShellExtDnd, &CLSID_TortoiseHgDropHandler>  {    protected:   virtual void RunDialog(const std::string&);    public: - explicit CShellExtDnd(const char dummy); + explicit CShellExtDnd();   ~CShellExtDnd();   + DECLARE_REGISTRY_RESOURCE(IDR_DRAGDROP) +   // IContextMenu3   STDMETHOD(QueryContextMenu)(   HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast,
Change 1 of 1 Show Entire File win32/​shellext/​CShellExtDnd.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {CEBD95BE-B733-415F-82A8-673D9158466E} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
 
1
2
 
3
4
5
6
7
8
9
10
 
11
12
13
 
30
31
32
33
 
34
35
36
 
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
3
4
5
6
7
8
 
 
9
10
11
12
 
29
30
31
 
32
33
34
35
 
76
77
78
 
 
79
80
 
81
82
 
83
84
 
 
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
@@ -1,13 +1,12 @@
 #include "stdafx.h" -#include "ShellExt.h" +#include "THgShell_h.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "QueryDirstate.h"  #include "RegistryConfig.h"  #include "CShellExtOverlay.h"   -#include <shlwapi.h> - +CComAutoCriticalSection CShellExtOverlay::m_cs;    STDMETHODIMP CShellExtOverlay::GetOverlayInfo(   LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags) @@ -30,7 +29,7 @@
   STDMETHODIMP CShellExtOverlay::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)  { - ThgCriticalSection cs(CShellExt::GetCriticalSection()); + CComCritSecLock<CComAutoCriticalSection> lock(m_cs);     std::string cval;   if (GetRegistryConfig("EnableOverlays", cval) != 0 && cval == "0") @@ -77,14 +76,28 @@
 CShellExtOverlay::CShellExtOverlay(char tortoiseClass) :   myTortoiseClass(tortoiseClass)  { - CShellExt::IncDllRef(); - ADDIFACE(IShellIconOverlayIdentifier);  }   -  CShellExtOverlay::~CShellExtOverlay()  { - CShellExt::DecDllRef();  }   -IMPLEMENT_UNKNOWN(CShellExtOverlay) \ No newline at end of file
+CTortoiseHgNormal::CTortoiseHgNormal() : + CShellExtOverlay('C') +{ +} + +CTortoiseHgAdded::CTortoiseHgAdded() : + CShellExtOverlay('A') +{ +} + +CTortoiseHgModified::CTortoiseHgModified() : + CShellExtOverlay('M') +{ +} + +CTortoiseHgUnversioned::CTortoiseHgUnversioned() : + CShellExtOverlay('?') +{ +}
 
1
2
3
4
 
 
 
 
 
5
6
7
8
9
10
11
12
13
14
 
 
 
15
16
17
 
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24
 
1
2
3
 
4
5
6
7
8
9
 
 
10
11
12
13
14
15
 
16
17
18
19
20
21
 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@@ -1,17 +1,21 @@
 #ifndef _CShellExtOverlay_h_  #define _CShellExtOverlay_h_   -#include "SimpleUnknown.h" +class CShellExtOverlay : + public CComObjectRootEx<CComMultiThreadModel>, + public IShellIconOverlayIdentifier +{ + static CComAutoCriticalSection m_cs;   -class CShellExtOverlay: public CSimpleUnknown, public IShellIconOverlayIdentifier -{   const char myTortoiseClass;    public:   explicit CShellExtOverlay(char Class);   ~CShellExtOverlay();   - DECLARE_UNKNOWN() + BEGIN_COM_MAP(CShellExtOverlay) + COM_INTERFACE_ENTRY(IShellIconOverlayIdentifier) + END_COM_MAP()     // IShellIconOverlayIdentifier   STDMETHOD(GetOverlayInfo)( @@ -20,5 +24,44 @@
  STDMETHOD(IsMemberOf)(LPCWSTR pwszPath, DWORD dwAttrib);  };   +class CTortoiseHgNormal : + public CShellExtOverlay, + public CComCoClass<CTortoiseHgNormal, &CLSID_TortoiseHgNormal> +{ +public: + CTortoiseHgNormal(); + + DECLARE_REGISTRY_RESOURCE(IDR_NORMAL) +}; + +class CTortoiseHgAdded : + public CShellExtOverlay, + public CComCoClass<CTortoiseHgAdded, &CLSID_TortoiseHgAdded> +{ +public: + CTortoiseHgAdded(); + + DECLARE_REGISTRY_RESOURCE(IDR_ADDED) +}; + +class CTortoiseHgModified : + public CShellExtOverlay, + public CComCoClass<CTortoiseHgModified, &CLSID_TortoiseHgNormal> +{ +public: + CTortoiseHgModified(); + + DECLARE_REGISTRY_RESOURCE(IDR_MODIFIED) +}; + +class CTortoiseHgUnversioned : + public CShellExtOverlay, + public CComCoClass<CTortoiseHgUnversioned, &CLSID_TortoiseHgNormal> +{ +public: + CTortoiseHgUnversioned(); + + DECLARE_REGISTRY_RESOURCE(IDR_UNVERSIONED) +};    #endif
 
1
 
 
 
 
2
3
4
5
6
7
8
9
10
11
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
 
 
 
 
 
 
39
40
41
42
43
44
45
46
47
 
48
49
50
51
52
53
 
54
55
56
57
58
59
60
61
62
63
 
64
65
66
67
 
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
133
134
135
136
137
138
139
140
141
142
143
 
1
2
3
4
5
6
7
8
9
 
10
11
12
 
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
 
30
31
32
33
34
 
 
35
36
37
38
39
40
 
41
42
43
 
44
45
46
 
 
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
 
 
 
 
 
 
 
 
 
 
@@ -1,143 +1,50 @@
 #include "stdafx.h" +#include <initguid.h> +#include "THgShell_h.h" +#include "THgShell_i.c" +  #include "ShellExt.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "InitStatus.h" -#include "ThgClassFactory.h"  #include "CShellExtCMenu.h"  #include "CShellExtDnd.h"  #include "CShellExtOverlay.h" -#include "ThgCLSIDs.h"   +CComModule _Module;   -#define TOLSTR(x) L ## #x -#define TOLSTR2(x) TOLSTR(x) - -#define CLSID_TortoiseHgCmenu TOLSTR2(THG_CLSID_TortoiseHgCmenu) -#define CLSID_TortoiseHgDropHandler TOLSTR2(THG_CLSID_TortoiseHgDropHandler) -#define CLSID_TortoiseHgNormal TOLSTR2(THG_CLSID_TortoiseHgNormal) -#define CLSID_TortoiseHgAdded TOLSTR2(THG_CLSID_TortoiseHgAdded) -#define CLSID_TortoiseHgModified TOLSTR2(THG_CLSID_TortoiseHgModified) -#define CLSID_TortoiseHgUnversioned TOLSTR2(THG_CLSID_TortoiseHgUnversioned) - -CRITICAL_SECTION CShellExt::cs_; -HMODULE CShellExt::hModule_ = NULL; -UINT CShellExt::cRef_ = 0; - -typedef struct -{ - HKEY hRootKey; - LPTSTR lpszSubKey; - LPTSTR lpszValueName; - LPTSTR lpszData; -} REGSTRUCT, *LPREGSTRUCT; - - -VOID _LoadResources(); -VOID _UnloadResources(); - +BEGIN_OBJECT_MAP(ObjectMap) + OBJECT_ENTRY(CLSID_TortoiseHgCmenu, CShellExtCMenu) + OBJECT_ENTRY(CLSID_TortoiseHgDropHandler, CShellExtDnd) + OBJECT_ENTRY(CLSID_TortoiseHgNormal, CTortoiseHgNormal) + OBJECT_ENTRY(CLSID_TortoiseHgAdded, CTortoiseHgAdded) + OBJECT_ENTRY(CLSID_TortoiseHgModified, CTortoiseHgModified) + OBJECT_ENTRY(CLSID_TortoiseHgUnversioned, CTortoiseHgUnversioned) +END_OBJECT_MAP()    BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)  {   if (dwReason == DLL_PROCESS_ATTACH)   {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); - CShellExt::hModule_ = hInstance; - ::InitializeCriticalSection(CShellExt::GetCriticalSection()); - _LoadResources(); + _Module.Init(ObjectMap, hInstance, &LIBID_THgShell);   }   else if (dwReason == DLL_PROCESS_DETACH)   {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); - ::DeleteCriticalSection(CShellExt::GetCriticalSection()); - _UnloadResources(); + _Module.Term();   }     return 1;  }   -  STDAPI DllCanUnloadNow(void)  {   TDEBUG_TRACE("DllCanUnloadNow"); - return (CShellExt::GetRefCount() == 0 ? S_OK : S_FALSE); + return _Module.GetLockCount() == 0 ? S_OK : S_FALSE;  }   - -STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut) +STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)  { - std::wstring clsid; - { - LPWSTR ptr = 0; - ::StringFromIID(rclsid, &ptr); - clsid = ptr; - ::CoTaskMemFree(ptr); - } - - TDEBUG_TRACEW("DllGetClassObject clsid = " << clsid); - - if (ppvOut == 0) - { - TDEBUG_TRACE("**** DllGetClassObject: error: ppvOut is 0"); - return E_POINTER; - } - - *ppvOut = NULL; - - typedef ThgClassFactory<CShellExtOverlay> FactOvl; - typedef ThgClassFactory<CShellExtCMenu> FactCmenu; - typedef ThgClassFactory<CShellExtDnd> FactDnd; - - if (clsid == CLSID_TortoiseHgCmenu) - { - FactCmenu *pcf = new FactCmenu(0); - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgCmenu"); - return pcf->QueryInterface(riid, ppvOut); - } - else if (clsid == CLSID_TortoiseHgDropHandler) - { - FactDnd *pcf = new FactDnd(0); - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgDropHandler"); - return pcf->QueryInterface(riid, ppvOut); - } - else if (clsid == CLSID_TortoiseHgNormal) - { - FactOvl *pcf = new FactOvl('C'); // clean - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgNormal"); - ++InitStatus::inst().unchanged_; - return pcf->QueryInterface(riid, ppvOut); - } - else if (clsid == CLSID_TortoiseHgAdded) - { - FactOvl *pcf = new FactOvl('A'); // added - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgAdded"); - ++InitStatus::inst().added_; - return pcf->QueryInterface(riid, ppvOut); - } - else if (clsid == CLSID_TortoiseHgModified) - { - FactOvl *pcf = new FactOvl('M'); // modified - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgModified"); - ++InitStatus::inst().modified_; - return pcf->QueryInterface(riid, ppvOut); - } - else if (clsid == CLSID_TortoiseHgUnversioned) - { - FactOvl *pcf = new FactOvl('?'); // not in repo - TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgUnversioned"); - ++InitStatus::inst().notinrepo_; - return pcf->QueryInterface(riid, ppvOut); - } - - return CLASS_E_CLASSNOTAVAILABLE; + return _Module.GetClassObject(rclsid, riid, ppv);  } - - -VOID _LoadResources(VOID) -{ -} - - -VOID _UnloadResources(VOID) -{ -}
Change 1 of 1 Show Entire File win32/​shellext/​ShellExt.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,38 +0,0 @@
-#ifndef _SHELL_EXT_H_ -#define _SHELL_EXT_H_ - - -class CShellExt -{ - static CRITICAL_SECTION cs_; - static HMODULE hModule_; - static UINT cRef_; - -public: - static LPCRITICAL_SECTION GetCriticalSection() { return &cs_; } - static UINT GetRefCount() { return cRef_; } - static void IncDllRef() { ::InterlockedIncrement(&cRef_); } - static void DecDllRef() { ::InterlockedDecrement(&cRef_); } - - friend BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); -}; - - -class ThgCriticalSection -{ - LPCRITICAL_SECTION cs_; - -public: - ThgCriticalSection(LPCRITICAL_SECTION cs): cs_(cs) - { - ::EnterCriticalSection(cs_); - } - - ~ThgCriticalSection() - { - ::LeaveCriticalSection(cs_); - } -}; - - -#endif // _SHELL_EXT_H_
Change 1 of 1 Show Entire File win32/​shellext/​SimpleUnknown.cpp Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,65 +0,0 @@
-// Copyright (C) 2011 Fog Creek Software -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -#include "stdafx.h" - -#include "SimpleUnknown.h" - -CSimpleUnknown::CSimpleUnknown() - : cRef_(0) -{ - AddInterface(IID_IUnknown, this); -} - -CSimpleUnknown::~CSimpleUnknown() -{ -} - -void CSimpleUnknown::AddInterface(REFIID riid, LPUNKNOWN punk) -{ - Entry e(riid, punk); - entries_.push_back(e); -} - -STDMETHODIMP CSimpleUnknown::QueryInterface(REFIID riid, LPVOID FAR* ppv) -{ - if (ppv == NULL) - return E_POINTER; - - for (EntriesT::const_iterator i = entries_.begin(); i != entries_.end(); ++i) - { - if (i->iid == riid) - { - i->punk->AddRef(); - *ppv = i->punk; - return S_OK; - } - } - *ppv = NULL; - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) CSimpleUnknown::AddRef() -{ - return ::InterlockedIncrement(&cRef_); -} - -STDMETHODIMP_(ULONG) CSimpleUnknown::Release() -{ - if (::InterlockedDecrement(&cRef_)) - return cRef_; - delete this; - return 0L; -}
Change 1 of 1 Show Entire File win32/​shellext/​SimpleUnknown.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,81 +0,0 @@
-// Copyright (C) 2011 Fog Creek Software -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -#ifndef _SIMPLEUNKNOWN_H_ -#define _SIMPLEUNKNOWN_H_ - -#include <vector> - -#define DECLARE_UNKNOWN() \ - STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR* ppv); \ - STDMETHOD_(ULONG, AddRef)(); \ - STDMETHOD_(ULONG, Release)(); \ - -#define IMPLEMENT_UNKNOWN(classname) \ - STDMETHODIMP classname::QueryInterface(REFIID riid, LPVOID FAR* ppv) \ - { \ - return CSimpleUnknown::QueryInterface(riid, ppv); \ - } \ - STDMETHODIMP_(ULONG) classname::AddRef() \ - { \ - return CSimpleUnknown::AddRef(); \ - } \ - STDMETHODIMP_(ULONG) classname::Release() \ - { \ - return CSimpleUnknown::Release(); \ - } - -#define INLINE_UNKNOWN() \ - STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv) \ - { \ - return CSimpleUnknown::QueryInterface(riid, ppv); \ - } \ - STDMETHODIMP_(ULONG) AddRef() \ - { \ - return CSimpleUnknown::AddRef(); \ - } \ - STDMETHODIMP_(ULONG) Release() \ - { \ - return CSimpleUnknown::Release(); \ - } - -#define ADDIFACE(iface) \ - AddInterface(IID_##iface, (iface*)this) - -class CSimpleUnknown : public IUnknown -{ - struct Entry - { - Entry(IID iid, LPUNKNOWN punk): iid(iid), punk(punk) {} - IID iid; - LPUNKNOWN punk; - }; - - typedef std::vector<Entry> EntriesT; - - EntriesT entries_; - UINT cRef_; - -protected: - void AddInterface(REFIID riid, IUnknown* punk); - -public: - CSimpleUnknown(); - virtual ~CSimpleUnknown(); - - DECLARE_UNKNOWN() -}; - -#endif
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@@ -1,17 +1,17 @@
-// Copyright (C) 2011 Fog Creek Software -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. +// Copyright (C) 2011 Fog Creek Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>.    import "objidl.idl";  import "shobjidl.idl";
 
217
218
219
220
221
222
223
 
240
241
242
243
244
 
245
246
247
248
249
250
251
252
 
255
256
257
 
 
258
 
 
 
 
259
260
261
 
217
218
219
 
220
221
222
 
239
240
241
 
 
242
243
244
245
 
 
246
247
248
 
251
252
253
254
255
256
257
258
259
260
261
262
263
@@ -217,7 +217,6 @@
  <ClCompile Include="QueryDirstate.cpp" />   <ClCompile Include="RegistryConfig.cpp" />   <ClCompile Include="ShellExt.cpp" /> - <ClCompile Include="SimpleUnknown.cpp" />   <ClCompile Include="StringUtils.cpp" />   <ClCompile Include="SysInfo.cpp" />   <ClCompile Include="ThgDebug.cpp" /> @@ -240,13 +239,10 @@
  <ClInclude Include="InitStatus.h" />   <ClInclude Include="QueryDirstate.h" />   <ClInclude Include="RegistryConfig.h" /> - <ClInclude Include="ShellExt.h" /> - <ClInclude Include="SimpleUnknown.h" /> + <ClInclude Include="resource.h" />   <ClInclude Include="stdafx.h" />   <ClInclude Include="StringUtils.h" />   <ClInclude Include="SysInfo.h" /> - <ClInclude Include="ThgClassFactory.h" /> - <ClInclude Include="ThgCLSIDs.h" />   <ClInclude Include="ThgDebug.h" />   <ClInclude Include="Thgstatus.h" />   <ClInclude Include="ThgVersion.h" /> @@ -255,7 +251,13 @@
  <ClInclude Include="Winstat.h" />   </ItemGroup>   <ItemGroup> + <None Include="CShellExtCMenu.rgs" /> + <None Include="CShellExtDnd.rgs" />   <None Include="ShellExt.def" /> + <None Include="TortoiseHgAdded.rgs" /> + <None Include="TortoiseHgModified.rgs" /> + <None Include="TortoiseHgNormal.rgs" /> + <None Include="TortoiseHgUnversioned.rgs" />   </ItemGroup>   <ItemGroup>   <ResourceCompile Include="shellext.rc" />
 
54
55
56
57
58
59
60
61
62
 
119
120
121
122
123
124
125
126
127
128
129
130
 
134
135
136
137
138
139
140
141
142
143
144
145
 
158
159
160
 
 
 
161
162
163
164
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
167
168
 
54
55
56
 
 
 
57
58
59
 
116
117
118
 
 
 
 
 
 
119
120
121
 
125
126
127
 
 
 
 
 
 
128
129
130
 
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@@ -54,9 +54,6 @@
  <ClCompile Include="ShellExt.cpp">   <Filter>Source Files</Filter>   </ClCompile> - <ClCompile Include="SimpleUnknown.cpp"> - <Filter>Source Files</Filter> - </ClCompile>   <ClCompile Include="StringUtils.cpp">   <Filter>Source Files</Filter>   </ClCompile> @@ -119,12 +116,6 @@
  <ClInclude Include="RegistryConfig.h">   <Filter>Header Files</Filter>   </ClInclude> - <ClInclude Include="ShellExt.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="SimpleUnknown.h"> - <Filter>Header Files</Filter> - </ClInclude>   <ClInclude Include="stdafx.h">   <Filter>Header Files</Filter>   </ClInclude> @@ -134,12 +125,6 @@
  <ClInclude Include="SysInfo.h">   <Filter>Header Files</Filter>   </ClInclude> - <ClInclude Include="ThgClassFactory.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="ThgCLSIDs.h"> - <Filter>Header Files</Filter> - </ClInclude>   <ClInclude Include="ThgDebug.h">   <Filter>Header Files</Filter>   </ClInclude> @@ -158,11 +143,32 @@
  <ClInclude Include="Winstat.h">   <Filter>Header Files</Filter>   </ClInclude> + <ClInclude Include="resource.h"> + <Filter>Header Files</Filter> + </ClInclude>   </ItemGroup>   <ItemGroup>   <None Include="ShellExt.def">   <Filter>Source Files</Filter>   </None> + <None Include="CShellExtCMenu.rgs"> + <Filter>Resource Files</Filter> + </None> + <None Include="CShellExtDnd.rgs"> + <Filter>Resource Files</Filter> + </None> + <None Include="TortoiseHgAdded.rgs"> + <Filter>Resource Files</Filter> + </None> + <None Include="TortoiseHgModified.rgs"> + <Filter>Resource Files</Filter> + </None> + <None Include="TortoiseHgNormal.rgs"> + <Filter>Resource Files</Filter> + </None> + <None Include="TortoiseHgUnversioned.rgs"> + <Filter>Resource Files</Filter> + </None>   </ItemGroup>   <ItemGroup>   <ResourceCompile Include="shellext.rc">
Change 1 of 1 Show Entire File win32/​shellext/​ThgCLSIDs.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,12 +0,0 @@
-#ifndef _THGCLSID_H_ -#define _THGCLSID_H_ - -#define THG_CLSID_TortoiseHgCmenu {46605027-5B8C-4DCE-BFE0-051B7972D64C} -#define THG_CLSID_TortoiseHgDropHandler {CEBD95BE-B733-415F-82A8-673D9158466E} -#define THG_CLSID_TortoiseHgNormal {869C8877-2C3C-438D-844B-31B86BFE5E8A} -#define THG_CLSID_TortoiseHgAdded {AF42ADAB-8C2E-4285-B746-99B31094708E} -#define THG_CLSID_TortoiseHgModified {CDA1C89D-E9B5-4981-A857-82DD932EA2FD} -#define THG_CLSID_TortoiseHgUnversioned {9E3D4EC9-0624-4393-8B48-204C217ED1FF} - - -#endif
Change 1 of 1 Show Entire File win32/​shellext/​ThgClassFactory.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,59 +0,0 @@
-#ifndef _ThgClassFactory_h_ -#define _ThgClassFactory_h_ - -#include "ShellExt.h" -#include "SimpleUnknown.h" - -template <class T> -class ThgClassFactory: public CSimpleUnknown, public IClassFactory -{ - const char myclassToMake; - -public: - explicit ThgClassFactory(char classToMake) : - myclassToMake(classToMake) - { - CShellExt::IncDllRef(); - ADDIFACE(IClassFactory); - } - - - ~ThgClassFactory() - { - CShellExt::DecDllRef(); - } - - INLINE_UNKNOWN() - - STDMETHODIMP CreateInstance( - LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObj) - { - if (ppvObj == 0) - return E_POINTER; - - *ppvObj = NULL; - - if (pUnkOuter) - return CLASS_E_NOAGGREGATION; - - T *pShellExt = new T(myclassToMake); - if (NULL == pShellExt) - return E_OUTOFMEMORY; - - const HRESULT hr = pShellExt->QueryInterface(riid, ppvObj); - if (FAILED(hr)) - delete pShellExt; - - return hr; - } - - - STDMETHODIMP LockServer(BOOL fLock) - { - return S_OK; - } - -}; - - -#endif
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgAdded.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {AF42ADAB-8C2E-4285-B746-99B31094708E} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgModified.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {CDA1C89D-E9B5-4981-A857-82DD932EA2FD} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgNormal.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {869C8877-2C3C-438D-844B-31B86BFE5E8A} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgUnversioned.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
@@ -0,0 +1,13 @@
+HKCR +{ + NoRemove CLSID + { + ForceRemove {9E3D4EC9-0624-4393-8B48-204C217ED1FF} = s 'TortoiseHg' + { + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + } + } +}
 
1
2
 
 
 
 
 
 
 
 
 
 
3
4
5
 
69
70
71
72
73
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
79
80
81
 
 
@@ -1,5 +1,15 @@
 #include "windows.h"  #include "parentid.h" +#include "resource.h" + +1 TYPELIB "THgShell.tlb" + +IDR_CMENU REGISTRY "CShellExtCMenu.rgs" +IDR_DRAGDROP REGISTRY "CShellExtDnd.rgs" +IDR_NORMAL REGISTRY "TortoiseHgNormal.rgs" +IDR_ADDED REGISTRY "TortoiseHgAdded.rgs" +IDR_MODIFIED REGISTRY "TortoiseHgModified.rgs" +IDR_UNVERSIONED REGISTRY "TortoiseHgUnversioned.rgs"    #ifndef THG_VERSION_FIRST  /* dummy version for shellext development */ @@ -69,5 +79,3 @@
  VALUE "Translation", 0x409, 1200   END  END - -1 TYPELIB "THgShell.tlb"
 
9
10
11
12
13
 
 
 
 
 
14
15
16
17
18
19
 
9
10
11
 
 
12
13
14
15
16
17
18
 
19
20
21
@@ -9,11 +9,13 @@
  */  #define WINVER 0x0500 // need to enable hbmpItem member in MENUITEMINFO   -#include <windows.h> -#include <windowsx.h> +#include "resource.h" + +#include <atlbase.h> +extern CComModule _Module; +#include <atlcom.h>  #include <shlobj.h>  #include <assert.h> -#include <tchar.h>  #include <string>    #include "ThgDebug.h"