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); }
protected override void ShowInner() { // Update paths to only include existing folders. _paths = _paths.Where(Directory.Exists).ToList(); // Initialize the shell library. // Information about Shell Libraries: http://msdn.microsoft.com/en-us/library/windows/desktop/dd758094(v=vs.85).aspx using (var activityContext = new ShellLibrary(_name, true)) { // TODO: Optionally set the icon of the library to the icon of the activity? For now, just set it to the icon of the executing assembly. activityContext.IconResourceId = new IconReference(Assembly.GetEntryAssembly().Location, 0); int retries = 5; var pathsToAdd = new List <string>(); pathsToAdd.AddRange(Paths); COMException innerException = null; while (pathsToAdd.Count > 0 && retries > 0) { foreach (string path in _paths) { try { activityContext.Add(path); pathsToAdd.Remove(path); } catch (COMException e) { innerException = e; // TODO: How to handle/prevent the COMException which is sometimes thrown? // System.Runtime.InteropServices.COMException (0x80070497): Unable to remove the file to be replaced. } finally { --retries; } } } if (pathsToAdd.Count > 0) { throw new COMException("Something went wrong while initializing the Activity Context library.", innerException); } } }
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); }
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();*/ }