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

fogcreek shellext: use ATL strings and collections, part 1

Changeset 44148c334a69

Parent 9d0bb7d14767

by David Golub

Changes to 32 files · Browse files at 44148c334a69 Showing diff from parent 9d0bb7d14767 Diff from another changeset...

 
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
 
157
158
159
160
 
161
162
163
 
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
 
196
197
198
199
200
201
 
 
202
203
204
 
206
207
208
209
210
 
 
211
212
213
 
220
221
222
223
 
224
225
226
 
234
235
236
237
 
238
239
240
241
242
 
243
244
245
246
247
248
 
249
250
251
 
253
254
255
256
257
 
 
258
259
260
 
268
269
270
271
 
272
273
274
 
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
 
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
 
462
463
464
465
 
466
467
468
 
486
487
488
489
 
490
491
492
 
 
493
494
495
 
 
496
497
498
499
500
 
501
502
503
 
506
507
508
509
 
 
510
511
512
 
 
513
514
515
 
522
523
524
525
 
526
527
528
529
530
 
 
531
532
533
 
618
619
620
621
 
622
623
624
625
 
626
627
628
 
629
630
631
 
757
758
759
760
 
761
762
763
 
 
764
765
766
767
768
 
769
770
771
 
772
773
774
775
 
776
777
778
 
783
784
785
786
787
 
 
788
789
790
791
 
792
793
 
794
795
796
 
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
 
892
893
894
895
896
 
 
897
898
899
 
911
912
913
914
 
915
916
917
 
943
944
945
946
 
947
948
949
 
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
 
152
153
154
 
155
156
157
158
 
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
 
191
192
193
 
 
 
194
195
196
197
198
 
200
201
202
 
 
203
204
205
206
207
 
214
215
216
 
217
218
219
220
 
228
229
230
 
231
232
233
234
235
 
236
237
238
239
240
241
 
242
243
244
245
 
247
248
249
 
 
250
251
252
253
254
 
262
263
264
 
265
266
267
268
 
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
 
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
 
455
456
457
 
458
459
460
461
 
479
480
481
 
482
483
484
 
485
486
487
 
 
488
489
490
 
 
 
 
491
492
493
494
 
497
498
499
 
500
501
502
 
 
503
504
505
506
507
 
514
515
516
 
517
518
 
 
 
 
519
520
521
522
523
 
608
609
610
 
611
612
613
614
 
615
616
617
 
618
619
620
621
 
747
748
749
 
750
751
 
 
752
753
754
755
756
757
 
758
759
760
 
761
762
763
764
 
765
766
767
768
 
773
774
775
 
 
776
777
778
779
780
 
781
782
 
783
784
785
786
 
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
 
878
879
880
 
 
881
882
883
884
885
 
897
898
899
 
900
901
902
903
 
929
930
931
 
