From d5f4902663da580c6a2d75079b93ede677310a0e Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sun, 6 Mar 2022 16:32:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E9=87=8D=E5=A4=8D=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=9B=BE=E7=89=87=E5=90=8EFile.Move()=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi.Core/Storage/StorageCover.cs | 10 ++++++---- DownKyi.Core/Storage/StorageHeader.cs | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/DownKyi.Core/Storage/StorageCover.cs b/DownKyi.Core/Storage/StorageCover.cs index ce45c31..a1556aa 100644 --- a/DownKyi.Core/Storage/StorageCover.cs +++ b/DownKyi.Core/Storage/StorageCover.cs @@ -165,12 +165,14 @@ namespace DownKyi.Core.Storage { string destFile = $"{StorageManager.GetCover()}/{md5}"; - // 如果不存在 - if (!File.Exists(destFile)) + try { - // 移动到指定位置 - File.Move(localFile, destFile); + File.Delete(destFile); } + catch { } + + // 移动到指定位置 + File.Move(localFile, destFile); return md5; } diff --git a/DownKyi.Core/Storage/StorageHeader.cs b/DownKyi.Core/Storage/StorageHeader.cs index d38ff91..09a768a 100644 --- a/DownKyi.Core/Storage/StorageHeader.cs +++ b/DownKyi.Core/Storage/StorageHeader.cs @@ -28,7 +28,7 @@ namespace DownKyi.Core.Storage public BitmapImage GetHeaderThumbnail(long mid, string name, string url, int width, int height) { string header = GetHeader(mid, name, url); - if(header == null) { return null; } + if (header == null) { return null; } return GetHeaderThumbnail(header, width, height); } @@ -42,6 +42,8 @@ namespace DownKyi.Core.Storage /// public BitmapImage GetHeaderThumbnail(string header, int width, int height) { + if (header == null) { return null; } + var bitmap = new Bitmap(header); var thumbnail = bitmap.GetThumbnailImage(width, height, null, IntPtr.Zero); @@ -141,7 +143,16 @@ namespace DownKyi.Core.Storage if (File.Exists(localFile)) { - File.Move(localFile, $"{StorageManager.GetHeader()}/{md5}"); + string destFile = $"{StorageManager.GetHeader()}/{md5}"; + + try + { + File.Delete(destFile); + } + catch { } + + // 移动到指定位置 + File.Move(localFile, destFile); return md5; }