コード例 #1
0
ファイル: AppsManager.cs プロジェクト: dingdayong/QTTabBar
 public static void SaveApps()
 {
     Registry.CurrentUser.DeleteSubKeyTree(RegConst.Root + RegConst.Apps);
     using (RegistryKey key = Registry.CurrentUser.CreateSubKey(RegConst.Root + RegConst.Apps)) {
         for (int i = 0; i < appList.Count; i++)
         {
             UserApp a = appList[i];
             using (RegistryKey akey = key.CreateSubKey("" + i)) {
                 akey.SetValue("", a.Name);
                 if (a.IsFolder)
                 {
                     akey.SetValue("children", a.ChildrenCount);
                 }
                 else
                 {
                     akey.SetValue("path", a.Path);
                     akey.SetValue("args", a.Args);
                     akey.SetValue("wdir", a.WorkingDir);
                     if (a.ShortcutKey != Keys.None)
                     {
                         akey.SetValue("key", (int)a.ShortcutKey);
                     }
                 }
             }
         }
     }
     InstanceManager.StaticBroadcast(LoadApps);
 }
コード例 #2
0
 public MenuItemArguments(UserApp app, ShellBrowserEx shellBrowser, MenuGenre genre)
 {
     App          = app;
     Path         = app.Path;
     ShellBrowser = shellBrowser;
     Genre        = genre;
 }
コード例 #3
0
 public AppEntry(UserApp app)
 {
     Path        = app.Path;
     Name        = app.Name;
     Args        = app.Args;
     WorkingDir  = app.WorkingDir;
     ShortcutKey = app.ShortcutKey;
 }
コード例 #4
0
        private static ToolStripItem CreateMenuItem_AppLauncher(UserApp app, EventPack ep, ShellBrowserEx shellBrowser)
        {
            string path = app.Path;

            try {
                path = Environment.ExpandEnvironmentVariables(path);
            }
            catch {
            }
            MenuItemArguments mia = new MenuItemArguments(app, shellBrowser, MenuGenre.Application);

            if (path.StartsWith(@"\\") || path.StartsWith("::") || !Directory.Exists(path))
            {
                mia.Target = MenuTarget.File;
                QMenuItem item = new QMenuItem(app.Name, mia)
                {
                    Name = app.Name
                };
                item.SetImageReservationKey(path, Path.GetExtension(path));
                item.MouseMove += qmi_File_MouseMove;
                if (!ep.FromTaskBar && app.ShortcutKey != Keys.None)
                {
                    item.ShortcutKeyDisplayString = QTUtility2.MakeKeyString(app.ShortcutKey).Replace(" ", string.Empty);
                }
                return(item);
            }
            else
            {
                mia.Target = MenuTarget.Folder;
                DropDownMenuReorderable reorderable = new DropDownMenuReorderable(null)
                {
                    MessageParent = ep.MessageParentHandle,
                    ImageList     = QTUtility.ImageListGlobal
                };
                reorderable.ItemRightClicked += ep.ItemRightClickEventHandler;
                DirectoryMenuItem item = new DirectoryMenuItem(app.Name)
                {
                    Name = app.Name,
                    Path = path,
                    MenuItemArguments  = mia,
                    EventPack          = ep,
                    ModifiedDate       = Directory.GetLastWriteTime(path),
                    DropDown           = reorderable,
                    DoubleClickEnabled = true
                };
                item.DropDownItems.Add(new ToolStripMenuItem());
                item.DropDownItemClicked += realDirectory_DropDownItemClicked;
                item.DropDownOpening     += realDirectory_DropDownOpening;
                item.DoubleClick         += ep.DirDoubleClickEventHandler;
                item.SetImageReservationKey(path, null);
                return(item);
            }
        }
コード例 #5
0
ファイル: AppsManager.cs プロジェクト: dingdayong/QTTabBar
 private static void ListFromNestedStructure <T>(ICollection <UserApp> outList, out int levelCount, IEnumerable <T> root, Converter <T, UserApp> appConvert, Converter <T, IEnumerable <T> > getChildren)
 {
     levelCount = 0;
     foreach (T node in root)
     {
         ++levelCount;
         UserApp app = appConvert(node);
         outList.Add(app);
         var children = getChildren(node);
         if (children != null)
         {
             ListFromNestedStructure(outList, out app.ChildrenCount, children, appConvert, getChildren);
         }
     }
 }
コード例 #6
0
ファイル: AppsManager.cs プロジェクト: dingdayong/QTTabBar
 private static IEnumerable <T> BuildNestedStructure <T>(RefInt r, int max, Converter <UserApp, T> makeAppNode, Func <string, T[], T> makeFolderNode) where T : class
 {
     for (int j = 0; j < max && r.i < appList.Count; j++)
     {
         UserApp app = appList[r.i++];
         T       node;
         if (app.IsFolder)
         {
             var children = BuildNestedStructure(r, app.ChildrenCount, makeAppNode, makeFolderNode);
             node = makeFolderNode(app.Name, children.ToArray());
         }
         else
         {
             node = makeAppNode(app);
         }
         if (node != null)
         {
             yield return(node);
         }
     }
 }
