-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.cs
More file actions
143 lines (131 loc) · 5.54 KB
/
Copy pathConfig.cs
File metadata and controls
143 lines (131 loc) · 5.54 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace ShowWrite
{
public class KeystonePoints
{
public float TLX { get; set; }
public float TLY { get; set; }
public float TRX { get; set; }
public float TRY { get; set; }
public float BRX { get; set; }
public float BRY { get; set; }
public float BLX { get; set; }
public float BLY { get; set; }
public string AspectRatio { get; set; } = "自由";
}
public class PenSettings
{
public int Denominator { get; set; } = 30;
public float RatioMin { get; set; } = 0.3f;
public float RatioMax { get; set; } = 1.5f;
public float SpeedThresholdFast { get; set; } = 15f;
public float SpeedThresholdSlow { get; set; } = 5f;
public float RatioChangeCoefficient { get; set; } = 0.95f;
public double PalmEraserThreshold { get; set; } = 5000.0;
public bool EnablePalmEraser { get; set; } = true;
public bool IsInfraredScreen { get; set; } = false;
public double PalmTouchMultiplier { get; set; } = 1.0;
public int PalmActivationSamples { get; set; } = 2;
public int PalmReleaseSamples { get; set; } = 3;
}
public class RandomNoteConfig
{
public bool Enabled { get; set; } = false;
public int DefaultCameraIndex { get; set; } = -1;
public int MicrophoneIndex { get; set; } = -1;
public string SavePath { get; set; } = "";
public string ShortcutKey { get; set; } = "Alt+Z";
public int RecordingDurationMinutes { get; set; } = 5;
}
public class OcrSettings
{
// 启用 OCR 识别目录(禁用后照片栏只显示照片选项卡,隐藏底部选择条)
public bool EnableOcrDirectory { get; set; } = true;
// 当前选用的模型集 Key(v4-mobile / v4-server / custom)
public string ModelSet { get; set; } = "v4-mobile";
// 是否启用版面分析(PicoDet 中文版面模型,识别标题/正文/表格区域;关闭则用字号聚类猜标题)
public bool EnableLayout { get; set; } = true;
// 版面分析模型 Key(picodet-layout-ch = PicoDet 中文 11 类)
public string LayoutModel { get; set; } = "picodet-layout-ch";
// 自定义模型路径(ModelSet=="custom" 时生效;cls 留空则用自带)
public string? CustomDetPath { get; set; }
public string? CustomRecPath { get; set; }
public string? CustomDictPath { get; set; }
public string? CustomClsPath { get; set; }
}
public class Config
{
public List<int> AvailableCameraIndices { get; set; } = new();
public Dictionary<int, string> AvailableCameraNames { get; set; } = new();
public DateTime LastScanTime { get; set; }
public int CurrentCameraIndex { get; set; } = 0;
public Dictionary<int, KeystonePoints> CameraKeystoneSettings { get; set; } = new();
public PenSettings PenSettings { get; set; } = new PenSettings();
public List<string> EnabledPlugins { get; set; } = new();
public string Theme { get; set; } = "Dark";
// 是否显示板中板按钮(默认不显示)
public bool ShowPictureInPicture { get; set; } = false;
// 摄像头保活:显示照片时不断开摄像头,返回时立即恢复画面
public bool CameraKeepAlive { get; set; } = false;
// 是否显示照片栏滚动条
public bool ShowPhotoPanelScrollbar { get; set; } = true;
// 启动图版本 API(默认当前使用的地址)
public string BootImageApiUrl { get; set; } = "https://sxvillage.dpdns.org/bootp/api/app";
public RandomNoteConfig RandomNote { get; set; } = new RandomNoteConfig();
public OcrSettings Ocr { get; set; } = new OcrSettings();
private static readonly string ConfigPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"ShowWrite",
"config.json");
public static string GetPluginsPath()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"ShowWrite",
"PKG");
}
/// <summary>
/// 启动图所在的目录(配置目录下的 bootP 文件夹)。
/// </summary>
public static string GetBootPath()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"ShowWrite",
"bootP");
}
public static Config Load()
{
try
{
if (File.Exists(ConfigPath))
{
var json = File.ReadAllText(ConfigPath);
return JsonSerializer.Deserialize<Config>(json) ?? new Config();
}
}
catch { }
return new Config();
}
public void Save()
{
try
{
var dir = Path.GetDirectoryName(ConfigPath);
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
var json = JsonSerializer.Serialize(this, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(ConfigPath, json);
}
catch { }
}
}
}