OSDN Git Service

-Add RLV @FindFolder command support 16/head
authorelliena-bulmer <elliena.bulmer@gmail.com>
Thu, 12 Mar 2015 07:51:53 +0000 (03:51 -0400)
committerelliena-bulmer <elliena.bulmer@gmail.com>
Thu, 12 Mar 2015 07:51:53 +0000 (03:51 -0400)
-Add preference to show RLV commands in chat
-Fix FindFolderInternal case sensitive folder name check

Radegast/Core/ChatTextManager.cs
Radegast/Core/RLV/RLVManager.cs
Radegast/GUI/Dialogs/Settings.Designer.cs
Radegast/GUI/Dialogs/Settings.cs

index d793906..0053d1f 100644 (file)
@@ -256,7 +256,9 @@ namespace Radegast
             {
                 instance.RLV.TryProcessCMD(e);
 #if !DEBUG
-                return;
+                if (!instance.RLV.EnabledDebugCommands) {
+                    return;
+                }
 #endif
             }
 
index f02e395..82c00d8 100644 (file)
@@ -182,7 +182,6 @@ namespace Radegast
 
         public bool Enabled
         {
-
             get
             {
                 if (instance.GlobalSettings["rlv_enabled"].Type == OSDType.Unknown)
@@ -208,6 +207,27 @@ namespace Radegast
             }
         }
 
+        public bool EnabledDebugCommands
+        {
+            get
+            {
+                if (instance.GlobalSettings["rlv_debugcommands"].Type == OSDType.Unknown)
+                {
+                    instance.GlobalSettings["rlv_debugcommands"] = new OSDBoolean(false);
+                }
+
+                return instance.GlobalSettings["rlv_debugcommands"].AsBoolean();
+            }
+
+            set
+            {
+                if (EnabledDebugCommands != instance.GlobalSettings["rlv_debugcommands"].AsBoolean())
+                {
+                    instance.GlobalSettings["rlv_debugcommands"] = new OSDBoolean(value);
+                }
+            }
+        }
+
         RadegastInstance instance;
         GridClient client { get { return instance.Client; } }
         Regex rlv_regex = new Regex(@"(?<behaviour>[^:=]+)(:(?<option>[^=]*))?=(?<param>\w+)", RegexOptions.Compiled);
@@ -715,12 +735,33 @@ namespace Radegast
                         }
                         break;
 
+                    case "findfolder":
+                        if (int.TryParse(rule.Param, out chan) && chan > 0)
+                        {
+                            string[] keywordsArray = rule.Option.Split(new string[] {"&&"}, StringSplitOptions.None);
+                            if (keywordsArray.Any())
+                            {
+                                InventoryNode target = FindFolderKeyword(keywordsArray);
+                                if  (target != null)
+                                {
+                                    string path = FindFullInventoryPath(target, "");
+
+                                    // remove #RLV/ from the path
+                                    if (path.Substring(0, 5).ToLower() == @"#rlv/")
+                                    {
+                                        path = path.Substring(5);
+                                        Respond(chan, path);
+                                    }
+                                }
+                            }
+                        }
+                        break;
+
                     #endregion #RLV folder and outfit manipulation
 
                 }
             }
 
-
             return true;
         }
 
@@ -835,6 +876,16 @@ namespace Radegast
             return null;
         }
 
