Skip to content

Commit

Permalink
perf(config): Configuration error Backup configuration file first
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Feb 1, 2024
1 parent 3c556c7 commit d5235aa
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion STranslate/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,24 @@ private ConfigModel ReadConfig()
}
catch (Exception ex)
{
LogService.Logger.Error("[READ CONFIG] 读取配置错误,本次运行加载初始化配置...", ex);
// 备份当前config
var path = BackupCurrentConfig();

LogService.Logger.Error($"[READ CONFIG] 读取配置错误,已备份旧配置至: {path} 当前加载初始化配置...", ex);
return InitialConfig();
}
}

/// <summary>
/// 备份当前配置文件
/// </summary>
private string BackupCurrentConfig()
{
var backupFilePath = $"{ApplicationData}\\{_appName.ToLower()}_{DateTime.Now:yyyyMMdd_HHmmssfff}.json";
File.Copy(CnfName, backupFilePath, true );
return backupFilePath;
}

private void WriteConfig(ConfigModel conf)
{
var copy = conf.ServiceDeepClone();
Expand Down

0 comments on commit d5235aa

Please sign in to comment.