Created
September 13, 2022 10:19
-
-
Save Schroedi/84ba8b103bd18604cb187e2f206da112 to your computer and use it in GitHub Desktop.
Get the element from the string produced by DumpFrameUnderCursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Element ElementFromPath(string path) | |
{ | |
if (!path.StartsWith("root")) | |
{ | |
Log.Error("[ElementFromPath] Path must start with root: root.Children[1].Children[102]"); | |
return null; | |
} | |
path = path.Substring("root.".Length); | |
// remove tailing . | |
if (path.EndsWith(".")) | |
path = path.Substring(0, path.Length - 1); | |
var root = LokiPoe.GetGuiElements().Where(x => x.IdLabel == "root").FirstOrDefault<Element>(); | |
if (root == null) | |
{ | |
Log.Error("[ElementFromPath] Could not find root element"); | |
return null; | |
} | |
var pathParts = path.Split('.'); | |
var current = root; | |
foreach (var part in pathParts) | |
{ | |
if (part == "Element") | |
return current; | |
// ger number in Children[xxx] | |
var numEnd = part.IndexOf("]", StringComparison.Ordinal); | |
var idx = int.Parse(part.Substring(9, numEnd - 9)); | |
if (idx <0 || idx >= current.Children.Count) | |
{ | |
Log.Error("[ElementFromPath] Index out of bounds: " + idx); | |
return null; | |
} | |
current = current.Children[idx]; | |
if (current == null) | |
{ | |
Log.Error($"[ElementFromPath] Could not find element: {path}, element is null"); | |
return null; | |
} | |
} | |
return current; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment