Skip to content

Commit

Permalink
修正错误错误;添加版本;添加Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayaku committed Feb 2, 2023
1 parent 67ad55e commit ccea151
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 62 deletions.
13 changes: 11 additions & 2 deletions ImageManager/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ImageManager.Data;
using ImageManager.ViewModels;
using Microsoft.EntityFrameworkCore;
using Stylet;
using StyletIoC;
using System;
Expand All @@ -15,11 +16,14 @@ protected override void ConfigureIoC(IStyletIoCBuilder builder)
var userSettingData = UserSettingData.Default;
builder.Bind<UserSettingData>().ToInstance(userSettingData);
// create Database context
builder.Bind<ImageContext>().ToSelf().InSingletonScope();
var context = new ImageContext();
context.Database.Migrate();
builder.Bind<ImageContext>().ToInstance(context);

// 清理文件
// 清理
Task.Run(() =>
{
// 清理待删除文件
if (userSettingData.WaitToDeleteFiles != null)
{
foreach (var file in userSettingData.WaitToDeleteFiles)
Expand All @@ -29,11 +33,16 @@ protected override void ConfigureIoC(IStyletIoCBuilder builder)
}
userSettingData.WaitToDeleteFiles = null;
}
// 清理临时文件夹
foreach (var file in Directory.GetFiles(userSettingData.TempFolderPath))
{
if (File.Exists(file))
File.Delete(file);
}
// 清理0引用的标签
var labels = context.Labels.Where(x => x.Num == 0).ToList();
context.Labels.RemoveRange(labels);
context.SaveChanges();
});
}
}
Expand Down
4 changes: 0 additions & 4 deletions ImageManager/Data/ImageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public override int SaveChanges(bool acceptAllChangesOnSuccess)
var label = ChangeTracker.Entries<Label>().Single(le => (int)le.CurrentValues["Id"] == labelId).Entity;
label.Num += e.State == EntityState.Added ? 1 : -1;
});
if (UserSettingData.Default.ClearUnUsedLabel)
ChangeTracker.Entries<Label>()
.Where(e => e.State == EntityState.Modified && (int)e.CurrentValues["Num"] == 0)
.ForEach(e => e.State = EntityState.Deleted);
return base.SaveChanges(acceptAllChangesOnSuccess);
}
}
Expand Down
8 changes: 8 additions & 0 deletions ImageManager/Data/Model/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ public class Label
public string NumToString => "(" + Num + ")";
[NotMapped]
public bool IsEdit { get; set; }
public override bool Equals(object? obj)
{
if (obj is Label label)
{
return label.Name == Name;
}
return false;
}
}
}
11 changes: 7 additions & 4 deletions ImageManager/ImageManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
<UseWPF>true</UseWPF>
<AssemblyName>ImageManager</AssemblyName>
<RootNamespace>ImageManager</RootNamespace>
<Version>1.0.0.0</Version>
<Version>3.1.0.0</Version>
<Configurations>Debug;Release</Configurations>
<Copyright>Copyright © ZMK 2022</Copyright>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Copyright>Copyright © Nayaku 2022</Copyright>
<FileVersion>3.1.0.0</FileVersion>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>icon.ico</ApplicationIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<Resource Include="icon.ico">
Expand Down
Binary file removed ImageManager/Resources/MainIcon.ico
Binary file not shown.
Binary file removed ImageManager/Resources/icon.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions ImageManager/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Stylet;
using System.Reflection;

namespace ImageManager.ViewModels
{
public class AboutViewModel : PropertyChangedBase
{
public string Version { get => Assembly.GetEntryAssembly().GetName().Version.ToString(); }

public void OpenProjectHome()
{
System.Diagnostics.Process.Start("explorer.exe", "https://github.com/nayaku/ImageManager");
}

}
}
16 changes: 0 additions & 16 deletions ImageManager/ViewModels/AddImageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,6 @@ public async void CancelAsync()
{
return;
}
_isWorking = true;
var dialog = Dialog.Show(new WaitingDialog());
await Task.Run(() =>
{
Pictures.ForEach(p =>
{
var file = Path.Combine(p.ImageFolderPath, p.Path);
File.Delete(file);
if (p.ThumbnailPath != null)
{
var thumbnailFile = Path.Combine(p.ImageFolderPath, p.ThumbnailPath);
File.Delete(thumbnailFile);
}
});
});
dialog.Close();
_canClose = true;
Result = false;
RequestClose();
Expand Down
4 changes: 4 additions & 0 deletions ImageManager/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public void SizeChanged(object sender, SizeChangedEventArgs e)
#region 右键菜单栏
public void OpenPicture(object sender, MouseButtonEventArgs e)
{
if (IsAddPictureMode)
return;
var picture = ((PictureSelectableItemWrapper)((Image)sender).DataContext).Item;
var sticker = new StickerWindow(Path.Join(picture.ImageFolderPath, picture.Path));
sticker.Show();
Expand Down Expand Up @@ -216,10 +218,12 @@ public void AddPictureLabel()

SelectedPictures.ForEach(p =>
{
p.Labels ??= new List<Label>();
if (!p.Labels.Contains(label))
p.Labels.Add(label);
});
Pictures.Refresh();
NotifyOfPropertyChange(nameof(PictureGroups));
if (!IsAddPictureMode)
Context.SaveChanges();
}
Expand Down
6 changes: 3 additions & 3 deletions ImageManager/ViewModels/ProgressViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private void ProcessFile(string file)
thumbFileName = saveFileName + "_s.png";
if (width > UserSettingData.ThumbnailWidth)
{
int targetWidth, targetHeight;
targetWidth = UserSettingData.ThumbnailWidth;
using var thumb = ImageUtility.Resize(bitmap, targetWidth);
int targetWidth = UserSettingData.ThumbnailWidth;
int targetHeight = bitmap.Height * targetWidth / bitmap.Width;
using var thumb = bitmap.GetThumbnailImage(targetWidth, targetHeight, () => false, IntPtr.Zero); //ImageUtility.Resize(bitmap, targetWidth);
thumb.Save(Path.Join(UserSettingData.TempFolderPath, thumbFileName));
}
else
Expand Down
30 changes: 3 additions & 27 deletions ImageManager/ViewModels/RootViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
using HandyControl.Data;
using HandyControl.Themes;
using ImageManager.Data;
using ImageManager.Data.Model;
using ImageManager.Tools;
using ImageManager.Windows;
using Microsoft.EntityFrameworkCore;
using SQLitePCL;
using Stylet;
using StyletIoC;
using System.Collections.Generic;
using System.Diagnostics;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Label = ImageManager.Data.Model.Label;
Expand Down Expand Up @@ -164,33 +157,16 @@ public void ScreenShot()
WindowState = preWindowState;
});
}

