-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
83 lines (77 loc) · 2.74 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WallHaven.WallHavenClient;
namespace WallHaven
{
public class Settings
{
private static string AppSettingPath
{
get
{
string roming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string appDataPath = Path.Combine(roming, AppName);
string appSettingPath = Path.Combine(appDataPath, "settings.json");
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
return appSettingPath;
}
}
public static string AppName
{
get
{
string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
return string.IsNullOrWhiteSpace(appName) ? "WallHaven" : appName;
}
}
public static string AppCacheImagePath => Path.Combine(AppSettingPath, "..", "wallhaven.jpg");
public static void SaveSetting(Settings setting)
{
try
{
File.WriteAllText(AppSettingPath, JsonConvert.SerializeObject(setting));
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.ToString());
}
}
public static Settings ReadSetting()
{
Settings settings = new Settings();
if (File.Exists(AppSettingPath))
{
try
{
string text = File.ReadAllText(AppSettingPath);
Settings result = JsonConvert.DeserializeObject<Settings>(text);
if (result != null) settings = result;
}
catch (Exception)
{
}
}
return settings;
}
public string APIKey { get; set; } = string.Empty;
public string BaseUrl { get; set; } = "https://wallhaven.cc/api/v1/";
public bool General { get; set; } = true;
public bool Anime { get; set; } = true;
public bool People { get; set; } = true;
public bool SFW { get; set; } = true;
public bool Sketchy { get; set; } = true;
public bool NSFW { get; set; } = true;
public bool Wide { get; set; } = true;
public bool UltraWide { get; set; } = true;
public bool Portrait { get; set; } = true;
public bool Square { get; set; } = true;
public double WindowWidth { get; set; }
public double WindowHeight { get; set; }
public Sorting Sort { get; set; } = Sorting.random;
}
}