private QbItemStruct copyTierProg(QbItemStruct prog, int toTierNo, params string[] qbKeyMask)
{
QbItemStruct copy = (QbItemStruct)prog.Clone();
//replace all 1s for our new number
copy.FindItem(true, delegate(QbItemBase qib)
{
if (qib.ItemQbKey != null)
{
if (qib is QbItemInteger && qib.ItemQbKey.Crc == QbKey.Create("tier").Crc)
((QbItemInteger)qib).Values[0] = (uint)toTierNo;
else if (qib is QbItemQbKey)
{
foreach (string s in qbKeyMask)
{
QbKey k = QbKey.Create(string.Format(s, "1"));
QbKey k2 = QbKey.Create(string.Format(s, "0"));
if (((QbItemQbKey)qib).Values[0].Crc == k.Crc)
((QbItemQbKey)qib).Values[0] = QbKey.Create(string.Format(s, toTierNo.ToString()));
else if (((QbItemQbKey)qib).Values[0].Crc == k2.Crc)
((QbItemQbKey)qib).Values[0] = QbKey.Create(string.Format(s, (toTierNo - 1).ToString()));
}
}
}
return false; //return false to continue search
});
return copy;
}