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

fogcreek shellext: use ATL strings and collections, part 4

Changeset 605b3738664e

Parent caf9be1e996d

by David Golub

Changes to 21 files · Browse files at 605b3738664e Showing diff from parent caf9be1e996d Diff from another changeset...

 
159
160
161
162
 
163
164
165
166
167
168
169
 
170
171
172
 
339
340
341
342
 
 
343
344
345
 
346
347
 
348
349
350
351
352
353
354
355
356
357
 
358
359
360
 
414
415
416
417
418
419
420
421
422
 
581
582
583
584
 
585
586
587
 
632
633
634
635
 
636
637
638
 
656
657
658
659
660
 
 
661
662
663
 
819
820
821
822
823
 
824
825
826
 
845
846
847
848
849
 
 
850
851
852
 
853
854
855
856
857
 
 
 
858
859
860
 
865
866
867
868
 
869
870
871
 
159
160
161
 
162
163
164
165
166
167
168
 
169
170
171
172
 
339
340
341
 
342
343
344
345
 
346
347
348
349
350
351
352
353
354
 
 
 
 
 
355
356
357
358
 
412
413
414
 
 
 
415
416
417
 
576
577
578
 
579
580
581
582
 
627
628
629
 
630
631
632
633
 
651
652
653
 
 
654
655
656
657
658
 
814
815
816
 
 
817
818
819
820
 
839
840
841
 
 
842
843
844
845
 
846
847
848
 
 
 
849
850
851
852
853
854
 
859
860
861
 
862
863
864
865
@@ -159,14 +159,14 @@
  RegCloseKey(hkey);  }   -void CShellExtCMenuBase::InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz) +void CShellExtCMenuBase::InitMenuMaps(const MenuDescription *menuDescs, int sz)  {   if (myDescMap.IsEmpty())   {   CString lang;   GetRegistryConfig("CMenuLang", lang);   - for (std::size_t i = 0; i < sz; i++) + for (int i = 0; i < sz; i++)   {   MenuDescription md = menuDescs[i];   @@ -339,22 +339,20 @@
  }     // allocate buffer for the string - std::vector<wchar_t> text(mii.cch + 1); + CStringW strMenuItemText; + LPWSTR lpszBuf = strMenuItemText.GetBuffer(mii.cch + 1);     // second GetMenuItemInfoW call: get string into buffer - mii.dwTypeData = &text[0]; + mii.dwTypeData = lpszBuf;   ++mii.cch; // size of buffer is one more than length of string   res = ::GetMenuItemInfoW(hMenu, i, true, &mii); + strMenuItemText.ReleaseBuffer();   if (res == 0) {   ATLTRACE("HasTortoiseMenu: second GetMenuItemInfo returned 0\n");   continue;   }   - const std::wstring menuitemtext(&text[0]); - //TDEBUG_TRACEW(L"HasTortoiseMenu: " - // << L"menuitemtext is '" << menuitemtext << L"'"); - - if (menuitemtext == TortoiseHgMenuEntryString) + if (strMenuItemText == TortoiseHgMenuEntryString)   {   ATLTRACE("HasTortoiseMenu: FOUND TortoiseHg menu entry\n");   hasmenu = true; @@ -414,9 +412,6 @@
    InitMenuMaps(CMenuMenuDescList, sizeof(CMenuMenuDescList) / sizeof(MenuDescription));   - typedef std::vector<std::string> entriesT; - typedef entriesT::const_iterator entriesIter; -   CString promoted_string = "commit,workbench"; // default value if key not found   GetRegistryConfig("PromotedItems", promoted_string);   @@ -581,7 +576,7 @@
  const char* psz = "";   const wchar_t* pszw = 0;   - std::string sflags = "?"; + CString sflags = "?";   switch (uFlags)   {   case GCS_HELPTEXTW: @@ -632,7 +627,7 @@
  else if (uFlags == GCS_VERBW || uFlags == GCS_VERBA)   {  #if 0 - psz = iter->second.name.c_str(); + psz = iter->second.name;  #else   // bugfix: don't provide verbs ("rename" conflicted with rename of explorer)   psz = ""; @@ -656,8 +651,8 @@
  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(); + CStringW wpsz = psz; + const wchar_t* const src = pszw ? pszw : wpsz;     wcsncpy_s(dest, cchMax, src, cchMax-1);   *(dest + cchMax-1) = 0; @@ -819,8 +814,7 @@
  return;   }   - typedef std::vector<std::string>::size_type ST; - for (ST i = 0; i < myFiles.GetCount(); i++) + for (int i = 0; i < myFiles.GetCount(); i++)   {   DWORD dwWritten;   ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)myFiles[i]); @@ -845,16 +839,16 @@
 #else   const char* shellexid = "{728E8840-5878-4EA7-918F-281C2697ABB1}";  #endif - std::vector<char> product_id(50, 0); - UINT msires = ::MsiGetProductCodeA(shellexid, &product_id[0]); + char szProductId[50]; + UINT msires = ::MsiGetProductCodeA(shellexid, szProductId);   ATLTRACE("MSI shellexid: %s\n", shellexid);   ATLTRACE("MSI msires: %d", msires); - ATLTRACE("MSI installed product id: %s\n", &product_id[0]); + ATLTRACE("MSI installed product id: %s\n", szProductId);     DWORD busize = 300; - std::vector<char> buf(busize, 0); - msires = ::MsiGetProductInfoA( - &product_id[0], INSTALLPROPERTY_INSTALLLOCATION, &buf[0], &busize); + CAutoVectorPtr<char> buf(new char[busize]); + msires = ::MsiGetProductInfo(szProductId, INSTALLPROPERTY_INSTALLLOCATION, + buf, &busize);   if (msires == ERROR_SUCCESS)   {   ATLTRACE("MSI install location: %s\n", &buf[0]); @@ -865,7 +859,7 @@
  }     ATLTRACE(L"---- TortoiseHg shell extension version %s ----", - ThgVersion::get().c_str()); + (LPCTSTR)ThgVersion::get());     ATLTRACE(" pIDFolder: %p\n", pIDFolder);   ATLTRACE(" pDataObj: %p\n", pDataObj);
 
