/* ArchiveTreeNode::merge * Merges [node] with this node. Entries within [node] are added * at [position] within this node. Returns false if [node] is invalid, * true otherwise *******************************************************************/ bool ArchiveTreeNode::merge(ArchiveTreeNode* node, unsigned position, int state) { // Check node was given to merge if (!node) return false; // Merge entries for (unsigned a = 0; a < node->numEntries(); a++) { if (node->getEntry(a)) { string name = Misc::lumpNameToFileName(node->getEntry(a)->getName()); node->getEntry(a)->setName(name); } ArchiveEntry* nentry = new ArchiveEntry(*(node->getEntry(a))); addEntry(nentry, position); nentry->setState(state); if (position < entries.size()) position++; } // Merge subdirectories for (unsigned a = 0; a < node->nChildren(); a++) { ArchiveTreeNode* child = (ArchiveTreeNode*)STreeNode::addChild(node->getChild(a)->getName()); child->merge((ArchiveTreeNode*)node->getChild(a)); child->getDirEntry()->setState(state); } return true; }
bool doUndo() { if (created) return archive->removeDir(path); else { // Create directory ArchiveTreeNode* dir = archive->createDir(path); // Restore entries/subdirs if needed if (dir && cb_tree) dir->merge(cb_tree->getTree(), 0, 0); dir->getDirEntry()->setState(0); return !!dir; } }