void Tree::listTree(TreeNode* tree, std::ostream &out) const { if(tree != NULL) { listTree(tree->getLeft(), out); //GenericData * el = tree->getElem()->list(out); listTree(tree->getRight(), out); } }
//This function uses listTree to build a "full" tree starting from the root element //The level is used to define the indentation of the printed output HRESULT buildFullTree(IUIAutomationElement* rootNode) { //Get a TreeWalker object, to parse the UI nodes IUIAutomationTreeWalker* walker = nullptr; auto hr = g_pAutomation->get_ControlViewWalker(&walker); if (FAILED(hr) || walker == nullptr) { logToFile("Failed walker"); logToFile("Error code: " + std::to_string(hr)); return hr; } //Now build the tree starting with level 1 indentation hr = listTree(1, rootNode, walker); SAFE_RELEASE(walker); return hr; }
void launchShell() { //allocate some memory for command string buffer. 1kB should be enough for now const int bufSize = 128; char bufStr[bufSize]; while (true) { print("\nQ-Kernel> ", 0x08); typingCmd = true; newCmd = true; readStr(bufStr, bufSize); typingCmd = false; if (strEql(strTrim(bufStr), "")) { print(COMMAND_HELP, 0x0F); } else if(strEql(bufStr, "help")) { kbHelp(); println(PRO_TIP, 0x0F); print(COMMAND_HELP, 0x0F); } else if(strEql(bufStr, "reboot")) { //reboots the computer reboot(); } else if(strEql(bufStr, "skip")) { // It literally does nothing... (Useful at callback) } else if(strEql(bufStr, "hi")) { print("\nHello!", 0x3F); } else if(strEql(bufStr, "files")) { newline(); listTree(); } else if(strEql(bufStr, "cat")) { print("\nFile Name> ", 0x0F); readStr(bufStr, bufSize); ASSERT(strlength(bufStr) < MAX_FNAME_LEN); catFile(finddir_fs(fs_root, bufStr)); } else if(strEql(bufStr,"execute")) { execute(); } else if(strEql(bufStr,"switch")) { print("\nThe specified directory was not found ", 0x0F); } else if(strEql(bufStr,"writer")) { writer(); } else if(strEql(bufStr, "writer -h")) { writerHelp(); } else if(strEql(bufStr, "calc")){ calc(); } else if(strEql(bufStr, "calc -h")){ calcHelp(); } else if(strEql(bufStr, "clear")) { clearScreen(); cursorX = 0; cursorY = 0; updateCursor(); } else if(strEql(bufStr, "clear -i")) { clearScreen(); printIntro(); } else if(strEql(bufStr, "newdir")) { print("\nReserved", 0x0F); } else if(strEql(bufStr, "erase")) { print("\nReserved", 0x0F); } else { print("\nCommand Not Found ", 0x0F); } newline(); } }
void Tree::list(std::ostream &out) const { if (root != NULL) { listTree(root, out); out << std::endl; } }
//This function builds a tree of nodes given a rootNode and level //A node is represented by an UI element //The function builds the tree with DFS iteration HRESULT listTree(int level, IUIAutomationElement* rootNode, IUIAutomationTreeWalker* walker) { HRESULT hr; IUIAutomationElement* element = nullptr; auto base = std::wstring(level, L'-'); //Get the first element hr = walker->GetFirstChildElement(rootNode, &element); if (FAILED(hr) || element == nullptr) { return hr; } while (element != nullptr) { //Is this a control element? BOOL isControl; hr = element->get_CurrentIsControlElement(&isControl); if (FAILED(hr)) { logToFile(base + L"Failed element is control type"); logToFile(base + L"Error code: " + std::to_wstring(hr)); } else if (isControl) { //Yes it is -> print it's details BSTR controlName; BSTR controlType; CONTROLTYPEID controlTypeId; hr = element->get_CurrentName(&controlName); hr += element->get_CurrentLocalizedControlType(&controlType); hr += element->get_CurrentControlType(&controlTypeId); if (FAILED(hr)) { logToFile(base + L"Failed element control type"); } if (controlName != nullptr) { logToFile(base + L" NAME: " + static_cast<std::wstring>(controlName)); } if (controlType != nullptr) { logToFile(base + L" TYPE: " + static_cast<std::wstring>(controlType)); } if (controlTypeId != NULL) { logToFile(base + L" ID: " + std::to_wstring(controlTypeId)); } } //Continue with children of the current element listTree(level * 2, element, walker); //After that, the next element to be locked at, is it's sibling IUIAutomationElement* next = nullptr; hr = walker->GetNextSiblingElement(element, &next); if (FAILED(hr)) { logToFile(base + L"Failed next element"); logToFile(base + L"Error code: " + std::to_wstring(hr)); } //Free the memory used for the current element SAFE_RELEASE(element); //Update the pointer to continue iteration element = next; } return S_OK; }