コード例 #1
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void ShowInfo(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         foreach (string libraryName in Directory.GetFiles(KnownFolders.Libraries))
         {
             try
             {
                 using (ShellLibrary library = ShellLibrary.Load(libraryName, true))
                 {
                     ShowInformation(library);
                 }
             }
             catch (Exception ex)
             {
                 System.Diagnostics.Trace.WriteLine(libraryName + " is probably not a library, Error: " + ex.Message);
             }
         }
     }
     else
     {
         using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
         {
             ShowInformation(library);
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Remove directory from a shell library
 /// </summary>
 /// <param name="folderPath">the directory path to remove</param>
 public void RemoveDirectory(string folderPath)
 {
     using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
     {
         shellLibrary.RemoveFolder(folderPath);
     }
 }
コード例 #3
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void RemoveFolder(string name, string folderPath)
 {
     using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
     {
         library.RemoveFolder(folderPath);
     }
 }
コード例 #4
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void RenameLibrary(string oldName, string newName)
 {
     using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(oldName), true))
     {
         library.Name = newName;
     }
 }
コード例 #5
0
        /// <summary>
        /// Use <see="FileSystemWatcher"> to update the library manager state whenever there is a change
        /// in the underline shell library
        /// </summary>
        private void ListenToShellLibraryChange()
        {
            if (_libraryWatcher != null)
            {
                _libraryWatcher.Dispose();
            }
            string directoryPath = System.IO.Path.GetDirectoryName(LibraryName);
            string fileName      = System.IO.Path.GetFileName(LibraryName);

            _libraryWatcher = new FileSystemWatcher(directoryPath);
            _libraryWatcher.NotifyFilter          = NotifyFilters.LastWrite;
            _libraryWatcher.Filter                = fileName;
            _libraryWatcher.IncludeSubdirectories = false;

            _libraryWatcher.Changed += (s, e) =>
            {
                //cross thread call
                this.Dispatcher.Invoke(new Action(() =>
                {
                    try
                    {
                        //We open the library with write permissions for ResolveFolder
                        using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
                        {
                            UpdateLibraryState(shellLibrary);
                        }
                    }
                    catch (Exception exp)
                    {
                        System.Diagnostics.Trace.WriteLine("Could not update the library:" + LibraryName + " state, Error: " + exp.Message);
                    }
                }));
            };
            _libraryWatcher.EnableRaisingEvents = true;
        }
コード例 #6
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void FolderType(string name, string folderType)
 {
     using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
     {
         if (string.IsNullOrEmpty(folderType))
         {
             Guid   folderTypeId   = library.FolderTypeId;
             string folderTypeName = folderTypeId.ToString();
             try
             {
                 folderTypeName = FolderTypes.GetFolderType(folderTypeId);
             }
             catch
             {
             }
             Console.WriteLine("Folder type: {0}", folderTypeName);
         }
         else
         {
             Guid folderTypeId;
             try
             {
                 folderTypeId = FolderTypes.GetFolderType(folderType);
             }
             catch
             {
                 folderTypeId = new Guid(folderType);
             }
             library.FolderTypeId = folderTypeId;
         }
     }
 }
コード例 #7
0
        public static List <string> GetMusicFiles()
        {
            var musicFiles = new List <string>();

            if (ShellLibrary.IsPlatformSupported)
            {
                var library = ShellLibrary.Load("Music", true);
                foreach (var folder in library)
                {
                    if (!Directory.Exists(folder.Path))
                    {
                        continue;
                    }

                    var files = GetDirectoryFiles(folder.Path, "*.*", SearchOption.AllDirectories)
                                .Where(s => s.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) ||
                                       s.EndsWith(".wma", StringComparison.OrdinalIgnoreCase)).ToList();
                    //var files = Directory.EnumerateFiles(folder.Path, "*.*", SearchOption.AllDirectories)
                    //        .Where(s => s.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase)
                    //                    || s.EndsWith(".wma", StringComparison.OrdinalIgnoreCase)).ToList();

                    musicFiles.AddRange(files);
                }
            }
            else
            {
                musicFiles =
                    Directory.EnumerateFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "*.*", SearchOption.AllDirectories)
                    .Where(s => s.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) ||
                           s.EndsWith(".wma", StringComparison.OrdinalIgnoreCase)).ToList();
            }

            return(musicFiles);
        }
