Skip to content

Commit

Permalink
Fix: SimpleStorage data file location
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoffer committed Mar 15, 2023
1 parent e4897c1 commit 367a5df
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Matomo.Xamarin.Forms/SimpleStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ public void Put<T>(string key, T value)

private void ReadFromDisk()
{
if (File.Exists($"{_filename}.json"))
var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) ?? "";
var filepath = Path.Combine(path, $"{_filename}.json");

if (File.Exists(filepath))
{
using (TextReader file = File.OpenText($"{_filename}.json"))
using (TextReader file = File.OpenText(filepath))
{
var json = file.ReadToEnd();
_data = (Dictionary<string, object>)JsonConvert.DeserializeObject(json);
Expand All @@ -82,7 +85,10 @@ private void ReadFromDisk()

private void WriteToDisk()
{
using (StreamWriter file = File.CreateText($"{_filename}.json"))
var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) ?? "";
var filepath = Path.Combine(path, $"{_filename}.json");

using (StreamWriter file = File.CreateText(filepath))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, _data);
Expand Down

0 comments on commit 367a5df

Please sign in to comment.