diff --git a/ImageManager/App.xaml.cs b/ImageManager/App.xaml.cs index cb09e55..8830c84 100644 --- a/ImageManager/App.xaml.cs +++ b/ImageManager/App.xaml.cs @@ -1,6 +1,7 @@ using HandyControl.Themes; using ImageManager.Tools; using System.Diagnostics; +using System.Reflection; using System.Windows; using System.Windows.Threading; @@ -28,8 +29,10 @@ internal void UpdateTheme(ApplicationTheme theme) // 每次启动应用程序,都会验证名称为OnlyRun的互斥是否存在 protected override void OnStartup(StartupEventArgs e) { - mutex = new Mutex(true, ResourceAssembly.GetName().Name); - if (mutex.WaitOne(0, false)) + var location = Assembly.GetEntryAssembly()!.Location; + var bs = System.Security.Cryptography.MD5.HashData(System.Text.Encoding.UTF8.GetBytes(location)); + mutex = new Mutex(true, Convert.ToBase64String(bs), out var isNewInstance); + if (isNewInstance) { try { @@ -56,25 +59,25 @@ protected override void OnStartup(StartupEventArgs e) void ThrowException(Exception e) { - - MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); Log.Error(e.ToString()); Log.ReportError(e.ToString()); + MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); } void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Exception.ToString(), "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); - e.Handled = true; Log.Error(e.Exception.ToString()); - Log.ReportError(e.ToString()); + Log.ReportError(e.Exception.ToString()); + MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Exception.Message.ToString(), "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); + e.Handled = true; } void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.ToString(), "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); - Log.Error(e.ToString()); - Log.ReportError(e.ToString()); + var ex = (Exception)e.ExceptionObject; + Log.Error(ex.ToString()); + Log.ReportError(ex.ToString()); + MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + ex.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); } } diff --git a/ImageManager/ImageManager.csproj b/ImageManager/ImageManager.csproj index c8aa975..09ea612 100644 --- a/ImageManager/ImageManager.csproj +++ b/ImageManager/ImageManager.csproj @@ -5,7 +5,7 @@ true ImageManager ImageManager - 3.1.2.0 + 3.1.3.0 Debug;Release Copyright © Nayaku 2022 enable @@ -20,7 +20,7 @@ TRACE;Core - portable + none diff --git a/ImageManager/ViewModels/MainPageViewModel.cs b/ImageManager/ViewModels/MainPageViewModel.cs index 1e79df7..1462153 100644 --- a/ImageManager/ViewModels/MainPageViewModel.cs +++ b/ImageManager/ViewModels/MainPageViewModel.cs @@ -3,7 +3,6 @@ using ImageManager.Data.Model; using ImageManager.Tools; using Microsoft.EntityFrameworkCore; -using Stylet; using StyletIoC; using System.Collections.Specialized; using System.Diagnostics; @@ -16,9 +15,6 @@ using ImageManager.Windows; using System.Windows.Input; using System.Windows.Controls; -using System.Collections.Generic; -using System.Linq; -using System; namespace ImageManager.ViewModels { @@ -96,9 +92,8 @@ public MainPageViewModel(object fatherViewModel) }; } - public async void UpdatePicture() + public void UpdatePicture() { - IQueryable query; if (_fatherViewModel is AddImageViewModel addImageViewModel) query = addImageViewModel.Pictures.AsQueryable(); @@ -214,7 +209,8 @@ public void AddPictureLabel() bool? res = WindowManager.ShowDialog(pictureAddLabelViewModel); if (res ?? false) { - var label = pictureAddLabelViewModel.ResultLabel; + var label = Context.Labels.SingleOrDefault(l => l.Name == pictureAddLabelViewModel.SearchText) + ?? new Label { Name = pictureAddLabelViewModel.SearchText }; SelectedPictures.ForEach(p => { diff --git a/ImageManager/ViewModels/PictureAddLabelViewModel.cs b/ImageManager/ViewModels/PictureAddLabelViewModel.cs index 56bd50f..51691eb 100644 --- a/ImageManager/ViewModels/PictureAddLabelViewModel.cs +++ b/ImageManager/ViewModels/PictureAddLabelViewModel.cs @@ -15,7 +15,6 @@ public class PictureAddLabelViewModel : Screen public string SearchText { get; set; } public bool ShowLabelPopup { get; set; } public List