From 562b1330c96eb99c992bf03f1a10ece800318b6a Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 2 Sep 2020 14:12:56 +1000 Subject: [PATCH] initial work on saving settings --- Listing.cs | 8 ++++---- MainWindow.cs | 1 + Settings.cs | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Listing.cs b/Listing.cs index 921cc2b..0e4dfd1 100644 --- a/Listing.cs +++ b/Listing.cs @@ -3,13 +3,13 @@ using System.Globalization; namespace Buypeeb { class Listing { - public string url; - public string id; - public string name; + public string url { get; set; } + public string id { get; set; } + public string name { get; set; } public int price; public int win_price; public string original_name; - public bool favourite; + public bool favourite { get; set; } = false; // start_date, end_date public int bids; public bool auto_extension; diff --git a/MainWindow.cs b/MainWindow.cs index 7a03379..954669b 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -39,6 +39,7 @@ namespace Buypeeb { private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) { this.settings = new Settings(); + this.settings.Save(); this.Title = "Buypeeb"; builder.Autoconnect(this); this.items = (ListStore)builder.GetObject("ListItems"); diff --git a/Settings.cs b/Settings.cs index 8f3b7f3..5ef5235 100644 --- a/Settings.cs +++ b/Settings.cs @@ -1,11 +1,31 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Text.Json; namespace Buypeeb { + class Settings { - public Dictionary watchlist; + private string location; + + public int updateInterval { get; set; } = 10 * 60; + public int favouriteUpdateInterval { get; set; } = 5 * 60; + public int updateIntervalCritical { get; set; } = 60; + public int favouriteUpdateIntervalCritical { get; set; } = 30; + + public Dictionary watchlist { + get; set; + } public Settings() { + if (Environment.OSVersion.Platform == PlatformID.Win32NT) { + // C:\Users\Beebus\AppData\Roaming\Lynnear Software\buypeeb + this.location = Path.Combine(Environment.ExpandEnvironmentVariables("%APPDATA%"), "Lynnear Software", "buypeeb"); + } + else { + // ~/.config/Lynnear Software/buypeeb + this.location = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".config", "Lynnear Software", "buypeeb"); + } this.watchlist = new Dictionary(); this.Watch("https://buypeeb.biz/whatever/k12345", "my thingy"); this.watchlist["k12345"].Update(); @@ -20,5 +40,14 @@ namespace Buypeeb { Console.WriteLine("{0} - {1}", entry.Value.name, entry.Value.price); } } + + public void Save() { + string j = JsonSerializer.Serialize(this); + Console.WriteLine(j); + } + + // public void Load() { + + // } } }