public void EnterEditMode()
        {
            IsInEditMode       = true;
            elPanel.Visibility = System.Windows.Visibility.Collapsed;
            elPanel.Focusable  = false;
            if (Undertextbox != null)
            {
                Undertextbox.Visibility = System.Windows.Visibility.Visible;
                //Undertextbox.SelectAll();
            }
            var obj = furthestrightitem.ShellObject;

            if (obj.ParsingName.StartsWith(":"))
            {
                var correctItems = KnownFolders.All.Where(w => obj.ParsingName.Contains(w.ParsingName)).ToArray();
                foreach (var item in correctItems)
                {
                    ShellObject realItem = (ShellObject)item;
                    HistoryCombo.Text = obj.ParsingName.Replace(realItem.ParsingName, realItem.GetDisplayName(DisplayNameType.Default)).Replace(".library-ms", "");
                    realItem.Dispose();
                }
            }
            else
            {
                HistoryCombo.Text = furthestrightitem.ShellObject.ParsingName;
            }
            FocusManager.SetIsFocusScope(this, true);
        }
Example #2
0
        /// <summary>
        /// Creates a new Property collection given an IShellItem2 native interface
        /// </summary>
        /// <param name="parent">Parent ShellObject</param>
        public ShellPropertyCollection(ShellObject parent)
            : base(new List <IShellProperty>())
        {
            this.ParentShellObject = parent;
            IPropertyStore nativePropertyStore = null;

            try
            {
                nativePropertyStore = CreateDefaultPropertyStore(this.ParentShellObject);
                this.AddProperties(nativePropertyStore);
            }
            catch
            {
                if (parent != null)
                {
                    parent.Dispose();
                }

                throw;
            }
            finally
            {
                if (nativePropertyStore != null)
                {
                    Marshal.ReleaseComObject(nativePropertyStore);
                    nativePropertyStore = null;
                }
            }
        }
Example #3
0
        private void ShareWizzard_Load(object sender, EventArgs e)
        {
            ShellObject sho = ShellObject.FromParsingName(CurrentPath);

            txtShareName.Text = sho.GetDisplayName(Microsoft.WindowsAPICodePack.Shell.DisplayNameType.Default);
            sho.Dispose();
        }
Example #4
0
        /// <summary>
        /// Creates a new Property collection given an IShellItem2 native interface
        /// </summary>
        /// <param name="parent">Parent ShellObject</param>
        public ShellPropertyCollection(ShellObject parent)
            : base(new List <IShellProperty>())
        {
            ParentShellObject = parent ?? throw new ArgumentNullException(nameof(parent));
            IPropertyStore nativePropertyStore = null;

            try
            {
                nativePropertyStore = CreateDefaultPropertyStore(ParentShellObject);
                AddProperties(nativePropertyStore);
            }
            catch
            {
                parent?.Dispose();

                throw;
            }
            finally
            {
                if (nativePropertyStore != null)
                {
                    _ = Marshal.ReleaseComObject(nativePropertyStore);
                    nativePropertyStore = null;
                }
            }
        }
Example #5
0
        private void GetThumbnail(VideoFolderChild file)
        {
            ImageSource imageSource = null;

            dispatcherService.InvokeDispatchAction(new Action(delegate
            {
                file.IsLoading    = true;
                ShellObject shell = ShellObject.FromParsingName(file.FullName);
                file.Thumbnail    = imageSource = shell.Thumbnail.LargeBitmapSource;
                shell.Dispose();
                file.IsLoading = false;
            }));
        }
Example #6
0
 public int GetExifRotationInfo(string path)
 {
     if (!_shellsupport) return 1;
     _shellitem = ShellObject.FromParsingName(path);
     object res = 1;
     foreach (var item in _shellitem.Properties.DefaultPropertyCollection)
     {
         if (item.CanonicalName == "System.Photo.Orientation")
         {
             res = item.ValueAsObject;
             break;
         }
     }
     _shellitem.Dispose();
     _shellitem = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
     GC.Collect();
     return Convert.ToInt32(res);
 }
Example #7
0
 public BitmapSource GetThumbnail(string path)
 {
     try
     {
         if (_shellsupport)
         {
             _shellitem = ShellObject.FromParsingName(path);
             BitmapSource ret = _shellitem.Thumbnail.LargeBitmapSource;
             _shellitem.Dispose();
             _shellitem = null;
             GC.Collect();
             GC.WaitForPendingFinalizers();
             GC.Collect();
             return ret;
         }
         else return FailSafeThumbnail(path);
     }
     catch (Exception)
     {
         return FailSafeThumbnail(path);
     }
 }
Example #8
0
 public override void Dispose()
 {
     _shellObject?.Dispose();
     _shellObject = null;
     base.Dispose();
 }