932
933
934
935
@@ -125,30 +125,25 @@
 ;     -void CShellExtCMenuBase::AddMenuList(UINT idCmd, const std::string& name) +void CShellExtCMenuBase::AddMenuList(UINT idCmd, const CString& name)  { - ATLTRACE("AddMenuList: idCmd = %d, name = '%s'\n", idCmd, name.c_str()); + ATLTRACE("AddMenuList: idCmd = %d, name = '%s'\n", idCmd, name);   myMenuIdMap[idCmd] = myDescMap[name];  }     -void GetCMenuTranslation( - const std::string& lang, - const std::string& name, - std::wstring& menuText, - std::wstring& helpText -) +void GetCMenuTranslation(const CString& lang, LPCSTR name, CStringW& menuText, + CStringW& helpText)  { - std::wstring subkey = L"Software\\TortoiseHg\\CMenu\\"; - subkey += MultibyteToWide(lang); + CStringW subkey = L"Software\\TortoiseHg\\CMenu\\"; + subkey += lang;   subkey += L"\\"; - subkey += MultibyteToWide(name); + subkey += name;   - ATLTRACE(L"GetCMenuTranslation: '%s'\n", subkey.c_str()); + ATLTRACE(L"GetCMenuTranslation: '%s'\n", (LPCWSTR)subkey);     HKEY hkey = 0; - LONG rv = RegOpenKeyExW( - HKEY_CURRENT_USER, subkey.c_str(), 0, KEY_READ, &hkey); + LONG rv = RegOpenKeyExW(HKEY_CURRENT_USER, subkey, 0, KEY_READ, &hkey);     if (rv == ERROR_SUCCESS && hkey)   { @@ -157,7 +152,7 @@
  }   else   { - ATLTRACE(L"GetCMenuTranslation: RegOpenKeyExW('%s') failed\n", subkey.c_str()); + ATLTRACE(L"GetCMenuTranslation: RegOpenKeyExW('%s') failed\n", (LPCWSTR)subkey);   }     if (hkey) @@ -166,25 +161,25 @@
   void CShellExtCMenuBase::InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz)  { - if (myDescMap.empty()) + if (myDescMap.IsEmpty())   { - std::string lang; + CString lang;   GetRegistryConfig("CMenuLang", lang);     for (std::size_t i = 0; i < sz; i++)   {   MenuDescription md = menuDescs[i];   - if (md.name.empty()) + if (md.name.IsEmpty())   {   ATLTRACE("**** InitMenuMaps: ignoring entry with empty name\n");   break;   }   - ATLTRACE("InitMenuMaps: adding '%s'\n", md.name.c_str()); + ATLTRACE("InitMenuMaps: adding '%s'\n", (LPCTSTR)md.name);     // Look for translation of menu and help text - if (!lang.empty()) + if (!lang.IsEmpty())   GetCMenuTranslation(lang, md.name, md.menuText, md.helpText);     myDescMap[md.name] = md; @@ -196,9 +191,8 @@
 }     -void InsertMenuItemWithIcon1( - HMENU hMenu, UINT indexMenu, UINT idCmd, - const std::wstring& menuText, const std::string& iconName) +void InsertMenuItemWithIcon1(HMENU hMenu, UINT indexMenu, UINT idCmd, + const CStringW& menuText, const CString& iconName)  {   // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING   // from Win2K onward) @@ -206,8 +200,8 @@
  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.dwTypeData = (LPWSTR)(LPCWSTR)menuText; + mi.cch = menuText.GetLength();   mi.wID = idCmd;     if (SysInfo::Instance().IsVistaOrLater()) @@ -220,7 +214,7 @@
  }   else   { - ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", iconName.c_str()); + ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", iconName);   }   }   else @@ -234,18 +228,18 @@
  }   else   { - ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", iconName.c_str()); + ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", iconName);   }   }   InsertMenuItemW(hMenu, indexMenu, TRUE, &mi);   - ATLTRACE(L"InsertMenuItemWithIcon1('%s') finished\n", menuText.c_str()); + ATLTRACE(L"InsertMenuItemWithIcon1('%s') finished\n", menuText);  }      void InsertSubMenuItemWithIcon2(   HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd, - const std::wstring& menuText, const std::string& iconName) + const CStringW& menuText, const CString& iconName)  {   // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING   // from Win2K onward) @@ -253,8 +247,8 @@
  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.dwTypeData = (LPWSTR)(LPCWSTR)menuText; + mi.cch = menuText.GetLength();   mi.wID = idCmd;   mi.hSubMenu = hSubMenu;   @@ -268,7 +262,7 @@
  }   else   { - ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", iconName.c_str()); + ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", (LPCTSTR)iconName);   }   }   else @@ -282,36 +276,35 @@
  }   else   { - ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", iconName.c_str()); + ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", (LPCTSTR)iconName);   }   }     InsertMenuItemW(hMenu, indexMenu, TRUE, &mi);   - ATLTRACE(L"InsertMenuItemWithIcon2('%s') finished\n", menuText.c_str()); + ATLTRACE(L"InsertMenuItemWithIcon2('%s') finished\n", (LPCWSTR)menuText);  }     -void CShellExtCMenuBase::InsertMenuItemByName( - HMENU hMenu, const std::string& name, UINT indexMenu, - UINT idCmd, UINT idCmdFirst, const std::wstring& prefix) +void CShellExtCMenuBase::InsertMenuItemByName(HMENU hMenu, const CString& name, UINT indexMenu, + UINT idCmd, UINT idCmdFirst, const CStringW& prefix)  { - MenuDescriptionMap::iterator iter = myDescMap.find(name); - if (iter == myDescMap.end()) + const MenuDescriptionMap::CPair* pPair = myDescMap.Lookup(name); + if (pPair == NULL)   { - ATLTRACE("***** InsertMenuItemByName: can't find menu info for '%s'\n", name.c_str()); + ATLTRACE("***** InsertMenuItemByName: can't find menu info for '%s'\n", (LPCTSTR)name);   return;   }     - MenuDescription md = iter->second; + const MenuDescription& md = pPair->m_value;   AddMenuList(idCmd - idCmdFirst, name);   InsertMenuItemWithIcon1(   hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);  }     -const std::wstring TortoiseHgMenuEntryString = L"TortoiseHg"; +const LPCWSTR TortoiseHgMenuEntryString = L"TortoiseHg";    int HasTortoiseMenu(HMENU hMenu, bool& hasmenu)  // returns -1 on error, 0 otherwise @@ -424,35 +417,35 @@
  typedef std::vector<std::string> entriesT;   typedef entriesT::const_iterator entriesIter;   - std::string promoted_string = "commit,workbench"; // default value if key not found + CString promoted_string = "commit,workbench"; // default value if key not found   GetRegistryConfig("PromotedItems", promoted_string);   - entriesT promoted; + CAtlList<CString> promoted;   Tokenize(promoted_string, promoted, ",");     // Select menu to show - bool fileMenu = !myFiles.empty(); + bool fileMenu = !myFiles.IsEmpty();   bool isHgrepo = false; - std::string cwd; - if (!myFolder.empty()) + CString cwd; + if (!myFolder.IsEmpty())   {   cwd = myFolder;   }   else if (fileMenu)   { - cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]); + cwd = ::PathIsDirectory(myFiles[0]) ? myFiles[0] : DirName(myFiles[0]);   }   - if (!cwd.empty()) + if (!cwd.IsEmpty())   {   // check if target directory is a Mercurial repository - std::string root = GetHgRepoRoot(cwd); - isHgrepo = !root.empty(); - if (myFiles.size() == 1 && root == myFiles[0]) + CString root = GetHgRepoRoot(cwd); + isHgrepo = !root.IsEmpty(); + if (myFiles.GetCount() == 1 && root == myFiles[0])   {   fileMenu = false;   myFolder = cwd; - myFiles.clear(); + myFiles.RemoveAll();   }   }   @@ -462,7 +455,7 @@
  if (!isHgrepo)   {   // we are not inside a repo - std::string cval; + CString cval;   if (GetRegistryConfig("HideMenuOutsideRepo", cval) != 0 && cval == "1")   {   return S_OK; // don't show thg cmenu entries @@ -486,18 +479,16 @@
  // start building TortoiseHg menus and submenus   InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);   - entriesT entries; + CAtlList<CString> entries;   Tokenize(entries_string, entries, " ");   - for (entriesIter i = entries.begin(); i != entries.end(); i++) + POSITION position = entries.GetHeadPosition(); + while (position != NULL)   { - std::string name = *i; - if (contains(promoted, name)) + CString strName = entries.GetNext(position); + if (promoted.Find(strName) != NULL)   { - InsertMenuItemByName( - hMenu, name, indexMenu++, - idCmd++, idCmdFirst, L"Hg " - ); + InsertMenuItemByName(hMenu, strName, indexMenu++, idCmd++, idCmdFirst, L"Hg ");   }   }   @@ -506,10 +497,11 @@
  {   UINT indexSubMenu = 0;   bool isSeparator = true; - for (entriesIter i = entries.begin(); i != entries.end(); i++) + POSITION position = entries.GetHeadPosition(); + while (position != NULL)   { - std::string name = *i; - if (name == "sep") + CString strName = entries.GetNext(position); + if (strName == "sep")   {   if (!isSeparator)   { @@ -522,12 +514,10 @@
  }   else   { - if (!contains(promoted, name)) + if (promoted.Find(strName) == NULL)   { - InsertMenuItemByName( - hSubMenu, name, - indexSubMenu++, idCmd++, idCmdFirst, L"" - ); + InsertMenuItemByName(hSubMenu, strName, indexSubMenu++, idCmd++, + idCmdFirst, L"");   isSeparator = false;   }   } @@ -618,14 +608,14 @@
  }   else   { - ATLTRACE("CShellExtCMenu::GetCommandString: name = '%s'\n", iter->second.name.c_str()); + ATLTRACE("CShellExtCMenu::GetCommandString: name = '%s'\n", iter->second.name);     if (uFlags == GCS_HELPTEXTW)   { - pszw = iter->second.helpText.c_str(); + pszw = iter->second.helpText;   res = S_OK;   - size_t size = iter->second.helpText.size(); + size_t size = iter->second.helpText.GetLength();   if (size >= 40)   {   ATLTRACE("***** CShellExtCMenu::GetCommandString: warning: " @@ -757,22 +747,22 @@
 }     -void CShellExtCMenuBase::RunDialog(const std::string &cmd) +void CShellExtCMenuBase::RunDialog(const CString& cmd)  { - std::string dir = GetTHgProgRoot(); - if (dir.empty()) + CString dir = GetTHgProgRoot(); + if (dir.IsEmpty())   {   ATLTRACE("RunDialog: THG root is empty\n");   return;   } - std::string hgcmd = dir + "\\thgw.exe"; + CString hgcmd = dir + "\\thgw.exe";     WIN32_FIND_DATAA data; - HANDLE hfind = FindFirstFileA(hgcmd.c_str(), &data); + HANDLE hfind = FindFirstFileA(hgcmd, &data);   if (hfind == INVALID_HANDLE_VALUE)   {   hgcmd = dir + "\\hgtk.exe"; - hfind = FindFirstFileA(hgcmd.c_str(), &data); + hfind = FindFirstFileA(hgcmd, &data);   if (hfind == INVALID_HANDLE_VALUE)   hgcmd = dir + "\\thg.cmd";   else @@ -783,14 +773,14 @@
    hgcmd = Quote(hgcmd) + " --nofork " + cmd;   - std::string cwd; - if (!myFolder.empty()) + CString cwd; + if (!myFolder.IsEmpty())   {   cwd = myFolder;   } - else if (!myFiles.empty()) + else if (!myFiles.IsEmpty())   { - cwd = IsDirectory(myFiles[0]) ? myFiles[0] : DirName(myFiles[0]); + cwd = ::PathIsDirectory(myFiles[0]) ? myFiles[0] : DirName(myFiles[0]);   }   else   { @@ -802,43 +792,39 @@
  {   if (Thgstatus::remove(cwd) != 0)   { - std::string p = dir + "\\TortoiseHgOverlayServer.exe"; + CString p = dir + "\\TortoiseHgOverlayServer.exe";   LaunchCommand(Quote(p), dir);   }   InitStatus::check();   return;   }   - if (!myFiles.empty()) + if (!myFiles.IsEmpty())   { - const std::string tempfile = GetTemporaryFile(); - if (tempfile.empty()) + CString tempfile = GetTemporaryFile(); + if (tempfile.IsEmpty())   {   ATLTRACE("***** RunDialog: error: GetTemporaryFile returned empty string\n");   return;   }   - ATLTRACE("RunDialog: temp file = %s\n", tempfile.c_str()); - HANDLE tempfileHandle = CreateFileA( - tempfile.c_str(), GENERIC_WRITE, - FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 - ); + ATLTRACE("RunDialog: temp file = %s\n", (LPCTSTR)tempfile); + HANDLE tempfileHandle = CreateFileA(tempfile, GENERIC_WRITE, FILE_SHARE_READ, 0, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);     if (tempfileHandle == INVALID_HANDLE_VALUE)   { - ATLTRACE("***** RunDialog: error: failed to create file '%s'\n", tempfile.c_str()); + ATLTRACE("***** RunDialog: error: failed to create file '%s'\n", + (LPCTSTR)tempfile);   return;   }     typedef std::vector<std::string>::size_type ST; - for (ST i = 0; i < myFiles.size(); i++) + for (ST i = 0; i < myFiles.GetCount(); i++)   {   DWORD dwWritten; - ATLTRACE("RunDialog: temp file adding '%s'\n", myFiles[i].c_str()); - WriteFile( - tempfileHandle, myFiles[i].c_str(), - static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0 - ); + ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)myFiles[i]); + WriteFile(tempfileHandle, (LPCTSTR)myFiles[i], myFiles[i].GetLength(), &dwWritten, 0);   WriteFile(tempfileHandle, "\n", 1, &dwWritten, 0);   }   CloseHandle(tempfileHandle); @@ -892,8 +878,8 @@
    PrintDebugHeader(pIDFolder, pDataObj);   - myFolder.clear(); - myFiles.clear(); + myFolder.Empty(); + myFiles.RemoveAll();     if (pDataObj)   { @@ -911,7 +897,7 @@
  if (DragQueryFile(hDrop, i, name, MAX_PATH) > 0)   {   ATLTRACE(" DragQueryFile [%d] = '%s'\n", i, name); - myFiles.push_back(name); + myFiles.Add(name);   }   }   } @@ -943,7 +929,7 @@
    // disable context menu if neither the folder nor the files   // have been found - if (myFolder.empty() && myFiles.empty()) { + if (myFolder.IsEmpty() && myFiles.IsEmpty()) {   ATLTRACE(" shell extension not available on this object\n");   return E_FAIL;   } else {
 
7
8
9
10
11
12
13
 
 
 
 
14
15
16
17
 
18
19
20
 
25
26
27
28
29
 
 
30
31
32
33
 
34
35
36
37
38
39
40
41
 
 
 
42
43
44
 
7
8
9
 
 
 
 
10
11
12
13
14
15
16
 
17
18
19
20
 
25
26
27
 
 
28
29
30
31
32
 
33
34
35
36
37
 
 
 
 
38
39
40
41
42
43
@@ -7,14 +7,14 @@
   struct MenuDescription  { - std::string name; - std::wstring menuText; - std::wstring helpText; - std::string iconName; + CString name; + CStringW menuText; + CStringW helpText; + CString iconName;   UINT idCmd;  };   -typedef std::map<std::string, MenuDescription> MenuDescriptionMap; +typedef CAtlMap<CString, MenuDescription> MenuDescriptionMap;    typedef std::map<UINT, MenuDescription> MenuIdCmdMap;   @@ -25,20 +25,19 @@
  public IShellExtInit  {  protected: - std::vector<std::string> myFiles; - std::string myFolder; + CAtlArray<CString> myFiles; + CString myFolder;   MenuDescriptionMap myDescMap;   MenuIdCmdMap myMenuIdMap;   - virtual void RunDialog(const std::string&); + virtual void RunDialog(const CString& cmd);     void TweakMenuForVista(HMENU menu);   void PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj);   void InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz); - void InsertMenuItemByName( - HMENU hMenu, const std::string& name, UINT indexMenu, - UINT idCmd, UINT idCmdFirst, const std::wstring& prefix); - void AddMenuList(UINT idCmd, const std::string& name); + void InsertMenuItemByName(HMENU hMenu, const CString& name, UINT indexMenu, + UINT idCmd, UINT idCmdFirst, const CStringW& prefix); + void AddMenuList(UINT idCmd, const CString& name);    public:   CShellExtCMenuBase();
 
50
51
52
53
 
54
55
56
 
57
58
59
60
61
62
 
 
 
 
63
64
65
 
72
73
74
75
 
76
77
78
79
 
80
81
82
 
89
90
91
92
93
 
 
94
95
96
 
100
101
102
103
 
104
105
106
 
107
108
109
 
128
129
130
131
 
132
133
134
 
135
136
137
 
155
156
157
158
 
159
160
161
 
50
51
52
 
53
54
55
 
56
57
 
 
 
 
 
58
59
60
61
62
63
64
 
71
72
73
 
74
75
76
77
 
78
79
80
81
 
88
89
90
 
 
91
92
93
94
95
 
99
100
101
 
102
103
104
 
105
106
107
108
 
127
128
129
 
130
131
132
 
133
134
135
136
 
154
155
156
 
157
158
159
160
@@ -50,16 +50,15 @@
  typedef entriesT::const_iterator entriesIter;     const char* entries_string = DropMenu; - entriesT entries; + CAtlList<CString> entries;   Tokenize(entries_string, entries, " ");   - for (entriesIter i = entries.begin(); i != entries.end(); i++) + for (;;)   { - std::string name = *i; - InsertMenuItemByName( - hMenu, name, indexMenu++, - idCmd++, idCmdFirst, L"" - ); + CString strName = entries.GetHead(); + if (strName.IsEmpty()) + break; + InsertMenuItemByName(hMenu, strName, indexMenu++, idCmd++, idCmdFirst, L"");   }     // separator @@ -72,11 +71,11 @@
 }     -void CShellExtDnd::RunDialog(const std::string &cmd) +void CShellExtDnd::RunDialog(const CString& cmd)  {   if (cmd == "drag_move" || cmd == "drag_copy") {   //Append the current directory as the dest - myFiles.push_back(myFolder); + myFiles.Add(myFolder);   }   CShellExtCMenuBase::RunDialog(cmd);  } @@ -89,8 +88,8 @@
    PrintDebugHeader(pIDFolder, pDataObj);   - myFolder.clear(); - myFiles.clear(); + myFolder.Empty(); + myFiles.RemoveAll();     // if a directory background   if (pIDFolder) @@ -100,10 +99,10 @@
  myFolder = name;   }   - std::string root; + CString root;     //short circuit if we're dragging into a non-Hg repository - if (myFolder.empty() || (root = GetHgRepoRoot(myFolder)).empty()) + if (myFolder.IsEmpty() || (root = GetHgRepoRoot(myFolder)).IsEmpty())   {   ATLTRACE(" drag into a non-Hg repos directory\n");   return E_FAIL; @@ -128,10 +127,10 @@
  if (GetHgRepoRoot(name) != root)   {   ATLTRACE(" '%s' isn't in target dir repository\n", name); - myFiles.clear(); + myFiles.RemoveAll();   break;   } - myFiles.push_back(name); + myFiles.Add(name);   }   }   } @@ -155,7 +154,7 @@
    // disable context menu if neither the folder nor the files   // have been found - if (myFiles.empty()) { + if (myFiles.IsEmpty()) {   ATLTRACE(" shell extension not available on this object\n");   return E_FAIL;   } else {
 
10
11
12
13
 
14
15
16
 
10
11
12
 
13
14
15
16
@@ -10,7 +10,7 @@
 {    protected: - virtual void RunDialog(const std::string&); + virtual void RunDialog(const CString& cmd);    public:   explicit CShellExtDnd();
 
31
32
33
34
 
35
36
37
 
39
40
41
42
43
44
45
 
46
47
48
49
 
50
51
52
 
53
54
55
 
31
32
33
 
34
35
36
37
 
39
40
41
 
 
 
 
42
43
44
45
 
46
47
48
 
49
50
51
52
@@ -31,7 +31,7 @@
 {   CComCritSecLock<CComAutoCriticalSection> lock(m_cs);   - std::string cval; + CString cval;   if (GetRegistryConfig("EnableOverlays", cval) != 0 && cval == "0")   return S_FALSE;   @@ -39,17 +39,14 @@
  // "C:\FOO\BAR\Baz.TXT" will be considered equal to "C:\foo\bar\baz.txt"   // (note that mercurial preserves the case of filenames in .hg/dirstate)   - std::wstring lowerpath(pwszPath); - ::CharLowerW(const_cast<wchar_t*>(lowerpath.c_str())); - - std::string path = WideToMultibyte(lowerpath.c_str()); + CString path = CString(pwszPath).MakeLower();     if (GetRegistryConfig("LocalDisksOnly", cval) != 0 && cval != "0")   { - if (::PathIsNetworkPath(path.c_str())) + if (::PathIsNetworkPath(path))   return S_FALSE;   - if (path.size() > 2 && path[1] == ':') + if (path.GetLength() > 2 && path[1] == ':')   {   std::string t = "C:\\";   t[0] = path[0];
 
24
25
26
27
 
28
29
30
31
 
32
33
 
34
35
36
 
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
 
82
83
84
85
 
86
87
88
89
 
90
91
92
 
115
116
117
118
 
119
120
121
 
 
122
123
124
125
126
 
130
131
132
133
 
134
135
136
137
 
138
139
140
 
161
162
163
164
 
165
166
167
 
 
168
169
170
171
172
 
176
177
178
179
 
180
181
182
183
184
 
 
185
186
187
 
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
 
24
25
26
 
27
28
29
30
 
31
32
 
33
34
35
36
 
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
 
81
82
83
 
84
85
86
87
 
88
89
90
91
 
114
115
116
 
117
118
 
 
119
120
121
 
122
123
124
 
128
129
130
 
131
132
133
134
 
135
136
137
138
 
159
160
161
 
162
163
 
 
164
165
166
 
167
168
169
 
173
174
175
 
176
177
178
179
 
 
180
181
182
183
184
 
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
@@ -24,13 +24,13 @@
     Directory::Directory( - Directory* p, const std::string& n, const std::string& basepath + Directory* p, const CString& n, const CString& basepath  ):   parent_(p), name_(n)  { - if (n.empty()) + if (n.IsEmpty())   path_ = basepath; - else if (basepath.empty()) + else if (basepath.IsEmpty())   path_ = n;   else   path_ = basepath + '/' + n; @@ -46,35 +46,34 @@
 }     -int splitbase(const std::string& n, std::string& base, std::string& rest) +int splitbase(const CString& n, CString& base, CString& rest)  { - if (n.empty()) + if (n.IsEmpty())   return 0;   - size_t x = n.find_first_of ('/'); - if (x == std::string::npos) + int x = n.Find('/'); + if (x == -1)   { - base.clear(); + base.Empty();   rest = n;   return 1;   }   - if (x == 0 || x == n.length()-1) + if (x == 0 || x == n.GetLength()-1)   return 0;   - base = n.substr(0, x); - rest = n.substr(x+1); + base = n.Left(x); + rest = n.Mid(x+1);     return 1;  }     -int Directory::add(const std::string& n_in, Direntry& e) +int Directory::add(CString n, Direntry& e)  { - std::string base; - std::string rest; + CString base; + CString rest;   - std::string n = n_in;   Directory* cur = this;     for (;;) @@ -82,11 +81,11 @@
    if (!splitbase(n, base, rest)) {   ATLTRACE("Directory('%s')::add(%d): splitbase returned 0\n", - path().c_str(), n_in.c_str()); + (LPCTSTR)path(), (LPCTSTR)n);   return 0;   }   - if (base.empty()) + if (base.IsEmpty())   {   e.name = n;   cur->files_.push_back(e); @@ -115,12 +114,11 @@
 }     -const Direntry* Directory::get(const std::string& n_in) const +const Direntry* Directory::get(CString n) const  { - std::string base; - std::string rest; + CString base; + CString rest;   - std::string n = n_in;   const Directory* cur = this;     for (;;) @@ -130,11 +128,11 @@
  if (!splitbase(n, base, rest))   {   ATLTRACE("Directory('%s')::get(%d): splitbase returned 0\n", - path().c_str(), n_in.c_str()); + (LPCTSTR)path(), n);   return 0;   }   - if (base.empty()) + if (base.IsEmpty())   {   for (FilesT::const_iterator i = cur->files_.begin();   i != cur->files_.end(); ++i) @@ -161,12 +159,11 @@
 }     -Directory* Directory::getdir(const std::string& n_in) +Directory* Directory::getdir(CString n)  { - std::string base; - std::string rest; + CString base; + CString rest;   - std::string n = n_in;   const Directory* cur = this;     for (;;) @@ -176,12 +173,12 @@
  if (!splitbase(n, base, rest))   {   ATLTRACE("Directory('%s')::getdir(%d): splitbase returned 0\n", - path().c_str(), n_in.c_str()); + path(), n);   return 0;   }   - const bool leaf = base.empty(); - const std::string& searchstr = (leaf ? n : base); + const bool leaf = base.IsEmpty(); + const CString& searchstr = (leaf ? n : base);     for (DirsT::const_iterator i = cur->subdirs_.begin();   i != cur->subdirs_.end(); ++i) @@ -208,33 +205,31 @@
  const Directory* d = *i;   if (!d)   { - ATLTRACE("Directory('%s')::print: error: d is 0\n", path().c_str()); + ATLTRACE("Directory('%s')::print: error: d is 0\n", (LPCTSTR)path());   return;   }   d->print();   }   - std::string base = path(); + CString base = path();     time_t t; - std::string s; + CString s;   char ctime_res[26];     for (FilesT::const_iterator i = files_.begin(); i != files_.end(); ++i)   { - std::string p = (!base.empty() ? base + "/" + i->name : i->name); + CString p = (!base.IsEmpty() ? base + "/" + i->name : i->name);   t = i->mtime;   errno_t err = ctime_s(ctime_res, 26, &t);   if (err == 0) {   s = ctime_res; - s.resize(s.size() - 1); // strip ending '\n' + s.Truncate(s.GetLength() - 1); // strip ending '\n'   }   else {   s = "unset";   } - printf( - "%c %6o %10u %-24s %s\n", - i->state, i->mode, i->size, s.c_str(), p.c_str() - ); + printf("%c %6o %10u %-24s %s\n", i->state, i->mode, i->size, + (LPCTSTR)s, (LPCTSTR)p);   }  }
 
30
31
32
33
34
 
 
35
36
37
38
39
40
 
41
42
43
 
44
45
 
46
47
48
 
 
49
50
51
 
30
31
32
 
 
33
34
35
36
37
38
39
 
40
41
42
 
43
44
 
45
46
 
 
47
48
49
50
51
@@ -30,22 +30,22 @@
  typedef std::vector<Direntry> FilesT;     Directory* const parent_; - const std::string name_; - std::string path_; + const CString name_; + CString path_;     DirsT subdirs_;   FilesT files_;    public: - Directory(Directory* p, const std::string& n, const std::string& basepath); + Directory(Directory* p, const CString& n, const CString& basepath);   ~Directory();   - const std::string& path() const { return path_; } + const CString& path() const { return path_; }   - int add(const std::string& relpath, Direntry& e); + int add(CString relpath, Direntry& e);   - const Direntry* get(const std::string& relpath) const; - Directory* getdir(const std::string& n); + const Direntry* get(CString relpath) const; + Directory* getdir(CString n);     void print() const;  };
 
21
22
23
24
 
25
26
27
28
29
30
 
31
32
33
34
35
36
 
 
37
38
39
 
56
57
58
59
 
60
61
62
63
64
 
65
66
 
67
68
69
70
 
71
72
73
 
137
138
139
140
 
141
142
143
 
147
148
149
150
 
151
152
153
 
155
156
157
158
 
159
160
161
 
21
22
23
 
24
25
26
27
28
29
 
30
31
32
33
34
 
 
35
36
37
38
39
 
56
57
58
 
59
60
61
62
63
 
64
65
 
66
67
68
69
 
70
71
72
73
 
137
138
139
 
140
141
142
143
 
147
148
149
 
150
151
152
153
 
155
156
157
 
158
159
160
161
@@ -21,19 +21,19 @@
 #include "TortoiseUtils.h"     -char DirectoryStatus::status(const std::string& relpath_) const +char DirectoryStatus::status(CString relpath) const  {   char res = 'C';   bool added = false;   bool modified = false;   - const std::string relpath = relpath_ + '/'; + relpath += '/';     for (V::const_iterator i = v_.begin(); i != v_.end(); ++i)   {   const E& e = *i; - if (relpath_.empty() || - e.path_.compare(0, relpath.length(), relpath) == 0) + if (relpath.IsEmpty() || + e.path_.compare(0, relpath.GetLength(), relpath) == 0)   {   if (e.status_ == 'm' || e.status_ == 'r')   { @@ -56,18 +56,18 @@
 }     -int DirectoryStatus::read(const std::string& hgroot, const std::string& cwd) +int DirectoryStatus::read(const CString& hgroot, const CString& cwd)  {   v_.clear();   noicons_ = false;   - std::string p = hgroot + "\\.hg\\thgstatus"; + CString p = hgroot + "\\.hg\\thgstatus";   - FILE *f = fopenReadRenameAllowed(p.c_str()); + FILE *f = fopenReadRenameAllowed(p);   if (!f)   {   ATLTRACE("DirectoryStatus::read: can't open '%s'\n", p); - std::string p = (cwd.size() < hgroot.size() ? hgroot : cwd); + CString p = (cwd.GetLength() < hgroot.GetLength() ? hgroot : cwd);   Thgstatus::update(p);   return 0;   } @@ -137,7 +137,7 @@
   struct CacheEntry  { - std::string hgroot_; + CString hgroot_;   DirectoryStatus ds_;   bool readfailed_;   unsigned tickcount_; @@ -147,7 +147,7 @@
     DirectoryStatus* DirectoryStatus::get( - const std::string& hgroot, const std::string& cwd) + const CString& hgroot, const CString& cwd)  {   static CacheEntry ce;   @@ -155,7 +155,7 @@
    if (ce.hgroot_ != hgroot || (tc - ce.tickcount_) > 2000)   { - ce.hgroot_.clear(); + ce.hgroot_.Empty();   ce.readfailed_ = (ce.ds_.read(hgroot, cwd) == 0);   ce.hgroot_ = hgroot;   ce.tickcount_ = GetTickCount();
 
35
36
37
38
39
40
 
 
41
42
43
44
 
45
 
35
36
37
 
 
 
38
39
40
41
42
 
43
44
@@ -35,11 +35,10 @@
 public:   DirectoryStatus(): noicons_(false) {}   - static DirectoryStatus* get( - const std::string& hgroot, const std::string& cwd); - char status(const std::string& relpath) const; + static DirectoryStatus* get(const CString& hgroot, const CString& cwd); + char status(CString relpath) const;   bool noicons() const { return noicons_; }    private: - int read(const std::string& hgroot, const std::string& cwd); + int read(const CString& hgroot, const CString& cwd);  };
 
35
36
37
38
 
39
40
41
 
35
36
37
 
38
39
40
41
@@ -35,7 +35,7 @@
  unsigned size;   unsigned mtime;   - std::string name; + CString name;     int read(FILE* f, std::vector<char>& relpath);   char status(const Winstat& stat) const;
 
29
30
31
32
33
34
 
 
35
36
37
 
63
64
65
66
 
67
68
69
 
82
83
84
85
 
86
87
88
 
106
107
108
109
 
110
111
112
113
 
114
115
116
 
159
160
161
162
 
163
164
165
166
 
167
168
169
 
173
174
175
176
 
177
178
179
 
29
30
31
 
 
 
32
33
34
35
36
 
62
63
64
 
65
66
67
68
 
81
82
83
 
84
85
86
87
 
105
106
107
 
108
109
110
111
 
112
113
114
115
 
158
159
160
 
161
162
163
164
 
165
166
167
168
 
172
173
174
 
175
176
177
178
@@ -29,9 +29,8 @@
 }     -Dirstate* Dirstatecache::get( - const std::string& hgroot, const std::string& cwd, bool& unset, - bool usekbfiles) +Dirstate* Dirstatecache::get(const CString& hgroot, const CString& cwd, + bool& unset, bool usekbfiles)  {   unset = false;   @@ -63,7 +62,7 @@
    if (cache().size() >= 10)   { - ATLTRACE("Dirstatecache::get: dropping '%s'\n", cache().back().hgroot.c_str()); + ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)cache().back().hgroot);   delete cache().back().dstate;   cache().back().dstate = 0;   cache().pop_back(); @@ -82,7 +81,7 @@
  if (0 != stat.lstat(path.c_str(), true))   {   ATLTRACE("Dirstatecache::get: lstat('%s') failed\n", path.c_str()); - ATLTRACE("Dirstatecache::get: dropping '%s'\n", iter->hgroot.c_str()); + ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)iter->hgroot);   delete iter->dstate;   iter->dstate = 0;   cache().erase(iter); @@ -106,11 +105,11 @@
  return iter->dstate;   }   - ATLTRACE("Dirstatecache::get: refreshing '%s'\n", hgroot.c_str()); + ATLTRACE("Dirstatecache::get: refreshing '%s'\n", hgroot);   }   else   { - ATLTRACE("Dirstatecache::get: reading '%s'\n", hgroot.c_str()); + ATLTRACE("Dirstatecache::get: reading '%s'\n", hgroot);   }     unset = false; @@ -159,11 +158,11 @@
 }     -void Dirstatecache::invalidate(const std::string& hgroot, bool usekbfiles) +void Dirstatecache::invalidate(const CString& hgroot, bool usekbfiles)  {   typedef std::list<E>::iterator Iter;   - if (hgroot.empty()) + if (hgroot.IsEmpty())   return;     for (Iter i = cache().begin(); i != cache().end(); ++i) @@ -173,7 +172,7 @@
  delete i->dstate;   i->dstate = 0;   cache().erase(i); - ATLTRACE("Dirstatecache::invalidate('%s')\n", hgroot.c_str()); + ATLTRACE("Dirstatecache::invalidate('%s')\n", (LPCTSTR)hgroot);   break;   }   }
 
