diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-29 13:15:09 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-29 13:15:09 +0200 |
| commit | 9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966 (patch) | |
| tree | 131c98a3b19bfca2ce81259f8921c409fda7bee7 /Software/Visual_Studio/Tango.Core | |
| parent | ac3c227bb5d12339fee6fb4c243f3a5f67217915 (diff) | |
| download | Tango-9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966.tar.gz Tango-9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966.zip | |
Working on machine studio storage module.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/IO/KnownFolders.cs | 112 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Tango.Core.csproj | 3 |
2 files changed, 114 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Core/IO/KnownFolders.cs b/Software/Visual_Studio/Tango.Core/IO/KnownFolders.cs new file mode 100644 index 000000000..841b0d8c4 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/IO/KnownFolders.cs @@ -0,0 +1,112 @@ +using System; +using System.Runtime.InteropServices; + +namespace Tango.Core.IO +{ + /// <summary> + /// Class containing methods to retrieve specific file system paths. + /// </summary> + public static class KnownFolders + { + private static string[] _knownFolderGuids = new string[] + { + "{56784854-C6CB-462B-8169-88E350ACB882}", // Contacts + "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}", // Desktop + "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}", // Documents + "{374DE290-123F-4565-9164-39C4925E467B}", // Downloads + "{1777F761-68AD-4D8A-87BD-30B759FA33DD}", // Favorites + "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}", // Links + "{4BD8D571-6D19-48D3-BE97-422220080E43}", // Music + "{33E28130-4E1E-4676-835A-98395C3BC3BB}", // Pictures + "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}", // SavedGames + "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}", // SavedSearches + "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}", // Videos + }; + + /// <summary> + /// Gets the current path to the specified known folder as currently configured. This does + /// not require the folder to be existent. + /// </summary> + /// <param name="knownFolder">The known folder which current path will be returned.</param> + /// <returns>The default path of the known folder.</returns> + /// <exception cref="System.Runtime.InteropServices.ExternalException">Thrown if the path + /// could not be retrieved.</exception> + public static string GetPath(KnownFolder knownFolder) + { + return GetPath(knownFolder, false); + } + + /// <summary> + /// Gets the current path to the specified known folder as currently configured. This does + /// not require the folder to be existent. + /// </summary> + /// <param name="knownFolder">The known folder which current path will be returned.</param> + /// <param name="defaultUser">Specifies if the paths of the default user (user profile + /// template) will be used. This requires administrative rights.</param> + /// <returns>The default path of the known folder.</returns> + /// <exception cref="System.Runtime.InteropServices.ExternalException">Thrown if the path + /// could not be retrieved.</exception> + public static string GetPath(KnownFolder knownFolder, bool defaultUser) + { + return GetPath(knownFolder, KnownFolderFlags.DontVerify, defaultUser); + } + + private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags, + bool defaultUser) + { + int result = SHGetKnownFolderPath(new Guid(_knownFolderGuids[(int)knownFolder]), + (uint)flags, new IntPtr(defaultUser ? -1 : 0), out IntPtr outPath); + if (result >= 0) + { + string path = Marshal.PtrToStringUni(outPath); + Marshal.FreeCoTaskMem(outPath); + return path; + } + else + { + throw new ExternalException("Unable to retrieve the known folder path. It may not " + + "be available on this system.", result); + } + } + + [DllImport("Shell32.dll")] + private static extern int SHGetKnownFolderPath( + [MarshalAs(UnmanagedType.LPStruct)]Guid rfid, uint dwFlags, IntPtr hToken, + out IntPtr ppszPath); + + [Flags] + private enum KnownFolderFlags : uint + { + SimpleIDList = 0x00000100, + NotParentRelative = 0x00000200, + DefaultPath = 0x00000400, + Init = 0x00000800, + NoAlias = 0x00001000, + DontUnexpand = 0x00002000, + DontVerify = 0x00004000, + Create = 0x00008000, + NoAppcontainerRedirection = 0x00010000, + AliasOnly = 0x80000000 + } + } + + /// <summary> + /// Standard folders registered with the system. These folders are installed with Windows Vista + /// and later operating systems, and a computer will have only folders appropriate to it + /// installed. + /// </summary> + public enum KnownFolder + { + Contacts, + Desktop, + Documents, + Downloads, + Favorites, + Links, + Music, + Pictures, + SavedGames, + SavedSearches, + Videos + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index ca9a0a82f..16451aa4e 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -85,6 +85,7 @@ <Compile Include="..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="IO\KnownFolders.cs" /> <Compile Include="Threading\ThreadFactory.cs" /> <Compile Include="Threading\TimeoutTask.cs" /> <None Include="ActiveDirectoryAuthenticationProvider.cs" /> @@ -190,7 +191,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> |
