UserFoldersHelper.cs 1.2 KB

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. namespace Optimizer
  5. {
  6. internal static class KnownFolders
  7. {
  8. private static readonly Dictionary<KnownFolder, Guid> _guids = new Dictionary<KnownFolder, Guid>
  9. {
  10. [KnownFolder.Contacts] = new Guid("56784854-C6CB-462B-8169-88E350ACB882"),
  11. [KnownFolder.Downloads] = new Guid("374DE290-123F-4565-9164-39C4925E467B"),
  12. [KnownFolder.Favorites] = new Guid("1777F761-68AD-4D8A-87BD-30B759FA33DD"),
  13. [KnownFolder.Links] = new Guid("BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968"),
  14. [KnownFolder.SavedGames] = new Guid("4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4"),
  15. [KnownFolder.SavedSearches] = new Guid("7D1D3A04-DEBB-4115-95CF-2F29DA2920DA")
  16. };
  17. internal static string GetPath(KnownFolder knownFolder)
  18. {
  19. return SHGetKnownFolderPath(_guids[knownFolder], 0);
  20. }
  21. [DllImport("shell32",
  22. CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
  23. private static extern string SHGetKnownFolderPath(
  24. [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags,
  25. uint hToken = 0);
  26. }
  27. }