Ejemplo n.º 1
0
        HResult IShellBrowser.BrowseObject(IntPtr pidl, SBSP wFlags)
        {
            IntPtr result = IntPtr.Zero;

            if ((wFlags & SBSP.SBSP_RELATIVE) != 0)
            {
                ShellItem child = new ShellItem(m_ShellView.CurrentFolder, pidl);
            }
            else if ((wFlags & SBSP.SBSP_PARENT) != 0)
            {
                m_ShellView.NavigateParent();
            }
            else if ((wFlags & SBSP.SBSP_NAVIGATEBACK) != 0)
            {
                m_ShellView.NavigateBack();
            }
            else if ((wFlags & SBSP.SBSP_NAVIGATEFORWARD) != 0)
            {
                m_ShellView.NavigateForward();
            }
            else
            {
                m_ShellView.Navigate(new ShellItem(ShellItem.Desktop, pidl));
            }
            return HResult.S_OK;
        }
        public void Execute()
        {
            string path;
            var selectedItem = this.treeViewModel.SelectedItem;
            if (selectedItem == null)
            {
                path = this.workspaceDirectoryModel.CurrentWorkspaceDirectory;
            }
            else
            {
                path = selectedItem.Path;
            }

            if (String.IsNullOrEmpty(path) || (!File.Exists(path) && !Directory.Exists(path)))
            {
                return;
            }

            var uri = new Uri(path);
            ShellItem shellItem = new ShellItem(uri);
            ShellContextMenu menu = new ShellContextMenu(shellItem);
            try
            {
                menu.ShowContextMenu(System.Windows.Forms.Control.MousePosition);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Failed to show Windows Explorer Context Menu");
            }
        }
Ejemplo n.º 3
0
        internal void Add(ShellItem folder)
        {
            while (m_Current < m_History.Count - 1)
            {
                m_History.RemoveAt(m_Current + 1);
            }

            m_History.Add(folder);
            m_Current = m_History.Count - 1;
        }
Ejemplo n.º 4
0
 public void Names()
 {
     string location = @"C:\Program Files";
     string displayName = @"Program Files";
     ShellItem item = new ShellItem(location);
     Assert.AreEqual(displayName, item.DisplayName);
     Assert.AreEqual(location, item.FileSystemPath);
     Assert.AreEqual(
         Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
         ShellItem.Desktop.FileSystemPath);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellComboBox"/> class.
        /// </summary>
        public ShellComboBox()
        {
            m_Combo.Dock = DockStyle.Fill;
            m_Combo.DrawMode = DrawMode.OwnerDrawFixed;
            m_Combo.DropDownStyle = ComboBoxStyle.DropDownList;
            m_Combo.DropDownHeight = 300;
            m_Combo.ItemHeight = SystemInformation.SmallIconSize.Height + 1;
            m_Combo.Parent = this;
            m_Combo.Click += new EventHandler(m_Combo_Click);
            m_Combo.DrawItem += new DrawItemEventHandler(m_Combo_DrawItem);
            m_Combo.SelectedIndexChanged += new EventHandler(m_Combo_SelectedIndexChanged);

            m_Edit.Anchor = AnchorStyles.Left | AnchorStyles.Top |
                            AnchorStyles.Right | AnchorStyles.Bottom;
            m_Edit.BorderStyle = BorderStyle.None;
            m_Edit.Left = 8 + SystemInformation.SmallIconSize.Width;
            m_Edit.Top = 4;
            m_Edit.Width = Width - m_Edit.Left - 3 - SystemInformation.VerticalScrollBarWidth;
            m_Edit.Parent = this;
            m_Edit.Visible = false;
            m_Edit.GotFocus += new EventHandler(m_Edit_GotFocus);
            m_Edit.LostFocus += new EventHandler(m_Edit_LostFocus);
            m_Edit.KeyDown += new KeyEventHandler(m_Edit_KeyDown);
            m_Edit.MouseDown += new MouseEventHandler(m_Edit_MouseDown);
            m_Edit.BringToFront();

            m_ShellListener.DriveAdded += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.DriveRemoved += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.FolderRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed);
            m_ShellListener.FolderUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.ItemRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed);
            m_ShellListener.ItemUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated);
            m_ShellListener.SharingChanged += new ShellItemEventHandler(m_ShellListener_ItemUpdated);

            m_SelectedFolder = ShellItem.Desktop;
            m_Edit.Text = GetEditString();

            if (m_Computer == null)
            {
                m_Computer = new ShellItem(Environment.SpecialFolder.MyComputer);
            }

            CreateItems();
        }
Ejemplo n.º 6
0
        public void EnumerateChildren()
        {
            string location = @"C:\Program Files";
            ShellItem item = new ShellItem(location);
            List<string> children = new List<string>();

            children.AddRange(Directory.GetFiles(location));
            children.AddRange(Directory.GetDirectories(location));

            // The shell does not include desktop.ini in its enumeration.
            children.Remove(Path.Combine(location, "desktop.ini"));

            foreach (ShellItem child in item)
            {
                children.Remove(child.FileSystemPath);
            }

            Assert.IsEmpty(children);
        }
Ejemplo n.º 7
0
        public ImageSource GetImageSourceForFileSystemEntry(string path, bool isExcluded, bool isValid)
        {
            try
            {
                ShellItem shellItem = new ShellItem(new Uri(path));
                var icon = shellItem.ShellIcon;
                ImageSource shellIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                if (!isExcluded && isValid)
                {
                    return shellIcon;
                }

                BitmapImage overlayIcon;
                if (!isValid)
                {
                    overlayIcon = iconsMap["overlay_invalid"];
                }
                else
                {
                    overlayIcon = iconsMap["overlay_excluded"];
                }

                Rect rect = new Rect(new Size(16, 16));
                DrawingGroup iconOverlays = new DrawingGroup();
                iconOverlays.Children.Add(new ImageDrawing(shellIcon, rect));
                iconOverlays.Children.Add(new ImageDrawing(overlayIcon, rect));

                return new DrawingImage(iconOverlays);
            }
            catch (Exception e)
            {
                if (File.Exists(path))
                {
                    return iconsMap["file"];
                }
                if (Directory.Exists(path))
                {
                    return iconsMap["directory"];
                }
                return null;
            }
        }
