Exemple #1
0
        private JumpListLink ParseApplyJumpListTask(JumpListItemObject jumplistItem, int itemIndex)
        {
            JumpListLink task = new JumpListLink
            {
                Title = jumplistItem.ItemName
            };

            if (jumplistItem.ItemIconToString().Equals("Don't use an icon") != true)
            {
                // Icon processing
                string localIconPath = IconPathToLocal(jumplistItem.ItemIconPath, jumplistItem.ItemIconIndex, itemIndex, CurrentAppId, false);
                if (File.Exists(localIconPath))
                {
                    task.IconReference = new IconReference(localIconPath, 0);
                }
            }

            switch (jumplistItem.TaskAction)
            {
            case JumpListItemObject.ActionType.Keyboard:
                string kbdScriptName = GetKeyboardScriptFilename(jumplistItem, itemIndex);
                if (File.Exists(kbdScriptName))
                {    // It should already have been made
                    task.Path      = Common.Path_ProgramFiles + "\\AutoHotKey.exe";
                    task.Arguments = "\"" + kbdScriptName + "\"";
                }
                else
                {
                    return(null);
                }
                break;

            case JumpListItemObject.ActionType.CommandLine:
                if (jumplistItem.TaskCMDShowWindow)
                {
                    task.Path      = "cmd.exe";
                    task.Arguments = "/k \"" + jumplistItem.ItemCmdToString().Replace("\"", "\"\"") + "\"";
                }
                else
                {
                    task.Path      = jumplistItem.TaskCMDPath;
                    task.Arguments = jumplistItem.TaskCMDArgs;
                }
                break;

            case JumpListItemObject.ActionType.AutoHotKey:
                string ahkFilename = GetAhkScriptFilename(false, jumplistItem, itemIndex);
                if (File.Exists(ahkFilename))     // It should have already been made.
                {
                    task.Path      = Common.Path_ProgramFiles + "\\AutoHotKey.exe";
                    task.Arguments = "\"" + ahkFilename + "\"";
                }
                else
                {
                    return(null);
                }
                break;
            }
            return(task);
        }
Exemple #2
0
 private string GetKeyboardScriptFilename(JumpListItemObject jumplistItem, int itemIndex)
 {
     // keyboard_1.ahk
     return(Path.Combine(Common.Path_AppData, CurrentAppId + "\\keyboard_" + itemIndex + ".ahk"));
 }
Exemple #3
0
        private string GetAhkScriptFilename(bool isPack, JumpListItemObject jumplistItem, int itemIndex)
        {
            // ahk_1.ahk

            return(Path.Combine(Common.Path_AppData, CurrentAppId + "\\ahk_" + itemIndex + ".ahk"));
        }
