-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.cs
61 lines (53 loc) · 1.45 KB
/
Config.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
/**********************************************************************/
/* Copyright (c) 2023 Carpe Diem Software Developing by Alex Versetty */
/* http://carpediem.0fees.us */
/**********************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CDSD.Data;
namespace TrayTextPaste
{
public class Config
{
public string CopySwitchPasteHotkey { get; set; } = "Отключить";
public string Strings { get; set; } = "";
public Config clone()
{
return (Config) MemberwiseClone();
}
}
class ConfigManager
{
static string configFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.xml");
public static Config Current { get; set; }
public static void load()
{
try {
var xml = File.ReadAllText(configFilename);
Current = Serialization.XmlDeserialize<Config>(xml);
}
catch (Exception ex) {
Current = new Config();
if (isConfigFileExists()) throw ex;
}
}
public static void save()
{
if (Current == null) throw new InvalidOperationException("Load config first");
var clone = Current.clone();
try {
var xml = Serialization.XmlSerialize(clone);
File.WriteAllText(configFilename, xml);
}
catch (Exception ex) {
throw ex;
}
}
public static bool isConfigFileExists()
{
return File.Exists(configFilename);
}
}
}