31
32
33
34
 
35
36
37
 
49
50
51
52
53
 
54
55
 
56
57
58
 
31
32
33
 
34
35
36
37
 
49
50
51
 
 
52
53
 
54
55
56
57
@@ -31,7 +31,7 @@
  __int64 dstate_mtime;   __int64 dstate_size;   - std::string hgroot; + CString hgroot;   unsigned tickcount;   bool unset;   bool usekbfiles; @@ -49,10 +49,9 @@
  static std::list<E>& cache();    public: - static Dirstate* get( - const std::string& hgroot, const std::string& cwd, bool& unset, + static Dirstate* get(const CString& hgroot, const CString& cwd, bool& unset,   bool usekbfiles = false); - static void invalidate(const std::string& hgroot, bool usekbfiles = false); + static void invalidate(const CString& hgroot, bool usekbfiles = false);  };    #endif
 
27
28
29
30
 
31
32
 
33
34
35
36
37
38
 
39
40
41
 
42
43
44
 
49
50
51
52
 
53
54
55
 
56
57
58
 
 
59
60
 
27
28
29
 
30
31
 
32
33
34
35
36
37
 
38
39
40
 
41
42
43
44
 
49
50
51
 
52
53
54
 
55
56
 
 
57
58
59
60
@@ -27,18 +27,18 @@
 }     -void InitStatus::add(std::string& s, const char* missing) +void InitStatus::add(CString& s, const char* missing)  { - if (!s.empty()) + if (!s.IsEmpty())   s += ", ";   s += missing;  }     -std::string InitStatus::check() +CString InitStatus::check()  {   const InitStatus& self = inst(); - std::string missing; + CString missing;     if (self.unchanged_ == 0)   add(missing, "unchanged"); @@ -49,12 +49,12 @@
  if (self.notinrepo_ == 0)   add(missing, "notinrepo");   - if (missing.empty()) + if (missing.IsEmpty())   return "";   - std::string reason = "uninitialized handlers: " + missing; + CString reason = "uninitialized handlers: " + missing;   Thgstatus::error(reason); - std::string res = "InitStatus: error: " + reason; - ATLTRACE("***** %s\n", res.c_str()); + CString res = "InitStatus: error: " + reason; + ATLTRACE("***** %s\n", (LPCTSTR)res);   return res;  }
 
