*.js files: keep the style consistent
[TortoiseGit.git] / contrib / issue-tracker-plugins / ExampleAtlPlugin / Provider.cpp
blob703f505673d839a20029ad2f7699eeb68c7532ed
1 #include "stdafx.h"
2 #include "Provider.h"
3 #include "WaitDialog.h"
5 CProvider::CProvider()
9 HRESULT CProvider::FinalConstruct()
11 return S_OK;
14 void CProvider::FinalRelease()
18 CProvider::parameters_t CProvider::ParseParameters(BSTR parameters) const
20 CString temp(parameters);
22 parameters_t result;
24 // TODO: Handle quoting and stuff
25 int pos = 0;
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);
33 result[name] = value;
35 token = temp.Tokenize(_T(";"), pos);
38 return result;
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;
48 return S_OK;
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")];
58 if (prompt.IsEmpty())
59 *linkText = SysAllocString(L"Choose Task...");
60 else
61 *linkText = prompt.AllocSysString();
63 return S_OK;
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)
86 USES_CONVERSION;
88 if (commonURL)
90 // do something with the common root url
91 // if necessary
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);
100 return S_OK;
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);
110 DWORD bytesWritten;
111 HANDLE hPathListFile = CreateFile(szPathListTempFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
113 LONG a, b;
114 if (FAILED(SafeArrayGetLBound(pathList, 1, &a)) || (FAILED(SafeArrayGetUBound(pathList, 1, &b))))
115 return E_FAIL;
117 for (LONG i = a; i <= b; ++i)
119 BSTR path = NULL;
120 SafeArrayGetElement(pathList, &i, &path);
122 CStringA line = OLE2A(path);
123 line += "\r\n";
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);
150 DWORD bytesRead;
151 ReadFile(hOrig, buffer, cb, &bytesRead, NULL);
152 CloseHandle(hOrig);
154 message = A2T((const char *)buffer);
157 DeleteFile(szPathListTempFile);
158 DeleteFile(szOriginalMessageTempFile);
160 *newMessage = message.AllocSysString();
161 return S_OK;
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();
174 return S_OK;
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);
183 return S_OK;
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
196 return E_NOTIMPL;