Skip to content

Commit

Permalink
修改图片Hash数据库的存储方式;
Browse files Browse the repository at this point in the history
修改感知Hash的计算和判断方式;
添加图片数据库的导入和导出 #1;
添加文件夹的导入;
修改日志记录器;
修改项目组织结构;
增加新的转换器;
更新包;
修正了添加图片时,添加已有标签后出错的bug。
  • Loading branch information
nayaku committed Sep 13, 2023
1 parent fa7f617 commit 63d6769
Show file tree
Hide file tree
Showing 42 changed files with 1,638 additions and 564 deletions.
5 changes: 3 additions & 2 deletions ImageManager/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
x:Class="ImageManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:ImageManager.Tools.Converter"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:ImageManager"
xmlns:local2="clr-namespace:ImageManager.Views"
xmlns:s="https://github.com/canton7/Stylet">
<Application.Resources>
<s:ApplicationLoader>
Expand All @@ -23,7 +23,8 @@
<Setter Property="OtherButtonBackground" Value="{DynamicResource DangerBrush}" />
<Setter Property="MinHeight" Value="100" />
</Style>
<local2:StyleConverter x:Key="StyleConverter" />
<conv:StyleConverter x:Key="StyleConverter" />
<conv:IsNullOrEmptyToVisibilityConverter x:Key="IsNullOrEmptyToVisibilityConverter" />
</ResourceDictionary>
</s:ApplicationLoader.MergedDictionaries>
</s:ApplicationLoader>
Expand Down
12 changes: 5 additions & 7 deletions ImageManager/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using HandyControl.Themes;
using ImageManager.Tools;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using System.Windows.Threading;
using LoggerFactory = ImageManager.Logging.LoggerFactory;
using LogLevel = ImageManager.Logging.LogLevel;

namespace ImageManager
{
Expand Down Expand Up @@ -59,24 +60,21 @@ protected override void OnStartup(StartupEventArgs e)

void ThrowException(Exception e)
{
Log.Error(e.ToString());
Log.ReportError(e.ToString());
LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: e);
MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
}

void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Log.Error(e.Exception.ToString());
Log.ReportError(e.Exception.ToString());
LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: e.Exception);
MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Exception.Message.ToString(), "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
e.Handled = true;
}

void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
Log.Error(ex.ToString());
Log.ReportError(ex.ToString());
LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: ex);
MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + ex.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
}

Expand Down
15 changes: 13 additions & 2 deletions ImageManager/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
using ImageManager.Data;
using ImageManager.Logging;
using ImageManager.Migrations;
using ImageManager.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using StyletIoC;

namespace ImageManager
{
public class Bootstrapper : Bootstrapper<RootViewModel>
{
private Logging.Logger _logger = LoggerFactory.GetLogger(nameof(Bootstrapper));
protected override void ConfigureIoC(IStyletIoCBuilder builder)
{
var userSettingData = UserSettingData.Default;
builder.Bind<UserSettingData>().ToInstance(userSettingData);
// create Database context

// 准备数据库
var context = new ImageContext();
context.Database.Migrate();
var migrator = context.GetService<IMigrator>();
foreach (var migration in context.Database.GetPendingMigrations())
{
migrator.MigrateEx(migration, context);
}
// 为每个窗体都配置一个DB上下文
builder.Bind<ImageContext>()
.ToFactory(container => new ImageContext());


// 清理
Task.Run(() =>
{
Expand Down
5 changes: 5 additions & 0 deletions ImageManager/Data/Model/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public override bool Equals(object? obj)
}
return false;
}

public override int GetHashCode()
{
return Name.GetHashCode();
}
}
}
38 changes: 32 additions & 6 deletions ImageManager/Data/Model/Picture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using ImageManager.Logging;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Windows.Media.Imaging;
Expand Down Expand Up @@ -36,9 +37,10 @@ public class Picture
public int Width { get; set; }
public int Height { get; set; }
public DateTime AddTime { get; set; }
public string Hash { get; set; }
public ulong? WeakHash { get; set; }
public virtual List<Label> Labels { get; set; }
public byte[] Hash { get; set; }
[Required]
public byte[]? WeakHash { get; set; }
public virtual List<Label> Labels { get; set; } = new();

[NotMapped]
public bool AcceptToAdd { get; set; }
Expand All @@ -51,9 +53,9 @@ public PictureAddStateEnum AddState
{
get
{
if (SamePicture != null && SamePicture.Count > 0)
if (SamePicture?.Any() ?? false)
return PictureAddStateEnum.SameConflict;
if (SimilarPictures != null && SimilarPictures.Count > 0)
if (SimilarPictures?.Any() ?? false)
return PictureAddStateEnum.SimilarConflict;
return PictureAddStateEnum.WaitToAdd;
}
Expand Down Expand Up @@ -109,5 +111,29 @@ public void CopyTo(string folderPath)
}
ImageFolderPath = folderPath;
}

public void SafeDeleteFile()
{
var logger = LoggerFactory.GetLogger(nameof(Picture));
try
{
File.Delete(System.IO.Path.Join(ImageFolderPath, Path));
}
catch (Exception e)
{
logger.Error(e);
}
if (ThumbnailPath != null)
{
try
{
File.Delete(System.IO.Path.Join(ImageFolderPath, ThumbnailPath));
}
catch (Exception e)
{
logger.Error(e);
}
}
}
}
}
Loading

0 comments on commit 63d6769

Please sign in to comment.