コード例 #1
0
        private static void AddLibraryToSystem(WinLibrary library)
        {
            using (ShellLibrary shellLibrary = new ShellLibrary(library.Name, true))
            {
                shellLibrary.LibraryType = library.LibraryType;

                foreach (string folderPath in library.Folders)
                {
                    try
                    {
                        shellLibrary.Add(folderPath);
                    }
                    catch (System.Exception ex)
                    {
                        throw new LibraryCreationException(String.Format("Failed to add folder '{0}'.\n\nError: {1}", folderPath, ex.Message));
                    }
                }

                if (!String.IsNullOrEmpty(library.SaveFolder))
                {
                    try
                    {
                        shellLibrary.DefaultSaveFolder = library.SaveFolder;
                    }
                    catch
                    {
                        // Certain folders cannot be used as the save folder (e.g. read-only folders).
                        // Ignore - setting a property should never throw an exception!
                        // Hopefully this will be fixed by MS in the future.
                    }
                }

                if (!String.IsNullOrEmpty(library.IconReference.ReferencePath))
                {
                    shellLibrary.IconResourceId = library.IconReference;
                }

                // Library is now created in OS.
            }

            // Note: This is a temporary *hack* whilst I wait for feedback for how to set
            // properties on the library.  See this thread:
            // http://code.msdn.microsoft.com/WindowsAPICodePack/Thread/View.aspx?ThreadId=2998

            string libraryFilePath = Path.Combine(GetLibrariesStoragePath(), library.Name + ".library-ms");

            var doc = XDocument.Load(libraryFilePath);

            XNamespace ns  = "http://schemas.microsoft.com/windows/2009/library";
            XElement   xe1 = new XElement(ns + "property", new XCData("false"));

            xe1.Add(new XAttribute("name", "ShowNonIndexedLocationsInfoBar"));
            xe1.Add(new XAttribute("type", "boolean"));
            doc.Descendants(ns + "propertyStore").First().Add(xe1);

            doc.Save(libraryFilePath);
        }
コード例 #2
0
        public void CreateLibrary(string libraryName)
        {
            WinLibrary       winLibrary = new WinLibrary(libraryName);
            LibraryViewModel library    = new LibraryViewModel(winLibrary, _userInterface);

            library.IsSelected = true;

            WinLibrarySetStorage.Libraries.Add(winLibrary);
            _libraries.Add(library);
            CurrentLibrary = library;
        }
コード例 #3
0
        public LibraryViewModel(WinLibrary winLibrary, Window userInterface)
            : base(null, true)
        {
            _winLibrary    = winLibrary;
            _userInterface = userInterface;

            _setSaveCommand       = new Commands.SetSaveCommand(this);
            _removeCommand        = new Commands.RemoveFolderCommand(this);
            _includeFolderCommand = new Commands.IncludeFolderCommand(this);
            _chooseIconCommand    = new Commands.ChooseIconCommand(this);
        }
コード例 #4
0
        private static WinLibrary WinLibraryFromShellLibrary(ShellLibrary shellLibrary)
        {
            WinLibrary winLibrary = new WinLibrary(shellLibrary.Name);

            foreach (ShellFolder folder in shellLibrary)
            {
                winLibrary.Folders.Add(folder.ParsingName);
            }

            try
            {
                winLibrary.SaveFolder = shellLibrary.DefaultSaveFolder;
            }
            catch
            {
                // Ignore - accessing a property should never throw an exception!
                // Hopefully this will be fixed by MS in the future.
                // Just pick the first folder as the default save folder (this is how
                // libraries work in Windows).

                if (winLibrary.Folders.Count > 0)
                {
                    winLibrary.SaveFolder = winLibrary.Folders[0];
                }
            }

            try
            {
                winLibrary.IconReference = shellLibrary.IconResourceId;
            }
            catch
            {
                winLibrary.IconReference = new IconReference(WinLibrary.DefaultIconReference);
            }

            try
            {
                winLibrary.LibraryType = shellLibrary.LibraryType;
            }
            catch
            {
                // Ignore - accessing a property should never throw an exception!
                // Hopefully this will be fixed by MS in the future.
                // Just pick the first folder as the default save folder (this is how
                // libraries work in Windows).

                winLibrary.LibraryType = LibraryFolderType.Generic;
            }

            return(winLibrary);
        }
コード例 #5
0
        public MainWindow()
        {
            InitializeComponent();

            // Get raw library data.
            WinLibrary[] libraries = new WinLibrary[] { };

            // Create UI-friendly wrappers around the
            // raw data objects (i.e. the view-model).
            LibrarySetViewModel _viewModel = new LibrarySetViewModel(libraries, this);

            // Let the UI bind to the view-model.
            base.DataContext = _viewModel;
        }