Skip to content

Commit 0eb9fcb

Browse files
committed
Fixes; UI improvements; ...
1 parent 2f80bfd commit 0eb9fcb

File tree

15 files changed

+294
-128
lines changed

15 files changed

+294
-128
lines changed

SmartImage.Benchmark/Benchmark1.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Deci SmartImage.Benchmark Benchmark1.cs
2+
// $File.CreatedYear-$File.CreatedMonth-6 @ 13:53
3+
4+
using BenchmarkDotNet.Attributes;
5+
using Novus.FileTypes;
6+
using SixLabors.ImageSharp;
7+
using SmartImage.Lib;
8+
9+
namespace SmartImage.Benchmark;
10+
11+
public class Benchmark1
12+
{
13+
14+
public string s;
15+
16+
[GlobalSetup]
17+
public void GlobalSetup()
18+
{
19+
s =
20+
@"C:\Users\Deci\Pictures\MPV Screenshots\mpv_[SubsPlease] Jujutsu Kaisen - 30 (1080p) [3DAACE2D]_00_04_56.630_00h04m56s630ms_ns].png";
21+
22+
}
23+
24+
[Benchmark]
25+
public async Task<ImageInfo> Test1()
26+
{
27+
return await Image.IdentifyAsync(s);
28+
}
29+
30+
[Benchmark]
31+
public async Task<SearchQuery> Test2()
32+
{
33+
return await SearchQuery.TryCreateAsync(s);
34+
}
35+
36+
[Benchmark]
37+
public async Task<UniSource> Test3()
38+
{
39+
return await UniSource.TryGetAsync(s);
40+
}
41+
42+
}

SmartImage.Benchmark/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Diagnosers;
3+
using BenchmarkDotNet.Exporters;
4+
using BenchmarkDotNet.Jobs;
5+
using BenchmarkDotNet.Running;
6+
7+
namespace SmartImage.Benchmark
8+
{
9+
public static class Program
10+
{
11+
12+
public static void Main(string[] args)
13+
{
14+
var cfg = ManualConfig.CreateMinimumViable()
15+
.AddExporter(new HtmlExporter())
16+
.AddDiagnoser(new MemoryDiagnoser(new MemoryDiagnoserConfig()))
17+
.AddJob(Job.InProcess);
18+
BenchmarkRunner.Run<Benchmark1>(cfg);
19+
}
20+
21+
}
22+
23+
// [MemoryDiagnoser]
24+
// [SimpleJob()]
25+
// [RyuJitX64Job]
26+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
12+
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.13.12" />
13+
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
14+
<PackageReference Include="Flurl.Http" Version="4.0.0" />
15+
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
16+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.1" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\SmartImage.Lib 3\SmartImage.Lib.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Reference Include="Kantan">
25+
<HintPath>..\..\..\VSProjects\Kantan\Kantan\bin\Release\net8.0\Kantan.dll</HintPath>
26+
</Reference>
27+
<Reference Include="Kantan.Net">
28+
<HintPath>..\..\..\VSProjects\Kantan\Kantan.Net\bin\Release\net8.0\Kantan.Net.dll</HintPath>
29+
</Reference>
30+
<Reference Include="Novus">
31+
<HintPath>..\..\..\VSProjects\Novus\Novus\bin\Release\net8.0\Novus.dll</HintPath>
32+
</Reference>
33+
</ItemGroup>
34+
35+
</Project>

SmartImage.Lib 3/Engines/Impl/Upload/BaseUploadEngine.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -151,33 +151,3 @@ public void Dispose() { }
151151

152152
}
153153

154-
public abstract class BaseCatboxEngine : BaseUploadEngine
155-
{
156-
157-
public override async Task<UploadResult> UploadFileAsync(string file, CancellationToken ct = default)
158-
{
159-
Verify(file);
160-
161-
var response = await Client.Request(EndpointUrl)
162-
.WithSettings(r =>
163-
{
164-
r.Timeout = Timeout;
165-
})
166-
.WithHeaders(new
167-
{
168-
User_Agent = HttpUtilities.UserAgent
169-
})
170-
.PostMultipartAsync(mp =>
171-
{
172-
mp.AddFile("fileToUpload", file)
173-
.AddString("reqtype", "fileupload")
174-
.AddString("time", "1h")
175-
.AddString("userhash", string.Empty);
176-
}, cancellationToken: ct, completionOption: HttpCompletionOption.ResponseHeadersRead);
177-
178-
return await ProcessResultAsync(response, ct).ConfigureAwait(false);
179-
}
180-
181-
protected BaseCatboxEngine(string s) : base(s) { }
182-
183-
}

SmartImage.Lib 3/Engines/Impl/Upload/CatboxEngine.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
using System.ComponentModel;
22
using Flurl.Http;
3+
using Kantan.Net.Utilities;
4+
using SmartImage.Lib.Results;
35

46
namespace SmartImage.Lib.Engines.Impl.Upload;
57

