降低CPU使用率,处置好因降低CPU使用率带来的颜色偏差

This commit is contained in:
2026-01-31 10:43:41 +08:00
parent 6661edfc44
commit 4afbf06439
17 changed files with 360 additions and 64 deletions

View File

@@ -24,23 +24,41 @@ namespace SHH.MjpegPlayer
/// <returns></returns>
public static MjpegConfig LoadConfig()
{
// [修复] 路径处理脆弱性:使用 BaseDirectory 拼接,避免相对路径替换的风险
// 生产环境:强制使用绝对路径确保能找到配置文件
if (!Debugger.IsAttached)
try
{
JsonConfigUris.MjpegConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(JsonConfigUris.MjpegConfig));
}
// [修复] 路径处理脆弱性:使用 BaseDirectory 拼接,避免相对路径替换的风险
// 生产环境:强制使用绝对路径确保能找到配置文件
if (!Debugger.IsAttached)
{
if (!string.IsNullOrEmpty(JsonConfigUris.MjpegConfig))
JsonConfigUris.MjpegConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(JsonConfigUris.MjpegConfig));
}
// 加载配置文件
var cfg = JsonConfig.Load<MjpegConfig>(JsonConfigUris.MjpegConfig);
if (cfg == null)
{
cfg = new MjpegConfig();
JsonConfig.Save(cfg, JsonConfigUris.MjpegConfig, "MjpegServer配置项");
_sysLog.Warning("未找到配置文件,已生成默认配置: {Path}", JsonConfigUris.MjpegConfig);
// 加载配置文件
MjpegConfig? cfg = null;
if (!string.IsNullOrEmpty(JsonConfigUris.MjpegConfig))
{
cfg = JsonConfig.Load<MjpegConfig>(JsonConfigUris.MjpegConfig);
if (cfg == null)
{
cfg = new MjpegConfig();
JsonConfig.Save(cfg, JsonConfigUris.MjpegConfig, "MjpegServer配置项");
_sysLog.Warning("未找到配置文件,已生成默认配置: {Path}", JsonConfigUris.MjpegConfig);
}
MjpegStatics.Cfg = cfg;
}
if (cfg == null)
cfg = new MjpegConfig();
return cfg;
}
catch(Exception ex)
{
_sysLog.Error("加载配置文件失败.");
Console.ReadLine();
return new MjpegConfig();
}
MjpegStatics.Cfg = cfg;
return cfg;
}
#endregion