Пример #1
0
        /*
         * /// <summary>
         * /// Returns a URI representation of the <see cref="ShellItem"/>.
         * /// </summary>
         * public Uri ToUri() {
         *      return this.ParsingName.StartsWith("::") ? new Uri("shell:///" + this.ParsingName) : new Uri(this.FileSystemPath);
         *      StringBuilder path = new StringBuilder("shell:///");
         *
         *      if (this.ParsingName.StartsWith("::")) {
         *              path.Append(this.ParsingName);
         *              return new Uri(path.ToString());
         *      }
         *      return new Uri(this.FileSystemPath);
         * }
         */

        private void Initialize(Uri uri)
        {
            if (uri.Scheme == "file")
            {
                ComInterface = CreateItemFromParsingName(uri.LocalPath);
            }
            else if (uri.Scheme == "shell")
            {
                //InitializeFromShellUri(uri);
                //TO_DO: add shell folders handling here
                //KnownFolderManager manager = new KnownFolderManager();
                string path = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
                string knownFolder;
                string restOfPath;
                int    separatorIndex = path.IndexOf('/');

                if (separatorIndex != -1)
                {
                    knownFolder = path.Substring(0, separatorIndex);
                    restOfPath  = path.Substring(separatorIndex + 1);
                }
                else
                {
                    knownFolder = path;
                    restOfPath  = string.Empty;
                }

                try {
                    IKnownFolder knownFolderI = KnownFolderHelper.FromParsingName(knownFolder);
                    if (knownFolderI != null)
                    {
                        ComInterface = (knownFolderI as ShellItem).ComInterface;
                    }
                    else if (knownFolder.StartsWith(KnownFolders.Libraries.ParsingName))
                    {
                        var lib = ShellLibrary.Load(Path.GetFileNameWithoutExtension(knownFolder), true);

                        if (lib != null)
                        {
                            ComInterface = lib.ComInterface;
                        }
                    }
                }
                catch {
                }

                if (restOfPath != string.Empty)
                {
                    ComInterface = this[restOfPath.Replace('/', '\\')].ComInterface;
                }
            }
            else
            {
                throw new InvalidOperationException("Invalid URI scheme");
            }
        }
Пример #2
0
 /// <summary>
 /// Shows the library management dialog which enables users to mange the library folders and default save location.
 /// </summary>
 /// <param name="sourceKnownFolder">A known folder.</param>
 /// <param name="windowHandle">The parent window,or IntPtr.Zero for no parent</param>
 /// <param name="title">A title for the library management dialog, or null to use the library name as the title</param>
 /// <param name="instruction">An optional help string to display for the library management dialog</param>
 /// <param name="allowAllLocations">If true, do not show warning dialogs about locations that cannot be indexed</param>
 /// <remarks>If the library is already open in read-write mode, the dialog will not save the changes.</remarks>
 public static void ShowManageLibraryUI(IKnownFolder sourceKnownFolder, IntPtr windowHandle, string title, string instruction, bool allowAllLocations)
 {
     // this method is not safe for MTA consumption and will blow
     // Access Violations if called from an MTA thread so we wrap this
     // call up into a Worker thread that performs all operations in a
     // single threaded apartment
     using (ShellLibrary shellLibrary = ShellLibrary.Load(sourceKnownFolder, true)) {
         ShowManageLibraryUI(shellLibrary, windowHandle, title, instruction, allowAllLocations);
     }
 }
Пример #3
0
        /// <summary>
        /// Is the current <paramref name="checkedItem">Item</paramref> in the <paramref name="currentFolder">Folder</paramref>?
        /// </summary>
        /// <param name="checkedItem">The current item who's container/parent you want to check</param>
        /// <param name="currentFolder">The folder you are looking for</param>
        /// <returns>Is the current <paramref name="checkedItem">Item</paramref> in the <paramref name="currentFolder">Folder</paramref>?</returns>
        /// <remarks>
        /// 1. Special Logic for Library folders (.library-ms)
        /// </remarks>
        public static Boolean IsInCurrentFolder(this IListItemEx checkedItem, IListItemEx currentFolder)
        {
            var isLibraryContainer = currentFolder?.Extension == ".library-ms";

            if (isLibraryContainer)
            {
                var library        = ShellLibrary.Load(currentFolder.DisplayName, true);
                var libraryFolders = library.Select(w => w).ToArray();
                if (libraryFolders.Count(
                        c => c.ParsingName.Equals(checkedItem.Parent?.ParsingName, StringComparison.InvariantCultureIgnoreCase)) > 0)
                {
                    library.Close();
                    return(true);
                }
                library.Close();
                return(false);
            }
            else
            {
                return(checkedItem?.Parent?.ParsingName == currentFolder.ParsingName);
            }
        }