Ejemplo n.º 8
0
        public void SetPreviewItem(ShellItem shellItem)
        {
            //  Create a stream for the item.
            using (var managedStream = new FileStream(shellItem.Path, FileMode.Open, FileAccess.Read))
            {
                var stream = new StreamWrapper(managedStream);
                ((IInitializeWithStream) sharpThumbnailHandler).Initialize(stream, 0);
                IntPtr bitmapHandle;
                WTS_ALPHATYPE alphaType;
                ((IThumbnailProvider) sharpThumbnailHandler).GetThumbnail((uint)pictureBox1.Width, out bitmapHandle, out alphaType);
                pictureBox1.Image = Image.FromHbitmap(bitmapHandle);
                /*
                var bitmap = (Bitmap) sharpThumbnailHandler.GetType().GetMethod("GetThumbnailImage", BindingFlags.Instance | BindingFlags.NonPublic)
                                                           .Invoke(sharpThumbnailHandler, new object[] { (uint)pictureBox1.Width });

                var hbmp = bitmap.GetHbitmap();
                var converted = Image.FromHbitmap(hbmp);
                pictureBox1.Image = converted;*/
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds a new folder to the toolbar.
        /// </summary>
        /// 
        /// <param name="folder">
        /// A <see cref="ShellItem"/> representing the folder to be added.
        /// </param>
        /// 
        /// <returns>
        /// true if the item was sucessfully added, false otherwise.
        /// </returns>
        public bool Add(ShellItem folder)
        {
            bool include = IncludeItem(folder);

            if (include)
            {
                ToolStripButton button = new ToolStripButton();
                Image image = folder.ShellIcon.ToBitmap();

                toolStrip.ImageScalingSize = image.Size;
                button.AutoSize = false;
                button.Image = image;
                button.Size = new Size(84, image.Height + 35);
                button.Tag = folder;
                button.Text = WrapButtonText(button, folder.DisplayName);
                button.TextImageRelation = TextImageRelation.ImageAboveText;
                button.ToolTipText = folder.ToolTipText;
                button.Click += new EventHandler(button_Click);
                toolStrip.Items.Add(button);
            }

            return include;
        }
Ejemplo n.º 10
0
 IEnumerator<ShellItem> GetFolderEnumerator(ShellItem folder)
 {
     SHCONTF filter = SHCONTF.FOLDERS;
     if (ShouldShowHidden()) filter |= SHCONTF.INCLUDEHIDDEN;
     return folder.GetEnumerator(filter);
 }
Ejemplo n.º 11
0
        void SelectItem(TreeNode node, ShellItem value)
        {
            CreateChildren(node);

            foreach (TreeNode child in node.Nodes)
            {
                ShellItem folder = (ShellItem)child.Tag;

                if (folder == value)
                {
                    m_TreeView.SelectedNode = child;
                    child.EnsureVisible();
                    child.Expand();
                    return;
                }
                else if (folder.IsParentOf(value))
                {
                    SelectItem(child, value);
                    return;
                }
            }
        }
Ejemplo n.º 12
0
 protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
 {
     return(new CustomBottomNavAppearance());
 }
Ejemplo n.º 13
0
        void CreateItem(TreeNode parent, ShellItem folder)
        {
            string displayName = folder.DisplayName;
            TreeNode node;

            if (parent != null)
            {
                node = InsertNode(parent, folder, displayName);
            }
            else
            {
                node = m_TreeView.Nodes.Add(displayName);
            }

            if (folder.HasSubFolders)
            {
                node.Nodes.Add("");
            }

            node.Tag = folder;
            SetNodeImage(node);
        }
Ejemplo n.º 14
0
 protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
 {
     return(new ShellWithCustomRendererDisabledAnimationsShellItemRenderer(this));
 }
Ejemplo n.º 15
0
 public void Pidl()
 {
     ShellItem myDocuments = new ShellItem(Environment.SpecialFolder.MyDocuments);
     IntPtr pidl = myDocuments.Pidl;
 }
Ejemplo n.º 16
0
 protected virtual IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
 {
     return(new ShellItemRenderer(this));
 }
			protected override void WndProc(ref Message m) {
				if (m.Msg == WM_SHNOTIFY) {
					SHNOTIFYSTRUCT notify = (SHNOTIFYSTRUCT)
						Marshal.PtrToStructure(m.WParam,
							typeof(SHNOTIFYSTRUCT));

					switch ((SHCNE)m.LParam) {
						case SHCNE.CREATE:
							if (m_Parent.ItemCreated != null) {
								ShellItem item = new ShellItem(notify.dwItem1);
								m_Parent.ItemCreated(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));
							}
							break;

						case SHCNE.DELETE:
							if (m_Parent.ItemDeleted != null)
								m_Parent.ItemDeleted(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.DRIVEADD:
							if (m_Parent.DriveAdded != null)
								m_Parent.DriveAdded(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.DRIVEREMOVED:
							if (m_Parent.DriveRemoved != null)
								m_Parent.DriveRemoved(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.MKDIR:
							if (m_Parent.FolderCreated != null)
								m_Parent.FolderCreated(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.RMDIR:
							if (m_Parent.FolderDeleted != null)
								m_Parent.FolderDeleted(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.UPDATEDIR:
							if (m_Parent.FolderUpdated != null)
								m_Parent.FolderUpdated(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.UPDATEITEM:
							if (m_Parent.ItemUpdated != null)
								m_Parent.ItemUpdated(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
						case SHCNE.RENAMEFOLDER:
							if (m_Parent.FolderRenamed != null)
								m_Parent.FolderRenamed(m_Parent, new ShellItemChangeEventArgs(new ShellItem(notify.dwItem1), new ShellItem(notify.dwItem2)));

							break;
						case SHCNE.RENAMEITEM:
							if (m_Parent.ItemRenamed != null)
								m_Parent.ItemRenamed(m_Parent, new ShellItemChangeEventArgs(new ShellItem(notify.dwItem1), new ShellItem(notify.dwItem2)));


							break;
						case SHCNE.NETSHARE:
						case SHCNE.NETUNSHARE:
							if (m_Parent.SharingChanged != null)
								m_Parent.SharingChanged(m_Parent, new ShellItemEventArgs(new ShellItem(notify.dwItem1)));

							break;
					}
				}
				else {
					base.WndProc(ref m);
				}
			}
Ejemplo n.º 18
0
 protected override Controls.Platform.Compatibility.IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
 {
     return(new ShellWithCustomRendererDisabledAnimationsShellItemRenderer(this));
 }
Ejemplo n.º 19
0
 IShellBottomNavViewAppearanceTracker IShellContext.CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
 {
     return(CreateBottomNavViewAppearanceTracker(shellItem));
 }
Ejemplo n.º 20
0
 protected ReadOnlyCollection <ShellSection> GetItems(ShellItem item)
 {
     return((item as IShellItemController).GetItems());
 }
 public ShellBottomNavViewAppearanceTracker(IShellContext shellContext, ShellItem shellItem)
 {
     _shellItem    = shellItem;
     _shellContext = shellContext;
 }
Ejemplo n.º 22
0
 protected virtual ShellItemRenderer CreateShellItemRenderer(ShellItem item)
 {
     return(new ShellItemRenderer(item));
 }
Ejemplo n.º 23
0
        ShellItem[] ParseShellIDListArray(ComTypes.IDataObject pDataObj)
        {
            List<ShellItem> result = new List<ShellItem>();
            ComTypes.FORMATETC format = new ComTypes.FORMATETC();
            ComTypes.STGMEDIUM medium = new ComTypes.STGMEDIUM();

            format.cfFormat = (short)User32.RegisterClipboardFormat("Shell IDList Array");
            format.dwAspect = ComTypes.DVASPECT.DVASPECT_CONTENT;
            format.lindex = 0;
            format.ptd = IntPtr.Zero;
            format.tymed = ComTypes.TYMED.TYMED_HGLOBAL;

            pDataObj.GetData(ref format, out medium);
            Kernel32.GlobalLock(medium.unionmember);

            try
            {
                ShellItem parentFolder = null;
                int count = Marshal.ReadInt32(medium.unionmember);
                int offset = 4;

                for (int n = 0; n <= count; ++n)
                {
                    int pidlOffset = Marshal.ReadInt32(medium.unionmember, offset);
                    int pidlAddress = (int)medium.unionmember + pidlOffset;

                    if (n == 0)
                    {
                        parentFolder = new ShellItem(new IntPtr(pidlAddress));
                    }
                    else
                    {
                        result.Add(new ShellItem(parentFolder, new IntPtr(pidlAddress)));
                    }

                    offset += 4;
                }
            }
            finally
            {
                Marshal.FreeHGlobal(medium.unionmember);
            }

            return result.ToArray();
        }
Ejemplo n.º 24
0
 protected virtual IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
 {
     return(new ShellBottomNavViewAppearanceTracker(this, shellItem));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Tests the context menu.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        private void DoTestMenu(ShellItem item, int x, int y)
        {
            //  If we don't have a context menu, we can bail now.
            if (TestContextMenu == null)
                return;

            //  Get the interfaces we need to test with.
            var shellExtInitInterface = (IShellExtInit) TestContextMenu;
            var contextMenuInterface = (IContextMenu) TestContextMenu;

            //  Try init first.
            try
            {
                //  Create the file paths.
                var filePaths = new StringCollection {item.Path};

                //  Create the data object from the file paths.
                var dataObject = new DataObject();
                dataObject.SetFileDropList(filePaths);

                //  Get the IUnknown COM interface address. Jesus .NET makes this easy.
                var dataObjectInterfacePointer = Marshal.GetIUnknownForObject(dataObject);

                //  Pass the data to the shell extension, attempt to initialise it.
                //  We must provide the data object as well as the parent folder PIDL.
                shellExtInitInterface.Initialize(item.ParentItem.PIDL, dataObjectInterfacePointer, IntPtr.Zero);
            }
            catch (Exception)
            {
                //  Not supported for the file
                return;
            }

            //  Create a native menu.
            var menuHandle = CreatePopupMenu();

            //  Build the menu.
            contextMenuInterface.QueryContextMenu(menuHandle, 0, 0, 1, 0);

            //  Track the menu.
            TrackPopupMenu(menuHandle,
                           0, x, y, 0, Handle, IntPtr.Zero);
        }
Ejemplo n.º 26
0
        protected virtual void SwitchFragment(FragmentManager manager, AView targetView, ShellItem newItem, bool animate = true)
        {
            Profile.FrameBegin();

            Profile.FramePartition("IsDesignerContext");
            if (AndroidContext.IsDesignerContext())
            {
                return;
            }

            Profile.FramePartition("CreateShellItemRenderer");
            var previousRenderer = _currentRenderer;

            _currentRenderer           = CreateShellItemRenderer(newItem);
            _currentRenderer.ShellItem = newItem;
            var fragment = _currentRenderer.Fragment;

            Profile.FramePartition("Transaction");
            FragmentTransaction transaction = manager.BeginTransactionEx();

            if (animate)
            {
                transaction.SetTransitionEx((int)global::Android.App.FragmentTransit.EnterMask);
            }

            transaction.ReplaceEx(_frameLayout.Id, fragment);
            transaction.CommitAllowingStateLossEx();

            Profile.FramePartition("OnDestroyed");
            void OnDestroyed(object sender, EventArgs args)
            {
                previousRenderer.Destroyed -= OnDestroyed;

                previousRenderer.Dispose();
                previousRenderer = null;
            }

            if (previousRenderer != null)
            {
                previousRenderer.Destroyed += OnDestroyed;
            }

            Profile.FrameEnd();
        }
		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="ShellItemChangeEventArgs"/> class.
		/// </summary>
		/// 
		/// <param name="oldItem">
		/// The ShellItem before the change
		/// </param>
		/// 
		/// <param name="newItem">
		/// The ShellItem after the change
		/// </param>
		public ShellItemChangeEventArgs(ShellItem oldItem, ShellItem newItem) {
			OldItem = oldItem;
			NewItem = newItem;
		}
Ejemplo n.º 28
0
 public DragEnterEventArgs(ShellItem parent, Control dragStartControl)
 {
     this.parent           = parent;
     this.dragStartControl = dragStartControl;
 }
Ejemplo n.º 29
0
        public void Uri()
        {
            string desktopExpected = "shell:///Desktop";
            string myComputerExpected = "shell:///MyComputerFolder";
            string myDocumentsExpected = "shell:///Personal";
            ShellItem desktop1 = ShellItem.Desktop;
            ShellItem desktop2 = new ShellItem(desktopExpected);
            ShellItem myComputer = new ShellItem(myComputerExpected);
            ShellItem myDocuments = new ShellItem(Environment.SpecialFolder.MyDocuments);
            ShellItem myDocumentsChild = myDocuments["GongShellTestFolder"];
            ShellItem myDocumentsChild2 = new ShellItem(myDocumentsExpected + "/GongShellTestFolder");
            ShellItem myDocumentsChild3 = new ShellItem(myDocumentsExpected + "/GongShellTestFolder/Nested");
            ShellItem cDrive = new ShellItem(@"C:\");
            ShellItem controlPanel = new ShellItem((Environment.SpecialFolder)CSIDL.CONTROLS);

            Assert.AreEqual(desktopExpected, desktop1.ToString());
            Assert.AreEqual(desktopExpected, desktop2.ToString());
            Assert.AreEqual(myComputerExpected, myComputer.ToString());
            Assert.AreEqual(myDocumentsExpected, myDocuments.ToString());
            Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder",
                myDocumentsChild.ToString());
            Assert.AreEqual("file:///C:/", cDrive.ToString());
            Assert.IsTrue(myDocumentsChild.Equals(myDocumentsChild2));
            Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder/Nested",
                myDocumentsChild3.ToString());
        }
Ejemplo n.º 30
0
 IShellItemRenderer IShellContext.CreateShellItemRenderer(ShellItem shellItem)
 {
     return(CreateShellItemRenderer(shellItem));
 }
Ejemplo n.º 31
0
        public async Task RelativeGoTo()
        {
            Routing.RegisterRoute("RelativeGoTo_Page1", typeof(ContentPage));
            Routing.RegisterRoute("RelativeGoTo_Page2", typeof(ContentPage));

            var shell = new Shell
            {
            };

            var one = new ShellItem {
                Route = "one"
            };
            var two = new ShellItem {
                Route = "two"
            };

            var tab11 = MakeSimpleShellSection("tab11", "content");
            var tab12 = MakeSimpleShellSection("tab12", "content");
            var tab21 = MakeSimpleShellSection("tab21", "content");
            var tab22 = MakeSimpleShellSection("tab22", "content");
            var tab23 = MakeSimpleShellSection("tab23", "content");

            one.Items.Add(tab11);
            one.Items.Add(tab12);

            two.Items.Add(tab21);
            two.Items.Add(tab22);
            two.Items.Add(tab23);

            shell.Items.Add(one);
            shell.Items.Add(two);

            await shell.GoToAsync("//two/tab21/");

            await shell.GoToAsync("/tab22", false, true);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab22/content"));

            await shell.GoToAsync("tab21", false, true);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab21/content"));

            await shell.GoToAsync("/tab23", false, true);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab23/content"));

            await shell.GoToAsync("RelativeGoTo_Page1", false);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab23/content/RelativeGoTo_Page1"));

            await shell.GoToAsync("../RelativeGoTo_Page2", false);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab23/content/RelativeGoTo_Page2"));

            await shell.GoToAsync("..", false);

            Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("//two/tab23/content"));

            /*
             * removing support for .. notation for now
             * await shell.GoToAsync("../one/tab11");
             * Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("app:///s/one/tab11/content/"));
             *
             * await shell.GoToAsync("/eee/hm../../../../two/../one/../two/tab21");
             * Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("app:///s/two/tab21/content/"));
             *
             * await shell.GoToAsync(new ShellNavigationState("../one/tab11"));
             * Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("app:///s/one/tab11/content/"));
             *
             * await shell.GoToAsync(new ShellNavigationState($"../two/tab23/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
             * Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("app:///s/two/tab23/content/"));
             * Assert.AreEqual("1234", (two.CurrentItem.CurrentItem.Content as ShellTestPage).SomeQueryParameter);
             *
             * await shell.GoToAsync(new ShellNavigationState($"../one/tab11#fragment"));
             * Assert.That(shell.CurrentState.Location.ToString(), Is.EqualTo("app:///s/one/tab11/content/"));
             */
        }
Ejemplo n.º 32
0
 void SwitchShellItem(ShellItem newItem, bool animate = true)
 {
     SelectedItem = newItem;
     ItemRenderer.NavigateToShellItem(newItem, animate);
 }
Ejemplo n.º 33
0
        public void SpecialFolders()
        {
            Environment.SpecialFolder myComputerFolder =
                Environment.SpecialFolder.MyComputer;
            Environment.SpecialFolder myPicturesFolder =
                Environment.SpecialFolder.MyPictures;
            ShellItem myComputer = new ShellItem(myComputerFolder);
            ShellItem myComputer2 = new ShellItem(myComputer.ToUri());
            ShellItem myPictures = new ShellItem(myPicturesFolder);
            ShellItem myPictures2 = new ShellItem(myPictures.ToUri());

            Assert.IsTrue(myComputer.Equals(myComputer2));
            Assert.AreEqual(Environment.GetFolderPath(myPicturesFolder), myPictures.FileSystemPath);
            Assert.AreEqual(myPictures, myPictures2);

            try
            {
                string path = myComputer.FileSystemPath;
                Assert.Fail("FileSystemPath from virtual folder should throw exception");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("FileSystemPath from virtual folder should throw ArgumentException");
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Determines whether a server is associated with a shell item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="shellItem">The shell item.</param>
        /// <returns>
        ///   <c>true</c> if a server is associated with the shell item; otherwise, <c>false</c>.
        /// </returns>
        private bool IsServerAssociatedWithShellItem(ISharpShellServer server, ShellItem shellItem)
        {
            //  If we don't have the server, bail.
            if (server == null || shellItem == null)
            {
                return(false);
            }

            //  Get the associations.
            var associationType = COMServerAssociationAttribute.GetAssociationType(server.GetType());
            var associations    = COMServerAssociationAttribute.GetAssociations(server.GetType());

            //  TODO: This is potentially a very useful check - maybe it should be moved into the
            //  COMServerAssociationAttribute class so that it can be reused.

            //  We have a special case for icon overlays.
            if (server is SharpIconOverlayHandler && TestIconOverlayHandler != null && shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
            {
                if (((IShellIconOverlayIdentifier)TestIconOverlayHandler).IsMemberOf(shellItem.Path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL) == 0)
                {
                    return(true);
                }
            }

            //  Based on the assocation type, we can check the shell item.
            switch (associationType)
            {
                //  This is checked for backwards compatibility.
#pragma warning disable 618
            case AssociationType.FileExtension:
#pragma warning restore 618

                //  File extensions are easy to check.
                if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                {
                    return
                        (associations.Any(
                             a =>
                             string.Compare(Path.GetExtension(shellItem.DisplayName), a,
                                            StringComparison.OrdinalIgnoreCase) == 0));
                }

                break;

            case AssociationType.ClassOfExtension:

                //  TODO must be tested.
                if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                {
                    //  Get our class.
                    var registry = ServiceRegistry.GetService <IRegistry>();
                    using (var classesRoot = registry.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default))
                    {
                        var fileClass = FileExtensionClass.Get(classesRoot, Path.GetExtension(shellItem.DisplayName), false);

                        //  Do we match it?
                        return(associations.Any(a => string.Compare(fileClass, FileExtensionClass.Get(classesRoot, a, false), StringComparison.InvariantCultureIgnoreCase) == 0));
                    }
                }

                break;

            case AssociationType.Class:
                //  TODO must be tested.
                break;

            case AssociationType.AllFiles:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && shellItem.IsFolder == false);

            case AssociationType.Directory:

                //  Directories are filesystem, not streams, and folder.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && !shellItem.Attributes.HasFlag(SFGAO.SFGAO_STREAM) && shellItem.IsFolder);

            case AssociationType.Drive:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_STORAGEANCESTOR));

            case AssociationType.UnknownFiles:
                //  TODO must be tested.
                break;
            }

            return(false);
        }
Ejemplo n.º 35
0
        TreeNode InsertNode(TreeNode parent, ShellItem folder, string displayName)
        {
            ShellItem parentFolder = (ShellItem)parent.Tag;
            IntPtr folderRelPidl = Shell32.ILFindLastID(folder.Pidl);
            TreeNode result = null;

            foreach (TreeNode child in parent.Nodes)
            {
                ShellItem childFolder = (ShellItem)child.Tag;
                IntPtr childRelPidl = Shell32.ILFindLastID(childFolder.Pidl);
                short compare = parentFolder.GetIShellFolder().CompareIDs(0,
                       folderRelPidl, childRelPidl);

                if (compare < 0)
                {
                    result = parent.Nodes.Insert(child.Index, displayName);
                    break;
                }
            }

            if (result == null)
            {
                result = parent.Nodes.Add(displayName);
            }

            return result;
        }
Ejemplo n.º 36
0
        protected virtual void SwitchFragment(FragmentManager manager, AView targetView, ShellItem newItem, bool animate = true)
        {
            var previousRenderer = _currentRenderer;

            _currentRenderer           = CreateShellItemRenderer(newItem);
            _currentRenderer.ShellItem = newItem;
            var fragment = _currentRenderer.Fragment;

            FragmentTransaction transaction = manager.BeginTransaction();

            if (animate)
            {
                transaction.SetTransition((int)global::Android.App.FragmentTransit.FragmentFade);
            }

            transaction.Replace(_frameLayout.Id, fragment);
            transaction.CommitAllowingStateLoss();

            void OnDestroyed(object sender, EventArgs args)
            {
                previousRenderer.Destroyed -= OnDestroyed;

                previousRenderer.Dispose();
                previousRenderer = null;
            }

            if (previousRenderer != null)
            {
                previousRenderer.Destroyed += OnDestroyed;
            }
        }
Ejemplo n.º 37
0
        void SelectItem(ShellItem value)
        {
            TreeNode node = m_TreeView.Nodes[0];
            ShellItem folder = (ShellItem)node.Tag;

            if (folder == value)
            {
                m_TreeView.SelectedNode = node;
            }
            else
            {
                SelectItem(node, value);
            }
        }
Ejemplo n.º 38
0
        void m_Edit_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string path = m_Edit.Text;
				string path2 = Path.Combine(m_SelectedFolder.FileSystemPath, path);

				if (path == string.Empty || string.Compare(path, "Desktop", true) == 0)
                {
                    SelectedFolder = ShellItem.Desktop;
                }
				else if (Directory.Exists(path))
                {
                    SelectedFolder = new ShellItem(path);
                }           
                else if (Directory.Exists(path2))
                {
                    SelectedFolder = new ShellItem(path2);
                }
            }
        }
Ejemplo n.º 39
0
        TreeNode FindItem(ShellItem item, TreeNode parent)
        {
            if ((ShellItem)parent.Tag == item)
            {
                return parent;
            }

            foreach (TreeNode node in parent.Nodes)
            {
                if ((ShellItem)node.Tag == item)
                {
                    return node;
                }
                else
                {
                    TreeNode found = FindItem(item, node);
                    if (found != null) return found;
                }
            }
            return null;
        }
Ejemplo n.º 40
0
 IShellItemView Controls.Platform.IShellContext.CreateShellItemView(ShellItem shellItem)
 {
     return((this as IShellContext).CreateShellItemRenderer(shellItem));
 }
Ejemplo n.º 41
0
		public override void OnApplyTemplate() {
			dropDownBtn = this.GetTemplateChild(partDropDown) as Control;
			contextMenu = this.GetTemplateChild(partMenu) as ContextMenu;
			if (contextMenu != null) {
				contextMenu.Opened += new RoutedEventHandler(contextMenu_Opened);
			}
			if (dropDownBtn != null) {
				dropDownBtn.MouseDown += new MouseButtonEventHandler(dropDownBtn_MouseDown);
			}

			base.OnApplyTemplate();
			Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)(() => {
				var data = this.DataContext as ShellItem;
			  if (data == null || data.DisplayName == "Search.search-ms") return;
				if (data != null && data.CachedParsingName != KnownFolders.Computer.ParsingName && data.CachedParsingName != KnownFolders.Desktop.ParsingName) {
					data = new ShellItem(data.CachedParsingName.ToShellParsingName());
					if (data.IsSearchFolder) return;
					var aditionalItems = new List<ShellItem>();
          ShellItem.IsCareForMessageHandle = false;
					foreach (var item in data) {
						try {
							if (item.IsFolder) {
								aditionalItems.Add(item);
							}
						}
						catch { }
					}
          ShellItem.IsCareForMessageHandle = true;
					this.ItemsSource = aditionalItems;
				}
			}));
		}
Ejemplo n.º 42
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == (int)ShellAPI.WM.SH_NOTIFY)
            {
                ShellAPI.SHNOTIFYSTRUCT shNotify =
                    (ShellAPI.SHNOTIFYSTRUCT)Marshal.PtrToStructure(m.WParam, typeof(ShellAPI.SHNOTIFYSTRUCT));

                //Console.Out.WriteLine("Event: {0}", (ShellAPI.SHCNE)m.LParam);
                //if (shNotify.dwItem1 != IntPtr.Zero)
                //PIDL.Write(shNotify.dwItem1);
                //if (shNotify.dwItem2 != IntPtr.Zero)
                //PIDL.Write(shNotify.dwItem2);

                switch ((ShellAPI.SHCNE)m.LParam)
                {
                    #region File Changes

                case ShellAPI.SHCNE.CREATE:
                    #region Create Item
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        IntPtr parent, child, relative;
                        PIDL.SplitPidl(shNotify.dwItem1, out parent, out child);

                        PIDL      parentPIDL = new PIDL(parent, false);
                        ShellItem parentItem = br.GetShellItem(parentPIDL);
                        if (parentItem != null && parentItem.FilesExpanded && !parentItem.SubFiles.Contains(child))
                        {
                            ShellAPI.SHGetRealIDL(
                                parentItem.ShellFolder,
                                child,
                                out relative);
                            parentItem.AddItem(new ShellItem(br, parentItem, relative));
                        }

                        Marshal.FreeCoTaskMem(child);
                        parentPIDL.Free();
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.RENAMEITEM:
                    #region Rename Item
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1) && !PIDL.IsEmpty(shNotify.dwItem2))
                    {
                        ShellItem item = br.GetShellItem(new PIDL(shNotify.dwItem1, true));
                        if (item != null)
                        {
                            item.Update(shNotify.dwItem2, ShellItemUpdateType.Renamed);
                        }
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.DELETE:
                    #region Delete Item
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        IntPtr parent, child;
                        PIDL.SplitPidl(shNotify.dwItem1, out parent, out child);

                        PIDL      parentPIDL = new PIDL(parent, false);
                        ShellItem parentItem = br.GetShellItem(parentPIDL);
                        if (parentItem != null && parentItem.SubFiles.Contains(child))
                        {
                            parentItem.RemoveItem(parentItem.SubFiles[child]);
                        }

                        Marshal.FreeCoTaskMem(child);
                        parentPIDL.Free();
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.UPDATEITEM:
                    #region Update Item
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        ShellItem item = br.GetShellItem(new PIDL(shNotify.dwItem1, true));
                        if (item != null)
                        {
                            Console.Out.WriteLine("Item: {0}", item);
                            item.Update(IntPtr.Zero, ShellItemUpdateType.Updated);
                            item.Update(IntPtr.Zero, ShellItemUpdateType.IconChange);
                        }
                    }
                }
                    #endregion
                    break;

                    #endregion

                    #region Folder Changes

                case ShellAPI.SHCNE.MKDIR:
                case ShellAPI.SHCNE.DRIVEADD:
                case ShellAPI.SHCNE.DRIVEADDGUI:
                    #region Make Directory
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        IntPtr parent, child, relative;
                        PIDL.SplitPidl(shNotify.dwItem1, out parent, out child);

                        PIDL      parentPIDL = new PIDL(parent, false);
                        ShellItem parentItem = br.GetShellItem(parentPIDL);
                        if (parentItem != null && parentItem.FoldersExpanded && !parentItem.SubFolders.Contains(child))
                        {
                            ShellAPI.SHGetRealIDL(
                                parentItem.ShellFolder,
                                child,
                                out relative);

                            IntPtr shellFolderPtr;
                            if (parentItem.ShellFolder.BindToObject(
                                    relative,
                                    IntPtr.Zero,
                                    ref ShellAPI.IID_IShellFolder,
                                    out shellFolderPtr) == ShellAPI.S_OK)
                            {
                                parentItem.AddItem(new ShellItem(br, parentItem, relative, shellFolderPtr));
                            }
                            else
                            {
                                Marshal.FreeCoTaskMem(relative);
                            }
                        }

                        Marshal.FreeCoTaskMem(child);
                        parentPIDL.Free();
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.RENAMEFOLDER:
                    #region Rename Directory
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1) && !PIDL.IsEmpty(shNotify.dwItem2))
                    {
                        ShellItem item = br.GetShellItem(new PIDL(shNotify.dwItem1, false));
                        if (item != null)
                        {
                            //Console.Out.WriteLine("Update: {0}", item);
                            item.Update(shNotify.dwItem2, ShellItemUpdateType.Renamed);
                        }
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.RMDIR:
                case ShellAPI.SHCNE.DRIVEREMOVED:
                    #region Remove Directory
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        IntPtr parent, child;
                        PIDL.SplitPidl(shNotify.dwItem1, out parent, out child);

                        PIDL      parentPIDL = new PIDL(parent, false);
                        ShellItem parentItem = br.GetShellItem(parentPIDL);
                        if (parentItem != null && parentItem.SubFolders.Contains(child))
                        {
                            parentItem.RemoveItem(parentItem.SubFolders[child]);
                        }

                        Marshal.FreeCoTaskMem(child);
                        parentPIDL.Free();
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.UPDATEDIR:
                case ShellAPI.SHCNE.ATTRIBUTES:
                    #region Update Directory
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        ShellItem item = br.GetShellItem(new PIDL(shNotify.dwItem1, true));
                        if (item != null)
                        {
                            item.Update(IntPtr.Zero, ShellItemUpdateType.Updated);
                            item.Update(IntPtr.Zero, ShellItemUpdateType.IconChange);
                        }
                    }
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.MEDIAINSERTED:
                case ShellAPI.SHCNE.MEDIAREMOVED:
                    #region Media Change
                {
                    if (!PIDL.IsEmpty(shNotify.dwItem1))
                    {
                        ShellItem item = br.GetShellItem(new PIDL(shNotify.dwItem1, true));
                        if (item != null)
                        {
                            item.Update(IntPtr.Zero, ShellItemUpdateType.MediaChange);
                        }
                    }
                }
                    #endregion
                    break;

                    #endregion

                    #region Other Changes

                case ShellAPI.SHCNE.ASSOCCHANGED:
                    #region Update Images
                {
                }
                    #endregion
                    break;

                case ShellAPI.SHCNE.NETSHARE:
                case ShellAPI.SHCNE.NETUNSHARE:
                    break;

                case ShellAPI.SHCNE.UPDATEIMAGE:
                    UpdateRecycleBin();
                    break;

                    #endregion
                }
            }

            base.WndProc(ref m);
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Determines whether a server is associated with a shell item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="shellItem">The shell item.</param>
        /// <returns>
        ///   <c>true</c> if a server is associated with the shell item; otherwise, <c>false</c>.
        /// </returns>
        private bool IsServerAssociatedWithShellItem(ISharpShellServer server, ShellItem shellItem)
        {
            //  If we don't have the server, bail.
            if (server == null || shellItem == null)
                return false;

            //  Get the associations.
            var associationType = COMServerAssociationAttribute.GetAssociationType(server.GetType());
            var associations = COMServerAssociationAttribute.GetAssociations(server.GetType());

            //  TODO: This is potentially a very useful check - maybe it should be moved into the
            //  COMServerAssociationAttribute class so that it can be reused.

            //  We have a special case for icon overlays.
            if (server is SharpIconOverlayHandler && TestIconOverlayHandler != null && shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                if (((IShellIconOverlayIdentifier)TestIconOverlayHandler).IsMemberOf(shellItem.Path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL) == 0)
                    return true;

            //  Based on the assocation type, we can check the shell item.
            switch (associationType)
            {
                case AssociationType.FileExtension:

                    //  File extensions are easy to check.
                    if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                    {
                        return
                            associations.Any(
                                a =>
                                string.Compare(Path.GetExtension(shellItem.DisplayName), a,
                                               StringComparison.OrdinalIgnoreCase) == 0);
                    }

                    break;

                case AssociationType.ClassOfExtension:

                    //  TODO must be tested.
                    if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                    {
                        //  Get our class.
                        var fileClass = ServerRegistrationManager.GetClassForExtension(Path.GetExtension(shellItem.DisplayName));

                        //  Do we match it?
                        return associations.Any(a => string.Compare(fileClass, ServerRegistrationManager.GetClassForExtension(a), StringComparison.InvariantCultureIgnoreCase) == 0);
                    }

                    break;

                case AssociationType.Class:
                    //  TODO must be tested.
                    break;

                case AssociationType.AllFiles:

                    //  TODO must be tested.
                    return shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && shellItem.IsFolder == false;

                case AssociationType.Directory:

                    //  Directories are filesystem, not streams, and folder.
                    return shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && !shellItem.Attributes.HasFlag(SFGAO.SFGAO_STREAM) && shellItem.IsFolder;

                case AssociationType.Drive:

                    //  TODO must be tested.
                    return shellItem.Attributes.HasFlag(SFGAO.SFGAO_STORAGEANCESTOR);

                case AssociationType.UnknownFiles:
                    //  TODO must be tested.
                    break;
            }

            return false;
        }
Ejemplo n.º 44
0
        public void Attributes()
        {
            ShellItem cDrive = new ShellItem(@"C:\");
            ShellItem myComputer =
                new ShellItem(Environment.SpecialFolder.MyComputer);
            ShellItem file = new ShellItem(Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.System),
                "kernel32.dll"));

            Assert.IsTrue(cDrive.IsFolder);
            Assert.IsTrue(myComputer.IsFolder);
            Assert.IsFalse(file.IsFolder);
        }
		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="ShellItemEventArgs"/> class.
		/// </summary>
		/// 
		/// <param name="item">
		/// The ShellItem that has changed.
		/// </param>
		public ShellItemEventArgs(ShellItem item) { Item = item; }
