forked from bmsimons/huecli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preferences.cs
49 lines (44 loc) · 1.31 KB
/
Preferences.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
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
namespace huecli
{
public class Preferences
{
public string PreferencesFile { get; set; }
public string PreferencesString { get; set; }
public FileStream fs { get; set; }
public Preferences(string file = null)
{
if (file == null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
PreferencesFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\huecli-preferences.json";
}
else
{
PreferencesFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"/huecli-preferences.json";
}
}
else
{
PreferencesFile = file;
}
}
public void Load()
{
fs = File.Open(PreferencesFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
}
public void Save()
{
byte[] contents = new UTF8Encoding(true).GetBytes(PreferencesString);
fs.Write(contents, 0, contents.Length);
}
public void Close()
{
fs.Close();
}
}
}