コード例 #8
0
        ///// <summary>
        ///// 新しいClientWindowを表示
        ///// </summary>
        ///// <param name="files"></param>
        //public void ShowNewClient(IEnumerable<string> files)
        //{
        //    ((App)Application.Current).ShowClientWindow(files);
        //}

        /// <summary>
        /// フォルダを登録
        /// </summary>
        /// <param name="defaultPath"></param>
        /// <param name="lastSelectedPath"></param>
        /// <returns></returns>
        public bool AddFolder(string defaultPath, out string lastSelectedPath)
        {
            lastSelectedPath = null;

            string folderPath = null;

            using (var fbd = new FolderSelectDialog())
            {
                if (System.IO.Directory.Exists(defaultPath))
                {
                    fbd.DefaultDirectory = defaultPath;
                }

                if (fbd.ShowDialog() == true)
                {
                    folderPath = fbd.SelectedPath;
                }
            }

            if (string.IsNullOrWhiteSpace(folderPath))
            {
                return(false);
            }

            var folders = new List <string>();

            try
            {
                if ((".library-ms").Equals(Path.GetExtension(folderPath)))
                {
                    //Windowsライブラリの場合

                    var libraryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                   @"Microsoft\Windows\Libraries\");
                    var libraryName = Path.GetFileNameWithoutExtension
                                          (folderPath.Split(Path.DirectorySeparatorChar).Last());

                    using (var shellLibrary = ShellLibrary.Load(libraryName, libraryPath, true))
                    {
                        foreach (var folder in shellLibrary)
                        {
                            folders.Add(folder.Path);
                            lastSelectedPath = folder.Path;
                        }
                    }
                }
                else
                {
                    //通常フォルダ
                    folders.Add(folderPath);
                    lastSelectedPath = folderPath;
                }
            }
            catch
            {
            }

            return(this.Library.Folders.RegisterFolders(folders.ToArray()));
        }
コード例 #9
0
 /// <summary>
 /// Set the icon of the library
 /// </summary>
 /// <param name="iconId">the Shell stock icon ID</param>
 public void SetIcon(int iconId)
 {
     using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
     {
         shellLibrary.Icon = Helper.GetIcon(iconId);
         ShellIcon         = StockIcons.GetBitmapSource((StockIconIdentifier)iconId);
     }
 }
コード例 #10
0
 /// <summary>
 /// Open an existing shell library
 /// </summary>
 /// <param name="shellLibraryPath">The path to the .library-ms file</param>
 public void OpenShellLibrary(string shellLibraryPath)
 {
     using (ShellLibrary shellLibrary = ShellLibrary.Load(shellLibraryPath, true))
     {
         LibraryName = shellLibraryPath;
         ListenToShellLibraryChange();
         UpdateLibraryState(shellLibrary);
     }
 }
コード例 #11
0
        /// <summary>
        /// Set the pinning state in the explorer navigation pane
        /// <remarks>Clients of this class use the <see cref="PinnedToNavigationPaneState"/> property</remarks>
        /// </summary>
        /// <param name="state"></param>
        private void SetPinnedToNavigationPaneState(bool state)
        {
            if (_isIgnoreEvent)
            {
                return;
            }

            using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
            {
                shellLibrary.IsPinnedToNavigationPane = state;
            }
        }
コード例 #12
0
        /// <summary>
        /// Set the shell library default folder
        /// <remarks>Clients of this class use the <see cref="DefaultSaveFolder"/> property</remarks>
        /// </summary>
        /// <param name="folderPath">the path to the default folder</param>
        private void SetDefaultSaveFolder(string folderPath)
        {
            if (_isIgnoreEvent)
            {
                return;
            }

            using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
            {
                shellLibrary.DefaultSaveFolder = folderPath;
            }
        }
