Exemple #1
0
        /// <summary>
        /// Create a Shell Library and return a <see cref="ShellLibrary"/> object
        /// </summary>
        /// <param name="name">The library name</param>
        /// <param name="isPinnedToNavigationPane">Whether the library is pinned to the Explorer window navigatin Pane </param>
        /// <returns>A <see cref="ShellLibrary"/> object</returns>
        public static ShellLibrary Create(string name, bool isPinnedToNavigationPane)
        {
            IShellLibrary newLibrary = new ShellLibraryClass();
            Guid libraryfolderId = new Guid(KFIDGuid.Libraries);
            IShellItem savesToShellItem;
            newLibrary.SaveInKnownFolder(ref libraryfolderId, name, Windows7.DesktopIntegration.Interop.SafeNativeMethods.LIBRARYSAVEFLAGS.LSF_OVERRIDEEXISTING, out savesToShellItem);
            newLibrary.Commit();

            string fullName = CreateLibraryFullName(name);
            ShellLibrary shellLibrary = new ShellLibrary(newLibrary, fullName);
            Marshal.ReleaseComObject(savesToShellItem);
            shellLibrary.IsPinnedToNavigationPane = isPinnedToNavigationPane;
            return shellLibrary;
        }
Exemple #2
0
        /// <summary>
        /// Create a Shell Library and return a <see cref="ShellLibrary"/> object
        /// </summary>
        /// <param name="name">The library name</param>
        /// <param name="folderToSaveIn">The folder (library) to add the new library to</param>
        /// <returns>A <see cref="ShellLibrary"/> object</returns>
        public static ShellLibrary Create(string name, string folderToSaveIn)
        {
            IShellLibrary newLibrary = new ShellLibraryClass();
            IShellItem folderToSaveInShellItem = Helpers.GetShellItemFromPath(folderToSaveIn);
            IShellItem savesToShellItem;
            newLibrary.Save(folderToSaveInShellItem, name, Windows7.DesktopIntegration.Interop.SafeNativeMethods.LIBRARYSAVEFLAGS.LSF_OVERRIDEEXISTING, out savesToShellItem);
            newLibrary.Commit();

            string baseName = System.IO.Path.Combine(folderToSaveIn, name);
            string fullName = System.IO.Path.ChangeExtension(baseName, ".library-ms");

            ShellLibrary shellLibrary = new ShellLibrary(newLibrary, fullName);
            Marshal.ReleaseComObject(savesToShellItem);
            return shellLibrary;
        }
Exemple #3
0
        /// <summary>
        /// Make the library manager state coherent with the underline shell library
        /// </summary>
        /// <param name="shellLibrary">The shell library path</param>
        private void UpdateLibraryState(ShellLibrary shellLibrary)
        {
            try
            {
                //break update loop
                _isIgnoreEvent = true;

                FolderList.Clear();
                foreach (string folder in shellLibrary.GetFolders())
                    FolderList.Add(folder);
                DefaultSaveFolder = shellLibrary.DefaultSaveFolder;
                IsPinnedToNavigationPane = shellLibrary.IsPinnedToNavigationPane;

                string iconPath = shellLibrary.Icon;
                ShellIcon = string.IsNullOrEmpty(iconPath) ? null : Helper.GetIconBitmap(iconPath);
                
                string folderType;
                try
                {
                    folderType = FolderTypes.GetFolderType(shellLibrary.FolderTypeId);
                }
                catch
                {
                    folderType = "";
                }
                FolderType = folderType;
            }
            finally
            {
                _isIgnoreEvent = false;
            }
        }
Exemple #4
0
 /// <summary>
 /// Load an existing library and create a <see cref="ShellLibrary"/> object that enables 
 /// the management of this library
 /// </summary>
 /// <param name="path">The library to load.</param>
 /// <param name="isWritable">Define the access code to the library</param>
 /// <returns>A <see cref="ShellLibrary"/> object</returns>
 public static ShellLibrary Load(string path, bool isWritable)
 {
     IShellLibrary library = new ShellLibraryClass();
     IShellItem pathShellItem = Helpers.GetShellItemFromPath(path);
     library.LoadLibraryFromItem(pathShellItem, isWritable ? Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READWRITE : Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READ);
     ShellLibrary shellLibrary = new ShellLibrary(library, path);
     return shellLibrary;
 }
Exemple #5
0
 /// <summary>
 /// Load an existing library and create a <see cref="ShellLibrary"/> object that enables 
 /// the management of this library from a known folder location
 /// </summary>
 /// <param name="knownFolderLibrary">The known folder library to load</param>
 /// <param name="isWritable">Define the access code to the library</param>
 /// <returns>A <see cref="ShellLibrary"/> object</returns>
 public static ShellLibrary Load(KnownFolder knownFolderLibrary, bool isWritable)
 {
     IShellLibrary library = new ShellLibraryClass();
     Guid folderId = knownFolderLibrary.FolderId;
     library.LoadLibraryFromKnownFolder(ref folderId, isWritable ? Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READWRITE : Windows7.DesktopIntegration.Interop.SafeNativeMethods.StorageInstantiationModes.STGM_READ);
     string fullName = System.IO.Path.ChangeExtension(knownFolderLibrary.Path, ".library-ms");
     ShellLibrary shellLibrary = new ShellLibrary(library, fullName);
     return shellLibrary;
 }
Exemple #6
0
        private static void ShowInformation(ShellLibrary library)
        {
            Console.WriteLine("\nShowing information of {0} library", library.Name);
            Console.WriteLine("\tLibrary path: {0}", library.FullName);
            Console.WriteLine("\tIs pinned to navigation pane: {0}", library.IsPinnedToNavigationPane);
            string saveFolder = library.DefaultSaveFolder;
            Console.WriteLine("\tSave folder: {0}", saveFolder);
            Console.WriteLine("\tIcon: {0}", library.Icon);
            Guid folderTypeId = library.FolderTypeId;
            string folderTypeName = folderTypeId.ToString();
            try
            {
                folderTypeName = FolderTypes.GetFolderType(folderTypeId);
            }
            catch
            {
            }
            Console.WriteLine("\tFolder type: {0}", folderTypeName);

            Console.WriteLine("\tFolder list:");
            foreach (string folder in library.GetFolders())
            {
                Console.WriteLine("\t\t{0} {1}", folder, saveFolder == folder ? "*" : "");
            }
        }