示例#1
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);
        }
示例#2
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
            }
        }
示例#3
0
        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);
        }
示例#4
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);
     }
 }
        public string CreateNewLibrary(string name)
        {

            string endname = name;
            int suffix = 0;
            ShellLibrary lib = null;
            try
            {
                lib = ShellLibrary.Load(endname, true);
            }
            catch
            {

            }
            if (lib != null)
            {
                do
                {
                    endname = String.Format(name + "({0})",
                        ++suffix);
                    try
                    {
                        lib = ShellLibrary.Load(endname, true);
                    }
                    catch
                    {
                        lib = null;
                    }
                } while (lib != null);
            }


            ShellLibrary libcreate = new ShellLibrary(endname, false);

            return libcreate.GetDisplayName(DisplayNameType.Default);
        }
示例#6
0
 private static void CreateLib()
 {
     ShellLibrary sl = new ShellLibrary("MyShellLib2", Microsoft.WindowsAPICodePack.Shell.KnownFolders.Libraries, true);
 }
示例#7
0
 public static void DeleteLibrary(string name)
 {
     ShellLibrary.Delete(ShellLibrary.CreateLibraryFullName(name));
 }
示例#8
0
 public static void ManageUI(string name)
 {
     ShellLibrary.ShowManageLibraryUI(ShellLibrary.CreateLibraryFullName(name), IntPtr.Zero, null, null, true);
 }
示例#9
0
 public static void CreateLibrary(string name)
 {
     using (ShellLibrary library = ShellLibrary.Create(name, true))
     {
     }
 }
    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);
    }
示例#11
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);
            }
        }