Exemple #4
0
        public void ReadJumpList(string jumplistPath)
        {
            Common.Log("Reading jumplist at: " + jumplistPath, 1);
            if (!File.Exists(jumplistPath))
            {
                return;
            }
            JumpListItemObject jumplistItem = new JumpListItemObject(this);

            // TODO:
            // 1a. T7EPreferences, if no icon path is set, tough: It's empty. Add button to
            // app to set icon to program's icon

            // Get XML file from appdata\[AppId]\jumplist.xml
            XmlReader reader = XmlReader.Create(jumplistPath);

            // Jumplist Packs: If user decides to ADD to list, these vars will correspond
            // to the positions where JLE should add new items
            // If JumplistListBox.Items.Length is 0, safe to assume no pack is being loaded.
            int currentItemPosition       = 0;
            int tasksCategoryItemPosition = 0;
            int oldListBoxCount           = 0;

            // Find the tasks category. Set currentItemPosition to its position.
            for (int i = 0; i < JumplistListBox.Items.Count; i++)
            {
                if (((JumpListItemObject)JumplistListBox.Items[i]).ItemType == JumpListItemObject.ItemTypeVar.CategoryTasks)
                {
                    currentItemPosition       = i;
                    tasksCategoryItemPosition = i + 1;
                    oldListBoxCount           = JumplistListBox.Items.Count;
                    break;
                }
            }

            try
            {
                // Find <jumpList>. If found, break.
                // We just do this to find if jumpList is the top element, first.
                // If there's not, XmlReader seeks to the end, and it can't read anymore
                while (reader.Read())
                {
                    if (reader.IsStartElement("jumpList"))
                    {
                        break;
                    }
                }

                // Under <jumpList>, find the following tags <category> and <tasks>.
                while (reader.Read())
                {
                    if (reader.IsStartElement("category"))
                    {
                        jumplistItem          = new JumpListItemObject(this);
                        jumplistItem.ItemName = reader["name"];
                        jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.Category;
                        JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                        currentItemPosition++;
                    }

                    else if (reader.IsStartElement("tasksCategory"))
                    {
                        if (tasksCategoryItemPosition > 0)
                        {// If there's already a tasks category, skip it.
                            currentItemPosition = JumplistListBox.Items.Count;
                            // add a separator, IF tasksCategory is not the end of the thing
                            if (tasksCategoryItemPosition < oldListBoxCount)
                            {
                                jumplistItem          = new JumpListItemObject(this);
                                jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.Separator;
                                JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                                currentItemPosition++;
                            }
                        }
                        else
                        {
                            jumplistItem          = new JumpListItemObject(this);
                            jumplistItem.ItemName = "Tasks";
                            jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.CategoryTasks;
                            JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                            currentItemPosition++;
                        }
                    }

                    else if (reader.IsStartElement("task"))
                    {
                        jumplistItem          = new JumpListItemObject(this);
                        jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.Task;
                        jumplistItem.ItemName = reader["name"];
                        // Now read for <icon> and <action>
                        while (reader.Read())
                        {
                            if (reader.IsStartElement("icon"))
                            {
                                // Consider translating this to norm. values
                                reader.Read();
                                string iconString = reader.Value;
                                jumplistItem.StringToItemIcon(iconString);
                            }

                            else if (reader.IsStartElement("action"))
                            {
                                switch (reader["type"])
                                {
                                case "T7E_TYPE_KBD":
                                    jumplistItem.TaskAction = JumpListItemObject.ActionType.Keyboard;
                                    bool.TryParse(reader["delay"], out jumplistItem.TaskKBDDelay);
                                    if (jumplistItem.TaskKBDDelay)
                                    {
                                        int.TryParse(reader["delayLength"], out jumplistItem.TaskKBDDelayLength);
                                    }
                                    bool.TryParse(reader["newWindow"], out jumplistItem.TaskKBDNew);
                                    bool.TryParse(reader["isShortcut"], out jumplistItem.TaskKBDShortcutMode);
                                    reader.Read();     // Read to text node
                                    jumplistItem.TaskKBDString = reader.Value;
                                    break;

                                case "T7E_TYPE_CMD":
                                    jumplistItem.TaskAction = JumpListItemObject.ActionType.CommandLine;
                                    bool.TryParse(reader["showWindow"], out jumplistItem.TaskCMDShowWindow);
                                    reader.Read();     // Read to text node
                                    string cmdString = "";
                                    cmdString = Common.ReplaceEnvVarToExpandedPath(reader.Value);

                                    jumplistItem.StringToItemCmd(cmdString);
                                    break;

                                case "T7E_TYPE_AHK":
                                    jumplistItem.TaskAction = JumpListItemObject.ActionType.AutoHotKey;
                                    reader.Read();     // Read to text node
                                    string ahkPath;

                                    // If PackLoading, just load the AHK from the temp path
                                    ahkPath = Path.Combine(Common.Path_AppData, CurrentAppId + "\\" + reader.Value);

                                    if (!File.Exists(ahkPath))
                                    {
                                        MessageBox.Show(ahkPath); break;
                                    }
                                    using (StreamReader ahkReader = new StreamReader(ahkPath))
                                    {
                                        jumplistItem.TaskAHKScript = ahkReader.ReadToEnd();
                                    }
                                    break;
                                }
                            }

                            else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "task")
                            {
                                break;
                            }
                        }

                        JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                        currentItemPosition++;
                    }

                    else if (reader.IsStartElement("link"))
                    {
                        jumplistItem          = new JumpListItemObject(this);
                        jumplistItem.ItemName = reader["name"];
                        bool.TryParse(reader["runWithApp"], out jumplistItem.FileRunWithApp);

                        // Now read for <icon> and <action>
                        while (reader.Read())
                        {
                            if (reader.IsStartElement("icon"))
                            {
                                reader.Read();
                                string iconString = reader.Value;
                                jumplistItem.StringToItemIcon(iconString);
                            }

                            else if (reader.IsStartElement("location"))
                            {
                                reader.Read(); // Get text node
                                string locationPath = "";
                                locationPath = Common.ReplaceEnvVarToExpandedPath(reader.Value);

                                if (!File.Exists(locationPath) && !Directory.Exists(locationPath))
                                {
                                    break;
                                }
                                else
                                {
                                    jumplistItem.FilePath = locationPath;
                                }

                                // Check if directory
                                //FileAttributes attr = File.GetAttributes(locationPath);
                                //if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                                jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.FileFolder;
                            }

                            else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "link")
                            {
                                break;
                            }
                        }

                        JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                        currentItemPosition++;
                    }

                    else if (reader.IsStartElement("separator"))
                    {
                        jumplistItem          = new JumpListItemObject(this);
                        jumplistItem.ItemType = JumpListItemObject.ItemTypeVar.Separator;
                        JumplistListBox.Items.Insert(currentItemPosition, jumplistItem);
                        currentItemPosition++;
                    }

                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "jumpList")
                    {
                        break;
                    }
                }
            }

            catch (Exception e)
            {
                Common.Log("ReadJumpList error!\r\n"
                           + e.ToString() + "\r\nJumpList was not read.");
            }

            reader.Close();

            Common.Log("Finished reading jumplist.", -1);
        }
