-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSettingsManager.cs
106 lines (99 loc) · 3.23 KB
/
SettingsManager.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Latex4CorelDraw
{
public class SettingsManager
{
static private SettingsManager m_current = null;
private Settings m_settings;
public Settings SettingsData
{
get { return m_settings; }
set { m_settings = value; }
}
public SettingsManager()
{
m_settings = new Settings();
}
public static SettingsManager getCurrent()
{
if (m_current == null)
{
m_current = new SettingsManager();
m_current.loadSettings();
}
return m_current;
}
// Serialization
public void saveSettings()
{
try
{
string path = AddinUtilities.getAppDataLocation();
XmlSerializer s = new XmlSerializer(typeof(Settings));
TextWriter w = new StreamWriter(path + "\\settings.xml");
s.Serialize(w, m_settings);
w.Close();
}
catch (Exception ex)
{
MessageBox.Show("Exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Deserialization
public bool loadSettings()
{
bool result = true;
try
{
string path = AddinUtilities.getAppDataLocation();
XmlSerializer s = new XmlSerializer(typeof(Settings));
TextReader r = new StreamReader(path + "\\settings.xml");
m_settings = (Settings)s.Deserialize(r);
r.Close();
}
catch
{
// Set default values
m_settings = new Settings();
m_settings.textColor = "0,0,0";
m_settings.fontSize = "12";
m_settings.font = "Times Roman";
m_settings.fontSeries = "Standard";
m_settings.fontShape = "Standard";
m_settings.insertAtCursor = true;
result = false;
}
// If the miktex path was not found, try to find it in the registry
if ((m_settings.miktexPath == null) || (m_settings.miktexPath == ""))
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MiKTeX 2.8", false);
if (key != null)
{
m_settings.miktexPath = (string)key.GetValue("InstallLocation", "");
if (m_settings.miktexPath != "")
{
m_settings.miktexPath += "\\miktex\\bin";
}
}
}
return result;
}
}
public class Settings
{
public string textColor;
public string fontSize;
public string miktexPath;
public string font;
public string fontSeries;
public string fontShape;
public bool insertAtCursor;
}
}