This repository has been archived by the owner on Oct 24, 2021. It is now read-only.
forked from null7323/QMidiCore-Quaver-Stream-Renderer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfig.cs
73 lines (69 loc) · 2.11 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
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QQS_UI
{
public struct DialogPath
{
public string MidiDirectory;
public string VideoDirectory;
public string ColorDirectory;
}
/// <summary>
/// 表示用于存储Midi文件夹路径和视频文件夹路径.
/// </summary>
public class Config
{
private DialogPath ConfigPath;
private readonly string ConfigName;
/// <summary>
/// 初始化一个新的 <see cref="Config"/> 实例.
/// </summary>
/// <param name="configName">配置文件的文件名, 需要".json"后缀.</param>
public Config(string configName = "config.json")
{
ConfigName = configName;
if (File.Exists(configName))
{
try
{
string jsonData = File.ReadAllText(configName);
ConfigPath = JsonConvert.DeserializeObject<DialogPath>(jsonData);
}
catch
{
File.Create(ConfigName).Close();
ConfigPath = new DialogPath();
}
}
else
{
File.Create(ConfigName).Close();
ConfigPath = new DialogPath();
}
}
public string CachedVideoDirectory
{
get => ConfigPath.VideoDirectory;
set => ConfigPath.VideoDirectory = value;
}
public string CachedColorDirectory
{
get => ConfigPath.ColorDirectory;
set => ConfigPath.ColorDirectory = value;
}
public string CachedMIDIDirectory
{
get => ConfigPath.MidiDirectory;
set => ConfigPath.MidiDirectory = value;
}
public void SaveConfig()
{
File.WriteAllText(ConfigName, JsonConvert.SerializeObject(ConfigPath));
}
}
}