From 54fcc0bc37d27775292bd3c6a64dc4ba627bb885 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Sun, 20 May 2018 19:47:34 +0200 Subject: [PATCH] NativeAPI UWP --- AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj | 4 +-- AideDeJeu/AideDeJeu.UWP/NativeAPI.cs | 30 ++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj b/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj index 210c9124..7e1137ee 100644 --- a/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj +++ b/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj @@ -102,9 +102,9 @@ Designer - + Assets\database.db - + diff --git a/AideDeJeu/AideDeJeu.UWP/NativeAPI.cs b/AideDeJeu/AideDeJeu.UWP/NativeAPI.cs index 72d24e5c..393100b9 100644 --- a/AideDeJeu/AideDeJeu.UWP/NativeAPI.cs +++ b/AideDeJeu/AideDeJeu.UWP/NativeAPI.cs @@ -1,14 +1,20 @@ using AideDeJeu.Tools; using System.IO; +using System.Reflection; +using Windows.ApplicationModel; -[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Droid.Version_Android))] -namespace AideDeJeu.Droid +[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.UWP.Version_UWP))] +namespace AideDeJeu.UWP { - public class Version_Android : INativeAPI + public class Version_UWP : INativeAPI { public string GetVersion() { - return ""; + Package package = Package.Current; + PackageId packageId = package.Id; + PackageVersion version = packageId.Version; + + return string.Format("{0}.{1}", version.Major, version.Minor); } public int GetBuild() @@ -18,7 +24,21 @@ namespace AideDeJeu.Droid public string GetDatabasePath(string databaseName) { - return Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, databaseName); + var documentsDirectoryPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path; + var path = Path.Combine(documentsDirectoryPath, databaseName); + + if (!File.Exists(path)) + { + var assembly = typeof(Version_UWP).GetTypeInfo().Assembly; + using (var inStream = assembly.GetManifestResourceStream("AideDeJeu.UWP.Assets." + databaseName)) + { + using (var outStream = new FileStream(path, FileMode.Create)) + { + inStream.CopyTo(outStream); + } + } + } + return path; } } } \ No newline at end of file