コード例 #13
0
ファイル: IOHelpers.cs プロジェクト: mingslogar/dimension4
        public static string[] GetFoldersIncludedInLibrary(string libraryName)
        {
            ShellLibrary  shellLib = ShellLibrary.Load(libraryName, true);
            List <string> folders  = new List <string>();

            foreach (ShellFileSystemFolder each in shellLib)
            {
                folders.Add(each.Path);
            }

            return(folders.ToArray());
        }
コード例 #14
0
        public static List <WinLibrary> EnumerateLibraries()
        {
            foreach (string libraryFilePath in WinLibraryOSHelper.GetAllLibraries())
            {
                // Library name is the actual file name!
                string libraryName = Path.GetFileNameWithoutExtension(libraryFilePath);
                using (ShellLibrary shellLibrary = ShellLibrary.Load(libraryName, false))
                {
                    WinLibrarySetStorage.Libraries.Add(WinLibraryFromShellLibrary(shellLibrary));
                }
            }

            return(WinLibrarySetStorage.Libraries);
        }
コード例 #15
0
        /// <summary>
        /// Set the folder type template
        /// </summary>
        /// <param name="typeName">The folder type name</param>
        private void SetFolderType(string typeName)
        {
            Guid folderType = FolderTypes.GetFolderType(typeName);

            if (_isIgnoreEvent || folderType == Guid.Empty)
            {
                return;
            }

            using (ShellLibrary shellLibrary = ShellLibrary.Load(LibraryName, true))
            {
                shellLibrary.FolderTypeId = folderType;
            }
        }
コード例 #16
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void SaveFolder(string name, string folderPath)
 {
     using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
     {
         if (string.IsNullOrEmpty(folderPath))
         {
             Console.WriteLine("Save folder: {0}", library.DefaultSaveFolder);
         }
         else
         {
             library.DefaultSaveFolder = folderPath;
         }
     }
 }
コード例 #17
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
 public static void Icon(string name, string icon)
 {
     using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
     {
         if (string.IsNullOrEmpty(icon))
         {
             Console.WriteLine("Icon: {0}", library.Icon);
         }
         else
         {
             library.Icon = icon;
         }
     }
 }
コード例 #18
0
ファイル: ShellCommands.cs プロジェクト: mehome/cs
        public static void NavPanePinnedState(string name, string stateText)
        {
            using (ShellLibrary library = ShellLibrary.Load(ShellLibrary.CreateLibraryFullName(name), true))
            {
                bool state;

                if (bool.TryParse(stateText, out state))
                {
                    library.IsPinnedToNavigationPane = state;
                }
                else
                {
                    Console.WriteLine("The library {0} is{1}pinned to the navigation pane.", name, library.IsPinnedToNavigationPane ? " " : " not ");
                }
            }
        }
コード例 #19
0
        /// <summary>
        ///   Save any new paths which might have been added by the user.
        /// </summary>
        internal void UpdatePaths()
        {
            // When the library is not 'visible', its paths are not accessible and can not be changed.
            if (!IsVisible)
            {
                return;
            }

            using (var activityContext = ShellLibrary.Load(_name, true))
            {
                _paths.Clear();
                foreach (var folder in activityContext)
                {
                    _paths.Add(folder.Path);
                }
            }
        }