+        public string FindFullInventoryPath(InventoryNode input, string pathConstruct)
+        {
+            if (input.Parent == null) {
+                return pathConstruct.TrimEnd('/');
+            } else {
+                pathConstruct = input.Data.Name + "/" + pathConstruct;
+                return FindFullInventoryPath (input.Parent, pathConstruct);
+            }
+        }
+
         public InventoryNode FindFolder(string path)
         {
             var root = RLVRootFolder();
@@ -845,7 +896,7 @@ namespace Radegast
 
         protected InventoryNode FindFolderInternal(InventoryNode currentNode, string currentPath, string desiredPath)
         {
-            if (desiredPath == currentPath)
+            if (desiredPath.ToLower() == currentPath.ToLower())
             {
                 return currentNode;
             }
@@ -862,6 +913,47 @@ namespace Radegast
             return null;
         }
 
+        public InventoryNode FindFolderKeyword(string[] keywords)
+        {
+            var root = RLVRootFolder();
+            if (root == null) return null;
+
+            return FindFolderKeywordsInternal (root, keywords);
+        }
+
+        protected InventoryNode FindFolderKeywordsInternal(InventoryNode currentNode, string[] keywords)
+        {
+            bool mustSkip = false;
+            foreach(string kw in keywords)
+            {
+                if (!mustSkip)
+                {
+                    if (!currentNode.Data.Name.ToLower().Contains(kw.ToLower()))
+                    {
+                        mustSkip = true;
+                        break;
+                    }
+                }
+            }
+
+            if (!mustSkip)
+            {
+                return currentNode;
+            }
+
+            foreach (var n in currentNode.Nodes.Values)
+            {
+                if (n.Data.Name.StartsWith(".")) continue;
+
+                var res = FindFolderKeywordsInternal(n, keywords);
+                if (res != null)
+                {
+                    return res;
+                }
+            }
+            return null;
+        }
+
         public void Clear(UUID id)
         {
             lock (rules)
index 6c43e3f..d8a3e0c 100644 (file)
@@ -80,6 +80,7 @@ namespace Radegast
             this.cbAutoReconnect = new System.Windows.Forms.CheckBox();
             this.label2 = new System.Windows.Forms.Label();
             this.cbRLV = new System.Windows.Forms.CheckBox();
+            this.cbRLVDebug = new System.Windows.Forms.CheckBox();
             this.cbMinToTrey = new System.Windows.Forms.CheckBox();
             this.cbRadegastClientTag = new System.Windows.Forms.CheckBox();
             this.cbSyntaxHighlight = new System.Windows.Forms.CheckBox();
@@ -255,12 +256,13 @@ namespace Radegast
             this.cbMisc.Controls.Add(this.cbAutoReconnect);
             this.cbMisc.Controls.Add(this.label2);
             this.cbMisc.Controls.Add(this.cbRLV);
+            this.cbMisc.Controls.Add(this.cbRLVDebug);
             this.cbMisc.Controls.Add(this.cbMinToTrey);
             this.cbMisc.Controls.Add(this.cbRadegastClientTag);
             this.cbMisc.Controls.Add(this.cbSyntaxHighlight);
             this.cbMisc.Location = new System.Drawing.Point(270, 6);
             this.cbMisc.Name = "cbMisc";
-            this.cbMisc.Size = new System.Drawing.Size(236, 310);
+            this.cbMisc.Size = new System.Drawing.Size(236, 330);
             this.cbMisc.TabIndex = 2;
             this.cbMisc.TabStop = false;
             // 
@@ -389,6 +391,17 @@ namespace Radegast
             this.cbRLV.UseVisualStyleBackColor = true;
             this.cbRLV.CheckedChanged += new System.EventHandler(this.cbTrasactChat_CheckedChanged);
             // 
+            // cbRLVDebug
+            //
+            this.cbRLVDebug.AutoSize = true;
+            this.cbRLVDebug.Location = new System.Drawing.Point(6, 300);
+            this.cbRLVDebug.Name = "cbRLVDebug";
+            this.cbRLVDebug.Size = new System.Drawing.Size(130, 17);
+            this.cbRLVDebug.TabIndex = 12;
+            this.cbRLVDebug.Text = "Output RLV commands";
+            this.cbRLVDebug.UseVisualStyleBackColor = true;
+            this.cbRLVDebug.CheckedChanged += new System.EventHandler(this.cbTrasactChat_CheckedChanged);
+            //
             // cbMinToTrey
             // 
             this.cbMinToTrey.AutoSize = true;
@@ -1025,6 +1038,7 @@ namespace Radegast
         public System.Windows.Forms.CheckBox cbAutoReconnect;
         public System.Windows.Forms.CheckBox cbHideLoginGraphics;
         public System.Windows.Forms.CheckBox cbRLV;
+        public System.Windows.Forms.CheckBox cbRLVDebug;
         public System.Windows.Forms.CheckBox cbMUEmotes;
         public System.Windows.Forms.CheckBox cbFriendsHighlight;
         public System.Windows.Forms.CheckBox cbMinToTrey;
index b92ac2d..cca3633 100644 (file)
@@ -69,6 +69,11 @@ namespace Radegast
                 s["rlv_enabled"] = new OSDBoolean(false);
             }
 
+            if (s["rlv_debugcommands"].Type == OSDType.Unknown)
+            {
+                s["rlv_debugcommands"] = new OSDBoolean(false);
+            }
+
             if (s["mu_emotes"].Type == OSDType.Unknown)
             {
                 s["mu_emotes"] = new OSDBoolean(false);
@@ -181,6 +186,12 @@ namespace Radegast
                 s["rlv_enabled"] = new OSDBoolean(cbRLV.Checked);
             };
 
+            cbRLVDebug.Checked = s["rlv_debugcommands"].AsBoolean();
+            cbRLVDebug.CheckedChanged += (object sender, EventArgs e) =>
+            {
+                s["rlv_debugcommands"] = new OSDBoolean(cbRLVDebug.Checked);
+            };
+
             cbMUEmotes.Checked = s["mu_emotes"].AsBoolean();
             cbMUEmotes.CheckedChanged += (object sender, EventArgs e) =>
             {