Ejemplo n.º 46
0
        public void Compare()
        {
            ShellItem desktop1 = ShellItem.Desktop;
            ShellItem desktop2 = new ShellItem("shell:///Desktop");
            ShellItem item1 = new ShellItem(@"C:\Program Files");
            ShellItem item2 = item1.Parent[@"Program Files"];

            Assert.IsTrue(desktop1.Equals(desktop2));
            Assert.AreEqual(item1.FileSystemPath, item2.FileSystemPath);
            Assert.IsTrue(item1 == item2);
            Assert.IsFalse(item1 != item2);
        }
Ejemplo n.º 47
0
		/*
        void CreateItems(ShellItem folder, int indent)
        {
			IEnumerator<ShellItem> e = folder.GetEnumerator( SHCONTF.FOLDERS | SHCONTF.INCLUDEHIDDEN);
			while (e.MoveNext())
			{
				CreateItem(e.Current, indent);
			}
        }
		*/

		/// <summary>
		/// Creates a <see cref="ComboItem"/> and adds it to <see cref="m_Combo"/>
		/// </summary>
		/// <param name="folder">Sets <see cref="ComboItem.Folder"/></param>
		/// <param name="indent">Sets <see cref="ComboItem.Indent"/></param>
		void CreateItem(ShellItem folder, int indent)
        {
			//TODO: Double Check recursive code
            int index = m_Combo.Items.Add(new ComboItem(folder, indent));

            if (folder == m_SelectedFolder)
            {
                m_Combo.SelectedIndex = index;
            }

			if (folder == m_Computer || folder == ShellItem.Desktop || folder.IsParentOf(m_SelectedFolder))
            {
				foreach (var item in folder)
				{
					CreateItem(item, indent + 1);
				}
			}
        }
