예제 #1
0
        private void CompareWMIClasses()
        {
            Dictionary <string, string> CatagoryPairs = new Dictionary <string, string>
            {
                { "ccm", "CCM" },
                { "cim", "CIM" },
                { "hp", "HP" },
                { "msft", "MSFT" },
                { "office2013", "Office2013" },
                { "sms", "SMS" },
                { "win32", "Win32" },
                { "win32reg", "Win32Reg" }
            };

            foreach (string ClassName in ClassNames)
            {
                int FoundClass = WMIClasses.Where(x => x.Name == ClassName).Count();

                if (FoundClass == 0)
                {
                    string category = string.Empty;
                    if (ClassName.StartsWith("_"))
                    {
                        category = "Internal";
                    }
                    else if (ClassName.Contains("perf"))
                    {
                        category = "Perf";
                    }
                    else
                    {
                        int underscore = ClassName.IndexOf('_');
                        if (underscore > 0)
                        {
                            if (CatagoryPairs.ContainsKey(ClassName.Substring(0, underscore).ToLower()))
                            {
                                category = CatagoryPairs[ClassName.Substring(0, underscore).ToLower()];
                            }
                            else
                            {
                                category = "unknown";
                            }
                        }
                    }
                    WMIClasses.Add(new WMIClass {
                        Name     = ClassName,
                        Catagory = category,
                        Status   = "Unknown"
                    });
                }
            }
        }
        public void Compile()
        {
            if (Target.InputPaths.Count != 1)
            {
                throw new ContentFileException("Only one input file expected");
            }

            if (Target.OutputPaths.Count != 2)
            {
                throw new ContentFileException("Only two output files expected");
            }

            ParsedPath stringsFilePath = Target.InputPaths[0];
            ParsedPath csFilePath      = Target.OutputPaths[0];
            ParsedPath jsonFilePath    = Target.OutputPaths[1];

            if (ClassName.StartsWith("Xxx"))
            {
                this.ClassName = this.ClassName.Replace("Xxx", stringsFilePath.File + "Strings");
            }

            StringsContent stringsData = CreateStringsData(this.ClassName, ReadStringsFile(stringsFilePath));

            string[] strings = stringsData.Strings.Select(s => s.Value).ToArray();

            if (!Directory.Exists(jsonFilePath.VolumeAndDirectory))
            {
                Directory.CreateDirectory(jsonFilePath.VolumeAndDirectory);
            }

            WriteJsonFile(jsonFilePath, strings);

            if (!Directory.Exists(csFilePath.VolumeAndDirectory))
            {
                Directory.CreateDirectory(csFilePath.VolumeAndDirectory);
            }

            using (TextWriter writer = new StreamWriter(csFilePath))
            {
                WriteCsOutput(writer, stringsData);
            }
        }
