/************************************************** WalkTree(): Given a tree, recursively walk it. **************************************************/ void WalkTree (long Index, long Depth) { long LeftSet; if (Verbose) { int i; for(i=0; i<Depth; i++) printf(" "); printf("%ld\n",Tree[Index].UploadtreePk); } LeftSet = SetNum; SetNum++; if (Tree[Index].Child > -1) { WalkTree(Tree[Index].Child,Depth+1); SetNum++; } snprintf(SQL,sizeof(SQL),"UPDATE uploadtree SET lft='%ld', rgt='%ld' WHERE uploadtree_pk='%ld';", LeftSet,SetNum,Tree[Index].UploadtreePk); DBaccess(DB,SQL); if (Tree[Index].Sibling > -1) { SetNum++; WalkTree(Tree[Index].Sibling,Depth+1); } } /* WalkTree() */
int WalkTree(WORD **DestArray, WORD *Word) { int Status = SUCCESS; static WORD **Write = NULL; /* safety check */ assert(NULL != Word); /* store the starting point if this is the first call */ if(NULL != DestArray) { Write = DestArray; } /* Now add this node and it's kids */ if(NULL != Word) { *Write = Word; ++Write; if(NULL != Word->Left) { Status = WalkTree(NULL, Word->Left); } if(NULL != Word->Right) { Status = WalkTree(NULL, Word->Right); } } return Status; }
CDataNode* CDataNode::Search( const CString& query , char seperator , bool fromcurrent , bool treatChildAsCurrent ) const {GUCEF_TRACE; if ( fromcurrent ) { CString thisname( query.SubstrToChar( seperator, true ) ); if ( thisname == _name ) { CString remnant( query.CutChars( thisname.Length()+1, true ) ); if ( remnant.Length() > 0 ) { CString leftover; TDataNodeVector results = WalkTree( remnant , seperator , leftover ); if ( 0 == leftover.Length() && !results.empty() ) { return *results.begin(); } } else { // this node is the leaf node we are searching for return const_cast< CDataNode* >( this ); } } else if ( treatChildAsCurrent ) { TDataNodeList::const_iterator i = m_children.begin(); while ( i != m_children.end() ) { CDataNode* result = (*i)->Search( query , seperator , fromcurrent , false ); if ( nullptr != result ) return result; ++i; } } return nullptr; } else { CString leftover; TDataNodeVector results = WalkTree( query , seperator , leftover ); if ( 0 == leftover.Length() && !results.empty() ) { return *results.begin(); } return nullptr; } }
static void vfbInstallColormap(ColormapPtr pmap) { int index = pmap->pScreen->myNum; ColormapPtr oldpmap = InstalledMaps[index]; if (pmap != oldpmap) { int entries; XWDFileHeader *pXWDHeader; XWDColor *pXWDCmap; VisualPtr pVisual; Pixel * ppix; xrgb * prgb; xColorItem *defs; int i; if(oldpmap != (ColormapPtr)None) WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid); /* Install pmap */ InstalledMaps[index] = pmap; WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid); entries = pmap->pVisual->ColormapEntries; pXWDHeader = vfbScreens[pmap->pScreen->myNum].pXWDHeader; pXWDCmap = vfbScreens[pmap->pScreen->myNum].pXWDCmap; pVisual = pmap->pVisual; swapcopy32(pXWDHeader->visual_class, pVisual->class); swapcopy32(pXWDHeader->red_mask, pVisual->redMask); swapcopy32(pXWDHeader->green_mask, pVisual->greenMask); swapcopy32(pXWDHeader->blue_mask, pVisual->blueMask); swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue); swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries); ppix = (Pixel *)xalloc(entries * sizeof(Pixel)); prgb = (xrgb *)xalloc(entries * sizeof(xrgb)); defs = (xColorItem *)xalloc(entries * sizeof(xColorItem)); for (i = 0; i < entries; i++) ppix[i] = i; /* XXX truecolor */ QueryColors(pmap, entries, ppix, prgb); for (i = 0; i < entries; i++) { /* convert xrgbs to xColorItems */ defs[i].pixel = ppix[i] & 0xff; /* change pixel to index */ defs[i].red = prgb[i].red; defs[i].green = prgb[i].green; defs[i].blue = prgb[i].blue; defs[i].flags = DoRed|DoGreen|DoBlue; } (*pmap->pScreen->StoreColors)(pmap, entries, defs); xfree(ppix); xfree(prgb); xfree(defs); }
static bool WalkTree (DirEntry_s *direntry, walk_f f) { bool continue_walking; if (!direntry) return TRUE; if (!WalkTree(direntry->sibling, f)) return FALSE; if (direntry->type == T_DIR) { chdir(direntry->name); continue_walking = WalkTree(direntry->child, f); chdir(".."); if (!continue_walking) return FALSE; } return f(direntry); }
/********************************************* RunAllNew(): Run on all uploads WHERE the upload has no nested set numbers. This displays each upload as it runs! *********************************************/ void RunAllNew () { int Row,MaxRow; long UploadPk; void *UDB; DBaccess(DB,"SELECT DISTINCT upload_pk,upload_desc,upload_filename FROM upload WHERE upload_pk IN ( SELECT DISTINCT upload_fk FROM uploadtree WHERE lft IS NULL );"); UDB=DBmove(DB); MaxRow = DBdatasize(UDB); for(Row=0; Row < MaxRow; Row++) { UploadPk = atol(DBgetvalue(UDB,Row,0)); if (UploadPk >= 0) { char *S; printf("Processing %ld :: %s",UploadPk,DBgetvalue(UDB,Row,2)); S = DBgetvalue(UDB,Row,1); if (S && S[0]) printf(" (%s)",S); printf("\n"); LoadAdj(UploadPk); if (Tree) { DBaccess(DB,"BEGIN;"); WalkTree(0,0); DBaccess(DB,"COMMIT;"); } if (Tree) free(Tree); Tree=NULL; TreeSize=0; } } DBclose(UDB); } /* RunAllNew() */
//--------------------------------------------------------------------------- void __fastcall TCDirectoryOutline::BuildTree() { Clear(); AddChild(0, ForceCase(AnsiString(Drive) + ":")); // was ":\\" WalkTree(FDirectory); Change(); }
CDataNode* CDataNode::Structure( const CString& sequence , char seperator ) {GUCEF_TRACE; // walk the tree CString buildseg; TDataNodeVector walkResults = WalkTree( sequence , seperator , buildseg ); // do we need to add nodes ? if ( 0 < buildseg.Length() ) { CDataNode* parentNode = this; if ( !walkResults.empty() ) parentNode = *walkResults.begin(); CDataNode child; CString name; while ( buildseg.Length() ) { name = buildseg.SubstrToChar( seperator, true ); child.SetName( name ); buildseg = buildseg.CutChars( name.Length()+1, true ); parentNode = parentNode->AddChild( child ); } return parentNode; } if ( walkResults.empty() ) return nullptr; return *walkResults.begin(); }
void CObBinTree::GetArray( CObArray& array ) { array.SetSize( 0 ); WalkTree( StoreInArray, (LPVOID)&array, TV_INORDER ); ASSERT( array.GetSize()==GetCount() ); }
/* * Something changed; send events and adjust pointer position */ void RRTellChanged (ScreenPtr pScreen) { rrScrPriv (pScreen); int i; if (pScrPriv->changed) { UpdateCurrentTime (); if (pScrPriv->configChanged) { pScrPriv->lastConfigTime = currentTime; pScrPriv->configChanged = FALSE; } pScrPriv->changed = FALSE; WalkTree (pScreen, TellChanged, (pointer) pScreen); for (i = 0; i < pScrPriv->numOutputs; i++) pScrPriv->outputs[i]->changed = FALSE; for (i = 0; i < pScrPriv->numCrtcs; i++) pScrPriv->crtcs[i]->changed = FALSE; if (pScrPriv->layoutChanged) { pScrPriv->layoutChanged = FALSE; RRPointerScreenConfigured (pScreen); RRSendConfigNotify (pScreen); } } }
//////////////////////////////////////////////////////////////////////////// // Helper function: Walk all the Elements at a particular node //////////////////////////////////////////////////////////////////////////// HRESULT CXMLDocument::WalkTree(int iLevel, MSXML2::IXMLDOMNode* pNode) { HRESULT hr = S_OK; CComBSTR bstrNodeName; pNode->get_nodeName(&bstrNodeName); CComVariant vNodeValue; pNode->get_nodeValue(&vNodeValue); vNodeValue.ChangeType(VT_BSTR); CString strValueString = V_BSTR(&vNodeValue); if (m_pCallbackFunction) m_pCallbackFunction(iLevel, CString(bstrNodeName), (LPCSTR)NULL, strValueString, m_pCallbackParam); MSXML2::IXMLDOMNamedNodeMapPtr pAttributes = NULL; if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL)) { MSXML2::IXMLDOMNodePtr pAttribute = NULL; pAttributes->nextNode(&pAttribute); bool bRetVal = true; while (pAttribute) { CComBSTR bstrAttribName; pAttribute->get_nodeName(&bstrAttribName); CComVariant vNodeValue; pAttribute->get_nodeValue(&vNodeValue); vNodeValue.ChangeType(VT_BSTR); CString strValueString = V_BSTR(&vNodeValue); if (m_pCallbackFunction) bRetVal = m_pCallbackFunction(iLevel+1, CString(bstrNodeName), CString(bstrAttribName), strValueString, m_pCallbackParam); if (!bRetVal) { // set complete error message with node name and all attribute values m_strErrorNode = bstrNodeName; return S_FALSE; } pAttributes->nextNode(&pAttribute); } } MSXML2::IXMLDOMNodePtr pChild = NULL; pNode->get_firstChild(&pChild); while (pChild) { if (WalkTree(iLevel+1, pChild) != S_OK) return S_FALSE; MSXML2::IXMLDOMNode* pNext = NULL; pChild->get_nextSibling(&pNext); pChild = pNext; } return S_OK; }
void CObBinTree::GetList( CObList& list ) { ASSERT(list.IsEmpty()); if( !list.IsEmpty() )list.RemoveAll(); WalkTree( StoreInList, (LPVOID)&list, TV_INORDER ); ASSERT( list.GetCount()==GetCount() ); }
void rdpInstallColormap(ColormapPtr pmap) { ColormapPtr oldpmap; oldpmap = g_rdpInstalledColormap; if (pmap != oldpmap) { if (oldpmap != (ColormapPtr)None) { WalkTree(pmap->pScreen, TellLostMap, (char*)&oldpmap->mid); } /* Install pmap */ g_rdpInstalledColormap = pmap; WalkTree(pmap->pScreen, TellGainedMap, (char*)&pmap->mid); /*rfbSetClientColourMaps(0, 0);*/ } /*g_rdpScreen.InstallColormap(pmap);*/ }
//////////////////////////////////////////////////////////////////////////// // Function: Walk all the Elements in a loaded XML document. //////////////////////////////////////////////////////////////////////////// HRESULT CXMLDocument::WalkTree(CString& strSearchPattern) { HRESULT hr = S_OK; if (strSearchPattern.IsEmpty()) { MSXML2::IXMLDOMNodePtr pNode = m_pDoc; if (pNode == NULL) return E_FAIL; hr = WalkTree(0/*iLevel*/, pNode); } else { //j ("//video"); //j ("//video[@id='crap1']"); //j ("//video[@id='crap1']"); // filter the nodes using the search pattern MSXML2::IXMLDOMNodeListPtr pNodeList = NULL; hr = m_pDoc->selectNodes(CComBSTR(strSearchPattern), &pNodeList); hr = CheckHR(hr, "in the search pattern"); // get the length of the resulting node list if (pNodeList) { long lLength; hr = pNodeList->get_length(&lLength); hr = CheckHR(hr, "retrieving node list length"); MSXML2::IXMLDOMNodePtr pNode = NULL; for (long i = 0; i < lLength; i++) { hr = pNodeList->get_item(i, &pNode); hr = WalkTree(0/*iLevel*/, pNode); if (hr != S_OK) return hr; } } } return hr; }
StaticWorldObject::StaticWorldObject(ssgEntity *model, dSpaceID bigspace, sgVec3 initialpos) : WorldObject(model) { space = dSimpleSpaceCreate(bigspace); ssgTransform *trf = new ssgTransform(); trf->setTransform(initialpos); trf->addKid(model); entity = trf; name = "staticworldobject"; WalkTree(entity, initialpos); }
//----<DFS nodes of the tree for test>-- void WalkTree(PNode<std::string >* pPNode) { pPNode->clearMarks(); std::cout <<"\n "<<pPNode->value(); PNode<std::string >* pTemp; while (pTemp = pPNode->nextUnmarkedChild()) { pTemp->setMarkState(true); WalkTree(pTemp); } }
bool JsonDb::Validate(TransactionHandle &transaction) { std::set<ValueKey> tree_keys = WalkTree(transaction); std::set<ValueKey> db_keys = transaction->Walk(); // Item storing next id is a valid item if(db_keys.find(next_id_key) != db_keys.end()) tree_keys.insert(next_id_key); std::set<ValueKey> db_missing_keys; std::set_difference( tree_keys.begin(), tree_keys.end(), db_keys.begin(), db_keys.end(), std::inserter(db_missing_keys, db_missing_keys.begin())); std::set<ValueKey> db_stale_keys; std::set_difference( db_keys.begin(), db_keys.end(), tree_keys.begin(), tree_keys.end(), std::inserter(db_stale_keys, db_stale_keys.begin())); std::cout << "Keys found in tree: " << std::endl; for(std::set<ValueKey>::const_iterator i = tree_keys.begin(); i != tree_keys.end(); ++i) std::cout << (i != tree_keys.begin() ? ", " : "") << *i; std::cout << std::endl; std::cout << "Keys found in database: " << std::endl; for(std::set<ValueKey>::const_iterator i = db_keys.begin(); i != db_keys.end(); ++i) std::cout << (i != db_keys.begin() ? ", " : "") << *i; std::cout << std::endl; if(!db_missing_keys.empty()) { std::cout << "Following keys are missing from the database: " << std::endl; for(std::set<ValueKey>::const_iterator i = db_missing_keys.begin(); i != db_missing_keys.end(); ++i) std::cout << (i != db_missing_keys.begin() ? ", " : "") << *i; std::cout << std::endl; } if(!db_stale_keys.empty()) { std::cout << "Following stale keys where found in the database: " << std::endl; for(std::set<ValueKey>::const_iterator i = db_stale_keys.begin(); i != db_stale_keys.end(); ++i) std::cout << (i != db_stale_keys.begin() ? ", " : "") << *i; std::cout << std::endl; } return (db_missing_keys.empty() && db_stale_keys.empty()); }
void WalkTree(NODE *pNode) { // Make sure the tree isn't empty if (pNode != NULL) { // Traverse the left subtree, if there is one if (pNode->pLeftChild != NULL) { WalkTree(pNode->pLeftChild); } // Visit this node Visit(pNode); // Traverse the right subtree, if there is one if (pNode->pRightChild != NULL) { WalkTree(pNode->pRightChild); } } }
void rfbInstallColormap(ColormapPtr pmap) { ColormapPtr oldpmap = rfbInstalledColormap; SCREEN_PROLOGUE (pmap->pScreen, InstallColormap); (*pScreen->InstallColormap) (pmap); SCREEN_EPILOGUE (InstallColormap, rfbInstallColormap); if (pmap != oldpmap) { if (oldpmap != (ColormapPtr)None) WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid); /* Install pmap */ rfbInstalledColormap = pmap; WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid); rfbSetClientColourMaps(0, 0); } }
//////////////////////////////////////////////////////////////////////////// // Helper function: Walk all the Elements at a particular node //////////////////////////////////////////////////////////////////////////// HRESULT CXMLDocument::WalkTree(int iLevel, MSXML::IXMLDOMNode* pNode) { HRESULT hr = S_OK; CComBSTR bstrNodeName; pNode->get_nodeName(&bstrNodeName); CComVariant vNodeValue; pNode->get_nodeValue(&vNodeValue); vNodeValue.ChangeType(VT_BSTR); CString strValueString = V_BSTR(&vNodeValue); if (m_pCallbackFunction) m_pCallbackFunction(iLevel, CString(bstrNodeName), strValueString, m_pCallbackParam); MSXML::IXMLDOMNamedNodeMapPtr pAttributes = NULL; if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL)) { MSXML::IXMLDOMNodePtr pAttribute = NULL; pAttributes->nextNode(&pAttribute); while (pAttribute) { CComBSTR bstrNodeName; pAttribute->get_nodeName(&bstrNodeName); CComVariant vNodeValue; pAttribute->get_nodeValue(&vNodeValue); vNodeValue.ChangeType(VT_BSTR); CString strValueString = V_BSTR(&vNodeValue); if (m_pCallbackFunction) m_pCallbackFunction(iLevel+1, CString(bstrNodeName), strValueString, m_pCallbackParam); pAttributes->nextNode(&pAttribute); } } MSXML::IXMLDOMNodePtr pChild = NULL; pNode->get_firstChild(&pChild); while (pChild) { WalkTree(iLevel+1, pChild); MSXML::IXMLDOMNode* pNext = NULL; pChild->get_nextSibling(&pNext); pChild = pNext; } return S_OK; }
int PrintTree(char *name) { TreeNode *start; if (name == NULL || name[0]=='\0') { start = root; } else { start = LookupNode(name); } if (start == NULL) { printf("ERROR: Tree not found: @s\n", name); return -1; } WalkTree(start); return 0; }
static void winUpdateRgnRootless(WindowPtr pWin) { HRGN hRgn = CreateRectRgn(0, 0, 0, 0); if (hRgn != NULL) { WalkTree(pWin->drawable.pScreen, winAddRgn, &hRgn); SetWindowRgn(winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen, hRgn, TRUE); } else { ErrorF("winUpdateRgnRootless - CreateRectRgn failed.\n"); } }
void StaticWorldObject::WalkTree(ssgEntity *e, sgVec3 initialpos) { if (!e) return; if (e->isAKindOf (ssgTypeBranch()) ) { ssgBranch *branch = (ssgBranch*) e ; for (int i=0; i<branch->getNumKids(); i++) { ssgEntity *kid = branch->getKid(i); assert(kid!=NULL); WalkTree(kid, initialpos); } } if ( e->isAKindOf ( ssgTypeLeaf () ) ) { AddLeaf((ssgLeaf*)e, initialpos); } }
void CObBinTree::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nCount); WalkTree( SerialStore, (LPVOID)&ar, TV_PREORDER ); } else { DWORD nNewCount = (DWORD)ar.ReadCount(); CObject* newData; while (nNewCount--) { ar >> newData; Insert(newData); } } }
void __fastcall TCDirectoryOutline::SetDirectory(const TFileName NewDir) { if (NewDir.Length() > 0) { TFileName Path = ForceCase(ExpandFileName(NewDir)); int n = Path.Length(); if (n > 3 && Path.IsPathDelimiter(n)) Path.SetLength(n - 1); if (Path != FDirectory) { FDirectory = Path; chdir(FDirectory.c_str()); if (!SameLetter(Path[1], Drive)) Drive = Path[1]; else { WalkTree(Path); Change(); } } } }
void main() { NODE RootNode; int i; long StartTime; // Build a sample tree BuildTree(&RootNode, 14); // Walk the tree 1000 times and see how long it takes StartTime = time(NULL); for (i=0; i<1000; i++) { WalkTree(&RootNode); } printf("Seconds elapsed: %ld\n", time(NULL) - StartTime); getch(); }
void main() { std::cout<< "\n PNode<T> class demonstration"; std::cout<< "\n ============================\n"; //initialize PNode<std::string > root("root"); PNode<std::string > child1("child1"); PNode<std::string > child2("child2"); PNode<std::string > grandchild11("grandchild11"); PNode<std::string > grandchild21("grandchild21"); PNode<std::string > grandchild22("grandchild22"); PNode<std::string > grandgrandchild211("grandgrandchild211"); PNode<std::string > child3("child3"); //test adding child1.add(&grandchild11); grandchild21.add(&grandgrandchild211); child2.add(&grandchild21); child2.add(&grandchild22); root.add(&child1); root.add(&child2); root.add(&child3); WalkTree(&root); //test removing, mark operation std::cout<<"\n\n removing first child"; root.remove(&child1); std::cout<<"\n unmarked all nodes"; root.setMarkState(true); child1.setMarkState(true); grandchild11.setMarkState(true); child2.setMarkState(true); grandchild21.setMarkState(true); grandchild22.setMarkState(true); grandgrandchild211.setMarkState(true); child3.setMarkState(true); //show the tree WalkTree(&root); std::cout<<"\n\n"; std::cout<<"===========================XMLValues Test==================================="<<std::endl; XMLValue xmlv(XMLValue::TAG, "MyTag"); Attribute attr1("ATTR1","1"); Attribute attr2("ATTR2","2"); Attribute attr3("ATTR3","3"); xmlv.AddAttr("ATTR1","1"); xmlv.AddAttr("ATTR2","2"); xmlv.AddAttr("ATTR3","3"); //test == operator std::cout<<"Attribute Compare:\n"<<"attr1 == attr1: "<< (attr1 == attr1) <<"; attr2 == attr1: "<< (attr2 == attr1)<<std::endl; //test search and find attributes for(size_t i=0; i< xmlv.attributes().size();++i) std::cout<<xmlv.attributes().at(i).AttrName.c_str()<<" "<<xmlv.attributes().at(i).AttrValue.c_str() <<std::endl; std::cout<<"Find ATTR2's index: "<<xmlv.Find("ATTR2","2")<<std::endl; std::cout<<"Find ATTR4's index: "<<xmlv.Find("ATTR4","4")<<std::endl; //test removing attributes xmlv.RemoveAttr("ATTR2","2"); std::cout<<"====================ATTR2 Removed==========================\n"; for(size_t i=0; i< xmlv.attributes().size();++i) std::cout<<xmlv.attributes().at(i).AttrName.c_str()<<" "<<xmlv.attributes().at(i).AttrValue.c_str() <<std::endl; std::cout<<"=================Nodes with XMLValues======================"<<std::endl; PNode<XMLValue> xmlroot(xmlv); PNode<XMLValue> xmlcld1(XMLValue(XMLValue::TAG,"xmlChild1")); PNode<XMLValue> xmlcld2(XMLValue(XMLValue::TAG,"xmlChild2")); xmlroot.add(&xmlcld1); xmlroot.add(&xmlcld2); PNode<XMLValue> *pTemp; //test searching through the tree while (pTemp = xmlroot.nextUnmarkedChild()) { std::cout<<"The child of root: "<<pTemp->value().TagName()<<std::endl; pTemp->setMarkState(true); } std::cout<<"=================Children of Nodes======================"<<std::endl; for (size_t i = 0; i < xmlroot.getChildren().size(); i++) std::cout<<"a Child of ROOT: "<<xmlroot.getChildren()[i].TagName()<<std::endl; ::system("pause"); }
static void RRDeliverPropertyEvent(ScreenPtr pScreen, xEvent *event) { if (!(dispatchException & (DE_RESET | DE_TERMINATE))) WalkTree(pScreen, DeliverPropertyEvent, event); }
void COXCopyTree::WalkTree(WORD wLevel) { static COXDirSpec UpDir(_T("..")); short nReturn; #ifndef WIN32 struct _find_t findStruct; #else HANDLE hSearch; WIN32_FIND_DATA w32FindBuf; #endif // make sure the getcurrentdirectory worked correctly if (!m_SourceDir.DoGetCurrentDir()) { m_nStatus = F_GETCURRENTDIR; return; } #ifndef WIN32 UINT uReturn = _dos_findfirst(_T("*.*"),_A_SUBDIR|_A_NORMAL,&findStruct); if (uReturn != 0) #else hSearch=FindFirstFile(_T("*"),&w32FindBuf); if (hSearch == (HANDLE)INVALID_HANDLE_VALUE) #endif { if (wLevel) { m_DestDir.RemoveLastSubdirectory(); if (!UpDir.DoSetCurrentDir()) { m_nStatus = F_SETCURRENTDIR; } } return; } for (;;) { // if this file is .. or . then get next and continue #ifndef WIN32 if (strcmp(findStruct.name,_T(".")) == 0 || strcmp(findStruct.name,_T("..")) == 0) { if (_dos_findnext(&findStruct)) #else if (_tcscmp(w32FindBuf.cFileName,_T(".")) == 0 || _tcscmp(w32FindBuf.cFileName,_T("..")) == 0) { if (FindNextFile(hSearch, &w32FindBuf) == FALSE) #endif { if (!UpDir.DoSetCurrentDir()) { m_nStatus = F_SETCURRENTDIR; } #ifdef WIN32 FindClose(hSearch); #endif m_DestDir.RemoveLastSubdirectory(); return; } continue; } // if this is a directory walk it #ifndef WIN32 if (findStruct.attrib & _A_SUBDIR) { if (!m_SourceDir.AppendDirectory(COXDirSpec(findStruct.name)) || !m_SourceDir.DoSetCurrentDir()) #else if (w32FindBuf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!m_SourceDir.AppendDirectory(COXDirSpec(w32FindBuf.cFileName)) || !m_SourceDir.DoSetCurrentDir()) #endif { TRACE(_T("COXCopyTree::WalkTree : Could not set '%s' as current dir \n"), LPCTSTR(m_SourceDir.GetDirectory())); m_nStatus = F_SETCURRENTDIR; #ifdef WIN32 FindClose(hSearch); #endif return; } #ifndef WIN32 m_DestDir.AppendDirectory(COXDirSpec(findStruct.name)); #else m_DestDir.AppendDirectory(COXDirSpec(w32FindBuf.cFileName)); #endif m_BufferDir.DoGetCurrentDir(); if (!m_DestDir.Exists()) { if (!m_DestDir.DoMakeNew()) { TRACE(_T("COXCopyTree::WalkTree : Could not create '%s' \n"), LPCTSTR(m_DestDir.GetDirectory())); m_nStatus = F_CREATEDIR; #ifdef WIN32 FindClose(hSearch); #endif return; } else // add this directory to list of created dirs { if ((nReturn = m_dsDirs.Add(m_DestDir.GetDirectory())) != SUCCESS) { TRACE(_T("COXCopyTree::WalkTree : Could not add '%s' to recovery List\n"), LPCTSTR(m_DestDir.GetDirectory())); m_nStatus = nReturn; #ifdef WIN32 FindClose(hSearch); #endif return; } } } m_BufferDir.DoSetCurrentDir(); WalkTree(++wLevel); // if anything failed then walk back up the tree if (m_nStatus != SUCCESS) if (m_nStatus != SUCCESS) { #ifdef WIN32 FindClose(hSearch); #endif return; } m_SourceDir.RemoveLastSubdirectory(); } else { // else it is a file copy it COXFileSpec FileSpec; #ifndef WIN32 FileSpec.SetFileName(findStruct.name); #else FileSpec.SetFileName(w32FindBuf.cFileName); #endif m_SourcePath.SetPath(m_SourceDir, FileSpec); m_DestPath.SetPath(m_DestDir, FileSpec); // Check if the user hit the cancel button if (m_pCpyStatDlg != NULL && m_pCpyStatDlg->IsCancelled()) { TRACE(_T("COXCopyTree::WalkTree : User Cancelled copy process, returning...\n")); m_nStatus = F_CANCEL; #ifdef WIN32 FindClose(hSearch); #endif return; } else { if (m_pCpyStatDlg != NULL) { m_pCpyStatDlg->SetStatusText(COXCopyStatusDialog::CSCopying, m_SourcePath.GetPath(), m_DestPath.GetPath()); } if (!m_SourcePath.DoCopy(m_DestPath)) { TRACE(_T("COXCopyTree::WalkTree : Could not copy '%s' to '´%s'\n"), LPCTSTR(m_SourcePath.GetPath()), LPCTSTR(m_DestPath.GetPath())); m_nStatus = F_COPYFILE; #ifdef WIN32 FindClose(hSearch); #endif return; } // add this file to list of created files if ((nReturn = m_dsFiles.Add(m_DestPath.GetPath())) != SUCCESS) { TRACE(_T("COXCopyTree::WalkTree : Could not add '%s' to recovery List\n"), LPCTSTR(m_DestPath.GetPath())); m_nStatus = nReturn; #ifdef WIN32 FindClose(hSearch); #endif return; } } } #ifndef WIN32 if (_dos_findnext(&findStruct)) #else if (FindNextFile(hSearch, &w32FindBuf) == FALSE) #endif { if (!UpDir.DoSetCurrentDir()) { m_nStatus = F_SETCURRENTDIR; } #ifdef WIN32 FindClose(hSearch); #endif m_DestDir.RemoveLastSubdirectory(); return; } } } void COXCopyTree::CleanUp() { LPTSTR lpsz; COXPathSpec CreatedFile; COXDirSpec CreatedDir; // check for required clean up if (m_nStatus != SUCCESS) { m_nStatus = F_CANCEL; if (m_dsDirs.GetCount() || m_dsFiles.GetCount()) { TRACE(_T("COXCopyTree::CleanUp : Several Files and/or dirs found to remove\n STARTING CLEAN PROCESS\n\n")); // hourglass SetHourGlass(); // update the look of the copystat dialog to remove format if (m_pCpyStatDlg != NULL) { m_pCpyStatDlg->SetWindowText(_T("Removal Status")); } // iterate the files for (lpsz = m_dsFiles.GetFirst(); lpsz; lpsz = m_dsFiles.GetNext()) { // tell the user what is being removed if (m_pCpyStatDlg != NULL) { m_pCpyStatDlg->SetStatusText(COXCopyStatusDialog::CSRemoving, lpsz); } CreatedFile.SetPath(lpsz); TRACE(_T("\tCOXCopyTree::CleanUp : Removing File '%s'\n"), LPCTSTR(CreatedFile.GetPath())); if (CreatedFile.DoRemove() == FALSE) { // remove dirs and files for double list m_dsDirs.RemoveAll(); m_dsFiles.RemoveAll(); SetArrow(); return; } } // iterate the dirs backwards for (lpsz = m_dsDirs.GetLast(); lpsz; lpsz = m_dsDirs.GetPrev()) { // tell the user what is being removed if (m_pCpyStatDlg != NULL) { m_pCpyStatDlg->SetStatusText(COXCopyStatusDialog::CSRemoving, lpsz); } CreatedDir.SetDirectory(lpsz); TRACE(_T("\tCOXCopyTree::CleanUp : Removing Dir '%s'\n"), LPCTSTR(CreatedDir.GetDirectory())); if (CreatedDir.DoRemove() == FALSE) { // remove dirs and files for double list m_dsDirs.RemoveAll(); m_dsFiles.RemoveAll(); SetArrow(); return; } } } } // remove dirs and files for double list m_dsDirs.RemoveAll(); m_dsFiles.RemoveAll(); SetArrow(); return; } void COXCopyTree::SetHourGlass() { m_hCursor = LoadCursor(NULL, IDC_WAIT); m_hCursor = SetCursor(m_hCursor); }
BOOL COXCopyTree::DoCopyTree(COXDirSpec SourceDir, COXDirSpec DestDir, BOOL bOnlyContents /* = TRUE */, BOOL bCleanUp /* = FALSE */, COXCopyStatusDialog* pCpyStatDlg /* = NULL */) { static BOOL bBusyCopying = FALSE; CWnd* pMainWnd = NULL; if (bBusyCopying) return FALSE; bBusyCopying = TRUE; m_SourceDir = SourceDir; m_DestDir = DestDir; // Store the current directory of this application // We'll use it to set the original situation back when finished COXDirSpec CurrDir; CurrDir.DoGetCurrentDir(); if (!bOnlyContents) // First Create the source dir physically under the Destination Dir { COXDirSpec TempDir = m_SourceDir.GetLastSubdirectory(); TempDir.SetDrive(_T("")); if (!m_DestDir.AppendDirectory(TempDir)) { m_nStatus = F_CREATEDIR; bBusyCopying = FALSE; return FALSE; } if (!m_DestDir.Exists()) { if (!m_DestDir.DoMakeNew()) { TRACE(_T("COXCopyTree::DoCopyTree : Directory creation %s failed\n"), LPCTSTR(m_DestDir.GetDirectory())); m_nStatus = F_CREATEDIR; bBusyCopying = FALSE; return FALSE; } // add this directory to list of created dirs short nReturn; if ((nReturn = m_dsDirs.Add(m_DestDir.GetDirectory())) != SUCCESS) { TRACE(_T("COXCopyTree::DoCopyTree : Could not add '%s' to recovery List\n"), LPCTSTR(m_DestDir.GetDirectory())); m_nStatus = nReturn; bBusyCopying = FALSE; return FALSE; } } } // The walkTree process needs that the source dir is the current dir when its // starts walking if (m_SourceDir.IsEmpty() || !m_SourceDir.DoSetCurrentDir()) { TRACE(_T("COXCopyTree::DoCopyTree : Could not set '%s' as current dir \n"), LPCTSTR(m_SourceDir.GetDirectory())); m_nStatus = F_SETCURRENTDIR; bBusyCopying = FALSE; return FALSE; } // start status as SUCCESS, if anything fails while walking the tree // the status will be set and walk will return up the tree m_nStatus = SUCCESS; if (pCpyStatDlg != NULL) { // Try to disable the mainframe, to eliminate interference // Note that AfxGetApp() will fail in a DLL pMainWnd = AfxGetApp()->m_pMainWnd; if (pMainWnd != NULL) pMainWnd->EnableWindow(FALSE); // put up a modeless dialog for copy status if (!pCpyStatDlg->Create()) { TRACE(_T("COXCopyTree::DoCopyTree : Creation of Status Dialog Failed")); } else m_pCpyStatDlg = pCpyStatDlg; } WalkTree(0); // replace the current working dir if (!CurrDir.IsEmpty()) CurrDir.DoSetCurrentDir(); if (bCleanUp) // clean up the dirs and files double list and check for required removal of files based on status CleanUp(); bBusyCopying = FALSE; if (m_pCpyStatDlg != NULL) m_pCpyStatDlg->DestroyWindow(); // get rid of the status window if (pMainWnd != NULL) pMainWnd->EnableWindow(TRUE); return (m_nStatus == SUCCESS); }