28
29
30
31
 
32
33
34
 
28
29
30
 
31
32
33
34
@@ -28,7 +28,7 @@
    void TweakMenuForVista(HMENU menu);   void PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj); - void InitMenuMaps(const MenuDescription *menuDescs, std::size_t sz); + void InitMenuMaps(const MenuDescription *menuDescs, int sz);   void InsertMenuItemByName(HMENU hMenu, const CString& name, UINT indexMenu,   UINT idCmd, UINT idCmdFirst, const CStringW& prefix);   void AddMenuList(UINT idCmd, const CString& name);
 
46
47
48
49
50
51
52
53
54
 
46
47
48
 
 
 
49
50
51
@@ -46,9 +46,6 @@
    InitMenuMaps(CDndMenuDescList, sizeof(CDndMenuDescList) / sizeof(MenuDescription));   - typedef std::vector<std::string> entriesT; - typedef entriesT::const_iterator entriesIter; -   const char* entries_string = DropMenu;   CAtlList<CString> entries;   Tokenize(entries_string, entries, " ");
 
48
49
50
51
52
53
 
 
 
54
55
56
 
48
49
50
 
 
 
51
52
53
54
55
56
@@ -48,9 +48,9 @@
    if (path.GetLength() > 2 && path[1] == ':')   { - std::string t = "C:\\"; - t[0] = path[0]; - if (::GetDriveType(t.c_str()) == 4) + CString t = "C:\\"; + t.SetAt(0, path[0]); + if (::GetDriveType(t) == 4)   return S_FALSE;   }   }
 
20
21
22
23
24
25
26
27
28
29
 
20
21
22
 
 
 
 
23
24
25
@@ -20,10 +20,6 @@
   #include "Direntry.h"   -#include <vector> -#include <string> - -  class Directory  {   Directory* const parent_;
 
159
160
161
162
163
164
165
166
 