Example #9
0
        /// <summary>
        /// Handles the <see cref="ChooseFolderMessage" /> on a window by showing a folder dialog based on the message options.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="message">The message.</param>
        /// <exception cref="System.ArgumentNullException">
        /// message
        /// </exception>
        public static void HandleChooseFolder(this Window owner, ChooseFolderMessage message)
        {
            //if (owner == null) { throw new ArgumentNullException("owner"); }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (CommonOpenFileDialog.IsPlatformSupported)
            {
                using (var diag = new CommonOpenFileDialog())
                {
                    diag.InitialDirectory = message.InitialFolder;
                    diag.IsFolderPicker   = true;
                    diag.Title            = message.Caption;
                    diag.Multiselect      = false;
                    // allow this for desktop, but now opens other locations up so need to check those
                    diag.AllowNonFileSystemItems = true;

REOPEN:

                    var result = owner == null?diag.ShowDialog() : diag.ShowDialog(owner);

                    if (result == CommonFileDialogResult.Ok)
                    {
                        ShellObject selectedSO = null;

                        try
                        {
                            // Try to get a valid selected item
                            selectedSO = diag.FileAsShellObject as ShellObject;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Could not create a ShellObject from the selected item: " + ex.Message);
                        }
                        if (selectedSO != null)
                        {
                            string name    = selectedSO.Name;
                            string path    = selectedSO.ParsingName;
                            bool   notReal = selectedSO is ShellNonFileSystemFolder;
                            selectedSO.Dispose();
                            if (notReal)
                            {
                                if (path.EndsWith(".library-ms", StringComparison.OrdinalIgnoreCase))
                                {
                                    using (var lib = ShellLibrary.Load(name, true))
                                    {
                                        if (lib != null)
                                        {
                                            path = lib.DefaultSaveFolder;
                                        }
                                    }
                                }
                                else
                                {
                                    if (MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "The location \"{0}\" is not valid, please select another.", name),
                                                        "Invalid Location", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
                                    {
                                        goto REOPEN;
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }

                            if (owner == null || owner.Dispatcher.CheckAccess())
                            {
                                message.DoCallback(path);
                            }
                            else
                            {
                                owner.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    message.DoCallback(path);
                                }));
                            }
                        }
                    }
                }
            }
            else
            {
                message.HandleWithPlatform(owner);
            }
        }
Example #10
0
 public void Dispose()
 {
     _shellObject?.Dispose();
 }