Ejemplo n.º 48
0
        private async Task HandleShellLibraryMessage(Dictionary <string, object> message)
        {
            switch ((string)message["action"])
            {
            case "Enumerate":
                // Read library information and send response to UWP
                var enumerateResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        var libraryItems = new List <ShellLibraryItem>();
                        // https://docs.microsoft.com/en-us/windows/win32/search/-search-win7-development-scenarios#library-descriptions
                        var libFiles = Directory.EnumerateFiles(ShellLibraryItem.LibrariesPath, "*" + ShellLibraryItem.EXTENSION);
                        foreach (var libFile in libFiles)
                        {
                            using var shellItem = ShellItem.Open(libFile);
                            if (shellItem is ShellLibrary library)
                            {
                                libraryItems.Add(ShellFolderExtensions.GetShellLibraryItem(library, libFile));
                            }
                        }
                        response.Add("Enumerate", JsonConvert.SerializeObject(libraryItems));
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Error(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, enumerateResponse, message.Get("RequestID", (string)null));

                break;

            case "Create":
                // Try create new library with the specified name and send response to UWP
                var createResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        using var library = new ShellLibrary((string)message["library"], Shell32.KNOWNFOLDERID.FOLDERID_Libraries, false);
                        response.Add("Create", JsonConvert.SerializeObject(ShellFolderExtensions.GetShellLibraryItem(library, library.GetDisplayName(ShellItemDisplayString.DesktopAbsoluteParsing))));
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Error(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, createResponse, message.Get("RequestID", (string)null));

                break;

            case "Update":
                // Update details of the specified library and send response to UWP
                var updateResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        var folders           = message.ContainsKey("folders") ? JsonConvert.DeserializeObject <string[]>((string)message["folders"]) : null;
                        var defaultSaveFolder = message.Get("defaultSaveFolder", (string)null);
                        var isPinned          = message.Get("isPinned", (bool?)null);

                        bool updated      = false;
                        var libPath       = (string)message["library"];
                        using var library = ShellItem.Open(libPath) as ShellLibrary;
                        if (folders != null)
                        {
                            if (folders.Length > 0)
                            {
                                var foldersToRemove = library.Folders.Where(f => !folders.Any(folderPath => string.Equals(folderPath, f.FileSystemPath, StringComparison.OrdinalIgnoreCase)));
                                foreach (var toRemove in foldersToRemove)
                                {
                                    library.Folders.Remove(toRemove);
                                    updated = true;
                                }
                                var foldersToAdd = folders.Distinct(StringComparer.OrdinalIgnoreCase)
                                                   .Where(folderPath => !library.Folders.Any(f => string.Equals(folderPath, f.FileSystemPath, StringComparison.OrdinalIgnoreCase)))
                                                   .Select(ShellItem.Open);
                                foreach (var toAdd in foldersToAdd)
                                {
                                    library.Folders.Add(toAdd);
                                    updated = true;
                                }
                                foreach (var toAdd in foldersToAdd)
                                {
                                    toAdd.Dispose();
                                }
                            }
                        }
                        if (defaultSaveFolder != null)
                        {
                            library.DefaultSaveFolder = ShellItem.Open(defaultSaveFolder);
                            updated = true;
                        }
                        if (isPinned != null)
                        {
                            library.PinnedToNavigationPane = isPinned == true;
                            updated = true;
                        }
                        if (updated)
                        {
                            library.Commit();
                            response.Add("Update", JsonConvert.SerializeObject(ShellFolderExtensions.GetShellLibraryItem(library, libPath)));
                        }
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Error(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, updateResponse, message.Get("RequestID", (string)null));

                break;
            }
        }
Ejemplo n.º 49
0
 public ComboItem(ShellItem folder, int indent)
 {
     Folder = folder;
     Indent = indent;
 }
Ejemplo n.º 50
0
 IShellBottomNavViewAppearanceTracker Microsoft.Maui.Controls.Platform.IShellContext.CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
 {
     return(CreateBottomNavViewAppearanceTracker(shellItem));
 }