コード例 #20
0
        private TreeViewItem AddLibraries()
        {
            StackPanel   panel        = new StackPanel();
            IKnownFolder iKnownFolder = KnownFolders.UsersLibraries;
            ShellObject  shellObject  = ShellFolder.FromParsingName(iKnownFolder.ParsingName);

            panel.Orientation = Orientation.Horizontal;
            Image image = new Image();

            image.Source = shellObject.Thumbnail.SmallBitmapSource;
            image.Width  = image.Height = 16;
            panel.Children.Add(image);
            TagInfo   info      = new TagInfo(shellObject.Name, iKnownFolder.Path);
            TextBlock textBlock = new TextBlock();

            textBlock.Text = info.Name;
            panel.Children.Add(textBlock);
            TreeViewItem item = new TreeViewItem();

            item.Header = panel;
            item.Tag    = info;
            dirView.Items.Add(item);
            item.IsExpanded = true;
            //item.Items.Add(CreatTreeViewItem(new TagInfo("Documents", Environment.GetFolderPath(Environment.SpecialFolder.Personal))));
            //item.Items.Add(CreatTreeViewItem(new TagInfo("Music", Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))));
            //item.Items.Add(CreatTreeViewItem(new TagInfo("Pictures", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))));
            //item.Items.Add(CreatTreeViewItem(new TagInfo("Videos", Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))));
            //item.Items.Add(CreatTreeViewItem(new TagInfo("Downloads", "")));
            foreach (var shellObj in iKnownFolder)
            {
                try
                {
                    ShellLibrary shellLibrary = ShellLibrary.Load(shellObj.Name, true);
                    if (shellLibrary.Count > 0 && Directory.Exists(shellLibrary.DefaultSaveFolder))
                    {
                        item.Items.Add(CreatTreeViewItem(new TagInfo(shellObj.Name, shellLibrary.DefaultSaveFolder)));
                    }
                }
                catch
                {
                }
            }
            return(item);
        }
コード例 #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            string       libraryName = "我的库";
            string       doc2        = @"D:\Temp\doc2";
            string       doc1        = @"D:\Temp\doc1";
            ShellLibrary library     = new ShellLibrary(libraryName, true)
            {
                doc2,
                doc1
            };

            string defaultSaveFolderPath = library.DefaultSaveFolder; // 默认保存到的文件夹,是第一个添加进库的目录

            library.DefaultSaveFolder = doc1;                         // 更改默认保存到的文件夹

            library.IconResourceId = new IconReference(Assembly.GetExecutingAssembly().Location, -32512);

            ShellLibrary lib = ShellLibrary.Load(libraryName, true); // 第二个参数isReadOnly表示是否允许改动库
        }
コード例 #22
0
        public CollectionViewModel()
        {
            Collection = new ObservableCollection <PlayListEntry>();

            //using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    var libraryFile = "library.json";
            //    //does the library file exist?
            //    if (!isf.FileExists(libraryFile))
            //    {
            //        //load existing library
            //        using (var sw = new StreamWriter(isf.CreateFile(libraryFile)))
            //        {

            //        }
            //    }

            //}

            //var data = JsonConvert.DeserializeObject<PlayListEntry[]>(sr.ReadToEnd());

            ////load the librart
            //foreach (var d in data)
            //{
            //    Collection.Add(d);
            //}


            //var musicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
            var sl = ShellLibrary.Load(KnownFolders.MusicLibrary, true);

            foreach (var l in sl)
            {
                Debug.WriteLine(l.Path);

                //setup filesystem watcher
            }
        }
コード例 #23
0
        public List <string> FoldersInLibrary(string shortLibraryName)
        {
            shortLibraryName = shortLibraryName.ToLower();
            IKnownFolder f;

            if (shortLibraryName.Equals("videos"))
            {
                f = KnownFolders.VideosLibrary;
            }
            else if (shortLibraryName.Equals("music"))
            {
                f = KnownFolders.MusicLibrary;
            }
            else if (shortLibraryName.Equals("pictures"))
            {
                f = KnownFolders.PicturesLibrary;
            }
            else if (shortLibraryName.Equals("documents"))
            {
                f = KnownFolders.DocumentsLibrary;
            }
            else
            {
                return(new List <string>());
            }

            List <string> output = new List <string>();

            using (ShellLibrary lib = ShellLibrary.Load(f, true))
            {
                foreach (ShellFileSystemFolder folder in lib)
                {
                    output.Add(folder.Path);
                }
            }

            return(output);
        }
