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