From 8109178795d70bd9d0e5eace9a1a15a489590ecd Mon Sep 17 00:00:00 2001 From: Jade_VAN_BRABANDT Date: Wed, 24 May 2023 15:23:25 +0200 Subject: [PATCH] =?UTF-8?q?Feat=20:=20Chemin=20relatif=20j'crois=20=C3=A7a?= =?UTF-8?q?=20marche=20wlh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/AppConsole/Program.cs | 5 +---- Sources/Persistance/Persistance.cs | 8 +++++--- Sources/Stim.Model/Game.cs | 2 +- Sources/Stim/App.xaml.cs | 12 ++++++++++-- Sources/Stim/MainPage.xaml.cs | 4 +++- Sources/TestProject1/Test.csproj | 1 + Sources/TestProject1/TestManager.cs | 7 ++++--- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Sources/AppConsole/Program.cs b/Sources/AppConsole/Program.cs index 4d4b74b..b38804b 100644 --- a/Sources/AppConsole/Program.cs +++ b/Sources/AppConsole/Program.cs @@ -3,7 +3,4 @@ using StimPersistance; using StimStub; using System.Collections.ObjectModel; -Console.WriteLine("Faut une ligne pour build"); -Manager Mgr = new Manager(new Stub()); -Mgr._persistance = new Persistance(); -Mgr.SaveGames(); \ No newline at end of file +Console.WriteLine("Faut une ligne pour build"); \ No newline at end of file diff --git a/Sources/Persistance/Persistance.cs b/Sources/Persistance/Persistance.cs index 6ce5867..111cf78 100644 --- a/Sources/Persistance/Persistance.cs +++ b/Sources/Persistance/Persistance.cs @@ -4,23 +4,25 @@ using System.Xml; using Microsoft.VisualBasic; using Microsoft.VisualBasic.FileIO; using Model; +using System.Runtime.InteropServices; namespace StimPersistance { public class Persistance : IPersistance { - public Persistance() + public Persistance(string chemin) { - Directory.SetCurrentDirectory("C:\\Users\\axvanbraba\\source\\repos\\Projet_IHM\\Sources\\XML"); + Directory.SetCurrentDirectory(chemin); } public void SaveGame(ObservableCollection games) { XmlWriterSettings settings = new() { Indent = true }; DataContractSerializer serializer = new(typeof(ObservableCollection)); + if (!File.Exists("games.xml")) File.Create("games.xml"); using (TextWriter tw = File.CreateText("games.xml")) - using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games); + using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games); } public void SaveUser(List users) diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index ca8fe42..767468d 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -89,7 +89,7 @@ namespace Model { Name = "Default"; Description = "Default"; - Cover = "Default"; + Cover = "Default.png"; Lien = "Default"; Year = 2023; tags = new ObservableCollection(); diff --git a/Sources/Stim/App.xaml.cs b/Sources/Stim/App.xaml.cs index 5a94200..4a3a143 100644 --- a/Sources/Stim/App.xaml.cs +++ b/Sources/Stim/App.xaml.cs @@ -1,11 +1,19 @@ -namespace Stim; +using Model; +using StimPersistance; + +namespace Stim; public partial class App : Application { + Manager Mgr + { + get; set; + } public App() { InitializeComponent(); - + string mainDir = FileSystem.Current.AppDataDirectory; + Mgr = new Manager(new Persistance(mainDir)); MainPage = new AppShell(); } } diff --git a/Sources/Stim/MainPage.xaml.cs b/Sources/Stim/MainPage.xaml.cs index 8383a66..41202c0 100644 --- a/Sources/Stim/MainPage.xaml.cs +++ b/Sources/Stim/MainPage.xaml.cs @@ -2,10 +2,12 @@ using Model; using StimPersistance; using StimStub; +using Microsoft.Maui.Storage; public partial class MainPage : ContentPage { - public IPersistance persistance = new Persistance(); + + public IPersistance persistance = new Persistance(FileSystem.Current.AppDataDirectory); public Manager Manager { get; set; } public MainPage() diff --git a/Sources/TestProject1/Test.csproj b/Sources/TestProject1/Test.csproj index e2cdbbe..17345d7 100644 --- a/Sources/TestProject1/Test.csproj +++ b/Sources/TestProject1/Test.csproj @@ -24,6 +24,7 @@ + diff --git a/Sources/TestProject1/TestManager.cs b/Sources/TestProject1/TestManager.cs index f8c210b..a7d88c1 100644 --- a/Sources/TestProject1/TestManager.cs +++ b/Sources/TestProject1/TestManager.cs @@ -1,6 +1,7 @@ using Model; using StimPersistance; - +using StimStub; + namespace Test { public class TestManager @@ -8,7 +9,7 @@ namespace Test [Fact] public void Constructor() { - IPersistance persistance = new Persistance(); + IPersistance persistance = new Stub(); Manager manager = new(persistance); Assert.NotNull(manager); } @@ -16,7 +17,7 @@ namespace Test [Fact] public void AddAndRemoveGame() { - IPersistance persistance = new Persistance(); + IPersistance persistance = new Stub(); Manager manager = new(persistance); Game game = new("game", "description", 2012, new List { "1", "2", "3" }, "cover", "www.link.com"); manager.AddGametoGamesList(game);