public void SelectAll()
{
MainPageViewModel.SelectAll();
}
public void SelectNone()
{
MainPageViewModel.SelectNone();
}
public void SelectInvert()
{
MainPageViewModel.SelectInvert();
}
public void CopyPicture()
{
MainPageViewModel.CopyPicture();
}
public void DeletePicture()
public void About()
{
MainPageViewModel.DeletePicture();
var aboutViewModel = new AboutViewModel();
_windowManager.ShowWindow(aboutViewModel);
}
#endregion


public void ParametersInjected()
{
Context.Database.Migrate();
// 得手动调用
MainPageViewModel.ParametersInjected();
ThemeManager.Current.ApplicationTheme = UserSettingData.Theme;
Expand Down
82 changes: 82 additions & 0 deletions ImageManager/Views/AboutView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<hc:Window
x:Class="ImageManager.Views.AboutView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:ImageManager.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:viewmodels="clr-namespace:ImageManager.ViewModels"
Title="关于"
Width="600"
Height="350"
d:DataContext="{d:DesignInstance Type=viewmodels:AboutViewModel}"
mc:Ignorable="d">
<hc:Window.Resources>
<Style x:Key="LinkButton" TargetType="Button">

<Setter Property="Width" Value="Auto" />

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}">
<ContentPresenter.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#FF55AAFF" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="#FFD64C4C" />
</Trigger>
</Style.Triggers>
</Style>
</hc:Window.Resources>
<StackPanel>
<TextBlock
Margin="0,40"
HorizontalAlignment="Center"
FontSize="40"
FontWeight="SemiBold"
Foreground="Orange">
素 材 管 理 姬
</TextBlock>
<StackPanel
Margin="0,5"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock FontSize="15">
版本号:
</TextBlock>
<TextBlock FontSize="15" Text="{Binding Version}" />
</StackPanel>

<Border Height="80" />
<StackPanel
Margin="0,5"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock>
项目地址:
</TextBlock>
<Button
Command="{s:Action OpenProjectHome}"
Content="https://github.com/nayaku/ImageManager"
Style="{DynamicResource LinkButton}" />
</StackPanel>
<TextBlock Margin="0,5" HorizontalAlignment="Center">
作者: Nayaku
</TextBlock>
</StackPanel>
</hc:Window>
27 changes: 27 additions & 0 deletions ImageManager/Views/AboutView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ImageManager.Views
{
/// <summary>
/// AboutView.xaml 的交互逻辑
/// </summary>
public partial class AboutView
{
public AboutView()
{
InitializeComponent();
}
}
}
6 changes: 3 additions & 3 deletions ImageManager/Views/RootView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:viewModels="clr-namespace:ImageManager.ViewModels"
Title="素材管理器"
Title="素材管理姬"
Width="1280"
Height="768"
d:DataContext="{d:DesignInstance Type=viewModels:RootViewModel}"
Icon="pack://application:,,,/icon.ico"
Loaded="{s:Action Loaded}"
ShowIcon="True"
ShowTitle="False"
WindowStartupLocation="CenterScreen"
WindowState="{Binding WindowState}"
Loaded="{s:Action Loaded}"
mc:Ignorable="d">
<hc:Window.InputBindings>
<KeyBinding Command="{s:Action ScreenShot}" Gesture="Ctrl+Alt+Shift+X" />
Expand Down Expand Up @@ -113,7 +113,7 @@
Header="删除图片"
InputGestureText="Delete" />
</MenuItem>
<!--<MenuItem Header="关于" />-->
<MenuItem Command="{s:Action About}" Header="关于" />
</Menu>
<hc:SearchBar
Name="SearchLabelBar"
Expand Down
Loading

0 comments on commit ccea151

Please sign in to comment.