25
26
27
28
 
29
30
31
32
33
34
 
35
 
25
26
27
 
28
29
30
31
32
33
 
34
35
@@ -25,11 +25,11 @@
  int notinrepo_;     static InitStatus& inst(); - static std::string check(); + static CString check();    private:   InitStatus()   : unchanged_(0), added_(0), modified_(0), notinrepo_(0) {}   - static void add(std::string& s, const char* missing); + static void add(CString& s, const char* missing);  };
 
31
32
33
34
 
35
36
37
 
 
38
39
40
 
43
44
45
46
 
47
48
49
50
51
52
 
53
54
55
 
56
57
 
58
59
60
61
 
62
63
64
 
67
68
69
70
 
71
72
73
 
103
104
105
106
107
 
 
108
109
110
 
114
115
116
117
 
118
119
120
 
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
 
157
158
159
160
 
161
162
163
164
 
 
165
166
 
167
168
169
170
171
172
173
 
174
175
176
177
 
178
179
180
 
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
 
215
216
217
218
 
219
220
221
 
233
234
235
236
 
237
238
239
 
242
243
244
245
 
246
247
248
 
252
253
254
255
 
256
257
258
259
 
260
261
262
 
263
264
265
 
269
270
271
272
 
273
274
275
 
284
285
286
287
 