Example #11
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == (int)WindowsAPI.WndMsg.WM_CONTEXTMENU)
            {
                this.Browser.IsRenameStarted = true;
                ShellObject[]    dirs = this.Browser.SelectedItems.ToArray();
                ContextShellMenu cm1  = new ContextShellMenu(this.Browser, this.Browser.SelectedItems.Count > 0 ? ShellViewGetItemObject.Selection : ShellViewGetItemObject.Background);
                cm1.ShowContextMenu(Cursor.Position);//new System.Drawing.Point(GetCursorPosition().X, GetCursorPosition().Y));
                return;
            }
            if (m.Msg == (int)WindowsAPI.WndMsg.WM_EXITMENULOOP)
            {
                //this.IsRenameStarted = false;
            }
            if (m.Msg == 78)
            {
                //var r = (WindowsAPI.NMHDR*)(IntPtr)lParam;
                WindowsAPI.NMHDR nmhdr = new WindowsAPI.NMHDR();
                nmhdr = (WindowsAPI.NMHDR)m.GetLParam(nmhdr.GetType());
                switch ((int)nmhdr.code)
                {
                case WNM.LVN_GETINFOTIP:
                    //TODO: Write here the code for the tooltip flyout
                    break;

                case WNM.NM_CUSTOMDRAW:
                    if (!this.Browser.NavigationLog.CurrentLocation.IsSearchFolder)
                    {
                        if (nmhdr.hwndFrom == this.SysListviewhandle)
                        {
                            var nmlvcd = WindowsAPI.PtrToStructure <WindowsAPI.NMLVCUSTOMDRAW>(m.LParam);
                            var index  = (int)nmlvcd.nmcd.dwItemSpec;
                            var hdc    = nmlvcd.nmcd.hdc;

                            Guid         IIFV2 = typeof(IShellItem).GUID;
                            IFolderView2 fv2   = this.Browser.GetFolderView2();
                            IShellItem   item  = null;
                            try
                            {
                                fv2.GetItem(index, ref IIFV2, out item);
                            }
                            catch (Exception)
                            {
                            }

                            object      ext     = null;
                            ShellObject itemobj = null;
                            if (item != null)
                            {
                                itemobj = ShellObjectFactory.Create(item);

                                ext = itemobj.Properties.System.FileExtension.Value;
                            }
                            Color?textColor = null;
                            if (this.Browser.LVItemsColorCodes != null && this.Browser.LVItemsColorCodes.Count > 0)
                            {
                                if (ext != null)
                                {
                                    var extItemsAvailable = this.Browser.LVItemsColorCodes.Where(c => c.ExtensionList.Contains(ext.ToString())).Count() > 0;
                                    if (extItemsAvailable)
                                    {
                                        var color = this.Browser.LVItemsColorCodes.Where(c => c.ExtensionList.ToLowerInvariant().Contains(ext.ToString().ToLowerInvariant())).Select(c => c.TextColor).SingleOrDefault();
                                        textColor = color;
                                    }
                                }
                            }

                            switch (nmlvcd.nmcd.dwDrawStage)
                            {
                            case CDDS_PREPAINT:
                                m.Result = (IntPtr)CDRF_NOTIFYITEMDRAW;
                                break;

                            case CDDS_ITEMPREPAINT:
                                // call default procedure in case system might do custom drawing and set special colors

                                if (textColor != null)
                                {
                                    nmlvcd.clrText = ColorTranslator.ToWin32(textColor.Value);
                                    Marshal.StructureToPtr(nmlvcd, m.LParam, false);

                                    m.Result = (IntPtr)(CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW);
                                }
                                else
                                {
                                    m.Result = (IntPtr)(CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW);
                                }
                                break;

                            case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
                                // before a subitem drawn
                                if ((nmlvcd.nmcd.uItemState & (WindowsAPI.CDIS.HOT | WindowsAPI.CDIS.DROPHILITED)) != 0 || 0 != WindowsAPI.SendMessage(this.SysListviewhandle, WindowsAPI.LVM.GETITEMSTATE, index, (int)WindowsAPI.LVIS.LVIS_SELECTED))
                                {
                                    // hot, drophilited or selected.
                                    if (nmlvcd.iSubItem == 0)
                                    {
                                        // do default to draw hilite bar
                                        m.Result = (IntPtr)CDRF_DODEFAULT;
                                    }
                                    else
                                    {
                                        // remaining region of a hilted item need to be drawn
                                        m.Result = (IntPtr)CDRF_NOTIFYPOSTPAINT;
                                    }
                                }
                                else if ((nmlvcd.iSubItem == 0 && nmlvcd.nmcd.uItemState.HasFlag(WindowsAPI.CDIS.FOCUS)))
                                {
                                    // if the subitem in selected column, or first item with focus
                                    m.Result = (IntPtr)CDRF_NOTIFYPOSTPAINT;
                                }
                                else
                                {
                                    if (textColor != null)
                                    {
                                        nmlvcd.clrText = ColorTranslator.ToWin32(textColor.Value);
                                        Marshal.StructureToPtr(nmlvcd, m.LParam, false);
                                        m.Result = (IntPtr)CDRF_NEWFONT;
                                    }
                                    else
                                    {
                                        m.Result = (IntPtr)CDRF_DODEFAULT;
                                    }
                                }
                                break;

                            case CDDS_ITEMPOSTPAINT:
                                //base.WndProc(ref m);
                                if (nmlvcd.clrTextBk != 0)
                                {
                                    var iconBounds = new WindowsAPI.RECT();

                                    iconBounds.Left = 1;

                                    WindowsAPI.SendMessage(this.SysListviewhandle, WindowsAPI.LVM.GETITEMRECT, index, ref iconBounds);

                                    //using (Graphics graphics = Graphics.FromHdc(nmlvcd.nmcd.hdc))
                                    //{
                                    //  graphics.Clip = new Region(iconBounds.ToRectangle()); ;
                                    //  graphics.FillRectangle(Brushes.Black, new Rectangle(iconBounds.left, iconBounds.bottom - 20, 20, 20));
                                    //}
                                    if (itemobj.IsShared)
                                    {
                                        if (this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.Details || this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.List || this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.SmallIcon)
                                        {
                                            small.DrawOverlay(hdc, 1, new Point(iconBounds.Left, iconBounds.Bottom - 16));
                                        }
                                        else
                                        {
                                            if (this.Browser.ContentOptions.ThumbnailSize > 180)
                                            {
                                                jumbo.DrawOverlay(hdc, 1, new Point(iconBounds.Left, iconBounds.Bottom - this.Browser.ContentOptions.ThumbnailSize / 3), this.Browser.ContentOptions.ThumbnailSize / 3);
                                            }
                                            else
                                            if (this.Browser.ContentOptions.ThumbnailSize > 64)
                                            {
                                                extra.DrawOverlay(hdc, 1, new Point(iconBounds.Left + 10, iconBounds.Bottom - 50));
                                            }
                                            else
                                            {
                                                large.DrawOverlay(hdc, 1, new Point(iconBounds.Left + 10, iconBounds.Bottom - 32));
                                            }
                                        }
                                    }
                                }
                                m.Result = (IntPtr)CDRF_SKIPDEFAULT;
                                break;
                            }
                            if (itemobj != null)
                            {
                                itemobj.Dispose();
                            }
                            return;
                        }
                    }
                    break;
                }
                //base.WndProc(ref m);
            }
            //return;
            // Perform whatever custom processing you must have for this message
            //System.Diagnostics.Debug.WriteLine(m.ToString());
            // forward message to base WndProc
            base.WndProc(ref m);
        }