示例#12
0
        private async Task HandleShellLibraryMessage(Dictionary <string, object> message)
        {
            switch ((string)message["action"])
            {
            case "Enumerate":
                // Read library information and send response to UWP
                var enumerateResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        var libraryItems = new List <ShellLibraryItem>();
                        // https://docs.microsoft.com/en-us/windows/win32/search/-search-win7-development-scenarios#library-descriptions
                        var libFiles = Directory.EnumerateFiles(ShellLibraryItem.LibrariesPath, "*" + ShellLibraryItem.EXTENSION);
                        foreach (var libFile in libFiles)
                        {
                            using var shellItem = ShellItem.Open(libFile);
                            if (shellItem is ShellLibrary library)
                            {
                                libraryItems.Add(ShellFolderExtensions.GetShellLibraryItem(library, libFile));
                            }
                        }
                        response.Add("Enumerate", JsonConvert.SerializeObject(libraryItems));
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Warn(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, enumerateResponse, message.Get("RequestID", (string)null));

                break;

            case "Create":
                // Try create new library with the specified name and send response to UWP
                var createResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        using var library = new ShellLibrary((string)message["library"], Shell32.KNOWNFOLDERID.FOLDERID_Libraries, false);
                        response.Add("Create", JsonConvert.SerializeObject(ShellFolderExtensions.GetShellLibraryItem(library, library.GetDisplayName(ShellItemDisplayString.DesktopAbsoluteParsing))));
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Warn(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, createResponse, message.Get("RequestID", (string)null));

                break;

            case "Update":
                // Update details of the specified library and send response to UWP
                var updateResponse = await Win32API.StartSTATask(() =>
                {
                    var response = new ValueSet();
                    try
                    {
                        var folders           = message.ContainsKey("folders") ? JsonConvert.DeserializeObject <string[]>((string)message["folders"]) : null;
                        var defaultSaveFolder = message.Get("defaultSaveFolder", (string)null);
                        var isPinned          = message.Get("isPinned", (bool?)null);

                        bool updated      = false;
                        var libPath       = (string)message["library"];
                        using var library = ShellItem.Open(libPath) as ShellLibrary;
                        if (folders != null)
                        {
                            if (folders.Length > 0)
                            {
                                var foldersToRemove = library.Folders.Where(f => !folders.Any(folderPath => string.Equals(folderPath, f.FileSystemPath, StringComparison.OrdinalIgnoreCase)));
                                foreach (var toRemove in foldersToRemove)
                                {
                                    library.Folders.Remove(toRemove);
                                    updated = true;
                                }
                                var foldersToAdd = folders.Distinct(StringComparer.OrdinalIgnoreCase)
                                                   .Where(folderPath => !library.Folders.Any(f => string.Equals(folderPath, f.FileSystemPath, StringComparison.OrdinalIgnoreCase)))
                                                   .Select(ShellItem.Open);
                                foreach (var toAdd in foldersToAdd)
                                {
                                    library.Folders.Add(toAdd);
                                    updated = true;
                                }
                                foreach (var toAdd in foldersToAdd)
                                {
                                    toAdd.Dispose();
                                }
                            }
                        }
                        if (defaultSaveFolder != null)
                        {
                            library.DefaultSaveFolder = ShellItem.Open(defaultSaveFolder);
                            updated = true;
                        }
                        if (isPinned != null)
                        {
                            library.PinnedToNavigationPane = isPinned == true;
                            updated = true;
                        }
                        if (updated)
                        {
                            library.Commit();
                            var libField = typeof(ShellLibrary).GetField("folders", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                            libField.SetValue(library, null);     // Force library folder reload
                            response.Add("Update", JsonConvert.SerializeObject(ShellFolderExtensions.GetShellLibraryItem(library, libPath)));
                        }
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Warn(e);
                    }
                    return(response);
                });

                await Win32API.SendMessageAsync(connection, updateResponse, message.Get("RequestID", (string)null));

                break;
            }
        }
示例#13
0
    private void SetupLibrariesTab(ShellLibrary lib) {
      IsFromSelectionOrNavigation = true;
      chkPinNav.IsChecked = lib.IsPinnedToNavigationPane;
      IsFromSelectionOrNavigation = false;

      foreach (ShellItem item in lib) {
        item.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
        item.Thumbnail.CurrentSize = new WIN.Size(16, 16);

        btnDefSave.Items.Add(Utilities.Build_MenuItem(item.GetDisplayName(SIGDN.NORMALDISPLAY), item, item.Thumbnail.BitmapSource, GroupName: "GRDS1", checkable: true,
                                                      isChecked: item.ParsingName == lib.DefaultSaveFolder, onClick: miItem_Click));
      }

      btnDefSave.IsEnabled = lib.Count != 0;
      lib.Close();
    }
示例#14
0
 /// <summary>
 /// Show the explorer library manage user interface
 /// </summary>
 /// <param name="hOwnerWnd">the parent window handle</param>
 public void OpenLibraryManageUI(IntPtr hOwnerWnd)
 {
     ShellLibrary.ShowManageLibraryUI(LibraryName, hOwnerWnd, "The Windows Shell Explorer Library Manager", "Manage the " + LibraryName, true);
 }
示例#15
0
 private static void CreateLib()
 {
     ShellLibrary sl = new ShellLibrary("MyShellLib2", Microsoft.WindowsAPICodePack.Shell.KnownFolders.Libraries, true);
 }
示例#16
0
        private void InstallJLE()
        {
            // Delete outdated files
            if (File.Exists(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Jumplist Extender.lnk")))
            {
                File.Delete(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Jumplist Extender.lnk"));
            }

            if (File.Exists(Path.Combine(Common.Path_AppData, "Icons\\[00] shell32.dll")))
            {
                File.Delete(Path.Combine(Common.Path_AppData, "Icons\\[00] shell32.dll"));
            }

            if (File.Exists(Path.Combine(Common.Path_ProgramFiles, "PinShortcut.vbs")))
            {
                File.Delete(Path.Combine(Common.Path_ProgramFiles, "PinShortcut.vbs"));
            }

            if (File.Exists(Path.Combine(Common.Path_AppData, "UpdateCheck2.txt")))
            {
                File.Delete(Path.Combine(Common.Path_AppData, "UpdateCheck2.txt"));
            }

            if (File.Exists(Path.Combine(Common.Path_AppData, "UpdateCheck.txt")))
            {
                File.Delete(Path.Combine(Common.Path_AppData, "UpdateCheck.txt"));
            }

            // Copy files to AppData, if needed
            string appDataDir      = Common.Path_AppData;
            string programFilesDir = Common.Path_ProgramFiles;

            //MessageBox.Show(appDataDir);
            if (!Directory.Exists(appDataDir))
            {
                try { Directory.CreateDirectory(appDataDir); }
                catch (Exception e) { Common.Fail("Data directory could not be created.", 1); }
                // Copy each file in programFiles\Defaults into appDataDir
            }

            // Copy each file into it’s new directory.
            DirectoryInfo source = new DirectoryInfo(Path.Combine(programFilesDir, "Defaults"));
            DirectoryInfo target = new DirectoryInfo(appDataDir);

            CopyAll(source, target, "AppList.xml", "Preferences.xml", "OrigProperties", "Icons");


            ReadAppList();

            if (Common.AppIds != null && Common.AppIds.Count > 0)
            {
                foreach (string appId in Common.AppIds)
                {
                    ReadAppSettings(appId); // Also reads jumplist into JumplistListBox
                    ApplyJumplistToTaskbar();

                    CurrentAppPath            = "";
                    CurrentAppId              = "";
                    CurrentAppName            = "";
                    CurrentAppProcessName     = "";
                    CurrentAppWindowClassName = "";

                    JumplistListBox.Items.Clear();
                }
            }

            // Shortcuts: Likely, we're gonna run T7EBackground anyways, so
            // let T7EBackground handle it.

            if (!Common.PrefExists("InstallDate"))
            {
                if (Common.AppCount > 0)
                {
                    Common.WritePref("InstallDate", DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + DateTime.Today.Day.ToString()
                                     , "InstallUpgrade", false.ToString());
                }
            }
            else
            {
                // Do we want to keep prefs for a donate code?
                Common.WritePref("InstallUpgrade", true.ToString()
                                 , "DonateDialogDisable", false.ToString()
                                 , "DonateBalloonDisable", false.ToString());
            }

            // Write library
            if (!File.Exists(Path.Combine(Common.Path_AppData, "Programs.library-ms")))
            {
                ShellLibrary programsLibrary = new ShellLibrary("Programs", Common.Path_AppData, true);

                if (Directory.Exists(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar")))
                {
                    programsLibrary.Add(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar"));
                }

                if (Directory.Exists(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\StartMenu")))
                {
                    programsLibrary.Add(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\StartMenu"));
                }

                if (Directory.Exists(Path.Combine(Common.EnvPath_AllUsersProfile, "Microsoft\\Windows\\Start Menu\\Programs")))
                {
                    programsLibrary.Add(Path.Combine(Common.EnvPath_AllUsersProfile, "Microsoft\\Windows\\Start Menu\\Programs"));
                }

                if (Directory.Exists(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Windows\\Start Menu\\Programs")))
                {
                    programsLibrary.Add(Path.Combine(Common.EnvPath_AppData, "Microsoft\\Windows\\Start Menu\\Programs"));
                }

                programsLibrary.Dispose(); // Library is written
            }

            // Add to startup

            /*RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
             * if (rkApp.GetValue("JumplistExtender") == null)
             *  rkApp.SetValue("JumplistExtender", Path.Combine(Common.Path_ProgramFiles, "T7EBackground.exe"));
             * rkApp.Close();*/
        }