-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.xaml.cs
102 lines (90 loc) · 3.53 KB
/
Settings.xaml.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml;
using System.IO;
namespace LaunchBoxPasteImage
{
/// <summary>
/// Interaction logic for Settings.xaml
/// </summary>
public partial class Settings : Window
{
public Settings()
{
InitializeComponent();
GetOrCreateSettings();
}
public void Open()
{
var w = new Settings();
w.DeleteExtraImages.IsChecked = GetSetting("DeleteExtraImages") == "True" ? true : false;
w.IgnoreRegion.IsChecked = GetSetting("IgnoreRegion") == "True" ? true : false;
w.Show();
}
public static string GetSetting(string setting)
{
GetOrCreateSettings();
string value = Globals.settings.DocumentElement.Attributes[setting].Value;
return value;
}
public static void SetSetting(string setting, string value)
{
GetOrCreateSettings();
XmlNode settingNode = Globals.settings.DocumentElement;
XmlAttribute settingAttribute = Globals.settings.CreateAttribute(setting);
settingAttribute.Value = value;
settingNode.Attributes.SetNamedItem(settingAttribute);
SaveSettings();
}
public static void SaveSettings()
{
GetOrCreateSettings();
string settingsDirectoryPath = System.IO.Directory.GetCurrentDirectory() + "\\Data\\";
string settingsFilePath = settingsDirectoryPath + "PasteImageSettings.xml";
Globals.settings.Save(settingsFilePath);
}
public static XmlDocument GetOrCreateSettings()
{
if(Globals._settings == null)
{
Globals._settings = new XmlDocument();
string settingsDirectoryPath = System.IO.Directory.GetCurrentDirectory() + "\\Data\\";
string settingsFilePath = settingsDirectoryPath + "PasteImageSettings.xml";
if (!System.IO.File.Exists(settingsFilePath))
{
StreamWriter settingsFileToWrite = System.IO.File.CreateText(settingsFilePath);
settingsFileToWrite.Write(@"<?xml version=""1.0"" standalone=""yes""?>
<Settings xmlns=""http://www.skarn-does-not-exist.com""
IgnoreRegion=""False""
DeleteExtraImages=""False"">
</Settings>");
settingsFileToWrite.Close();
}
StreamReader settingsFileToRead = new StreamReader(settingsFilePath);
Globals._settings.Load(settingsFileToRead);
settingsFileToRead.Close();
settingsFileToRead.Dispose();
}
return Globals._settings;
}
private void DeleteExtraImages_Click(object sender, RoutedEventArgs e)
{
bool? isChecked = this.DeleteExtraImages.IsChecked;
SetSetting("DeleteExtraImages", isChecked == true ? "True" : "False");
}
private void IgnoreRegion_Click(object sender, RoutedEventArgs e)
{
bool? isChecked = this.IgnoreRegion.IsChecked;
SetSetting("IgnoreRegion", isChecked == true ? "True" : "False");
}
}
}