コード例 #24
0
ファイル: IOHelpers.cs プロジェクト: mingslogar/dimension4
        public static bool LibraryExists(string library)
        {
            try
            {
                if (Environment.OSVersion.Version >= OSVersions.Win_7)
                {
                    if (File.Exists(library) && Path.GetExtension(library) == ".library-ms")
                    {
                        return(true);
                    }

                    try
                    {
                        ShellLibrary.Load(library, true);
                        return(true);
                    }
                    catch { }
                }
            }
            catch { }

            return(false);
        }
コード例 #25
0
 private void btnSet_Click(object sender, EventArgs e)
 {
     if (IsLibrary)
     {
         ShellLibrary lib = null;
         try
         {
             lib = ShellLibrary.Load(ShellView.SelectedItems[0].GetDisplayName(DisplayNameType.Default),
                                     false);
         }
         catch
         {
             lib = ShellLibrary.Load(ShellView.NavigationLog.CurrentLocation.GetDisplayName(DisplayNameType.Default),
                                     false);
         }
         lib.IconResourceId = new IconReference(tbLibrary.Text, (int)lvIcons.SelectedItems[0].Tag);
         lib.Close();
     }
     else
     {
         ShellView.SetFolderIcon(ShellView.SelectedItems[0].ParsingName, tbLibrary.Text, (int)lvIcons.SelectedItems[0].Tag);
     }
 }
コード例 #26
0
    static void Main(string[] args)
    {
        string libraryName = "All-In-One Code Framework";


        /////////////////////////////////////////////////////////////////////
        // Create a shell library.
        //

        Console.WriteLine("Create shell library: {0}", libraryName);
        using (ShellLibrary library = new ShellLibrary(libraryName, true))
        {
        }

        Console.WriteLine("Press ENTER to continue...");
        Console.ReadLine();


        /////////////////////////////////////////////////////////////////////
        // Show Manage Library UI.
        //

        Console.WriteLine("Show Manage Library UI");

        // ShowManageLibraryUI requires that the library is not currently
        // opened with write permission.
        ShellLibrary.ShowManageLibraryUI(libraryName, IntPtr.Zero,
                                         "CSWin7ShellLibrary", "Manage Library folders and settings", true);

        Console.WriteLine("Press ENTER to continue...");
        Console.ReadLine();


        // Open the shell libary
        Console.WriteLine("Open shell library: {0}", libraryName);
        using (ShellLibrary library = ShellLibrary.Load(libraryName, false))
        {
            /////////////////////////////////////////////////////////////////
            // Add a folder to the shell library.
            //

            Console.WriteLine("Add a folder to the shell library");

            string folderPath;

            // Display common dialog for selecting the folder to be added
            CommonOpenFileDialog fileDlg = new CommonOpenFileDialog();
            fileDlg.IsFolderPicker = true;
            if (fileDlg.ShowDialog() == CommonFileDialogResult.Cancel)
            {
                return;
            }

            folderPath = fileDlg.FileName;
            Console.WriteLine("The selected folder is {0}", folderPath);

            // Add the folder to the shell library
            library.Add(folderPath);
            library.DefaultSaveFolder = folderPath;

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();


            /////////////////////////////////////////////////////////////////
            // List all folders in the library.
            //

            Console.WriteLine("List all folders in the library");

            foreach (ShellFolder folder in library)
            {
                Console.WriteLine(folder);
            }

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();


            /////////////////////////////////////////////////////////////////
            // Remove a folder from the shell library.
            //

            Console.WriteLine("Remove a folder from the shell library");

            library.Remove(folderPath);

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
        }


        /////////////////////////////////////////////////////////////////////
        // Delete the shell library.
        //

        Console.WriteLine("Delete the shell library");

        string librariesPath = Path.Combine(Environment.GetFolderPath(
                                                Environment.SpecialFolder.ApplicationData),
                                            ShellLibrary.LibrariesKnownFolder.RelativePath);

        string libraryPath     = Path.Combine(librariesPath, libraryName);
        string libraryFullPath = Path.ChangeExtension(libraryPath, "library-ms");

        File.Delete(libraryFullPath);
    }
コード例 #27
0
ファイル: MessageRoutine.cs プロジェクト: wook8170/ModernWPF
        /// <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);
            }
        }