예제 #3
0
        public static string GetAutomationIdOfUiElement(RecordedUiTask recordedUiTask, List <string> pathNodes, ref UiTreeNode rootRet)
        {
            string lastValidAutomationId = string.Empty;

            rootRet = null;

            string tag, ClassName, Name, AutomationId, Pos;
            string xPath = "";

            UiTreeNode parent = null;

            for (int i = 0; i < pathNodes.Count; i++)
            {
                var nodePath = pathNodes[i];

                bool bStartsWithName   = false;
                bool bStartsWithClass  = false;
                bool bStartsWithAutoId = false;

                var tagAttrs = GetTagAttributes(nodePath);

                tag = tagAttrs.ContainsKey("Tag") ? tagAttrs["Tag"] : "Unknown";

                AutomationId = tagAttrs.ContainsKey("AutomationId") ? tagAttrs["AutomationId"] : null;

                Name = tagAttrs.ContainsKey("Name") ? tagAttrs["Name"] : null;

                ClassName = tagAttrs.ContainsKey("ClassName") ? tagAttrs["ClassName"] : null;
                ClassName = CheckAndFixNoneStaticValue(ClassName);

                Pos = tagAttrs.ContainsKey("position()") ? tagAttrs["position()"] : null;

                string xPathNode = $"/{tag}";

                // Set AutomationId to null if it is a GUID which is very likely generated at runtime
                AutomationId = CheckAndFixNoneStaticValue(AutomationId);

                // AutomationId (like UIs on Cortana search result list) created at runtime may end with digits
                if (!string.IsNullOrEmpty(AutomationId) && !AutomationId.StartsWith("starts-with:"))
                {
                    string patAutoIdEndsWithDigits = @"^([^\d]*)[_\.\-\d]+$";
                    System.Text.RegularExpressions.Regex regAutoId = new System.Text.RegularExpressions.Regex(patAutoIdEndsWithDigits, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regAutoId != null)
                    {
                        System.Text.RegularExpressions.Match matchAutoId = regAutoId.Match(AutomationId);
                        if (matchAutoId.Success && matchAutoId.Groups.Count > 1)
                        {
                            if (matchAutoId.Groups[1].Length > 0)
                            {
                                AutomationId      = "starts-with:" + matchAutoId.Groups[1].ToString();
                                bStartsWithAutoId = true;
                            }
                            else
                            {
                                AutomationId = null;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(ClassName) && string.IsNullOrEmpty(AutomationId))
                {
                    if (ClassName.StartsWith("starts-with:"))
                    {
                        ClassName        = ClassName.Remove(0, "starts-with:".Length);
                        xPathNode       += string.Format(sNameStartsWithValue, "ClassName", ClassName);
                        bStartsWithClass = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "ClassName", ClassName);
                    }
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    if (Name.StartsWith("starts-with:"))
                    {
                        Name            = Name.Remove(0, "starts-with:".Length);
                        xPathNode      += string.Format(sNameStartsWithValue, "Name", Name);
                        bStartsWithName = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "Name", Name);
                    }
                }

                if (!string.IsNullOrEmpty(AutomationId))
                {
                    if (AutomationId.StartsWith("starts-with:"))
                    {
                        AutomationId      = AutomationId.Remove(0, "starts-with:".Length);
                        xPathNode        += string.Format(sNameStartsWithValue, "AutomationId", AutomationId);
                        bStartsWithAutoId = true;
                    }
                    else
                    {
                        xPathNode += string.Format(sNameValue, "AutomationId", AutomationId);
                    }
                }

                if (!string.IsNullOrEmpty(Pos) && string.IsNullOrEmpty(AutomationId) && string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(ClassName))
                {
                    xPathNode += $"[position()={Pos}]";
                }

                // UiTreeNode
                var left      = tagAttrs.ContainsKey("x") ? tagAttrs["x"] : null;
                var top       = tagAttrs.ContainsKey("y") ? tagAttrs["y"] : null;
                var leftLocal = tagAttrs.ContainsKey("lx") ? tagAttrs["lx"] : null;
                var topLocal  = tagAttrs.ContainsKey("ly") ? tagAttrs["ly"] : null;
                var width     = tagAttrs.ContainsKey("width") ? tagAttrs["width"] : null;
                var height    = tagAttrs.ContainsKey("height") ? tagAttrs["height"] : null;
                var runtimeId = tagAttrs.ContainsKey("RuntimeId") ? tagAttrs["RuntimeId"] : null;

                xPath += xPathNode;

                var uiTreeNode = new UiTreeNode(parent)
                {
                    Title = $"{tag}, \"{Name}\", {ClassName}"
                };

                uiTreeNode.NodePath                  = xPathNode;
                uiTreeNode.Tag                       = tag;
                uiTreeNode.ClassName                 = ClassName;
                uiTreeNode.Name                      = Name;
                uiTreeNode.AutomationId              = AutomationId;
                uiTreeNode.Left                      = left;
                uiTreeNode.Top                       = left;
                uiTreeNode.Width                     = width;
                uiTreeNode.Height                    = height;
                uiTreeNode.RuntimeId                 = runtimeId;
                uiTreeNode.Position                  = Pos;
                uiTreeNode.NameCompareMethod         = bStartsWithName ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;
                uiTreeNode.ClassNameCompareMethod    = bStartsWithClass ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;
                uiTreeNode.AutomationIdCompareMethod = bStartsWithAutoId ? UiTreeNode.CompareMethod.StartsWith : UiTreeNode.CompareMethod.Equal;

                if (i == pathNodes.Count - 1)
                {
                    uiTreeNode.UiTask        = recordedUiTask;
                    recordedUiTask.Left      = left;
                    recordedUiTask.Top       = top;
                    recordedUiTask.LeftLocal = leftLocal;
                    recordedUiTask.TopLocal  = topLocal;
                    recordedUiTask.Name      = Name;
                    recordedUiTask.Tag       = tag;
                }

                if (rootRet == null)
                {
                    rootRet = uiTreeNode;
                }

                if (parent != null)
                {
                    parent.Items.Add(uiTreeNode);
                }

                parent = uiTreeNode;

                lastValidAutomationId = string.IsNullOrEmpty(AutomationId) ? lastValidAutomationId : AutomationId;
            }

            return(lastValidAutomationId);
        }
예제 #4
0
파일: CustomItem.cs 프로젝트: vadash/Pickit
        public CustomItem(LabelOnGround item, FilesContainer fs, float distance, Dictionary <string, int> weightsRules,
                          bool isMetamorphItem = false)
        {
            if (isMetamorphItem)
            {
                IsMetaItem    = true;
                LabelOnGround = item;
                Distance      = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldIcon        = itemItemOnGround?.GetComponent <MinimapIcon>();
                if (worldIcon == null)
                {
                    return;
                }
                //var groundItem = worldItem.ItemEntity;
                WorldIcon  = worldIcon;
                GroundItem = itemItemOnGround;
                Path       = GroundItem?.Path;

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World2: {worldIcon.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground2: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () =>
                {
                    var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                    return(isTargeted != null && (bool)isTargeted);
                };

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                    if (ClassName.StartsWith("Heist"))
                    {
                        IsHeist = true;
                    }
                }

                IsValid = true;
            }
            else
            {
                isMetamorphItem = false;
                LabelOnGround   = item;
                Distance        = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldItem        = itemItemOnGround?.GetComponent <WorldItem>();
                if (worldItem == null)
                {
                    return;
                }
                var groundItem = worldItem.ItemEntity;
                GroundItem = groundItem;
                Path       = groundItem?.Path;
                if (GroundItem == null)
                {
                    return;
                }

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World: {worldItem.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () => itemItemOnGround?.GetComponent <Targetable>()?.isTargeted == true;

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                    if (ClassName.StartsWith("Heist"))
                    {
                        IsHeist = true;
                    }
                }

                var WeaponClass = new List <string>
                {
                    "One Hand Mace",
                    "Two Hand Mace",
                    "One Hand Axe",
                    "Two Hand Axe",
                    "One Hand Sword",
                    "Two Hand Sword",
                    "Thrusting One Hand Sword",
                    "Bow",
                    "Claw",
                    "Dagger",
                    "Rune Dagger",
                    "Sceptre",
                    "Staff",
                    "Wand"
                };

                if (GroundItem.HasComponent <Quality>())
                {
                    var quality = GroundItem.GetComponent <Quality>();
                    Quality = quality.ItemQuality;
                }

                if (GroundItem.HasComponent <Base>())
                {
                    var @base = GroundItem.GetComponent <Base>();
                    IsElder    = @base.isElder;
                    IsShaper   = @base.isShaper;
                    IsHunter   = @base.isHunter;
                    IsRedeemer = @base.isRedeemer;
                    IsCrusader = @base.isCrusader;
                    IsWarlord  = @base.isWarlord;
                }

                if (GroundItem.HasComponent <Mods>())
                {
                    var mods = GroundItem.GetComponent <Mods>();
                    Rarity       = mods.ItemRarity;
                    IsIdentified = mods.Identified;
                    ItemLevel    = mods.ItemLevel;
                    IsVeiled     = mods.ItemMods.Any(m => m.DisplayName.Contains("Veil"));
                }

                if (GroundItem.HasComponent <Sockets>())
                {
                    var sockets = GroundItem.GetComponent <Sockets>();
                    IsRGB       = sockets.IsRGB;
                    Sockets     = sockets.NumberOfSockets;
                    LargestLink = sockets.LargestLinkSize;
                }

                if (GroundItem.HasComponent <Weapon>())
                {
                    IsWeapon = true;
                }

                MapTier = GroundItem.HasComponent <Map>() ? GroundItem.GetComponent <Map>().Tier : 0;
                IsValid = true;
            }
        }
예제 #5
0
        static string GetXPathFromUiTaskNode(XmlElement uiTaskNode)
        {
            if (uiTaskNode == null || uiTaskNode.ChildNodes.Count < 1)
            {
                return("");
            }

            string tag, ClassName, Name, AutomationId, Pos;
            string xPath = "";

            for (int i = 0; i < uiTaskNode.ChildNodes.Count; i++)
            {
                XmlNode childNode = uiTaskNode.ChildNodes[i];

                tag          = childNode.Name != "Unknown" ? childNode.Name : "*";
                AutomationId = XmlEncode(childNode.Attributes[ConstVariables.AutomationId].Value);
                AutomationId = CheckAndFixNoneStaticValue(AutomationId);

                Name = XmlEncode(childNode.Attributes[ConstVariables.Name].Value);

                ClassName = childNode.Attributes[ConstVariables.ClassName].Value;
                ClassName = CheckAndFixNoneStaticValue(ClassName);
                Pos       = childNode.Attributes[ConstVariables.Pos].Value;

                xPath += $"/{tag}";
                int nPos = xPath.Length;

                // AutomationId (like UIs on Cortana search result list) created at runtime may end with digits
                if (!string.IsNullOrEmpty(AutomationId) && !AutomationId.StartsWith("starts-with:"))
                {
                    string patAutoIdEndsWithDigits = @"^([^\d]*)[\d]+$";
                    System.Text.RegularExpressions.Regex regAutoId = new System.Text.RegularExpressions.Regex(patAutoIdEndsWithDigits, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regAutoId != null)
                    {
                        System.Text.RegularExpressions.Match matchAutoId = regAutoId.Match(AutomationId);
                        if (matchAutoId.Success && matchAutoId.Groups.Count > 1)
                        {
                            if (matchAutoId.Groups[1].Length > 0)
                            {
                                AutomationId = "starts-with:" + matchAutoId.Groups[1].ToString();
                            }
                            else
                            {
                                AutomationId = null;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(AutomationId))
                {
                    if (AutomationId.StartsWith("starts-with:"))
                    {
                        AutomationId = AutomationId.Remove(0, "starts-with:".Length);
                        xPath       += string.Format(sNameStartsWithValue, ConstVariables.AutomationId, AutomationId);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.AutomationId, AutomationId);
                    }
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    if (Name.StartsWith("starts-with:"))
                    {
                        Name   = Name.Remove(0, "starts-with:".Length);
                        xPath += string.Format(sNameStartsWithValue, ConstVariables.Name, Name);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.Name, Name);
                    }
                }

                if (!string.IsNullOrEmpty(ClassName) && string.IsNullOrEmpty(AutomationId))
                {
                    if (ClassName.StartsWith("starts-with:"))
                    {
                        ClassName = ClassName.Remove(0, "starts-with:".Length);
                        xPath    += string.Format(sNameStartsWithValue, ConstVariables.ClassName, ClassName);
                    }
                    else
                    {
                        xPath += string.Format(sNameValue, ConstVariables.ClassName, ClassName);
                    }
                }

                if (!string.IsNullOrEmpty(Pos) && string.IsNullOrEmpty(AutomationId) && string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(ClassName))
                {
                    //TODO: verify
                    xPath = xPath.Insert(nPos, $"[position()={Pos}]");
                }
            }

            return("\"" + xPath + "\",\n");
        }