예제 #1
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
#if FEATURE_APPX
            if (ApplicationModel.IsUap)
            {
                return(WinRTFolderPaths.GetFolderPath(folder, option));
            }
#endif

            // We're using SHGetKnownFolderPath instead of SHGetFolderPath as SHGetFolderPath is
            // capped at MAX_PATH.
            //
            // Because we validate both of the input enums we shouldn't have to care about CSIDL and flag
            // definitions we haven't mapped. If we remove or loosen the checks we'd have to account
            // for mapping here (this includes tweaking as SHGetFolderPath would do).
            //
            // The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.

            string folderGuid;

            switch (folder)
            {
            case SpecialFolder.ApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
                break;

            case SpecialFolder.CommonApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.ProgramData;
                break;

            case SpecialFolder.LocalApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.LocalAppData;
                break;

            case SpecialFolder.Cookies:
                folderGuid = Interop.Shell32.KnownFolders.Cookies;
                break;

            case SpecialFolder.Desktop:
                folderGuid = Interop.Shell32.KnownFolders.Desktop;
                break;

            case SpecialFolder.Favorites:
                folderGuid = Interop.Shell32.KnownFolders.Favorites;
                break;

            case SpecialFolder.History:
                folderGuid = Interop.Shell32.KnownFolders.History;
                break;

            case SpecialFolder.InternetCache:
                folderGuid = Interop.Shell32.KnownFolders.InternetCache;
                break;

            case SpecialFolder.Programs:
                folderGuid = Interop.Shell32.KnownFolders.Programs;
                break;

            case SpecialFolder.MyComputer:
                folderGuid = Interop.Shell32.KnownFolders.ComputerFolder;
                break;

            case SpecialFolder.MyMusic:
                folderGuid = Interop.Shell32.KnownFolders.Music;
                break;

            case SpecialFolder.MyPictures:
                folderGuid = Interop.Shell32.KnownFolders.Pictures;
                break;

            case SpecialFolder.MyVideos:
                folderGuid = Interop.Shell32.KnownFolders.Videos;
                break;

            case SpecialFolder.Recent:
                folderGuid = Interop.Shell32.KnownFolders.Recent;
                break;

            case SpecialFolder.SendTo:
                folderGuid = Interop.Shell32.KnownFolders.SendTo;
                break;

            case SpecialFolder.StartMenu:
                folderGuid = Interop.Shell32.KnownFolders.StartMenu;
                break;

            case SpecialFolder.Startup:
                folderGuid = Interop.Shell32.KnownFolders.Startup;
                break;

            case SpecialFolder.System:
                folderGuid = Interop.Shell32.KnownFolders.System;
                break;

            case SpecialFolder.Templates:
                folderGuid = Interop.Shell32.KnownFolders.Templates;
                break;

            case SpecialFolder.DesktopDirectory:
                folderGuid = Interop.Shell32.KnownFolders.Desktop;
                break;

            case SpecialFolder.Personal:
                // Same as Personal
                // case SpecialFolder.MyDocuments:
                folderGuid = Interop.Shell32.KnownFolders.Documents;
                break;

            case SpecialFolder.ProgramFiles:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFiles;
                break;

            case SpecialFolder.CommonProgramFiles:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommon;
                break;

            case SpecialFolder.AdminTools:
                folderGuid = Interop.Shell32.KnownFolders.AdminTools;
                break;

            case SpecialFolder.CDBurning:
                folderGuid = Interop.Shell32.KnownFolders.CDBurning;
                break;

            case SpecialFolder.CommonAdminTools:
                folderGuid = Interop.Shell32.KnownFolders.CommonAdminTools;
                break;

            case SpecialFolder.CommonDocuments:
                folderGuid = Interop.Shell32.KnownFolders.PublicDocuments;
                break;

            case SpecialFolder.CommonMusic:
                folderGuid = Interop.Shell32.KnownFolders.PublicMusic;
                break;

            case SpecialFolder.CommonOemLinks:
                folderGuid = Interop.Shell32.KnownFolders.CommonOEMLinks;
                break;

            case SpecialFolder.CommonPictures:
                folderGuid = Interop.Shell32.KnownFolders.PublicPictures;
                break;

            case SpecialFolder.CommonStartMenu:
                folderGuid = Interop.Shell32.KnownFolders.CommonStartMenu;
                break;

            case SpecialFolder.CommonPrograms:
                folderGuid = Interop.Shell32.KnownFolders.CommonPrograms;
                break;

            case SpecialFolder.CommonStartup:
                folderGuid = Interop.Shell32.KnownFolders.CommonStartup;
                break;

            case SpecialFolder.CommonDesktopDirectory:
                folderGuid = Interop.Shell32.KnownFolders.PublicDesktop;
                break;

            case SpecialFolder.CommonTemplates:
                folderGuid = Interop.Shell32.KnownFolders.CommonTemplates;
                break;

            case SpecialFolder.CommonVideos:
                folderGuid = Interop.Shell32.KnownFolders.PublicVideos;
                break;

            case SpecialFolder.Fonts:
                folderGuid = Interop.Shell32.KnownFolders.Fonts;
                break;

            case SpecialFolder.NetworkShortcuts:
                folderGuid = Interop.Shell32.KnownFolders.NetHood;
                break;

            case SpecialFolder.PrinterShortcuts:
                folderGuid = Interop.Shell32.KnownFolders.PrintersFolder;
                break;

            case SpecialFolder.UserProfile:
                folderGuid = Interop.Shell32.KnownFolders.Profile;
                break;

            case SpecialFolder.CommonProgramFilesX86:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
                break;

            case SpecialFolder.ProgramFilesX86:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesX86;
                break;

            case SpecialFolder.Resources:
                folderGuid = Interop.Shell32.KnownFolders.ResourceDir;
                break;

            case SpecialFolder.LocalizedResources:
                folderGuid = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
                break;

            case SpecialFolder.SystemX86:
                folderGuid = Interop.Shell32.KnownFolders.SystemX86;
                break;

            case SpecialFolder.Windows:
                folderGuid = Interop.Shell32.KnownFolders.Windows;
                break;

            default:
                return(string.Empty);
            }

            return(GetKnownFolderPath(folderGuid, option));
        }
예제 #2
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option) =>
 WinRTFolderPaths.GetFolderPath(folder, option);