8+
public abstract class BaseCatboxEngine : BaseUploadEngine
9+
{
10+
11+
public override async Task<UploadResult> UploadFileAsync(string file, CancellationToken ct = default)
12+
{
13+
Verify(file);
14+
15+
var response = await Client.Request(EndpointUrl)
16+
.WithSettings(r =>
17+
{
18+
r.Timeout = Timeout;
19+
})
20+
.WithHeaders(new
21+
{
22+
User_Agent = HttpUtilities.UserAgent
23+
})
24+
.PostMultipartAsync(mp =>
25+
{
26+
mp.AddFile("fileToUpload", file)
27+
.AddString("reqtype", "fileupload")
28+
.AddString("time", "1h")
29+
.AddString("userhash", string.Empty);
30+
}, cancellationToken: ct, completionOption: HttpCompletionOption.ResponseHeadersRead);
31+
32+
return await ProcessResultAsync(response, ct).ConfigureAwait(false);
33+
}
34+
35+
protected BaseCatboxEngine(string s) : base(s) { }
36+
37+
}
38+
639
public sealed class CatboxEngine : BaseCatboxEngine
740
{
841

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
// $User.Name $File.ProjectName $File.FileName
22
// $File.CreatedYear-$File.CreatedMonth-$File.CreatedDay @ $File.CreatedHour:$File.CreatedMinute
33

4-
using System.Drawing;
5-
64
namespace SmartImage.Lib.Model;
75

8-
public interface ISysImageSource : IBaseImageSource
9-
{
10-
[MN]
11-
public Image Image { get; set; }
12-
13-
}
14-
156
public interface IBaseImageSource
167
{
178

@@ -25,6 +16,12 @@ public interface IBaseImageSource
2516

2617
public int? Height { get; }
2718

28-
public bool LoadImage([CBN] IImageLoader l = null);
19+
[CBN]
20+
public string DimensionString
21+
{
22+
get;
23+
}
24+
25+
public bool LoadImage();
2926

3027
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -8,7 +9,8 @@ namespace SmartImage.Lib.Model
89
{
910
public interface IImageLoader
1011
{
12+
1113
bool LoadImage(IBaseImageSource p);
1214

1315
}
14-
}
16+
}

SmartImage.UI/ControlsHelper.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Kantan.Utilities;
1515
using Novus.FileTypes;
1616
using SmartImage.Lib.Engines;
17+
using SmartImage.Lib.Model;
1718

1819
namespace SmartImage.UI;
1920

@@ -127,12 +128,7 @@ public static string FormatDescription(string name, UniSource uni, int? w, int?
127128

128129
string i;
129130

130-
if (w.HasValue && h.HasValue) {
131-
i = $"({w}×{h})";
132-
}
133-
else {
134-
i = string.Empty;
135-
}
131+
i = FormatDimensions(w, h);
136132

137133
return $"{name} ⇉ [{uni.FileType}] [{bytes}] • {i}";
138134
}
@@ -156,4 +152,15 @@ public static (bool ctrl, bool alt, bool shift) GetModifiers()
156152
var shift = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift);
157153
return (ctrl, alt, shift);
158154
}
155+
156+
public static string FormatDimensions(int? w, int? h)
157+
{
158+
if (w.HasValue && h.HasValue)
159+
{
160+
return $"{w}\u00d7{h}";
161+
}
162+
163+
return string.Empty;
164+
}
165+
159166
}

