1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "BugTraqAssociations.h"
\r
22 #include <initguid.h>
\r
24 // {3494FA92-B139-4730-9591-01135D5E7831}
\r
25 DEFINE_GUID(CATID_BugTraqProvider,
\r
26 0x3494fa92, 0xb139, 0x4730, 0x95, 0x91, 0x1, 0x13, 0x5d, 0x5e, 0x78, 0x31);
\r
28 #define BUGTRAQ_ASSOCIATIONS_REGPATH _T("Software\\TortoiseGit\\BugTraq Associations")
\r
30 CBugTraqAssociations::~CBugTraqAssociations()
\r
32 for (inner_t::iterator it = m_inner.begin(); it != m_inner.end(); ++it)
\r
36 void CBugTraqAssociations::Load()
\r
39 if (RegOpenKeyEx(HKEY_CURRENT_USER, BUGTRAQ_ASSOCIATIONS_REGPATH, 0, KEY_READ, &hk) != ERROR_SUCCESS)
\r
42 for (DWORD dwIndex = 0; /* nothing */; ++dwIndex)
\r
44 TCHAR szSubKey[MAX_PATH];
\r
45 DWORD cchSubKey = MAX_PATH;
\r
46 LSTATUS status = RegEnumKeyEx(hk, dwIndex, szSubKey, &cchSubKey, NULL, NULL, NULL, NULL);
\r
47 if (status != ERROR_SUCCESS)
\r
51 if (RegOpenKeyEx(hk, szSubKey, 0, KEY_READ, &hk2) == ERROR_SUCCESS)
\r
53 TCHAR szWorkingCopy[MAX_PATH];
\r
54 DWORD cbWorkingCopy = sizeof(szWorkingCopy);
\r
55 RegQueryValueEx(hk2, _T("WorkingCopy"), NULL, NULL, (LPBYTE)szWorkingCopy, &cbWorkingCopy);
\r
57 TCHAR szClsid[MAX_PATH];
\r
58 DWORD cbClsid = sizeof(szClsid);
\r
59 RegQueryValueEx(hk2, _T("Provider"), NULL, NULL, (LPBYTE)szClsid, &cbClsid);
\r
61 CLSID provider_clsid;
\r
62 CLSIDFromString(szClsid, &provider_clsid);
\r
64 DWORD cbParameters = 0;
\r
65 RegQueryValueEx(hk2, _T("Parameters"), NULL, NULL, (LPBYTE)NULL, &cbParameters);
\r
66 TCHAR * szParameters = new TCHAR[cbParameters+1];
\r
67 RegQueryValueEx(hk2, _T("Parameters"), NULL, NULL, (LPBYTE)szParameters, &cbParameters);
\r
68 szParameters[cbParameters] = 0;
\r
69 m_inner.push_back(new CBugTraqAssociation(szWorkingCopy, provider_clsid, LookupProviderName(provider_clsid), szParameters));
\r
70 delete [] szParameters;
\r
79 void CBugTraqAssociations::Add(const CBugTraqAssociation &assoc)
\r
81 m_inner.push_back(new CBugTraqAssociation(assoc));
\r
84 bool CBugTraqAssociations::FindProvider(const CTGitPathList &pathList, CBugTraqAssociation *assoc) const
\r
86 return FindProviderForPathList(pathList, assoc);
\r
89 bool CBugTraqAssociations::FindProvider(const CString &path, CBugTraqAssociation *assoc) const
\r
93 gitpath.SetFromUnknown(path);
\r
94 return FindProviderForPath(gitpath,assoc);
\r
97 bool CBugTraqAssociations::FindProviderForPathList(const CTGitPathList &pathList, CBugTraqAssociation *assoc) const
\r
99 for (int i = 0; i < pathList.GetCount(); ++i)
\r
101 CTGitPath path = pathList[i];
\r
102 if (FindProviderForPath(path, assoc))
\r
109 bool CBugTraqAssociations::FindProviderForPath(CTGitPath path, CBugTraqAssociation *assoc) const
\r
113 inner_t::const_iterator it = std::find_if(m_inner.begin(), m_inner.end(), FindByPathPred(path));
\r
114 if (it != m_inner.end())
\r
120 path = path.GetContainingDirectory();
\r
121 } while(!path.IsEmpty());
\r
127 CString CBugTraqAssociations::LookupProviderName(const CLSID &provider_clsid)
\r
129 OLECHAR szClsid[40];
\r
130 StringFromGUID2(provider_clsid, szClsid, ARRAYSIZE(szClsid));
\r
132 TCHAR szSubKey[MAX_PATH];
\r
133 _stprintf_s(szSubKey, _T("CLSID\\%ls"), szClsid);
\r
135 CString provider_name = CString(szClsid);
\r
138 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szSubKey, 0, KEY_READ, &hk) == ERROR_SUCCESS)
\r
140 TCHAR szClassName[MAX_PATH];
\r
141 DWORD cbClassName = sizeof(szClassName);
\r
143 if (RegQueryValueEx(hk, NULL, NULL, NULL, (LPBYTE)szClassName, &cbClassName) == ERROR_SUCCESS)
\r
144 provider_name = CString(szClassName);
\r
149 return provider_name;
\r
152 LSTATUS RegSetValueFromCString(HKEY hKey, LPCTSTR lpValueName, CString str)
\r
154 LPCTSTR lpsz = str;
\r
155 DWORD cb = (str.GetLength() + 1) * sizeof(TCHAR);
\r
156 return RegSetValueEx(hKey, lpValueName, 0, REG_SZ, (const BYTE *)lpsz, cb);
\r
159 void CBugTraqAssociations::Save() const
\r
161 SHDeleteKey(HKEY_CURRENT_USER, BUGTRAQ_ASSOCIATIONS_REGPATH);
\r
164 if (RegCreateKeyEx(HKEY_CURRENT_USER, BUGTRAQ_ASSOCIATIONS_REGPATH, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hk, NULL) != ERROR_SUCCESS)
\r
168 for (const_iterator it = begin(); it != end(); ++it)
\r
170 TCHAR szSubKey[MAX_PATH];
\r
171 _stprintf_s(szSubKey, _T("%d"), dwIndex);
\r
174 if (RegCreateKeyEx(hk, szSubKey, 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL) == ERROR_SUCCESS)
\r
176 RegSetValueFromCString(hk2, _T("Provider"), (*it)->GetProviderClassAsString());
\r
177 RegSetValueFromCString(hk2, _T("WorkingCopy"), (*it)->GetPath().GetWinPath());
\r
178 RegSetValueFromCString(hk2, _T("Parameters"), (*it)->GetParameters());
\r
189 void CBugTraqAssociations::RemoveByPath(const CTGitPath &path)
\r
191 inner_t::iterator it = std::find_if(m_inner.begin(), m_inner.end(), FindByPathPred(path));
\r
192 if (it != m_inner.end())
\r
199 CString CBugTraqAssociation::GetProviderClassAsString() const
\r
201 OLECHAR szTemp[40];
\r
202 StringFromGUID2(m_provider.clsid, szTemp, ARRAYSIZE(szTemp));
\r
204 return CString(szTemp);
\r
208 std::vector<CBugTraqProvider> CBugTraqAssociations::GetAvailableProviders()
\r
210 std::vector<CBugTraqProvider> results;
\r
212 ICatInformation *pCatInformation = NULL;
\r
215 if (SUCCEEDED(hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL, IID_ICatInformation, (void **)&pCatInformation)))
\r
217 IEnumGUID *pEnum = NULL;
\r
218 if (SUCCEEDED(hr = pCatInformation->EnumClassesOfCategories(1, &CATID_BugTraqProvider, 0, NULL, &pEnum)))
\r
226 hrEnum = pEnum->Next(ARRAYSIZE(clsids), clsids, &cClsids);
\r
227 if (SUCCEEDED(hrEnum))
\r
229 for (ULONG i = 0; i < cClsids; ++i)
\r
231 CBugTraqProvider provider;
\r
232 provider.clsid = clsids[i];
\r
233 provider.name = LookupProviderName(clsids[i]);
\r
234 results.push_back(provider);
\r
237 } while (hrEnum == S_OK);
\r
245 if (pCatInformation)
\r
246 pCatInformation->Release();
\r
247 pCatInformation = NULL;
\r