159
160
161
 
 
162
163
164
@@ -159,8 +159,6 @@
   void Dirstatecache::invalidate(const CString& hgroot, bool usekbfiles)  { - typedef std::list<E>::iterator Iter; -   if (hgroot.IsEmpty())   return;  
 
18
19
20
21
22
23
24
25
 
18
19
20
 
 
21
22
23
@@ -18,8 +18,6 @@
 #ifndef _DIRSTATECACHE_H  #define _DIRSTATECACHE_H   -#include <list> -  class Dirstate;    class Dirstatecache
 
22
23
24
25
26
27
28
 
22
23
24
 
25
26
27
@@ -22,7 +22,6 @@
 #pragma once  #include <Uxtheme.h>  #include <GdiPlus.h> -#include <map>    typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow);  typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
 
14
15
16
17
18
19
20
21
 
14
15
16
 
 
17
18
19
@@ -14,8 +14,6 @@
 // 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 <string> -  class InitStatus  {  public:
 
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
 
129
130
131
132
 
133
134
135
 
156
157
158
159
160
 
 
161
162
163
 
170
171
172
173
 
174
175
176
177
 
178
179
180
 
209
210
211
212
 
213
214
215
 
279
280
281
282
283
 
 
284
285
286
 
288
289
290
291
 
292
293
294
295
296
297
298
 
 
299
300
301
 
346
347
348
349
 
350
351
352
 
353
354
355
 
368
369
370
371
 
372
373
374
375
376
 
377
378
379
 
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
 
129
130
131
 
132
133
134
135
 
156
157
158
 
 
159
160
161
162
163
 
170
171
172
 
173
174
175
176
 
177
178
179
180
 
209
210
211
 
212
213
214
215
 
279
280
281
 
 
282
283
284
285
286
 
288
289
290
 
291
292
293
294
295
296
 
 
297
298
299
300
301
 
346
347
348
 
349
350
351
 
352
353
354
355
 
368
369
370
 
371
372
373
374
375
 
376
377
378
379
@@ -76,25 +76,25 @@
   int findHgRoot(char cls, QueryState& cur, QueryState& last, bool outdated)  { - std::string dp = "["; dp += cls; dp += "] findHgRoot"; + CString dp = "["; dp += cls; dp += "] findHgRoot";     { - std::string p = cur.path; - p.push_back('\\'); + CString p = cur.path; + p.AppendChar('\\');   bool unset = false; - if (p.find("\\.hg\\") != std::string::npos) + if (p.Find("\\.hg\\") != -1)   {   // ignore files and dirs named '.hg'   last = cur;   return 0;   } - size_t pos; - if ((pos = p.find("\\.kbf\\")) != std::string::npos) + int pos; + if ((pos = p.Find("\\.kbf\\")) != -1)   { - p.resize(pos); + p.Truncate(pos);   p += "\\.hg\\kilnbfiles\\dirstate";   Winstat stat; - if (stat.lstat(p.c_str(), true) == 0) + if (stat.lstat(p, true) == 0)   {   // ignore files and dirs named '.kbf' when kbfiles is enabled   last = cur; @@ -129,7 +129,7 @@
  if (has_hg)   {   cur.hgroot = cur.path; - ATLTRACE("%s('%s'): hgroot = cur.path\n", dp.c_str(), cur.path); + ATLTRACE("%s('%s'): hgroot = cur.path\n", (LPCTSTR)dp, (LPCTSTR)cur.path);   return 1;   }   } @@ -156,8 +156,8 @@
  if (has_hg)   {   cur.hgroot = p; - ATLTRACE("%s('%s'): hgroot = '%s' (found repo)", dp.c_str(), - cur.path, cur.hgroot); + ATLTRACE("%s('%s'): hgroot = '%s' (found repo)", (LPCTSTR)dp, + (LPCTSTR)cur.path, (LPCTSTR)cur.hgroot);   return 1;   }   CString p2 = DirName(p); @@ -170,11 +170,11 @@
  if (file_access_is_unacceptably_slow)   {   ATLTRACE("****** %s('%s'): ignored, call took too long (%d ticks)\n", - dp.c_str(), cur.path, ticks); + (LPCTSTR)dp, (LPCTSTR)cur.path, ticks);   }   else   { - ATLTRACE("%s('%s'): NO repo found\n", dp.c_str(), cur.path); + ATLTRACE("%s('%s'): NO repo found\n", (LPCTSTR)dp, (LPCTSTR)cur.path);   }   last = cur;   return 0; @@ -209,7 +209,7 @@
  char& outStatus  )  { - std::string dp = "["; dp += cls; dp += "] HgQueryDirstate: "; + CString dp = "["; dp += cls; dp += "] HgQueryDirstate: ";     static QueryState last;   @@ -279,8 +279,8 @@
  Dirstate* pds = Dirstatecache::get(cur.hgroot, cur.basedir, unset);   if (!pds)   { - ATLTRACE("%s Dirstatecache::get('%s') returns no Dirstate\n", dp.c_str(), - cur.hgroot); + ATLTRACE("%s Dirstatecache::get('%s') returns no Dirstate\n", (LPCTSTR)dp, + (LPCTSTR)cur.hgroot);   last = cur;   return 0;   } @@ -288,14 +288,14 @@
  Winstat stat;   if (0 != stat.lstat(path))   { - ATLTRACE("%s lstat('%s') failed", dp.c_str(), path); + ATLTRACE("%s lstat('%s') failed", (LPCTSTR)dp, (LPCTSTR)path);   last = cur;   return 0;   }   cur.isdir = stat.isdir;  #if 0 - ATLTRACE("%s stat.lstat('%s') -> stat.isdir is %d\n" << dp.c_str(), - cur.path.c_str(), (int)stat.isdir); + ATLTRACE("%s stat.lstat('%s') -> stat.isdir is %d\n" << (LPCTSTR)dp, + (LPCTSTR)cur.path, (int)stat.isdir);  #endif     if (cur.isdir) @@ -346,10 +346,10 @@
  CString relbase;   if (pdirsta && get_relpath(cur.hgroot, cur.basedir, relbase))   { - ATLTRACE("%s relbase = '%s'\n", dp.c_str(), (LPCTSTR)relbase); + ATLTRACE("%s relbase = '%s'\n", (LPCTSTR)dp, (LPCTSTR)relbase);     char basedir_status = pdirsta->status(relbase); - ATLTRACE("%s basedir_status = '%c'\n", dp.c_str(), basedir_status); + ATLTRACE("%s basedir_status = '%c'\n", (LPCTSTR)dp, basedir_status);     if (basedir_status != 'M')   update = true; @@ -368,12 +368,12 @@
  lasttickcount = tc;   }   - ATLTRACE("%s outStatus is 'P'\n", dp.c_str()); + ATLTRACE("%s outStatus is 'P'\n", (LPCTSTR)dp);   }     if (update)   { - ATLTRACE("%s calling Thgstatus::update\n", dp.c_str()); + ATLTRACE("%s calling Thgstatus::update\n", (LPCTSTR)dp);   Thgstatus::update(path);   }  
 
1
2
3
4
5
6
7
8
 
1
2
3
 
 
4
5
6
@@ -1,8 +1,6 @@
 #ifndef _QUERY_DIRSTATE_H  #define _QUERY_DIRSTATE_H   -#include <string> -  int HgQueryDirstate(   const char myClass,   const CString& path,
 
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
 
18
19
20
 
 
 
21
22
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -18,53 +18,9 @@
 #include "stdafx.h"  #include "StringUtils.h"   -#include <vector> - -  // Quotes a string  CString Quote(const CString& str)  {   CString sResult = "\"" + str + "\"";   return sResult;  } - - -// Convert Unicode string to multibyte string -std::string WideToMultibyte(const std::wstring& wide, UINT CodePage) -{ - // Determine length of string - int ret = WideCharToMultiByte( - CodePage, 0, wide.c_str(), static_cast<int>(wide.length()), - NULL, 0, NULL, NULL - ); - - std::vector<CHAR> narrow(ret + 1); - - ret = WideCharToMultiByte( - CodePage, 0, wide.c_str(), static_cast<int>(wide.length()), - &narrow[0], ret, NULL, NULL - ); - narrow[ret] = '\0'; - - return &narrow[0]; -} - - -// Convert multibyte string to Unicode string -std::wstring MultibyteToWide(const std::string& multibyte, UINT CodePage) -{ - int ret = MultiByteToWideChar( - CodePage, 0, multibyte.c_str(), - static_cast<int>(multibyte.length()), 0, 0 - ); - - std::vector<wchar_t> wide(ret + 1); - - ret = MultiByteToWideChar( - CodePage, 0, multibyte.c_str(), - static_cast<int>(multibyte.length()), &wide[0], ret - ); - wide[ret] = L'\0'; - - return &wide[0]; -}
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
18
19
20
 
21
22
23
24
25
 
 
 
 
 
 
 
26
@@ -18,17 +18,9 @@
 #ifndef _STRING_UTILS_H  #define _STRING_UTILS_H   -#include <string>  #include <windows.h>    // Quotes a string  CString Quote(const CString& str);   -// Convert Unicode string to multibyte string -std::string WideToMultibyte(const std::wstring& wide, UINT CodePage = CP_ACP); - -// Convert multibyte string to Unicode string -std::wstring MultibyteToWide(const std::string& multibyte, UINT CodePage = CP_ACP); - -  #endif
 
 
1
2
3
 
6
7
8
9
 
10
11
12
 
1
2
3
4
 
7
8
9
 
10
11
12
13
@@ -1,3 +1,4 @@
+#include "stdafx.h"  #include "ThgVersion.h"  #include "parentid.h"   @@ -6,7 +7,7 @@
   #define THG_PARENT_ID_STRING TOSTR2(THG_PARENT_ID)   -std::wstring ThgVersion::get() +CString ThgVersion::get()  {   return THG_PARENT_ID_STRING;  }
 
1
2
3
4
5
6
7
8
9
 
10
11
12
 
1
2
3
 
 
4
5
6
 
7
8
9
10
@@ -1,12 +1,10 @@
 #ifndef _THGVERSION_H  #define _THGVERSION_H   -#include <string> -  class ThgVersion  {  public: - static std::wstring get(); + static CString get();  };    #endif
 
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
 
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
@@ -18,37 +18,32 @@
   #include "Thgstatus.h"   -#include <vector> - - -std::string GetPipeName() +CString GetPipeName()  {   DWORD size = 260; - std::vector<char> buf(size); - if (!::GetUserNameA(&buf[0], &size)) + char buf[260]; + if (!::GetUserNameA(buf, &size))   return ""; - std::string res = "\\\\.\\pipe\\TortoiseHgRpcServer-bc0c27107423-"; - res += &buf[0]; + CString res = "\\\\.\\pipe\\TortoiseHgRpcServer-bc0c27107423-"; + res += buf;   return res;  }      int Thgstatus::SendRequest(const CString& request)  { - static const std::string pname = GetPipeName(); + static const CString pname = GetPipeName();   - if (pname.empty()) + if (pname.IsEmpty())   return 0;     BOOL fSuccess;   DWORD cbRead;   - ATLTRACE("Thgstatus::update: sending '%s' to %s\n", (LPCTSTR)request, pname.c_str()); + ATLTRACE("Thgstatus::update: sending '%s' to %s\n", (LPCTSTR)request, (LPCTSTR)pname);   - fSuccess = ::CallNamedPipeA( - pname.c_str(), (void*)(LPCTSTR)request, request.GetLength(), 0, 0, &cbRead, - NMPWAIT_NOWAIT - ); + fSuccess = ::CallNamedPipeA(pname, (void*)(LPCTSTR)request, request.GetLength(), + 0, 0, &cbRead, NMPWAIT_NOWAIT);     DWORD err = GetLastError();   if (fSuccess || err == ERROR_MORE_DATA || err == ERROR_PIPE_NOT_CONNECTED)
 
17
18
19
20
21
22
23
24
 
17
18
19
 
 
20
21
22
@@ -17,8 +17,6 @@
 #ifndef _THGSTATUS_H  #define _THGSTATUS_H   -#include <string> -  class Thgstatus  {   static int SendRequest(const CString& request);
 
1
2
3
4
5
6
7
8
 
1
2
 
 
 
3
4
5
@@ -1,8 +1,5 @@
 #include "stdafx.h"  #include "TortoiseUtils.h" - -#include <map> -  #include "IconBitmapUtils.h"    HBITMAP GetTortoiseIconBitmap(const CString& iconname)
 
2
3
4
5
6
7
8
 
2
3
4
 
5
6
7
@@ -2,7 +2,6 @@
 #define TORTOISE_ICON_BITMAP_H_    #include <windows.h> -#include <string>    HBITMAP GetTortoiseIconBitmap(const CString& iconname);  
 
1
2
3
4
5
6
7
8
9
 
10
11
12
 
97
98
99
100
 
101
102
 
103
104
105
 
 
106
107
 
108
109
110
 
1
2
3
 
4
 
 
5
 
6
7
8
9
 
94
95
96
 
97
98
 
99
100
 
 
101
102
103
 
104
105
106
107
@@ -1,12 +1,9 @@
 #include "stdafx.h"  #include "TortoiseUtils.h"   -#include <vector>  #include <assert.h> -#include <map> -  #include <io.h> -#include "FCNTL.H" +#include <fcntl.h>    #include "shlwapi.h"   @@ -97,14 +94,14 @@
  return myfilename;  }   -std::string BaseName(const std::string& filename) +CString BaseName(const CString& 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 filename; - return filename.substr(pos+1); + return filename.Mid(pos+1);  }    
 
3
4
5
6
7
8
9
10
11
12
 
13
14
15
16
 
17
18
19
 
3
4
5
 
 
6
7
8
9
 
10
11
12
13
 
14
15
16
17
@@ -3,17 +3,15 @@
   #include <malloc.h>  #include <windows.h> -#include <string> -#include <vector>    CString GetTHgProgRoot();  CString GetTemporaryFile(LPCSTR prefix="THG");  CString DirName(const CString& filename); -std::string BaseName(const std::string&); +CString BaseName(const CString& filename);  bool LaunchCommand(const CString& command, const CString& cwd);  HICON GetTortoiseIcon(const CString& iconname);  CString GetHgRepoRoot(LPCTSTR path); -bool IsHgRepo(const std::string& path); +bool IsHgRepo(const CString& path);  FILE* fopenReadRenameAllowed(const char* path);  int GetRegSZValueW(HKEY hkey, const wchar_t* name, CStringW& res);  bool StartsWith(const CString& a, const CString& b);