Exemple #5
0
        public bool ApplyJumplistToTaskbar()
        {
            bool result = false;

            try
            {
                JumpList newList = JumpList.CreateJumpListForAppId(CurrentAppId);

                ListBox.ObjectCollection jumplistItems = JumplistListBox.Items;
                for (int i = 0; i < jumplistItems.Count; i++)
                {
                    // Look for a category
                    JumpListItemObject.ItemTypeVar jumplistItemType = ((JumpListItemObject)jumplistItems[i]).ItemType;
                    if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category ||
                        jumplistItemType == JumpListItemObject.ItemTypeVar.CategoryTasks)
                    {
                        JumpListCustomCategory category = new JumpListCustomCategory(((JumpListItemObject)jumplistItems[i]).ItemName);

                        // Look for a task
                        for (int j = i + 1; j < jumplistItems.Count; j++)
                        {
                            i = j - 1; // When J loop is exited, i has to be less.
                            JumpListItemObject jumplistItem = (JumpListItemObject)jumplistItems[j];
                            switch (jumplistItem.ItemType)
                            {
                            case JumpListItemObject.ItemTypeVar.Category:
                            case JumpListItemObject.ItemTypeVar.CategoryTasks:
                                j = jumplistItems.Count;     // Exit the for loop
                                break;

                            case JumpListItemObject.ItemTypeVar.Task:
                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                                {
                                    category.AddJumpListItems(
                                        ParseApplyJumpListTask(jumplistItem, j));
                                }
                                else
                                {
                                    newList.AddUserTasks(
                                        ParseApplyJumpListTask(jumplistItem, j));
                                }
                                break;

                            case JumpListItemObject.ItemTypeVar.FileFolder:
                                JumpListLink link = new JumpListLink
                                {
                                    Title     = jumplistItem.ItemName,
                                    Path      = "C:\\Windows\\explorer.exe",
                                    Arguments = jumplistItem.FilePath
                                };
                                if (jumplistItem.FileRunWithApp)
                                {
                                    link.Path = CurrentAppPath;
                                }
                                // Format icon
                                if (jumplistItem.ItemIconToString().Equals("Don't use an icon") != true)
                                {
                                    // Icon processing
                                    string localIconPath = IconPathToLocal(jumplistItem.ItemIconPath, jumplistItem.ItemIconIndex, j, CurrentAppId, false);
                                    if (File.Exists(localIconPath))
                                    {
                                        link.IconReference = new IconReference(localIconPath, 0);
                                    }
                                }

                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                                {
                                    category.AddJumpListItems(link);
                                }
                                else
                                {
                                    newList.AddUserTasks(link);
                                }
                                break;

                            case JumpListItemObject.ItemTypeVar.Separator:
                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.CategoryTasks)
                                {
                                    newList.AddUserTasks(new JumpListSeparator());
                                }
                                break;
                            }
                        }

                        if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                        {
                            newList.AddCustomCategories(category);
                        }
                    }
                }

                // ////////
                JumpList dummyList = JumpList.CreateJumpListForAppId(CurrentAppId);
                dummyList.AddUserTasks(new JumpListLink
                {
                    Title = "Dummy",
                    Path  = "%windir%\\explorer.exe"
                });
                dummyList.Refresh();
                newList.Refresh();
                // Remove appid from own window!
                SetAppIdBackAfterJumplist();
                result = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("JumpList applying not successful." + "\r\n"
                                + e.ToString());
            }

            return(result);
        }