3 #include "WaitDialog.h"
9 HRESULT
CProvider::FinalConstruct()
14 void CProvider::FinalRelease()
18 CProvider::parameters_t
CProvider::ParseParameters(BSTR parameters
) const
20 CString
temp(parameters
);
24 // TODO: Handle quoting and stuff
26 CString token
= temp
.Tokenize(_T(";"), pos
);
27 while (token
!= _T(""))
29 int x
= token
.Find('=');
30 CString name
= token
.Left(x
);
31 CString value
= token
.Mid(x
+ 1);
35 token
= temp
.Tokenize(_T(";"), pos
);
41 HRESULT STDMETHODCALLTYPE
CProvider::ValidateParameters(
42 /* [in] */ HWND hParentWnd
,
43 /* [in] */ BSTR parameters
,
44 /* [retval][out] */ VARIANT_BOOL
*valid
)
46 // Don't bother validating the parameters yet.
47 *valid
= VARIANT_TRUE
;
51 HRESULT STDMETHODCALLTYPE
CProvider::GetLinkText(
52 /* [in] */ HWND hParentWnd
,
53 /* [in] */ BSTR parameters
,
54 /* [retval][out] */ BSTR
*linkText
)
56 parameters_t params
= ParseParameters(parameters
);
57 CString prompt
= params
[CString("Prompt")];
59 *linkText
= SysAllocString(L
"Choose Task...");
61 *linkText
= prompt
.AllocSysString();
66 HRESULT STDMETHODCALLTYPE
CProvider::GetCommitMessage(
67 /* [in] */ HWND hParentWnd
,
68 /* [in] */ BSTR parameters
,
69 /* [in] */ BSTR commonRoot
,
70 /* [in] */ SAFEARRAY
* pathList
,
71 /* [in] */ BSTR originalMessage
,
72 /* [retval][out] */ BSTR
*newMessage
)
74 return GetCommitMessage2(hParentWnd
, parameters
, NULL
, commonRoot
, pathList
, originalMessage
, newMessage
);
77 HRESULT STDMETHODCALLTYPE
CProvider::GetCommitMessage2(
78 /* [in] */ HWND hParentWnd
,
79 /* [in] */ BSTR parameters
,
80 /* [in] */ BSTR commonURL
,
81 /* [in] */ BSTR commonRoot
,
82 /* [in] */ SAFEARRAY
* pathList
,
83 /* [in] */ BSTR originalMessage
,
84 /* [retval][out] */ BSTR
*newMessage
)
90 // do something with the common root url
94 parameters_t params
= ParseParameters(parameters
);
95 CString commandLine
= params
[CString("CommandLine")];
97 if (commandLine
.IsEmpty())
99 MessageBox(hParentWnd
, _T("CommandLine parameter is empty"), _T("ExampleAtlPlugin"), MB_OK
| MB_ICONERROR
);
103 TCHAR szTempPath
[MAX_PATH
];
104 GetTempPath(ARRAYSIZE(szTempPath
), szTempPath
);
106 // Create a temporary file to hold the path list, and write the list to the file.
107 TCHAR szPathListTempFile
[MAX_PATH
];
108 GetTempFileName(szTempPath
, _T("svn"), 0, szPathListTempFile
);
111 HANDLE hPathListFile
= CreateFile(szPathListTempFile
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
114 if (FAILED(SafeArrayGetLBound(pathList
, 1, &a
)) || (FAILED(SafeArrayGetUBound(pathList
, 1, &b
))))
117 for (LONG i
= a
; i
<= b
; ++i
)
120 SafeArrayGetElement(pathList
, &i
, &path
);
122 CStringA line
= OLE2A(path
);
125 WriteFile(hPathListFile
, line
, line
.GetLength(), &bytesWritten
, NULL
);
128 CloseHandle(hPathListFile
);
130 TCHAR szOriginalMessageTempFile
[MAX_PATH
];
131 GetTempFileName(szTempPath
, _T("svn"), 0, szOriginalMessageTempFile
);
133 HANDLE hOriginalMessageFile
= CreateFile(szOriginalMessageTempFile
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
135 CStringA temp
= OLE2A(originalMessage
);
136 WriteFile(hOriginalMessageFile
, temp
, temp
.GetLength(), &bytesWritten
, NULL
);
138 CloseHandle(hOriginalMessageFile
);
140 commandLine
.AppendFormat(_T(" \"%s\" \"%ls\" \"%s\""), szPathListTempFile
, commonRoot
, szOriginalMessageTempFile
);
142 CString message
= originalMessage
;
143 CWaitDialog
dlg(commandLine
);
144 if (dlg
.DoModal() == IDOK
)
146 HANDLE hOrig
= CreateFile(szOriginalMessageTempFile
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
147 DWORD cb
= GetFileSize(hOrig
, NULL
);
148 BYTE
*buffer
= (BYTE
*)malloc(cb
+ 1);
149 memset(buffer
, 0, cb
+ 1);
151 ReadFile(hOrig
, buffer
, cb
, &bytesRead
, NULL
);
154 message
= A2T((const char *)buffer
);
157 DeleteFile(szPathListTempFile
);
158 DeleteFile(szOriginalMessageTempFile
);
160 *newMessage
= message
.AllocSysString();
164 HRESULT STDMETHODCALLTYPE
CProvider::OnCommitFinished (
165 /* [in] */ HWND hParentWnd
,
166 /* [in] */ BSTR commonRoot
,
167 /* [in] */ SAFEARRAY
* pathList
,
168 /* [in] */ BSTR logMessage
,
169 /* [in] */ ULONG revision
,
170 /* [out, retval] */ BSTR
* error
)
172 CString err
= _T("Test error string");
173 *error
= err
.AllocSysString();
177 HRESULT STDMETHODCALLTYPE
CProvider::HasOptions(
178 /* [out, retval] */ VARIANT_BOOL
*ret
)
180 MessageBox(NULL
, _T("test"), _T("test"), MB_ICONERROR
);
181 *ret
= VARIANT_FALSE
;
182 MessageBox(NULL
, _T("test2"), _T("test2"), MB_ICONERROR
);
186 // this method is called if HasOptions() returned true before.
187 // Use this to show a custom dialog so the user doesn't have to
188 // create the parameters string manually
189 HRESULT STDMETHODCALLTYPE
CProvider::ShowOptionsDialog(
190 /* [in] */ HWND hParentWnd
,
191 /* [in] */ BSTR parameters
,
192 /* [out, retval] */ BSTR
* newparameters
195 // we don't show an options dialog