From e0f3c978cd0513a143d9ff79ef3a2dd67daa3225 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sun, 24 Oct 2021 15:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=90=8C=E6=97=B6=E5=90=91?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=8F=92=E5=85=A5=E6=97=B6=E5=86=B2?= =?UTF-8?q?=E7=AA=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi.Core/Storage/Database/CoverDb.cs | 29 ++++++++++++++++++---- DownKyi.Core/Storage/Database/HeaderDb.cs | 30 ++++++++++++++++++----- DownKyi.Core/Storage/StorageCover.cs | 9 ++++++- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/DownKyi.Core/Storage/Database/CoverDb.cs b/DownKyi.Core/Storage/Database/CoverDb.cs index bcaea92..15ba8ea 100644 --- a/DownKyi.Core/Storage/Database/CoverDb.cs +++ b/DownKyi.Core/Storage/Database/CoverDb.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using DownKyi.Core.Logging; +using System; +using System.Collections.Generic; namespace DownKyi.Core.Storage.Database { @@ -26,8 +28,16 @@ namespace DownKyi.Core.Storage.Database /// public void Insert(Cover cover) { - string sql = $"insert into cover values ({cover.Avid}, '{cover.Bvid}', {cover.Cid}, '{cover.Url}', '{cover.Md5}')"; - dbHelper.ExecuteNonQuery(sql); + try + { + string sql = $"insert into cover values ({cover.Avid}, '{cover.Bvid}', {cover.Cid}, '{cover.Url}', '{cover.Md5}')"; + dbHelper.ExecuteNonQuery(sql); + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("Insert()发生异常: {0}", e); + LogManager.Error("CoverDb", e); + } } /// @@ -36,8 +46,17 @@ namespace DownKyi.Core.Storage.Database /// public void Update(Cover cover) { - string sql = $"update cover set avid={cover.Avid}, bvid='{cover.Bvid}', cid={cover.Cid}, md5='{cover.Md5}' where url glob '{cover.Url}'"; - dbHelper.ExecuteNonQuery(sql); + try + { + string sql = $"update cover set avid={cover.Avid}, bvid='{cover.Bvid}', cid={cover.Cid}, md5='{cover.Md5}' where url glob '{cover.Url}'"; + dbHelper.ExecuteNonQuery(sql); + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("Update()发生异常: {0}", e); + LogManager.Error("CoverDb", e); + } + } /// diff --git a/DownKyi.Core/Storage/Database/HeaderDb.cs b/DownKyi.Core/Storage/Database/HeaderDb.cs index 6cb4500..67d3d06 100644 --- a/DownKyi.Core/Storage/Database/HeaderDb.cs +++ b/DownKyi.Core/Storage/Database/HeaderDb.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using DownKyi.Core.Logging; +using System; +using System.Collections.Generic; namespace DownKyi.Core.Storage.Database { @@ -26,8 +28,16 @@ namespace DownKyi.Core.Storage.Database /// public void Insert(Header header) { - string sql = $"insert into header values ({header.Mid}, '{header.Name}', '{header.Url}', '{header.Md5}')"; - dbHelper.ExecuteNonQuery(sql); + try + { + string sql = $"insert into header values ({header.Mid}, '{header.Name}', '{header.Url}', '{header.Md5}')"; + dbHelper.ExecuteNonQuery(sql); + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("Insert()发生异常: {0}", e); + LogManager.Error("HeaderDb", e); + } } /// @@ -36,8 +46,16 @@ namespace DownKyi.Core.Storage.Database /// public void Update(Header header) { - string sql = $"update header set name='{header.Name}', url='{header.Url}', md5='{header.Md5}' where mid={header.Mid}"; - dbHelper.ExecuteNonQuery(sql); + try + { + string sql = $"update header set name='{header.Name}', url='{header.Url}', md5='{header.Md5}' where mid={header.Mid}"; + dbHelper.ExecuteNonQuery(sql); + } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("Update()发生异常: {0}", e); + LogManager.Error("HeaderDb", e); + } } /// @@ -89,7 +107,7 @@ namespace DownKyi.Core.Storage.Database Mid = (long)reader["mid"], Name = (string)reader["name"], Url = (string)reader["url"], - Md5=(string)reader["md5"] + Md5 = (string)reader["md5"] }; headers.Add(header); } diff --git a/DownKyi.Core/Storage/StorageCover.cs b/DownKyi.Core/Storage/StorageCover.cs index 0ec6979..49e58c5 100644 --- a/DownKyi.Core/Storage/StorageCover.cs +++ b/DownKyi.Core/Storage/StorageCover.cs @@ -161,7 +161,14 @@ namespace DownKyi.Core.Storage if (File.Exists(localFile)) { - File.Move(localFile, $"{StorageManager.GetCover()}/{md5}"); + string destFile = $"{StorageManager.GetCover()}/{md5}"; + + // 如果不存在 + if (!File.Exists(destFile)) + { + // 移动到指定位置 + File.Move(localFile, destFile); + } return md5; }