コード例 #7
0
ファイル: AppsManager.cs プロジェクト: dingdayong/QTTabBar
        public static void Execute(UserApp app, ShellBrowserEx shellBrowser)
        {
            // todo validate app
            string pathCurrent;

            using (IDLWrapper wrapper = shellBrowser.GetShellPath()) {
                pathCurrent = wrapper.Path;
            }
            Address[] selection;
            shellBrowser.TryGetSelection(out selection, false);

            List <string> lstFiles = new List <string>();
            List <string> lstDirs  = new List <string>();

            if (selection != null)
            {
                foreach (Address address in selection)
                {
                    using (IDLWrapper wrapper = new IDLWrapper(address.ITEMIDLIST)) {
                        if (!wrapper.Available || !wrapper.HasPath)
                        {
                            continue;
                        }
                        (wrapper.IsFileSystemFile ? lstFiles : lstDirs).Add(address.Path.TrimEnd('\\').Enquote());
                    }
                }
            }

            string strFiles = lstFiles.StringJoin(" ");
            string strDirs  = lstDirs.StringJoin(" ");
            string strBoth  = (strFiles + " " + strDirs).Trim();

            pathCurrent = Directory.Exists(pathCurrent) ? pathCurrent.TrimEnd('\\').Enquote() : "";
            string args = app.Args;
            string work = app.WorkingDir;
            string path = app.Path;

            string[] variableValues =
            {
                strDirs.Length > 0 ? strDirs : pathCurrent,         // %cd%
                pathCurrent,                                        // %c%
                strDirs,                                            // %d%
                strFiles,                                           // %f%
                strBoth                                             // %s%
            };
            for (int i = 0; i < variableValues.Length; i++)
            {
                args = reVariables[i].Replace(args, variableValues[i]);
            }
            variableValues = new string[] {
                lstDirs.Count > 0 ? lstDirs[0] : pathCurrent,       // %cd%
                pathCurrent,                                        // %c%
                lstDirs.Count > 0 ? lstDirs[0] : "",                // %d%
                "",                                                 // %f%
                lstDirs.Count > 0 ? lstDirs[0] : ""                 // %s%
            };
            for (int i = 0; i < variableValues.Length; i++)
            {
                work = reVariables[i].Replace(work, variableValues[i]);
            }

            const int SW_SHOWNORMAL           = 1;
            const int SEE_MASK_IDLIST         = 0x00000004;
            const int SEE_MASK_DOENVSUBST     = 0x00000200; // Expand any environment variables specified in the string given by the lpDirectory or lpFile
            const int SEE_MASK_ASYNCOK        = 0x00100000;
            const int SEE_MASK_FLAG_LOG_USAGE = 0x04000000;

            // Open NameSpace folder.
            if (path.StartsWith(IDLWrapper.INDICATOR_NAMESPACE))
            {
                using (IDLWrapper idlw = new IDLWrapper(path)) {
                    if (idlw.Available)
                    {
                        SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO {
                            cbSize   = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)),
                            nShow    = SW_SHOWNORMAL,
                            fMask    = SEE_MASK_IDLIST,
                            lpIDList = idlw.PIDL,
                            hwnd     = shellBrowser.GetExplorerHandle()
                        };
                        PInvoke.ShellExecuteEx(ref sei);
                        return;
                    }
                }
            }
            else
            {
                // check whether target exists if link
                using (IDLWrapper idlw = new IDLWrapper(path)) {
                    if (idlw.IsLinkToDeadFolder)
                    {
                        return;
                    }
                }

                SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO {
                    cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)),
                    nShow  = SW_SHOWNORMAL,
                    fMask  = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_LOG_USAGE | SEE_MASK_ASYNCOK,
                    hwnd   = shellBrowser.GetExplorerHandle()
                };

                try {
                    sei.lpFile = Marshal.StringToCoTaskMemUni(path);

                    // Arguments
                    if (!string.IsNullOrEmpty(args))
                    {
                        sei.lpParameters = Marshal.StringToCoTaskMemUni(args);
                    }

                    // Working directory
                    if (!string.IsNullOrEmpty(work))
                    {
                        work            = work.Trim(new char[] { '"', '\'' });
                        sei.lpDirectory = Marshal.StringToCoTaskMemUni(work);
                    }
                    else
                    {
                        // "::" will cause an exception in Path.GetDirectoryName
                        if (QTUtility2.IsExecutable(Path.GetExtension(path)) &&
                            !path.StartsWith(IDLWrapper.INDICATOR_NAMESPACE))
                        {
                            work = Path.GetDirectoryName(path);
                        }
                        if (!string.IsNullOrEmpty(work))
                        {
                            sei.lpDirectory = Marshal.StringToCoTaskMemUni(work);
                        }
                    }

                    if (PInvoke.ShellExecuteEx(ref sei))
                    {
                        StaticReg.ExecutedPathsList.Add(path);
                        return;
                    }
                }
                finally {
                    if (sei.lpFile != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpFile);
                    }
                    if (sei.lpParameters != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpParameters);
                    }
                    if (sei.lpDirectory != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpDirectory);
                    }
                }
            }

            // Show Error Message.
            if (!String.IsNullOrEmpty(args))
            {
                path += ", " + args;
            }

            if (!String.IsNullOrEmpty(work))
            {
                path += ", " + work;
            }

            MessageBox.Show(
                String.Format(QTUtility.TextResourcesDic["ErrorDialogs"][0], path),
                QTUtility.TextResourcesDic["ErrorDialogs"][1],
                MessageBoxButtons.OK,
                MessageBoxIcon.Error
                );
        }