diff --git a/source/Trek-12/DataContractPersistence/DataContractJson.cs b/source/Trek-12/DataContractPersistence/DataContractJson.cs index 83f745a..2307f82 100644 --- a/source/Trek-12/DataContractPersistence/DataContractJson.cs +++ b/source/Trek-12/DataContractPersistence/DataContractJson.cs @@ -26,13 +26,13 @@ namespace DataContractPersistence /// /// Path (relative to the project) /// - public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); + public string FilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Trek_12"); /// /// Load all the data from JSON file /// /// A tuple with the lists of players, games, maps and best scores - public (List, List, List, List) LoadData() + public (ObservableCollection, ObservableCollection, ObservableCollection, ObservableCollection) LoadData() { var JsonSerializer = new DataContractJsonSerializer(typeof(DataToPersist)); DataToPersist? data = new DataToPersist(); @@ -52,8 +52,9 @@ namespace DataContractPersistence /// /// /// - public void SaveData(List players, List games, List maps, List bestScores) + public void SaveData(ObservableCollection players, ObservableCollection games, ObservableCollection maps, ObservableCollection bestScores) { + Debug.WriteLine("Saving data at " + Path.Combine(FilePath, FileName)); if (!Directory.Exists(FilePath)) { Debug.WriteLine("Directory created"); diff --git a/source/Trek-12/DataContractPersistence/DataContractXml.cs b/source/Trek-12/DataContractPersistence/DataContractXml.cs index e09489d..8255ecc 100644 --- a/source/Trek-12/DataContractPersistence/DataContractXml.cs +++ b/source/Trek-12/DataContractPersistence/DataContractXml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Text; @@ -23,13 +24,13 @@ namespace DataContractPersistence /// /// Path (relative to the project) /// - public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); + public string FilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Trek_12"); /// /// Load all the data from XML file /// /// A tuple with the lists of players, games, maps and best scores - public (List, List, List, List) LoadData() + public (ObservableCollection, ObservableCollection, ObservableCollection, ObservableCollection) LoadData() { var serializer = new DataContractSerializer(typeof(DataToPersist)); DataToPersist? data = new DataToPersist(); @@ -49,7 +50,7 @@ namespace DataContractPersistence /// /// /// - public void SaveData(List players, List games, List maps, List bestScores) + public void SaveData(ObservableCollection players, ObservableCollection games, ObservableCollection maps, ObservableCollection bestScores) { if(!Directory.Exists(FilePath)) { diff --git a/source/Trek-12/DataContractPersistence/DataToPersist.cs b/source/Trek-12/DataContractPersistence/DataToPersist.cs index 8aca714..b78b204 100644 --- a/source/Trek-12/DataContractPersistence/DataToPersist.cs +++ b/source/Trek-12/DataContractPersistence/DataToPersist.cs @@ -8,21 +8,21 @@ namespace DataContractPersistence /// /// List of players /// - public List Players { get; set; } + public ObservableCollection Players { get; set; } /// /// List of games (with all the data in it to be able to recreate the game) /// - public List Games { get; set; } + public ObservableCollection Games { get; set; } /// /// List of maps with their boards /// - public List Maps { get; set; } + public ObservableCollection Maps { get; set; } /// /// List of best scores /// - public List BestScores { get; set; } + public ObservableCollection BestScores { get; set; } } } \ No newline at end of file