From 6b1e5ac27410e31708cc1da84acf0b0501f5be1d Mon Sep 17 00:00:00 2001 From: William Bradley Date: Tue, 17 Oct 2017 19:10:44 +1300 Subject: [PATCH] -Added Base Folder Redirection for NetCore, you can now use the System's AppData folder, or a local folder in your Binaries folder. -Made NETCore a .NET Core 2.0 Library. -Added missing Pictures Enum. --- PlatformBindings-Core/Enums/PathRoot.cs | 1 + PlatformBindings-NETCore/NETCoreServices.cs | 2 ++ .../PlatformBindings-NETCore.csproj | 2 +- .../Services/CoreIOBindings.cs | 33 ++++++++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/PlatformBindings-Core/Enums/PathRoot.cs b/PlatformBindings-Core/Enums/PathRoot.cs index 765eedb..2bd5669 100644 --- a/PlatformBindings-Core/Enums/PathRoot.cs +++ b/PlatformBindings-Core/Enums/PathRoot.cs @@ -9,6 +9,7 @@ public enum PathRoot Application, Downloads, Videos, + Pictures, Documents, Music } diff --git a/PlatformBindings-NETCore/NETCoreServices.cs b/PlatformBindings-NETCore/NETCoreServices.cs index 0efe56d..768c951 100644 --- a/PlatformBindings-NETCore/NETCoreServices.cs +++ b/PlatformBindings-NETCore/NETCoreServices.cs @@ -11,6 +11,8 @@ public NETCoreServices() : base(true) IO = new CoreIOBindings(); } + public static bool UseGlobalAppData = true; + public override Version GetAppVersion() { throw new NotImplementedException(); diff --git a/PlatformBindings-NETCore/PlatformBindings-NETCore.csproj b/PlatformBindings-NETCore/PlatformBindings-NETCore.csproj index a8b519a..87c4169 100644 --- a/PlatformBindings-NETCore/PlatformBindings-NETCore.csproj +++ b/PlatformBindings-NETCore/PlatformBindings-NETCore.csproj @@ -1,7 +1,7 @@ - netcoreapp1.1 + netcoreapp2.0 PlatformBindings PlatformBindings-NETCore .NET Core Head for the .NET Platform Bindings Framework diff --git a/PlatformBindings-NETCore/Services/CoreIOBindings.cs b/PlatformBindings-NETCore/Services/CoreIOBindings.cs index 9292a14..1d5d216 100644 --- a/PlatformBindings-NETCore/Services/CoreIOBindings.cs +++ b/PlatformBindings-NETCore/Services/CoreIOBindings.cs @@ -6,6 +6,7 @@ using PlatformBindings.Models.FileSystem; using PlatformBindings.Models.Settings; using System.Reflection; +using PlatformBindings.Common; namespace PlatformBindings.Services { @@ -70,8 +71,38 @@ public override FolderContainerBase GetBaseFolder(PathRoot Root) { switch (Root) { - default: + case PathRoot.LocalAppStorage: + case PathRoot.RoamingAppStorage: + case PathRoot.AppStorageNoBackup: + if (NETCoreServices.UseGlobalAppData) + { + var folder = Root == PathRoot.LocalAppStorage ? Environment.SpecialFolder.LocalApplicationData : Environment.SpecialFolder.ApplicationData; + return new CoreFolderContainer(Environment.GetFolderPath(folder)); + } + else return new CoreFolderContainer(PlatformBindingHelpers.ResolvePath(new FolderPath(PathRoot.Application, "AppData"))); + + case PathRoot.Documents: + return new CoreFolderContainer(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); + + case PathRoot.Pictures: + return new CoreFolderContainer(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)); + + case PathRoot.Videos: + return new CoreFolderContainer(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)); + + case PathRoot.Music: + return new CoreFolderContainer(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)); + + case PathRoot.Downloads: + var path = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); + path = Path.Combine(path, "Downloads"); + return new CoreFolderContainer(path); + + case PathRoot.Application: return new CoreFolderContainer(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); + + default: + return null; } }