288
289
290
291
292
293
 
294
295
 
296
297
298
 
304
305
306
307
 
308
309
310
 
347
348
349
350
 
351
352
353
 
354
355
356
 
31
32
33
 
34
35
 
 
36
37
38
39
40
 
43
44
45
 
46
47
48
49
50
51
 
52
53
54
 
55
56
 
57
58
59
60
 
61
62
63
64
 
67
68
69
 
70
71
72
73
 
103
104
105
 
 
106
107
108
109
110
 
114
115
116
 
117
118
119
120
 
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
 
157
158
159
 
160
161
162
 
 
163
164
165
 
166
167
168
169
170
171
172
 
173
174
175
176
 
177
178
179
180
 
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
 
213
214
215
 
216
217
218
219
 
231
232
233
 
234
235
236
237
 
240
241
242
 
243
244
245
246
 
250
251
252
 
253
254
 
 
 
255
256
257
 
258
259
260
261
 
265
266
267
 
268
269
270
271
 
280
281
282
 
283
284
285
286
287
288
 
289
290
 
291
292
293
294
 
300
301
302
 
303
304
305
306
 
343
344
345
 
346
347
348
 
349
350
351
352
@@ -31,10 +31,10 @@
 class QueryState  {  public: - std::string path; + CString path;   bool isdir; - std::string basedir; - std::string hgroot; + CString basedir; + CString hgroot;     char status;   unsigned tickcount; @@ -43,22 +43,22 @@
 };     -bool hasHgDir(char cls, const std::string& path, unsigned& ticks) +bool hasHgDir(char cls, const CString& path, unsigned& ticks)  {   ticks = 0;     bool res = false;   - if (path.empty() || path == "\\") + if (path.IsEmpty() || path == "\\")   return res;   - const std::string p = path + "\\.hg"; + const CString p = path + "\\.hg";   - if (::PathIsUNCServerShare(p.c_str())) + if (::PathIsUNCServerShare(p))   return res;     unsigned tc0 = ::GetTickCount(); - res = ::PathIsDirectory(p.c_str()) != 0; + res = ::PathIsDirectory(p) != 0;   unsigned tc1 = ::GetTickCount();     ticks = tc1 - tc0; @@ -67,7 +67,7 @@
  {   // trace slower PathIsDirectory calls (untypical on local discs)   ATLTRACE("[%c] hasHgDir: PathIsDirectory('%s') -> %d, in %d ticks\n", - cls, p.c_str(), (int)res, ticks); + cls, (LPCTSTR)p, (int)res, ticks);   }     return res; @@ -103,8 +103,8 @@
  }   }   - if (!outdated && !last.hgroot.empty() - && cur.path.size() >= last.hgroot.size() + if (!outdated && !last.hgroot.IsEmpty() + && cur.path.GetLength() >= last.hgroot.GetLength()   && StartsWith(cur.path, last.hgroot + "\\"))   {   cur.hgroot = last.hgroot; @@ -114,7 +114,7 @@
  unsigned ticks = 0;   bool file_access_is_unacceptably_slow = false;   - if (!PathIsNetworkPath(cur.path.c_str())) + if (!::PathIsNetworkPath(cur.path))   {   // checking if we have a repo root, visible from its parent dir   @@ -129,25 +129,25 @@
  if (has_hg)   {   cur.hgroot = cur.path; - ATLTRACE("%s('%s'): hgroot = cur.path\n", dp.c_str(), cur.path.c_str()); + ATLTRACE("%s('%s'): hgroot = cur.path\n", dp.c_str(), cur.path);   return 1;   }   }     cur.basedir = DirName(cur.path);   - if (!outdated && !last.basedir.empty() && cur.basedir == last.basedir) + if (!outdated && !last.basedir.IsEmpty() && cur.basedir == last.basedir)   {   cur.hgroot = last.hgroot;   return 1;   }   - for (std::string p = cur.basedir;;) + for (CString p = cur.basedir;;)   {   bool has_hg = hasHgDir(cls, p, ticks);   if (ticks > 5000 /* ms */)   { - const std::string reason = "ignoring slow \"" + p + "\""; + CString reason = "ignoring slow \"" + p + "\"";   Thgstatus::error(reason);   file_access_is_unacceptably_slow = true;   goto exit; @@ -157,24 +157,24 @@
  {   cur.hgroot = p;   ATLTRACE("%s('%s'): hgroot = '%s' (found repo)", dp.c_str(), - cur.path.c_str(), cur.hgroot.c_str()); + cur.path, cur.hgroot);   return 1;   } - std::string p2 = DirName(p); - if (p2.size() == p.size()) + CString p2 = DirName(p); + if (p2.GetLength() == p.GetLength())   break; - p.swap(p2); + p = p2;   }    exit:   if (file_access_is_unacceptably_slow)   {   ATLTRACE("****** %s('%s'): ignored, call took too long (%d ticks)\n", - dp.c_str(), cur.path.c_str(), ticks); + dp.c_str(), cur.path, ticks);   }   else   { - ATLTRACE("%s('%s'): NO repo found\n", dp.c_str(), cur.path.c_str()); + ATLTRACE("%s('%s'): NO repo found\n", dp.c_str(), cur.path);   }   last = cur;   return 0; @@ -182,31 +182,29 @@
     int get_relpath( - const std::string& hgroot, - const std::string& path, - std::string& res + const CString& hgroot, + const CString& path, + CString& res  )  { - size_t offset = hgroot.size(); + int offset = hgroot.GetLength();   if (offset == 0)   return 0;   - if (offset > path.size()) + if (offset > path.GetLength())   return 0;     if (path[offset] == '\\')   offset++;   - const char* relpathptr = path.c_str() + offset; - - res = relpathptr; + res = path.Mid(offset);   return 1;  }      int HgQueryDirstate(   const char cls, - const std::string& path, + const CString& path,   const char& filterStatus,   char& outStatus  ) @@ -215,7 +213,7 @@
    static QueryState last;   - if (path.empty()) + if (path.IsEmpty())   return 0;     QueryState cur; @@ -233,7 +231,7 @@
  return 1;   }   - if (::PathIsRoot(path.c_str())) + if (::PathIsRoot(path))   {   last = cur;   return 0; @@ -242,7 +240,7 @@
  if (findHgRoot(cls, cur, last, outdated) == 0)   return 0;   - size_t offset = cur.hgroot.length(); + int offset = cur.hgroot.GetLength();     if (offset == 0)   { @@ -252,14 +250,12 @@
    if (path[offset] == '\\')   offset++; - const char* relpathptr = path.c_str() + offset; + CString relpath = path.Mid(offset);   - std::string relpath = relpathptr; - - for (size_t i = 0; i < relpath.size(); ++i) + for (int i = 0; i < relpath.GetLength(); ++i)   {   if (relpath[i] == '\\') - relpath[i] = '/'; + relpath.SetAt(i, '/');   }     DirectoryStatus* pdirsta = DirectoryStatus::get(cur.hgroot, cur.basedir); @@ -269,7 +265,7 @@
  return 0;   }   - if (relpath.empty()) + if (relpath.IsEmpty())   {   outStatus = (pdirsta ? pdirsta->status(relpath) : '?');   cur.status = outStatus; @@ -284,15 +280,15 @@
  if (!pds)   {   ATLTRACE("%s Dirstatecache::get('%s') returns no Dirstate\n", dp.c_str(), - cur.hgroot.c_str()); + cur.hgroot);   last = cur;   return 0;   }     Winstat stat; - if (0 != stat.lstat(path.c_str())) + if (0 != stat.lstat(path))   { - ATLTRACE("%s lstat('%s') failed", dp.c_str(), path.c_str()); + ATLTRACE("%s lstat('%s') failed", dp.c_str(), path);   last = cur;   return 0;   } @@ -304,7 +300,7 @@
    if (cur.isdir)   { - if (!relpath.empty() && !pds->root().getdir(relpath)) + if (!relpath.IsEmpty() && !pds->root().getdir(relpath))   {   // attempt to get status from kbfiles   pds = Dirstatecache::get(cur.hgroot, cur.basedir, unset, true); @@ -347,10 +343,10 @@
    if (outStatus == 'M')   { - std::string relbase; + CString relbase;   if (pdirsta && get_relpath(cur.hgroot, cur.basedir, relbase))   { - ATLTRACE("%s relbase = '%s'\n", dp.c_str(), relbase.c_str()); + ATLTRACE("%s relbase = '%s'\n", dp.c_str(), (LPCTSTR)relbase);     char basedir_status = pdirsta->status(relbase);   ATLTRACE("%s basedir_status = '%c'\n", dp.c_str(), basedir_status);
 
5
6
7
8
 
9
10
11
 
5
6
7
 
8
9
10
11
@@ -5,7 +5,7 @@
   int HgQueryDirstate(   const char myClass, - const std::string& path, + const CString& path,   const char& filterStatus,   char& outStatus  );
 
1
2
3
4
 
5
6
 
7
8
9
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
27
28
29
 
30
 
1
2
3
 
4
5
 
6
7
8
9
 
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
18
19
20
 
21
22
@@ -1,9 +1,9 @@
 #include "stdafx.h"  #include "RegistryConfig.h"   -int GetRegistryConfig(const std::string& name, std::string& res) +int GetRegistryConfig(const CString& name, CString& res)  { - const char* const subkey = "Software\\TortoiseHg"; + LPCTSTR subkey = "Software\\TortoiseHg";     HKEY hkey = 0;   LONG rv = RegOpenKeyExA( @@ -12,19 +12,11 @@
  if (rv != ERROR_SUCCESS || hkey == 0)   return 0;   - BYTE Data[MAX_PATH] = ""; - DWORD cbData = MAX_PATH * sizeof(BYTE); - - rv = RegQueryValueExA( - hkey, name.c_str(), 0, 0, Data, &cbData); - - int ret = 0; - if (rv == ERROR_SUCCESS) - { - res = reinterpret_cast<const char*>(&Data); - ret = 1; - } + DWORD cbData = MAX_PATH; + LPTSTR lpszData = res.GetBuffer(cbData); + rv = RegQueryValueExA(hkey, name, 0, 0, (LPBYTE)lpszData, &cbData); + res.ReleaseBuffer(cbData);     RegCloseKey(hkey); - return ret; + return rv == ERROR_SUCCESS;  }
 
1
2
3
4
5
6
 
7
8
 
1
2
3
 
 
 
4
5
6
@@ -1,8 +1,6 @@
 #ifndef REGISTRY_CONFIG_H_  #define REGISTRY_CONFIG_H_   -#include <string> - -int GetRegistryConfig(const std::string& name, std::string& res); +int GetRegistryConfig(const CString& name, CString& res);    #endif
 
15
16
17
 
18
19
20
21
22
23
24
 
25
26
 
27
28
29
 
15
16
17
18
19
20
21
22
23
24
 
25
26
 
27
28
29
30
@@ -15,15 +15,16 @@
 // along with this program; if not, write to the Free Software  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.   +#include "stdafx.h"  #include "StringUtils.h"    #include <vector>      // Quotes a string -std::string Quote(const std::string& str) +CString Quote(const CString& str)  { - std::string sResult = "\"" + str + "\""; + CString sResult = "\"" + str + "\"";   return sResult;  }  
 
22
23
24
25
 
26
27
28
 
22
23
24
 
25
26
27
28
@@ -22,7 +22,7 @@
 #include <windows.h>    // Quotes a string -std::string Quote(const std::string& str); +CString Quote(const CString& str);    // Convert Unicode string to multibyte string  std::string WideToMultibyte(const std::wstring& wide, UINT CodePage = CP_ACP);
 
219
220
221
222
223
224
225
 
243
244
245
246
247
248
249
 
219
220
221
 
222
223
224
 
242
243
244
 
245
246
247
@@ -219,7 +219,6 @@
  <ClCompile Include="ShellExt.cpp" />   <ClCompile Include="StringUtils.cpp" />   <ClCompile Include="SysInfo.cpp" /> - <ClCompile Include="ThgDebug.cpp" />   <ClCompile Include="Thgstatus.cpp" />   <ClCompile Include="ThgVersion.cpp" />   <ClCompile Include="TortoiseIconBitmap.cpp" /> @@ -243,7 +242,6 @@
  <ClInclude Include="stdafx.h" />   <ClInclude Include="StringUtils.h" />   <ClInclude Include="SysInfo.h" /> - <ClInclude Include="ThgDebug.h" />   <ClInclude Include="Thgstatus.h" />   <ClInclude Include="ThgVersion.h" />   <ClInclude Include="TortoiseIconBitmap.h" />
 
60
61
62
63
64
65
66
67
68
 
125
126
127
128
129
130
131
132
133
 
60
61
62
 
 
 
63
64
65
 
122
123
124
 
 
 
125
126
127
@@ -60,9 +60,6 @@
  <ClCompile Include="SysInfo.cpp">   <Filter>Source Files</Filter>   </ClCompile> - <ClCompile Include="ThgDebug.cpp"> - <Filter>Source Files</Filter> - </ClCompile>   <ClCompile Include="Thgstatus.cpp">   <Filter>Source Files</Filter>   </ClCompile> @@ -125,9 +122,6 @@
  <ClInclude Include="SysInfo.h">   <Filter>Header Files</Filter>   </ClInclude> - <ClInclude Include="ThgDebug.h"> - <Filter>Header Files</Filter> - </ClInclude>   <ClInclude Include="Thgstatus.h">   <Filter>Header Files</Filter>   </ClInclude>
Change 1 of 1 Show Entire File win32/​shellext/​ThgDebug.cpp Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,22 +0,0 @@
- -// Copyright (C) 2009 Adrian Buehlmann -// -// 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. - -#include "ThgDebug.h" -#include "RegistryConfig.h" - -bool ThgDebug::regDebugShellExt() -{ - std::string val; - return GetRegistryConfig("DebugShellExt", val) != 0 && val == "1"; -} - -bool ThgDebug::enabled() -{ - static bool e = regDebugShellExt(); - return e; -}
Change 1 of 1 Show Entire File win32/​shellext/​ThgDebug.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,23 +0,0 @@
- -// Copyright (C) 2009 Adrian Buehlmann -// -// 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. - -#ifndef THGDEBUG_H -#define THGDEBUG_H - -class ThgDebug -{ -public: - static bool enabled(); - -private: - ThgDebug(); - - static bool regDebugShellExt(); -}; - -#endif
 
33
34
35
36
 
37
38
39
 
43
44
45
46
 
47
48
49
 
50
51
52
 
33
34
35
 
36
37
38
39
 
43
44
45
 
46
47
48
 
49
50
51
52
@@ -33,7 +33,7 @@
 }     -int Thgstatus::SendRequest(const std::string& request) +int Thgstatus::SendRequest(const CString& request)  {   static const std::string pname = GetPipeName();   @@ -43,10 +43,10 @@
  BOOL fSuccess;   DWORD cbRead;   - ATLTRACE("Thgstatus::update: sending '%s' to %s\n", request.c_str(), pname.c_str()); + ATLTRACE("Thgstatus::update: sending '%s' to %s\n", (LPCTSTR)request, pname.c_str());     fSuccess = ::CallNamedPipeA( - pname.c_str(), (void*)request.c_str(), (DWORD)request.size(), 0, 0, &cbRead, + pname.c_str(), (void*)(LPCTSTR)request, request.GetLength(), 0, 0, &cbRead,   NMPWAIT_NOWAIT   );  
 
21
22
23
24
 
25
26
27
 
28
29
30
 
31
32
33
 
34
35
36
 
21
22
23
 
24
25
26
 
27
28
29
 
30
31
32
 
33
34
35
36
@@ -21,16 +21,16 @@
   class Thgstatus  { - static int SendRequest(const std::string& request); + static int SendRequest(const CString& request);    public: - static int update(const std::string& path) { + static int update(const CString& path) {   return SendRequest("update|" + path);   } - static int remove(const std::string& path) { + static int remove(const CString& path) {   return SendRequest("remove|" + path);   } - static int error(const std::string& text) { + static int error(const CString& text) {   return SendRequest("error|" + text);   }   static int terminate() {
 
5
6
7
8
9
 
10
11
12
13
14
15
16
17
 
 
18
19
 
 
 
 
 
20
21
22
 
34
35
36
37
 
38
39
40
 
41
42
43
 
5
6
7
 
 
8
9
10
 
 
11
 
 
 
12
13
14
 
15
16
17
18
19
20
21
22
 
34
35
36
 
37
38
39
 
40
41
42
43
@@ -5,18 +5,18 @@
   #include "IconBitmapUtils.h"   - -HBITMAP GetTortoiseIconBitmap(const std::string& iconname) +HBITMAP GetTortoiseIconBitmap(const CString& iconname)  {   IconBitmapUtils bmpUtils; - typedef std::map<std::string, HBITMAP> BitmapCacheT; - static BitmapCacheT bmpcache_;   - BitmapCacheT::const_iterator i = bmpcache_.find(iconname); - if (i != bmpcache_.end()) - return i->second; + typedef CAtlMap<CString, HBITMAP> CBitmapCache; + static CBitmapCache bmpcache;   - if (bmpcache_.size() > 200) + const CBitmapCache::CPair* p = bmpcache.Lookup(iconname); + if (p != NULL) + return p->m_value; + + if (bmpcache.GetCount() > 200)   {   ATLTRACE("**** GetTortoiseIconBitmap: error: too many bitmaps in cache\n");   return 0; @@ -34,10 +34,10 @@
  return 0;   }   - bmpcache_[iconname] = hBmp; + bmpcache[iconname] = hBmp;     ATLTRACE("GetTortoiseIconBitmap: added '%s' to bmpcache_ (%d bitmaps in cache)\n", - iconname.c_str(), bmpcache_.size()); + (LPCTSTR)iconname, bmpcache.GetCount());     return hBmp;  }
 
4
5
6
7
 
8
9
 
4
5
6
 
7
8
9
@@ -4,6 +4,6 @@
 #include <windows.h>  #include <string>   -HBITMAP GetTortoiseIconBitmap(const std::string& iconname); +HBITMAP GetTortoiseIconBitmap(const CString& iconname);    #endif
 
11
12
13
14
 
15
16
17
 
29
30
31
32
 
33
34
35
 
 
36
37
38
 
41
42
43
44
 
45
46
47
48
49
50
 
51
52
53
 
63
64
65
66
 
67
68
69
 
84
85
86
87
88
 
89
90
91
92
93
94
95
96
 
97
98
99
 
 
100
101
102
103
 
 
 
104
105
106
 
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
 
231
232
233
234
 
235
236
237
238
239
240
241
242
243
244
 
 
 
 
245
246
247
248
249
250
251
252
253
 
256
257
258
259
 
260
261
 
262
263
264
 
265
266
267
 
268
269
270
 
274
275
276
277
278
 
279
280
281
282
283
284
 
 
 
285
286
287
288
 
 
289
290
291
 
11
12
13
 
14
15
16
17
 
29
30
31
 
32
33
 
 
34
35
36
37
38
 
41
42
43
 
44
45
46
47
48
49
 
50
51
52
53
 
63
64
65
 
66
67
68
69
 
84
85
86
 
 
87
88
 
 
 
 
 
 
 
89
90
 
 
91
92
93
 
 
 
94
95
96
97
98
99
 
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
 
223
224
225
 
226
227
228
229
230
231
232
 
 
 
 
233
234
235
236
237
238
 
 
239
 
240
241
242
 
245
246
247
 
248
249
 
250
251
252
 
253
254
255
 
256
257
258
259
 
263
264
265
 
 
266
267
 
 
 
 
 
268
269
270
271
 
 
 
272
273
274
275
276
@@ -11,7 +11,7 @@
 #include "shlwapi.h"     -std::string GetTHgProgRoot() +CString GetTHgProgRoot()  {   LPCSTR regname = "Software\\TortoiseHg";   HKEY key = HKEY_LOCAL_MACHINE; @@ -29,10 +29,10 @@
 // Note: if the command is a batch file and the [full] path to the  // batch contains spaces, the path must be double-quoted.  // (see http://www.encocoservices.com/createprocess.html) -bool LaunchCommand(const std::string& command, const std::string& cwd) +bool LaunchCommand(const CString& command, const CString& cwd)  { - ATLTRACE("LaunchCommand: %s\n", command.c_str()); - ATLTRACE("LaunchCommand: in '%s'\n", cwd.c_str()); + ATLTRACE("LaunchCommand: %s\n", (LPCTSTR)command); + ATLTRACE("LaunchCommand: in '%s'\n", (LPCTSTR)cwd);   PROCESS_INFORMATION processInfo;   memset(&processInfo, 0, sizeof(processInfo));   @@ -41,13 +41,13 @@
    int res = CreateProcessA(   NULL, // No module name, use command line - const_cast<char*>(command.c_str()), + (LPTSTR)(LPCTSTR)command,   NULL, // Process handle not inherited   NULL, // Thread handle not inherited   FALSE,   CREATE_NO_WINDOW,   NULL, // use parent's environment - const_cast<char*>(cwd.c_str()), + cwd,   &startupInfo,   &processInfo   ); @@ -63,7 +63,7 @@
  return true;  }   -std::string GetTemporaryFile(LPCTSTR prefix) +CString GetTemporaryFile(LPCTSTR prefix)  {   char tempDir[MAX_PATH + 1];   char tempFile[MAX_PATH + 1]; @@ -84,23 +84,16 @@
  return "";  }   - -bool IsDirectory(const std::string& filename) +CString DirName(const CString& filename)  { - return ::PathIsDirectory(filename.c_str()) != 0; -} - - -std::string DirName(const std::string& filename) -{ - if (filename.empty()) + if (filename.IsEmpty())   return filename; - std::string::size_type pos = filename.find_last_of("\\"); - if (pos == std::string::npos) + int pos = filename.ReverseFind('\\'); + if (pos == -1)   return ""; - std::string myfilename = filename.substr(0, pos); - if (myfilename.size() > 0 && myfilename[myfilename.size()-1] == ':') - myfilename.push_back('\\'); + CString myfilename = filename.Left(pos); + if (!myfilename.IsEmpty() && myfilename[myfilename.GetLength()-1] == ':') + myfilename.AppendChar('\\');   return myfilename;  }   @@ -116,82 +109,81 @@
     // not reentrant -HICON GetTortoiseIcon(const std::string& iconname) +HICON GetTortoiseIcon(const CString& iconname)  { - typedef std::map<std::string, HICON> IconCacheT; - static IconCacheT iconcache_; + typedef CAtlMap<CString, HICON> CIconCache; + static CIconCache iconcache;   - std::string thgdir = GetTHgProgRoot(); - if (thgdir.empty()) + CString thgdir = GetTHgProgRoot(); + if (thgdir.IsEmpty())   {   ATLTRACE("GetTortoiseIcon: THG root is empty\n");   return 0;   }   - const std::string iconpath = thgdir + "\\icons\\" + iconname; + CString iconpath = thgdir + "\\icons\\" + iconname;   - IconCacheT::const_iterator i = iconcache_.find(iconpath); - if (i != iconcache_.end()) - return i->second; + const CIconCache::CPair* p = iconcache.Lookup(iconname); + if (p != NULL) + return p->m_value;   - if (iconcache_.size() > 200) + if (iconcache.GetCount() > 200)   {   ATLTRACE("**** GetTortoiseIcon: error: too many icons in cache\n");   return 0;   }   - HICON h = (HICON) LoadImageA(0, iconpath.c_str(), IMAGE_ICON, - 16, 16, LR_LOADFROMFILE); + HICON h = (HICON)::LoadImage(0, iconpath, IMAGE_ICON, + 16, 16, LR_LOADFROMFILE);   if (!h)   { - ATLTRACE("GetTortoiseIcon: can't find '%s'\n", iconpath.c_str()); + ATLTRACE("GetTortoiseIcon: can't find '%s'\n", (LPCTSTR)iconpath);   return 0;   }   - iconcache_[iconpath] = h; + iconcache[iconpath] = h;     ATLTRACE("GetTortoiseIcon: added '%s' to iconcache_ (%d icons in cache)\n", - iconpath.c_str(), iconcache_.size()); + (LPCTSTR)iconpath, iconcache.GetCount());     return h;  }     -std::string GetHgRepoRoot(const std::string& path) +CString GetHgRepoRoot(LPCTSTR path)  { - ATLTRACE("GetHgRepoRoot('%s')\n", path.c_str()); + ATLTRACE("GetHgRepoRoot('%s')\n", path);   - std::string p = - (::PathIsUNCServerShare(path.c_str()) || IsDirectory(path)) - ? path : DirName(path); + CString p = (::PathIsUNCServerShare(path) || ::PathIsDirectory(path)) ? + path : DirName(path);   for (;;)   { - std::string tdir = p + "\\.hg"; - if (::PathIsUNCServerShare(tdir.c_str())) + CString tdir = p + "\\.hg"; + if (::PathIsUNCServerShare(tdir))   { - ATLTRACE("GetHgRepoRoot: tdir is UNC share '%s'\n", tdir.c_str()); - p.clear(); + ATLTRACE("GetHgRepoRoot: tdir is UNC share '%s'\n", (LPCTSTR)tdir); + p.Empty();   break;   } - else if (IsDirectory(tdir)) + else if (::PathIsDirectory(tdir))   break; - std::string oldp = p; + CString oldp = p;   p = DirName(p);   if (p == oldp)   { - p.clear(); + p.Empty();   break;   }   }   - ATLTRACE("GetHgRepoRoot: returning '%s'\n", p.c_str()); + ATLTRACE("GetHgRepoRoot: returning '%s'\n", (LPCTSTR)p);   return p;  }     -bool IsHgRepo(const std::string& path) +bool IsHgRepo(LPCTSTR path)  { - return !GetHgRepoRoot(path).empty(); + return !GetHgRepoRoot(path).IsEmpty();  }     @@ -231,23 +223,20 @@
     // read string value from registry, wide version -int GetRegSZValueW(HKEY hkey, const wchar_t* name, std::wstring& res) +int GetRegSZValueW(HKEY hkey, const wchar_t* name, CStringW& res)  {   res = L"";     if (!hkey)   return 0;   - std::vector<BYTE> Data(600); - DWORD cbData = (DWORD)Data.size(); - - LONG rv = ::RegQueryValueExW(hkey, name, 0, 0, &Data[0], &cbData); + DWORD cbData = 600; + LPWSTR lpszData = res.GetBuffer(cbData); + LONG rv = ::RegQueryValueExW(hkey, name, 0, 0, (LPBYTE)lpszData, &cbData); + res.ReleaseBuffer(cbData);     if (rv == ERROR_SUCCESS) - { - res = reinterpret_cast<wchar_t*>(&Data[0]);   return 1; - }     ATLTRACE(L"GetRegSZValueW('%s') failed\n", name);   @@ -256,15 +245,15 @@
     // true if a starts with b -bool StartsWith(const std::string& a, const std::string& b) +bool StartsWith(const CString& a, const CString& b)  { - if (a.empty() || b.empty()) + if (a.IsEmpty() || b.IsEmpty())   return false;   - if (b.size() > a.size()) + if (b.GetLength() > a.GetLength())   return false;   - for (std::string::size_type i = 0; i < b.size(); ++i) + for (int i = 0; i < b.GetLength(); ++i)   {   if (a[i] != b[i])   return false; @@ -274,18 +263,14 @@
 }     -void Tokenize(const std::string& str, std::vector<std::string>& tokens, - const std::string& delimiters) +void Tokenize(CString str, CAtlList<CString>& tokens, LPCTSTR delimiters)  { - typedef std::string S; - S::size_type lastpos = str.find_first_not_of(delimiters, 0); - S::size_type pos = str.find_first_of(delimiters, lastpos); - - while (S::npos != pos || S::npos != lastpos) + int pos = 0; + CString strToken = str.Tokenize(delimiters, pos); + while (!strToken.IsEmpty())   { - tokens.push_back(str.substr(lastpos, pos - lastpos)); - lastpos = str.find_first_not_of(delimiters, pos); - pos = str.find_first_of(delimiters, lastpos); + tokens.AddTail(strToken); + strToken = str.Tokenize(delimiters, pos);   }  }  
 
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
 
6
7
8
 
 
 
 
9
10
11
12
 
 
 
13
14
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
21
22
@@ -6,30 +6,17 @@
 #include <string>  #include <vector>   -std::string GetTHgProgRoot(); -std::string GetTemporaryFile(LPCSTR prefix="THG"); -bool IsDirectory(const std::string&); -std::string DirName(const std::string&); +CString GetTHgProgRoot(); +CString GetTemporaryFile(LPCSTR prefix="THG"); +CString DirName(const CString& filename);  std::string BaseName(const std::string&); -bool LaunchCommand(const std::string& command, const std::string& cwd); -HICON GetTortoiseIcon(const std::string & iconname); -std::string GetHgRepoRoot(const std::string& path); +bool LaunchCommand(const CString& command, const CString& cwd); +HICON GetTortoiseIcon(const CString& iconname); +CString GetHgRepoRoot(LPCTSTR path);  bool IsHgRepo(const std::string& path);  FILE* fopenReadRenameAllowed(const char* path); -int GetRegSZValueW(HKEY hkey, const wchar_t* name, std::wstring& res); -bool StartsWith(const std::string& a, const std::string& b); -void Tokenize(const std::string& str, std::vector<std::string>& tokens, - const std::string& delimiters = " "); - -template <typename C, typename T> -bool contains(const C& c, const T& t) -{ - for (C::const_iterator i = c.begin(); i != c.end(); ++i) - { - if (*i == t) - return true; - } - return false; -} +int GetRegSZValueW(HKEY hkey, const wchar_t* name, CStringW& res); +bool StartsWith(const CString& a, const CString& b); +void Tokenize(CString str, CAtlList<CString>& tokens, LPCTSTR delimiters = " ");    #endif
 
40
41
42
43
 
44
45
46
 
40
41
42
 
43
44
45
46
@@ -40,7 +40,7 @@
    Directory& root() { return root_; }   - void add(const std::string& relpath, Direntry& e) { + void add(const CString& relpath, Direntry& e) {   root_.add(relpath, e);   ++num_entries_;   }
 
14
15
16
 
 
17
18
19
20
21
 
14
15
16
17
18
19
 
20
21
22
@@ -14,8 +14,9 @@
 #include <atlbase.h>  extern CComModule _Module;  #include <atlcom.h> +#include <atlstr.h> +#include <atlcoll.h>  #include <shlobj.h> -#include <string>    #endif