This repository was archived by the owner on Sep 19, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathConfigManager.cs
More file actions
64 lines (56 loc) · 2.13 KB
/
Copy pathConfigManager.cs
File metadata and controls
64 lines (56 loc) · 2.13 KB
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
// WindowCenter — 快捷键居中 Windows 窗口
// Copyright (C) 2026 WindowCenter contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
namespace WindowCenter;
/// <summary>INI 配置文件管理(仅用户主动设置时才创建)</summary>
internal static class ConfigManager
{
private const string FileName = "config.ini";
private static string FilePath => Path.Combine(AppContext.BaseDirectory, FileName);
/// <summary>读取快捷键配置。返回 false 表示文件不存在或读取失败</summary>
public static bool TryReadHotkey(out uint modifiers, out uint vk)
{
modifiers = 0;
vk = 0;
try
{
if (!File.Exists(FilePath)) return false;
foreach (var line in File.ReadAllLines(FilePath))
{
var trimmed = line.Trim();
if (trimmed.StartsWith("Modifiers="))
uint.TryParse(trimmed["Modifiers=".Length..], out modifiers);
else if (trimmed.StartsWith("Key="))
uint.TryParse(trimmed["Key=".Length..], out vk);
}
return modifiers != 0 && vk != 0;
}
catch
{
return false;
}
}
/// <summary>保存快捷键配置(创建或覆盖 config.ini)</summary>
public static void SaveHotkey(uint modifiers, uint vk)
{
var lines = new[]
{
"[Hotkey]",
$"Modifiers={modifiers}",
$"Key={vk}",
};
File.WriteAllLines(FilePath, lines);
}
}