SmartImage.UI/MainWindow.Handlers.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,15 @@ private void Lv_Results_SelectionChanged(object sender, SelectionChangedEventArg
393393
{
394394
if (e.AddedItems.Count > 0) {
395395

396-
var ai = e.AddedItems[0];
397-
var ri = ai as ResultItem;
398-
399-
var b = ri is UniResultItem uri;
396+
var ai = e.AddedItems[0];
397+
var ri = ai as ResultItem;
398+
399+
var b = ri is UniResultItem uri;
400400

401401
if (b || (ri.Result.Root.Engine.EngineOption != SearchEngineOptions.TraceMoe)) {
402+
if (b) {
403+
ri = (UniResultItem)ri;
404+
}
402405
SetPreview(ri);
403406
CheckMedia();
404407
}
@@ -865,6 +868,11 @@ private void Btn_Filter_Click(object sender, RoutedEventArgs e)
865868
Dispatcher.InvokeAsync(FilterResultsAsync);
866869
e.Handled = true;
867870
}
871+
private void Tb_SelUrl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
872+
{
873+
874+
FileSystem.Open(CurrentResult.Url);
875+
}
868876

869877
private void Tb_Search_TextChanged(object sender, TextChangedEventArgs e)
870878
{

SmartImage.UI/MainWindow.xaml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,11 @@
555555
<TextBox x:Name="Tb_Info_Dim" HorizontalAlignment="Left" Margin="362,65,0,0" TextWrapping="Wrap"
556556
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
557557
Foreground="White" TextAlignment="Center"
558-
Text="{Binding CurrentQuery.Dim, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay,
558+
Text="{Binding CurrentQuery.DimensionString, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay,
559559
UpdateSourceTrigger=PropertyChanged}" />
560-
561560
<Image x:Name="Img_Status" HorizontalAlignment="Left" Height="20px" Width="20px"
562561
Margin="10,5,0,0"
563562
VerticalAlignment="Top" Stretch="None" Grid.Row="1" />
564-
565-
<ProgressBar x:Name="Pb_Status" HorizontalAlignment="Left" Height="10" Margin="4,54,0,0"
566-
VerticalAlignment="Top" Width="100" Minimum="0" Maximum="100" Grid.Row="1" />
567563
<ListView x:Name="Lv_Results" Margin="0,120,0,0"
568564
MouseDoubleClick="Lv_Results_MouseDoubleClick"
569565
Foreground="White"
@@ -666,17 +662,19 @@
666662

667663
</ListView>
668664

669-
<Image x:Name="Img_Type" Width="20px" Height="20px" Stretch="None" Margin="48,5,0,0"
670-
HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" />
671-
672-
<TextBlock x:Name="Tb_Status" HorizontalAlignment="Left" Margin="4,33,0,0"
665+
<TextBlock x:Name="Tb_Status" HorizontalAlignment="Left" Margin="10,28,0,0"
673666
VerticalAlignment="Top" Foreground="White" FontStyle="Italic" Grid.Row="1"
674667
Text="{Binding CurrentQuery.Status, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}" />
675668

676-
<TextBlock x:Name="Tb_Status2" HorizontalAlignment="Left" Margin="115,49,0,0"
669+
<!--
670+
<TextBlock x:Name="Tb_Status2" HorizontalAlignment="Left" Margin="95,28,0,0"
677671
VerticalAlignment="Top" Foreground="White" Grid.Row="1" TextDecorations="Underline"
678672
Text="{Binding CurrentQuery.Status2, UpdateSourceTrigger=PropertyChanged,ElementName=Wnd_Main}"
679673
MaxWidth="400" />
674+
-->
675+
676+
<Image x:Name="Img_Type" Width="20px" Height="20px" Stretch="None" Margin="48,5,0,0"
677+
HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" />
680678

681679
<Button x:Name="Btn_Filter" Content="Filter" HorizontalAlignment="Left" Margin="585,0,0,0"
682680
VerticalAlignment="Center" Click="Btn_Filter_Click"
@@ -705,6 +703,40 @@
705703
<ProgressBar x:Name="Pb_Preview" Grid.Column="1" HorizontalAlignment="Right" Height="10"
706704
Margin="0,105,174,0" Grid.Row="1" VerticalAlignment="Top" Width="320"
707705
Value="{Binding CurrentResult.PreviewProgress}" />
706+
707+
<Label x:Name="Lb_SelUrl" Content="Item" HorizontalAlignment="Left" Margin="4,59,0,0"
708+
VerticalAlignment="Top" Height="26" Foreground="White"
709+
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Width="50" HorizontalContentAlignment="Center"
710+
Grid.Row="1" FontWeight="Bold" />
711+
712+
<TextBox x:Name="Tb_SelUrl" HorizontalAlignment="Left" Margin="57,61,0,0"
713+
VerticalAlignment="Top" Width="435" IsReadOnly="True" Height="20" Foreground="White" Background="Black"
714+
Text="{Binding CurrentResult.Result.Url, Converter={StaticResource urlConverter}, ElementName=Wnd_Main, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
715+
Grid.Row="1" MouseDoubleClick="Tb_SelUrl_MouseDoubleClick" />
716+
717+
<Label x:Name="Lb_SelInfo" Content="Info" HorizontalAlignment="Left" Margin="4,87,0,0"
718+
VerticalAlignment="Top" Height="26" FontWeight="Bold" Foreground="White"
719+
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" HorizontalContentAlignment="Center" Width="50"
720+
Grid.Row="1" />
721+
722+
<TextBox x:Name="Tb_SelInfo_Type" HorizontalAlignment="Left" Margin="57,89,0,0" TextWrapping="Wrap"
723+
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
724+
Foreground="White" TextAlignment="Center"
725+
Text="{Binding CurrentResult.Status, ElementName=Wnd_Main, FallbackValue={x:Null}, IsAsync=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
726+
Grid.Row="1" />
727+
728+
<TextBox x:Name="Tb_SelInfo_Size" HorizontalAlignment="Left" Margin="210,89,0,0"
729+
TextWrapping="Wrap"
730+
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
731+
Foreground="White" TextAlignment="Center"
732+
Text="..."
733+
Grid.Row="1" />
734+
735+
<TextBox x:Name="Tb_SelInfo_Dim" HorizontalAlignment="Left" Margin="362,89,0,0" TextWrapping="Wrap"
736+
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
737+
Foreground="White" TextAlignment="Center"
738+
Text="{Binding CurrentResult.DimensionString, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
739+
Grid.Row="1" />
708740

709741
</Grid>
710742
</TabItem>

0 commit comments

Comments
 (0)