This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigMgr.cs
59 lines (50 loc) · 1.62 KB
/
ConfigMgr.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace MusicBeePlugin
{
[Serializable()]
public class ConfigMgr
{
public string MaxEntries { get; set; }
public string OutputPath { get; set; }
public void SetDefaults(string path)
{
MaxEntries = "0";
OutputPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\MusicBee\\SongHistory.txt";
SerializeConfig(path);
}
public void SerializeConfig(string path)
{
using (StreamWriter file = new StreamWriter(path, false))
{
//MessageBox.Show($"Serializing {_path}");
XmlSerializer controlsDefaultsSerializer = new XmlSerializer(typeof(ConfigMgr));
controlsDefaultsSerializer.Serialize(file, this);
file.Close();
}
}
public ConfigMgr DeserializeConfig(string path)
{
//MessageBox.Show($"Deserializing {_path}");
try
{
StreamReader file = new StreamReader(path);
XmlSerializer xSerial = new XmlSerializer(typeof(ConfigMgr));
object oData = xSerial.Deserialize(file);
var thisConfig = (ConfigMgr)oData;
file.Close();
return thisConfig;
}
catch (Exception e)
{
Console.Write(e.Message);
return null;
}
}
}
}