Skip to content

Commit 43e71c3

Browse files
committed
When loading un-labelled triggers, aliases or timers, duplicates are ignored
1 parent 34684ef commit 43e71c3

File tree

3 files changed

+179
-11
lines changed

3 files changed

+179
-11
lines changed

OtherTypes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ typedef CTypedPtrList <CPtrList, CLine*> CLineList;
347347
/////////////////////////////////////////////////////////////////////////////
348348
// CAlias
349349

350+
// when adding new fields, update operator==
350351
class CAlias : public CObject
351352
{
352353
DECLARE_DYNAMIC(CAlias)
@@ -388,6 +389,8 @@ class CAlias : public CObject
388389

389390
~CAlias () { delete regexp; };
390391

392+
bool operator== (const CAlias & rhs) const;
393+
391394
public:
392395

393396
CString name;
@@ -457,6 +460,7 @@ typedef map <CAlias*, string> CAliasRevMap;
457460
#define TRIGGER_COLOUR_CHANGE_BACKGROUND 2
458461

459462

463+
// when adding new fields, update operator==
460464
class CTrigger : public CObject
461465
{
462466
DECLARE_DYNAMIC(CTrigger)
@@ -503,6 +507,8 @@ class CTrigger : public CObject
503507

504508
~CTrigger () { delete regexp; };
505509

510+
bool operator== (const CTrigger & rhs) const;
511+
506512
public:
507513

508514
CString trigger;
@@ -586,6 +592,7 @@ typedef map <CTrigger*, string> CTriggerRevMap;
586592
/////////////////////////////////////////////////////////////////////////////
587593
// CTimer
588594

595+
// when adding new fields, update operator==
589596
class CTimer : public CObject
590597
{
591598
DECLARE_DYNAMIC(CTimer)
@@ -629,6 +636,8 @@ class CTimer : public CObject
629636

630637
};
631638

639+
bool operator== (const CTimer & rhs) const;
640+
632641
int iType; // at or interval, see enum above
633642
CString strContents; // what to send when it triggers
634643

doc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,15 +1637,15 @@ class CMUSHclientDoc : public CDocument
16371637
UINT Load_Triggers_XML (CXMLelement & parent,
16381638
const unsigned long iMask,
16391639
const unsigned long iFlags);
1640-
void Load_One_Trigger_XML (CXMLelement & node,
1640+
bool Load_One_Trigger_XML (CXMLelement & node,
16411641
const unsigned long iMask,
16421642
const long iVersion,
16431643
bool bUseDefault,
16441644
const unsigned long iFlags);
16451645
UINT Load_Aliases_XML (CXMLelement & parent,
16461646
const unsigned long iMask,
16471647
const unsigned long iFlags);
1648-
void Load_One_Alias_XML (CXMLelement & node,
1648+
bool Load_One_Alias_XML (CXMLelement & node,
16491649
const unsigned long iMask,
16501650
const long iVersion,
16511651
bool bUseDefault,
@@ -1661,7 +1661,7 @@ class CMUSHclientDoc : public CDocument
16611661
UINT Load_Timers_XML (CXMLelement & parent,
16621662
const unsigned long iMask,
16631663
const unsigned long iFlags);
1664-
void Load_One_Timer_XML (CXMLelement & node,
1664+
bool Load_One_Timer_XML (CXMLelement & node,
16651665
const unsigned long iMask,
16661666
const long iVersion,
16671667
bool bUseDefault,

xml/xml_load_world.cpp

Lines changed: 167 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,108 @@ void CMUSHclientDoc::HandleLoadException (const char * sComment, CException* e)
216216

217217
#endif
218218

219+
// comparison for avoiding loading duplicates
220+
bool CAlias::operator== (const CAlias & rhs) const
221+
{
222+
if (
223+
bEchoAlias == rhs.bEchoAlias &&
224+
bEnabled == rhs.bEnabled &&
225+
bExpandVariables == rhs.bExpandVariables &&
226+
bIgnoreCase == rhs.bIgnoreCase &&
227+
bKeepEvaluating == rhs.bKeepEvaluating &&
228+
bMenu == rhs.bMenu &&
229+
bOmitFromCommandHistory == rhs.bOmitFromCommandHistory &&
230+
bOmitFromLog == rhs.bOmitFromLog &&
231+
bOmitFromOutput == rhs.bOmitFromOutput &&
232+
bOneShot == rhs.bOneShot &&
233+
bRegexp == rhs.bRegexp &&
234+
contents == rhs.contents &&
235+
iSendTo == rhs.iSendTo &&
236+
iSequence == rhs.iSequence &&
237+
name == rhs.name &&
238+
strGroup == rhs.strGroup &&
239+
strLabel == rhs.strLabel &&
240+
strProcedure == rhs.strProcedure &&
241+
strVariable == rhs.strVariable
242+
) return true;
243+
244+
return false;
245+
} // end of CAlias::operator==
246+
247+
// comparison for avoiding loading duplicates
248+
bool CTrigger::operator== (const CTrigger & rhs) const
249+
{
250+
if (
251+
bEnabled == rhs.bEnabled &&
252+
bExpandVariables == rhs.bExpandVariables &&
253+
bKeepEvaluating == rhs.bKeepEvaluating &&
254+
bLowercaseWildcard == rhs.bLowercaseWildcard &&
255+
bMultiLine == rhs.bMultiLine &&
256+
bOmitFromOutput == rhs.bOmitFromOutput &&
257+
bOneShot == rhs.bOneShot &&
258+
bRegexp == rhs.bRegexp &&
259+
bRepeat == rhs.bRepeat &&
260+
bSoundIfInactive == rhs.bSoundIfInactive &&
261+
colour == rhs.colour &&
262+
contents == rhs.contents &&
263+
iClipboardArg == rhs.iClipboardArg &&
264+
iColourChangeType == rhs.iColourChangeType &&
265+
iLinesToMatch == rhs.iLinesToMatch &&
266+
iMatch == rhs.iMatch &&
267+
iOtherBackground == rhs.iOtherBackground &&
268+
iOtherForeground == rhs.iOtherForeground &&
269+
iSendTo == rhs.iSendTo &&
270+
iSequence == rhs.iSequence &&
271+
iStyle == rhs.iStyle &&
272+
iUserOption == rhs.iUserOption &&
273+
ignore_case == rhs.ignore_case &&
274+
omit_from_log == rhs.omit_from_log &&
275+
sound_to_play == rhs.sound_to_play &&
276+
strGroup == rhs.strGroup &&
277+
strLabel == rhs.strLabel &&
278+
strProcedure == rhs.strProcedure &&
279+
strVariable == rhs.strVariable &&
280+
trigger == rhs.trigger
281+
282+
) return true;
283+
284+
return false;
285+
} // end of CTrigger::operator==
286+
287+
288+
// comparison for avoiding loading duplicates
289+
bool CTimer::operator== (const CTimer & rhs) const
290+
{
291+
if (
292+
bActiveWhenClosed == rhs.bActiveWhenClosed &&
293+
bEnabled == rhs.bEnabled &&
294+
bOmitFromLog == rhs.bOmitFromLog &&
295+
bOmitFromOutput == rhs.bOmitFromOutput &&
296+
bOneShot == rhs.bOneShot &&
297+
fAtSecond == rhs.fAtSecond &&
298+
fEverySecond == rhs.fEverySecond &&
299+
fOffsetSecond == rhs.fOffsetSecond &&
300+
iAtHour == rhs.iAtHour &&
301+
iAtMinute == rhs.iAtMinute &&
302+
iEveryHour == rhs.iEveryHour &&
303+
iEveryMinute == rhs.iEveryMinute &&
304+
iOffsetHour == rhs.iOffsetHour &&
305+
iOffsetMinute == rhs.iOffsetMinute &&
306+
iSendTo == rhs.iSendTo &&
307+
iType == rhs.iType &&
308+
iUserOption == rhs.iUserOption &&
309+
strContents == rhs.strContents &&
310+
strGroup == rhs.strGroup &&
311+
strLabel == rhs.strLabel &&
312+
strProcedure == rhs.strProcedure &&
313+
strVariable == rhs.strVariable
314+
315+
) return true;
316+
317+
return false;
318+
} // end of CTimer::operator==
319+
320+
219321
UINT CMUSHclientDoc::Load_World_XML (CArchive& ar,
220322
const unsigned long iMask,
221323
const unsigned long iFlags,
@@ -1068,7 +1170,7 @@ UINT CMUSHclientDoc::Load_Triggers_XML (CXMLelement & parent,
10681170
} // end of CMUSHclientDoc::Load_Triggers_XML
10691171

10701172

1071-
void CMUSHclientDoc::Load_One_Trigger_XML (CXMLelement & node,
1173+
bool CMUSHclientDoc::Load_One_Trigger_XML (CXMLelement & node,
10721174
const unsigned long iMask,
10731175
const long iVersion,
10741176
bool bUseDefault,
@@ -1257,14 +1359,33 @@ CString strVariable;
12571359
throw;
12581360
}
12591361

1362+
// check if this exact alias already exists (suggested by Fiendish 12 Dec 2011)
1363+
// version: 4.81
1364+
if (t->strLabel.IsEmpty ())
1365+
{
1366+
CTrigger * pExistingTrigger;
1367+
CString strExistingTriggerName;
1368+
1369+
for (POSITION pos = GetTriggerMap ().GetStartPosition(); pos; )
1370+
{
1371+
GetTriggerMap ().GetNextAssoc (pos, strExistingTriggerName, pExistingTrigger);
1372+
if (*pExistingTrigger == *t)
1373+
{
1374+
delete t; // get rid of duplicate trigger
1375+
return false; // and don't add it
1376+
} // end of duplicate
1377+
} // end of for loop
1378+
1379+
} // end of un-named trigger
1380+
12601381
// now add to our internal trigger map
12611382

12621383
t->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
12631384
t->strInternalName = strTriggerName; // for deleting one-shot triggers
12641385
GetTriggerMap ().SetAt (strTriggerName, t);
12651386

12661387
CheckUsed (node); // check we used all attributes
1267-
1388+
return true; // loaded OK
12681389
} // end of CMUSHclientDoc::Load_One_Trigger_XML
12691390

12701391

@@ -1282,8 +1403,8 @@ UINT count = 0;
12821403

12831404
try
12841405
{
1285-
Load_One_Alias_XML (*pElement, iMask, iVersion, bUseDefault, iFlags);
1286-
count++;
1406+
if (Load_One_Alias_XML (*pElement, iMask, iVersion, bUseDefault, iFlags))
1407+
count++;
12871408
}
12881409
catch (CException* e)
12891410
{
@@ -1302,7 +1423,7 @@ UINT count = 0;
13021423
} // end of CMUSHclientDoc::Load_Aliases_XML
13031424

13041425

1305-
void CMUSHclientDoc::Load_One_Alias_XML (CXMLelement & node,
1426+
bool CMUSHclientDoc::Load_One_Alias_XML (CXMLelement & node,
13061427
const unsigned long iMask,
13071428
const long iVersion,
13081429
bool bUseDefault,
@@ -1470,14 +1591,33 @@ CString strVariable;
14701591
throw;
14711592
}
14721593

1594+
// check if this exact alias already exists (suggested by Fiendish 12 Dec 2011)
1595+
// version: 4.81
1596+
if (a->strLabel.IsEmpty ())
1597+
{
1598+
CAlias * pExistingAlias;
1599+
CString strExistingAliasName;
1600+
1601+
for (POSITION pos = GetAliasMap ().GetStartPosition(); pos; )
1602+
{
1603+
GetAliasMap ().GetNextAssoc (pos, strExistingAliasName, pExistingAlias);
1604+
if (*pExistingAlias == *a)
1605+
{
1606+
delete a; // get rid of duplicate alias
1607+
return false; // and don't add it
1608+
} // end of duplicate
1609+
} // end of for loop
1610+
1611+
} // end of un-named alias
1612+
14731613
// now add to our internal alias map
14741614

14751615
a->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
14761616
a->strInternalName = strAliasName; // for deleting one-shot aliases
14771617
GetAliasMap ().SetAt (strAliasName, a);
14781618

14791619
CheckUsed (node); // check we used all attributes
1480-
1620+
return true; // loaded OK
14811621
} // end of CMUSHclientDoc::Load_One_Alias_XML
14821622

14831623

@@ -1515,7 +1655,7 @@ UINT count = 0;
15151655
} // end of CMUSHclientDoc::Load_Timers_XML
15161656

15171657

1518-
void CMUSHclientDoc::Load_One_Timer_XML (CXMLelement & node,
1658+
bool CMUSHclientDoc::Load_One_Timer_XML (CXMLelement & node,
15191659
const unsigned long iMask,
15201660
const long iVersion,
15211661
bool bUseDefault,
@@ -1657,6 +1797,25 @@ CString strTimerName,
16571797
throw;
16581798
}
16591799

1800+
// check if this exact timer already exists (suggested by Fiendish 12 Dec 2011)
1801+
// version: 4.81
1802+
if (t->strLabel.IsEmpty ())
1803+
{
1804+
CTimer * pExistingTimer;
1805+
CString strExistingTimerName;
1806+
1807+
for (POSITION pos = GetTimerMap ().GetStartPosition(); pos; )
1808+
{
1809+
GetTimerMap ().GetNextAssoc (pos, strExistingTimerName, pExistingTimer);
1810+
if (*pExistingTimer == *t)
1811+
{
1812+
delete t; // get rid of duplicate timer
1813+
return false; // and don't add it
1814+
} // end of duplicate
1815+
} // end of for loop
1816+
1817+
} // end of un-named timer
1818+
16601819
// now add to our internal timer map
16611820

16621821
t->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
@@ -1665,7 +1824,7 @@ CString strTimerName,
16651824
ResetOneTimer (t); // make sure it is reset
16661825

16671826
CheckUsed (node); // check we used all attributes
1668-
1827+
return true; // loaded OK
16691828
} // end of CMUSHclientDoc::Load_One_Timer_XML
16701829

16711830

0 commit comments

Comments
 (0)