Skip to content

Commit 5fc629f

Browse files
committed
CollectionInterface: overrideMap = don't add duplicate <association>
1 parent 65b413d commit 5fc629f

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

src/Classes/OverrideMapUpdaterClass.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ tinyxml2::XMLElement* OverrideMapUpdater::add_udl_assoc(std::wstring wsFilename,
8686
}
8787

8888
// add an <association> tag for a given UDL
89+
// (skip if already exists)
8990
tinyxml2::XMLElement* OverrideMapUpdater::add_udl_assoc(std::string sFilename, std::string sUDLname)
9091
{
92+
// first check if the UDL already exists in the <association> structure
93+
tinyxml2::XMLElement* pExist = _find_element_with_attribute_value(pAssociationMap, nullptr, "association", "userDefinedLangName", sUDLname, true);
94+
if (pExist) return pExist;
95+
96+
// if it doesn't, then add it
9197
tinyxml2::XMLElement* pAssoc = pAssociationMap->InsertNewChildElement("association");
9298
if (pAssoc) {
9399
pAssoc->SetAttribute("id", sFilename.c_str());
@@ -129,3 +135,62 @@ bool OverrideMapUpdater::experiment(void)
129135

130136
return true;
131137
}
138+
139+
// private: case-insensitive std::string equality check
140+
bool _string_insensitive_eq(std::string a, std::string b)
141+
{
142+
std::string a_copy = "";
143+
std::string b_copy = "";
144+
145+
// ignore conversion of int to char implicit in the <algorithm>std::transform, which I have no control over
146+
#pragma warning(push)
147+
#pragma warning(disable: 4244)
148+
for (size_t i = 0; i < a.size(); i++) { a_copy += std::tolower(a[i]); }
149+
for (size_t i = 0; i < b.size(); i++) { b_copy += std::tolower(b[i]); }
150+
#pragma warning(pop)
151+
return a_copy == b_copy;
152+
}
153+
154+
// private: case-insensitive std::string less-than check
155+
bool _string_insensitive_lt(std::string a, std::string b)
156+
{
157+
std::string a_copy = "";
158+
std::string b_copy = "";
159+
160+
// ignore conversion of int to char implicit in the <algorithm>std::transform, which I have no control over
161+
#pragma warning(push)
162+
#pragma warning(disable: 4244)
163+
for (size_t i = 0; i < a.size(); i++) { a_copy += std::tolower(a[i]); }
164+
for (size_t i = 0; i < b.size(); i++) { b_copy += std::tolower(b[i]); }
165+
#pragma warning(pop)
166+
return a_copy < b_copy;
167+
}
168+
169+
170+
// look for an element, based on {Parent, FirstChild, or both} which is of a specific ElementType, having a specific AttributeName with specific AttributeValue
171+
tinyxml2::XMLElement* OverrideMapUpdater::_find_element_with_attribute_value(tinyxml2::XMLElement* pParent, tinyxml2::XMLElement* pFirst, std::string sElementType, std::string sAttributeName, std::string sAttributeValue, bool caseSensitive)
172+
{
173+
if (!pParent && !pFirst) return nullptr;
174+
tinyxml2::XMLElement* pMyParent = pParent ? pParent->ToElement() : pFirst->Parent()->ToElement();
175+
tinyxml2::XMLElement* pFCE = pMyParent->FirstChildElement(sElementType.c_str());
176+
if (!pFirst && !pFCE) return nullptr;
177+
tinyxml2::XMLElement* pFoundElement = pFirst ? pFirst->ToElement() : pFCE->ToElement();
178+
while (pFoundElement) {
179+
// if this node has the right attribute pair, great!
180+
if (caseSensitive) {
181+
if (pFoundElement->Attribute(sAttributeName.c_str(), sAttributeValue.c_str()))
182+
return pFoundElement;
183+
}
184+
else {
185+
const char* cAttrValue = pFoundElement->Attribute(sAttributeName.c_str());
186+
if (cAttrValue) {
187+
if (_string_insensitive_eq(sAttributeValue, cAttrValue))
188+
return pFoundElement;
189+
}
190+
}
191+
192+
// otherwise, move on to next
193+
pFoundElement = pFoundElement->NextSiblingElement(sElementType.c_str());
194+
}
195+
return pFoundElement;
196+
}

src/Classes/OverrideMapUpdaterClass.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ class OverrideMapUpdater {
4141
std::string sOverMapPath(void) { return pcjHelper::wstring_to_utf8(_wsOverMapPath); }
4242

4343
private:
44+
////////////////
45+
// methods
46+
////////////////
47+
48+
// look for an element, based on {Parent, FirstChild, or both} which is of a specific ElementType, having a specific AttributeName with specific AttributeValue
49+
tinyxml2::XMLElement* _find_element_with_attribute_value(tinyxml2::XMLElement* pParent, tinyxml2::XMLElement* pFirst, std::string sElementType, std::string sAttributeName, std::string sAttributeValue, bool caseSensitive);
50+
51+
////////////////
4452
// properties
53+
////////////////
4554

4655
// paths
4756
std::wstring _wsOverMapPath; // <cfg>\functionList\overrideMap.xml path, or <exe> version

src/Dialogs/CollectionInterfaceDialog.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
393393
if (pobjCI->ask_overwrite_if_exists(wsPath)) {
394394
mapUacDelayed[wsURL] = wsPath;
395395
total--;
396-
// TODO: need to add a delayed-FL-ov map as well
397396
}
398397
else {
399398
total--;
@@ -424,7 +423,6 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
424423
if (pobjCI->ask_overwrite_if_exists(xPath)) {
425424
mapUacDelayed[xURL] = xPath;
426425
total--;
427-
// TODO: need to add a delayed-FL-ov map as well
428426
}
429427
else {
430428
total--;
@@ -509,7 +507,6 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
509507
doUpdateOverrideMap = false;
510508
}
511509

512-
//::MessageBox(hwndDlg, (std::wstring(L"cmd.exe ") + args).c_str(), L"TODO: UAC Command", MB_OK);
513510
ShellExecute(hwndDlg, L"runas", L"cmd.exe", args.c_str(), NULL, SW_SHOWMINIMIZED);
514511

515512
::SendDlgItemMessage(hwndDlg, IDC_CI_PROGRESSBAR, PBM_SETPOS, 100, 0);

0 commit comments

Comments
 (0)