BOOL C4UpdatePackage::Optimize(C4Group *pGrpFrom, C4GroupEx *pGrpTo, const char *strFileName) { // group file? C4Group ItemGroupFrom; if (!ItemGroupFrom.OpenAsChild(pGrpFrom, strFileName)) return TRUE; // try to open target group C4GroupEx ItemGroupTo; char strTempGroup[_MAX_PATH + 1]; strTempGroup[0] = 0; if (!ItemGroupTo.OpenAsChild(pGrpTo, strFileName)) return TRUE; // update children char ItemFileName[_MAX_PATH]; ItemGroupFrom.ResetSearch(); while (ItemGroupFrom.FindNextEntry("*", ItemFileName)) Optimize(&ItemGroupFrom, &ItemGroupTo, ItemFileName); // set head if (ItemGroupTo.HeadIdentical(ItemGroupFrom, true)) ItemGroupTo.SetHead(ItemGroupFrom); // write group (do not change any headers set by DoGrpUpdate!) ItemGroupTo.Close(FALSE); // set core (C4Group::Save overwrites it) pGrpTo->SaveEntryCore(*pGrpFrom, strFileName); pGrpTo->SetSavedEntryCore(strFileName); return TRUE; }
BOOL C4UpdatePackage::Optimize(C4Group *pGroup, const char *strTarget) { // Open target group C4GroupEx TargetGrp; if (!TargetGrp.Open(strTarget)) return FALSE; // Both groups must be packed if (!pGroup->IsPacked() || !TargetGrp.IsPacked()) { TargetGrp.Close(FALSE); return FALSE; } // update children char ItemFileName[_MAX_PATH]; pGroup->ResetSearch(); while (pGroup->FindNextEntry("*", ItemFileName)) if (!SEqual(ItemFileName, C4CFN_UpdateCore) && !SEqual(ItemFileName, C4CFN_UpdateEntries)) Optimize(pGroup, &TargetGrp, ItemFileName); // set header if (TargetGrp.HeadIdentical(*pGroup, true)) TargetGrp.SetHead(*pGroup); // save TargetGrp.Close(FALSE); // okay return TRUE; }