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

fogcreek shellext: perform file I/O using CAtlFile, part 1

Changeset ef6ea1af6f56

Parent 7654159f827b

by David Golub

Changes to 2 files · Browse files at ef6ea1af6f56 Showing diff from parent 7654159f827b 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
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
 // 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 "RunDialog.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "THgStatus.h"  #include "Kiln.h"  #include "KeyboardHelpDialog.h"    void RunDialog(HWND hWnd, const CString& strCmd, const CAtlList<CString>& listFiles,   const CString& strFolder)  {   CString strDir = GetTHgProgRoot();   if (strDir.IsEmpty())   {   ATLTRACE("RunDialog: THG root is empty\n");   return;   }   CString strHgCmd = strDir + "\\thgw.exe";     WIN32_FIND_DATA data;   HANDLE hFind = ::FindFirstFile(strHgCmd, &data);   if (hFind == INVALID_HANDLE_VALUE)   {   strHgCmd = strDir + "\\hgtk.exe";   hFind = ::FindFirstFile(strHgCmd, &data);   if (hFind == INVALID_HANDLE_VALUE)   {   strHgCmd = strDir + "\\thg.cmd";   }   else   {   ::FindClose(hFind);   }   }   else   {   ::FindClose(hFind);   }     strHgCmd = Quote(strHgCmd) + " --nofork " + strCmd;     CString strCwd;   if (!strFolder.IsEmpty())   {   strCwd = strFolder;   }   else if (!listFiles.IsEmpty())   {   strCwd = listFiles.GetHead();   if (!::PathIsDirectory(strCwd)) strCwd = DirName(strCwd);   }   else   {   ATLTRACE("***** RunDialog: can't get cwd\n");   return;   }     if (strCmd == "thgstatus")   {   if (CTHgStatus::Remove(strCwd) != 0)   {   CString strPath = strDir + "\\TortoiseHgOverlayServer.exe";   LaunchCommand(Quote(strPath), strDir);   }   return;   }   else if (strCmd == "keyboard")   {   CKeyboardHelpDialog dlg;   dlg.DoModal(hWnd);   }   else if (strCmd == "kiln")   {   KilnOpenRepo(hWnd, strCwd);   return;   }   else if (strCmd == "kilnfiles")   {   KilnOpenFiles(hWnd, strCwd, listFiles);   return;   }     if (!listFiles.IsEmpty())   {   CString strTempFile = GetTemporaryFile();   if (strTempFile.IsEmpty())   {   ATLTRACE("***** RunDialog: error: GetTemporaryFile returned empty string\n");   return;   }     ATLTRACE("RunDialog: temp file = %s\n", (LPCTSTR)strTempFile); - HANDLE hTempFile = ::CreateFile(strTempFile, GENERIC_WRITE, FILE_SHARE_READ, 0, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (hTempFile == INVALID_HANDLE_VALUE) + CAtlFile file; + if (FAILED(file.Create(strTempFile, GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS)))   {   ATLTRACE("***** RunDialog: error: failed to create file '%s'\n",   (LPCTSTR)strTempFile);   return;   }   - DWORD dwWritten;   POSITION position = listFiles.GetHeadPosition();   while (position != NULL)   {   CString strFile = listFiles.GetNext(position);   ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)strFile); - ::WriteFile(hTempFile, (LPCTSTR)strFile, strFile.GetLength(), &dwWritten, 0); - ::WriteFile(hTempFile, "\n", 1, &dwWritten, 0); + file.Write((LPCTSTR)strFile, strFile.GetLength()); + file.Write("\n", 1);   }   if (strCmd == "drag_move" || strCmd == "drag_copy")   {   // Append the current directory as the dest. - ::WriteFile(hTempFile, (LPCTSTR)strCwd, strCwd.GetLength(), &dwWritten, 0); - ::WriteFile(hTempFile, "\n", 1, &dwWritten, 0); + file.Write((LPCTSTR)strCwd, strCwd.GetLength()); + file.Write("\n", 1);   }   - ::CloseHandle(hTempFile); + file.Close();   strHgCmd += " --listfile " + Quote(strTempFile);   }     LaunchCommand(strHgCmd, strCwd);  }
 
27
28
29
 
30
 
27
28
29
30
31
@@ -27,4 +27,5 @@
 #include <atlwin.h>  #include <atlstr.h>  #include <atlcoll.h> +#include <atlfile.h>  #include <shlobj.h>