示例#1
0
        public static RazorScript AddScript(string file)
        {
            RazorScript script = new RazorScript
            {
                Lines = File.ReadAllLines(file),
                Name  = Path.GetFileNameWithoutExtension(file),
                Path  = file
            };

            if (Path.GetDirectoryName(script.Path).Equals(Config.GetUserDirectory("Scripts")))
            {
                script.Category = string.Empty;
            }
            else
            {
                string cat = file.Replace(Config.GetUserDirectory("Scripts"), "").Substring(1);
                script.Category = Path.GetDirectoryName(cat).Replace("/", "\\");
            }

            AddHotkey(script);

            _scriptList.Add(script);

            return(script);
        }
示例#2
0
        private static void Recurse(TreeNodeCollection nodes, string path)
        {
            try
            {
                var razorFiles = Directory.GetFiles(path, "*.razor");
                razorFiles = razorFiles.OrderBy(fileName => fileName).ToArray();

                foreach (var file in razorFiles)
                {
                    RazorScript script = AddScript(file);

                    if (nodes != null)
                    {
                        TreeNode node = new TreeNode(script.Name)
                        {
                            Tag = script
                        };

                        nodes.Add(node);
                    }
                }
            }
            catch
            {
                // ignored
            }

            try
            {
                foreach (string directory in Directory.GetDirectories(path))
                {
                    if (!string.IsNullOrEmpty(directory) && !directory.Equals(".") && !directory.Equals(".."))
                    {
                        if (nodes != null)
                        {
                            TreeNode node = new TreeNode($"[{Path.GetFileName(directory)}]")
                            {
                                Tag = directory
                            };

                            nodes.Add(node);

                            Recurse(node.Nodes, directory);
                        }
                        else
                        {
                            Recurse(null, directory);
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }
        }
示例#3
0
        public static void RemoveScript(RazorScript script)
        {
            RemoveHotkey(script);

            _scriptList.Remove(script);
        }
示例#4
0
        public static void OnHotKey(ref object state)
        {
            RazorScript script = (RazorScript)state;

            PlayScript(script.Lines);
        }
示例#5
0
 private static void RemoveHotkey(RazorScript script)
 {
     HotKey.Remove(Language.Format(LocString.PlayScript, script.ToString()));
 }
示例#6
0
 private static void AddHotkey(RazorScript script)
 {
     HotKey.Add(HKCategory.Scripts, HKSubCat.None, Language.Format(LocString.PlayScript, script), OnHotKey,
                script);
 }
示例#7
0
 public static void AddHotkey(RazorScript script)
 {
     HotKey.Add(HKCategory.Scripts, HKSubCat.None, Language.Format(LocString.PlayScript, script), HotkeyCallback,
                script);
 }