This commit is contained in:
Chenx221 2023-10-06 17:42:54 +08:00
parent d8dd0e9f66
commit 156da8786d

View File

@ -373,7 +373,25 @@ namespace AsmrManage
}
Logp1("输入内容与选择的类别不匹配");
return;
case "Auto": // Auto Detect Type
if (keyword.StartsWith("RJ"))
{
selectedText = "H_RJ";
}
else if (keyword.StartsWith("D"))
{
selectedText = "H_D";
}
else if (keyword.StartsWith("VJ"))
{
selectedText = "H_VJ";
}
else
{
Logp1("无法自动检测类型");
return;
}
break;
case "H_D":
if (System.Text.RegularExpressions.Regex.IsMatch(keyword, @"^D\d+$"))
{
@ -408,12 +426,63 @@ namespace AsmrManage
bool Feature_Auto_Clear = checkBox6.Checked; //添加后自动清空输入框
//bool Feature_Auto_Detect_Type = checkBox7.Checked; //自动检测类型 //功能已移动
bool Feature_Auto_Backup = checkBox8.Checked; //自动备份数据库
//执行备份(如果有需要)
if(Feature_Auto_Backup)
//执行备份(如果有需要)
if (Feature_Auto_Backup)
{
// string DbPath = Program.config.DatabaseFilePath; //数据库所在位置
// 创建备份目录
string backupDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "backup");
if (!Directory.Exists(backupDir)){
Directory.CreateDirectory(backupDir);
}
// 构造备份文件名(使用日期时间作为文件名)
string backupFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".7z";
string backupFilePath = Path.Combine(backupDir, backupFileName);
string sevenZipPath;
// 判断系统位数
if (Environment.Is64BitOperatingSystem)
{
sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64", "7za.exe");
}
else
{
sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7za.exe");
}
if (!File.Exists(sevenZipPath))
{
Logp1("错误丢失7za.exe文件");
return;
}
// 执行备份
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = sevenZipPath; // 7-Zip的可执行文件路径
processInfo.Arguments = $"a -mx9 \"{backupFilePath}\" \"{DbPath}\""; // 执行7z压缩命令
Process process = new Process();
process.StartInfo = processInfo;
process.Start();
process.WaitForExit();
// 检查备份是否成功
if (File.Exists(backupFilePath))
{
Logp1($"自动备份成功!数据库已备份至{backupFilePath}");
}
else
{
Logp1("备份失败!");
return;
}
}
//开始查找
//pending
}
private void button17_Click(object sender, EventArgs e) //P3 读取信息