Skip to content

Commit 0ce048a

Browse files
committed
4.0.2
1 parent 1e77908 commit 0ce048a

File tree

13 files changed

+232
-92
lines changed

13 files changed

+232
-92
lines changed

SmartImage.Lib 3/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ protected virtual ValueTask<Url> GetRawUrlAsync(SearchQuery query)
9393
public abstract void Dispose();
9494

9595
public static readonly BaseSearchEngine[] All =
96-
ReflectionHelper.CreateAllInAssembly<BaseSearchEngine>(TypeProperties.Subclass).ToArray();
96+
ReflectionHelper.CreateAllInAssembly<BaseSearchEngine>(InheritanceProperties.Subclass).ToArray();
9797

9898
}

SmartImage.Lib 3/Engines/Impl/Search/YandexEngine.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Dynamic;
33
using System.Net.NetworkInformation;
44
using AngleSharp.Dom;
5+
using AngleSharp.Html.Dom;
56
using AngleSharp.XPath;
67
using Flurl.Http;
78
using Kantan.Monad;
@@ -229,6 +230,10 @@ private static IEnumerable<SearchResultItem> ParseExternalInfo(IDocument doc, Se
229230
var rg = new List<SearchResultItem>(items.Count);
230231

231232
foreach (INode item in items) {
233+
if (item is IHtmlElement elem) {
234+
var title1 = elem.QuerySelector(".CbirSites-ItemTitle");
235+
var href1 = title1.Children[0].Attributes["href"];
236+
}
232237
// var thumb = item.ChildNodes[0];
233238
var info = item.ChildNodes[1];
234239
var title = info.ChildNodes[0].TextContent;
@@ -261,7 +266,7 @@ protected override string[] ErrorBodyMessages
261266
{
262267
"Please confirm that you and not a robot are sending requests",
263268
"Изображение не загрузилось, попробуйте загрузить другое.",
264-
"No matching images found"
269+
// "No matching images found"
265270
};
266271

267272
protected override async ValueTask<INode[]> GetNodes(IDocument doc)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected void Verify(string file)
102102
}
103103

104104
public static readonly BaseUploadEngine[] All =
105-
ReflectionHelper.CreateAllInAssembly<BaseUploadEngine>(TypeProperties.Subclass).ToArray();
105+
ReflectionHelper.CreateAllInAssembly<BaseUploadEngine>(InheritanceProperties.Subclass).ToArray();
106106

107107
/*public async Task<bool> IsAlive()
108108
{

SmartImage.Lib 3/Model/BaseImageHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public abstract class BaseImageHost
5353
public abstract bool Refine(string b);
5454

5555
public static readonly BaseImageHost[] All =
56-
ReflectionHelper.CreateAllInAssembly<BaseImageHost>(TypeProperties.Subclass).ToArray();
56+
ReflectionHelper.CreateAllInAssembly<BaseImageHost>(InheritanceProperties.Subclass).ToArray();
5757

5858
public static async Task<UniSource[]> ScanAsync(Url u, Predicate<UniSource> pred = null,
5959
CancellationToken ct = default)

SmartImage.Lib 3/Results/SearchResultItem.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,23 @@ public sealed record SearchResultItem : IDisposable,
111111

112112
// public bool IsUniType { get; internal set; }
113113

114+
public bool IsRaw { get; internal set; }
115+
116+
internal static SearchResultItem GetRaw(SearchResult r)
117+
=> new SearchResultItem(r)
118+
{
119+
IsRaw = true,
120+
Url = r.RawUrl
121+
};
122+
114123
internal SearchResultItem(SearchResult r)
115124
{
116125
Root = r;
117126
Metadata = new ExpandoObject();
118127
m_isScored = false;
119128
Uni = null;
120129
Parent = null;
130+
IsRaw = false;
121131
Sisters = new List<SearchResultItem>();
122132
}
123133

@@ -161,7 +171,8 @@ public void UpdateScore()
161171
Score++;
162172
}
163173

164-
var a = new string[] { Source, Artist, Character, Description, Title, Site, (string) Thumbnail, ThumbnailTitle };
174+
var a = new string[]
175+
{ Source, Artist, Character, Description, Title, Site, (string) Thumbnail, ThumbnailTitle };
165176
Score += a.Count(s => !string.IsNullOrWhiteSpace(s));
166177

167178
var b = new[] { Similarity, Width, Height, };

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
global using MN = System.Diagnostics.CodeAnalysis.MaybeNullAttribute;
22
global using CBN = JetBrains.Annotations.CanBeNullAttribute;
33
global using NN = System.Diagnostics.CodeAnalysis.NotNullAttribute;
4+
global using MNNW = System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute;
45
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
57
using System.Drawing;
68
using System.Runtime.CompilerServices;
79
using System.Security.Cryptography;
@@ -20,6 +22,7 @@ namespace SmartImage.Lib;
2022

2123
public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
2224
{
25+
[MN]
2326
public UniSource Uni { get; }
2427

2528
[MN]
@@ -30,7 +33,15 @@ public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
3033
public ReadOnlyMemory<byte> MD5Hash { get; private init; }
3134

3235
[CBN]
33-
public string ValueString => Uni?.Value.ToString();
36+
public string ValueString => HasUni ? Uni.Value.ToString() : null;
37+
38+
[MNNW(true, nameof(Upload))]
39+
public bool IsUploaded => Url.IsValid(Upload);
40+
41+
public bool IsUploading { get; private set; }
42+
43+
[MNNW(true, nameof(Uni))]
44+
public bool HasUni => Uni != null;
3445

3546
internal SearchQuery([CBN] UniSource f)
3647
{
@@ -57,20 +68,20 @@ public static async Task<SearchQuery> TryCreateAsync(string value, CancellationT
5768
{
5869
MD5Hash = await MD5.HashDataAsync(uf.Stream, ct)
5970
};
60-
71+
6172
return sq;
6273

6374
}
6475
}
6576

66-
public bool IsUploaded => Url.IsValid(Upload);
67-
6877
public async Task<Url> UploadAsync(BaseUploadEngine engine = null, CancellationToken ct = default)
6978
{
7079
if (IsUploaded) {
7180
return Upload;
7281
}
7382

83+
IsUploading = true;
84+
7485
var fu = Uni.Value.ToString();
7586

7687
if (Uni.IsUri) {
@@ -99,6 +110,7 @@ public async Task<Url> UploadAsync(BaseUploadEngine engine = null, CancellationT
99110
Size = u.Size ?? Size;
100111
u.Dispose();
101112
}
113+
IsUploading = false;
102114

103115
return Upload;
104116
}

SmartImage.UI/MainWindow.Handlers.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void Btn_Reset_Click(object sender, RoutedEventArgs e)
187187
e.Handled = true;
188188
}
189189

190-
private void Btn_Restart_Click(object sender, RoutedEventArgs e)
190+
private void Btn_Reload_Click(object sender, RoutedEventArgs e)
191191
{
192192
Cancel();
193193
ClearResults(false);
@@ -206,12 +206,12 @@ private void Btn_Restart_Click(object sender, RoutedEventArgs e)
206206
e.Handled = true;
207207
}
208208

209-
private void Btn_Restart_MouseEnter(object sender, MouseEventArgs e)
209+
private void Btn_Reload_MouseEnter(object sender, MouseEventArgs e)
210210
{
211211
e.Handled = true;
212212
}
213213

214-
private void Btn_Restart_MouseLeave(object sender, MouseEventArgs e)
214+
private void Btn_Reload_MouseLeave(object sender, MouseEventArgs e)
215215
{
216216
e.Handled = true;
217217
}
@@ -383,6 +383,12 @@ private void Lv_Results_SelectionChanged(object sender, SelectionChangedEventArg
383383
Me_Preview.UnloadedBehavior = MediaState.Close;
384384
Me_Preview.LoadedBehavior = MediaState.Manual;
385385
// Me_Preview.LoadedBehavior = MediaState.Manual;
386+
/*if (!await m_us2.WaitAsync(TimeSpan.Zero)) {
387+
return;
388+
389+
}*/
390+
Tb_Preview.Text = $"Preview: loading {ri.Name}";
391+
386392
var uri = await CacheAsync(doc.video);
387393

388394
Me_Preview.Source = new Uri(uri);
@@ -391,6 +397,7 @@ private void Lv_Results_SelectionChanged(object sender, SelectionChangedEventArg
391397

392398
ShowMedia = true;
393399
Tb_Preview.Text = $"Preview: {ri.Name}";
400+
// m_us2.Release();
394401
});
395402

396403
}
@@ -596,9 +603,9 @@ private void Wnd_Main_Loaded(object sender, RoutedEventArgs e)
596603
}
597604

598605
// todo: not used for now
599-
// m_trDispatch.Start();
600-
e.Handled = true;
606+
m_trDispatch.Start();
601607
Debug.WriteLine("Main loaded");
608+
e.Handled = true;
602609

603610
}
604611

@@ -707,7 +714,8 @@ private void Img_Preview_MouseLeftButtonDown(object sender, MouseButtonEventArgs
707714

708715
private void Me_Preview_MouseDown(object sender, MouseButtonEventArgs e)
709716
{
710-
717+
CloseMedia();
718+
UpdatePreview();
711719
e.Handled = true;
712720

713721
}
@@ -772,7 +780,10 @@ private void Tb_Search_TextChanged(object sender, TextChangedEventArgs e)
772780
else {
773781
var selected = (string) Cb_SearchFields.SelectionBoxItem;
774782
var strFunc = SearchFields[selected];
783+
if (!IsSearching) {
784+
CurrentQueueItem.BackupResults();
775785

786+
}
776787
var searchResults = CurrentQueueItem.Results.Where(r =>
777788
{
778789
var s = strFunc(r);
@@ -783,8 +794,9 @@ private void Tb_Search_TextChanged(object sender, TextChangedEventArgs e)
783794

784795
return s.Contains(Tb_Search.Text, StringComparison.InvariantCultureIgnoreCase);
785796
});
786-
Lv_Results.ItemsSource = searchResults;
787-
IsSearching = true;
797+
CurrentQueueItem.Results = new ObservableCollection<ResultItem>(searchResults);
798+
// Lv_Results.ItemsSource = searchResults;
799+
IsSearching = true;
788800

789801
}
790802

SmartImage.UI/MainWindow.State.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,22 @@ public bool ShowMedia
154154

155155
private void CheckMedia()
156156
{
157-
if (ShowMedia)
158-
{
159-
Me_Preview.Stop();
160-
// Me_Preview.Position = TimeSpan.Zero;
161-
Me_Preview.Close();
162-
Me_Preview.Source = null;
163-
// Me_Preview.Dispose();
164-
ShowMedia = false;
157+
if (ShowMedia) {
158+
CloseMedia();
165159
}
166160
else { }
167161
}
168162

163+
private void CloseMedia()
164+
{
165+
Me_Preview.Stop();
166+
// Me_Preview.Position = TimeSpan.Zero;
167+
Me_Preview.Close();
168+
Me_Preview.Source = null;
169+
// Me_Preview.Dispose();
170+
ShowMedia = false;
171+
}
172+
169173
#endregion
170174

171175
}

SmartImage.UI/MainWindow.xaml

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
xmlns:model="clr-namespace:SmartImage.UI.Model"
1212
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
1313
DataContext="{Binding RelativeSource={RelativeSource Self}}"
14-
mc:Ignorable="d" Height="600" Width="1300" MinWidth="1300" MinHeight="300" Loaded="Wnd_Main_Loaded"
14+
mc:Ignorable="d" Height="600" Width="1315" MinWidth="1315" MinHeight="300" Loaded="Wnd_Main_Loaded"
1515
Closed="Wnd_Main_Closed"
1616
Closing="Wnd_Main_Closing" Title="SmartImage" Unloaded="Wnd_Main_Unloaded" Background="#FF191919"
1717
KeyDown="Wnd_Main_KeyDown">
@@ -171,7 +171,7 @@
171171

172172
<Button x:Name="Btn_Run" Content="Run" HorizontalAlignment="Left" Margin="499,8,0,0"
173173
VerticalAlignment="Top" Click="Btn_Run_Click" Height="20" FontWeight="Bold"
174-
Loaded="Btn_Run_Loaded" Width="35">
174+
Loaded="Btn_Run_Loaded" Width="35" ToolTip="Run search">
175175

176176
<Button.Style>
177177
<Style TargetType="{x:Type Button}">
@@ -206,7 +206,7 @@
206206

207207
<Button x:Name="Btn_Cancel"
208208
BorderBrush="{DynamicResource Border2}" Content="Cancel"
209-
HorizontalAlignment="Left" Margin="539,8,0,0"
209+
HorizontalAlignment="Left" Margin="539,8,0,0" ToolTip="Cancel current operation(s)"
210210
VerticalAlignment="Top" Click="Btn_Cancel_Click" Height="20" Width="39">
211211

212212
<Button.Style>
@@ -242,8 +242,7 @@
242242
</Button>
243243
<Button x:Name="Btn_Remove" Content="Remove"
244244
HorizontalAlignment="Left" Margin="583,8,0,0" VerticalAlignment="Top"
245-
Click="Btn_Remove_Click" Height="20" Width="46"
246-
IsEnabled="{Binding Path=CurrentQueueItem.HasQuery, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}">
245+
Click="Btn_Remove_Click" Height="20" Width="46" ToolTip="Remove query from queue">
247246

248247
<Button.Style>
249248
<Style TargetType="{x:Type Button}">
@@ -278,7 +277,8 @@
278277
</Button>
279278
<Button x:Name="Btn_Delete" Content="Delete"
280279
HorizontalAlignment="Left" Margin="634,8,0,0" VerticalAlignment="Top"
281-
Click="Btn_Delete_Click" Height="20" Width="39" IsEnabled="{Binding Path=CurrentQueueItem.CanDelete, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}">
280+
Click="Btn_Delete_Click" Height="20" Width="39" ToolTip="Delete query file (Recycle Bin)"
281+
IsEnabled="{Binding Path=CurrentQueueItem.CanDelete, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}">
282282

283283
<Button.Style>
284284
<Style TargetType="{x:Type Button}">
@@ -454,22 +454,28 @@
454454
<TextBox x:Name="Tb_Upload" HorizontalAlignment="Left" Margin="57,37,0,0" TextWrapping="Wrap"
455455
VerticalAlignment="Top" Width="437" IsReadOnly="True" Height="20"
456456
MouseDoubleClick="Tb_Upload_MouseDoubleClick" Foreground="White" Background="Black"
457-
Text="{Binding CurrentQueueItem.Query.Upload, Mode=OneWay, Converter={StaticResource urlConverter}, ElementName=Wnd_Main}">
457+
Text="{Binding CurrentQueueItem.Query.Upload, Mode=OneWay, UpdateSourceTrigger=PropertyChanged,
458+
Converter={StaticResource urlConverter}, ElementName=Wnd_Main}">
458459

459460
</TextBox>
460461

461462
<Button x:Name="Btn_Clear" Content="Clear" HorizontalAlignment="Left" Margin="501,0,0,0"
462-
VerticalAlignment="Center" Height="20" Click="Btn_Clear_Click" />
463+
VerticalAlignment="Center" Height="20" Click="Btn_Clear_Click"
464+
ToolTip="Clear query &amp; results" IsEnabled="{Binding CurrentQueueItem.IsComplete}" />
463465

464-
<Button x:Name="Btn_Restart" Content="Restart" HorizontalAlignment="Left" Margin="537,0,0,0"
465-
VerticalAlignment="Center" Click="Btn_Restart_Click"
466-
MouseEnter="Btn_Restart_MouseEnter"
467-
MouseLeave="Btn_Restart_MouseLeave" Width="49" Height="20" />
466+
<Button x:Name="Btn_Reload" Content="Reload" HorizontalAlignment="Left" Margin="537,0,0,0"
467+
VerticalAlignment="Center" Click="Btn_Reload_Click"
468+
MouseEnter="Btn_Reload_MouseEnter"
469+
MouseLeave="Btn_Reload_MouseLeave" Width="49" Height="20"
470+
ToolTip="Clear query &amp; results, then reload query &amp; config" IsEnabled="{Binding CanReload, UpdateSourceTrigger=PropertyChanged}"/>
468471

469472
<Button x:Name="Btn_Reset" Content="Reset" HorizontalAlignment="Left" Margin="591,0,0,0"
470-
VerticalAlignment="Center" Click="Btn_Reset_Click" Width="41" Height="20" />
473+
VerticalAlignment="Center" Click="Btn_Reset_Click" Width="41" Height="20"
474+
ToolTip="Reload &amp; reset state" />
475+
471476
<Button x:Name="Btn_Browse" Content="Browse" HorizontalAlignment="Left" Margin="637,0,0,0"
472-
VerticalAlignment="Center" Click="Btn_Browse_Click" Height="20" Grid.ColumnSpan="2" />
477+
VerticalAlignment="Center" Click="Btn_Browse_Click" Height="20" Grid.ColumnSpan="2"
478+
ToolTip="Browse for input(s)" />
473479

474480
<Label x:Name="Lb_Info" Content="Info" HorizontalAlignment="Left" Margin="4,62,0,0"
475481
VerticalAlignment="Top" Height="26" FontWeight="Bold" Foreground="White"
@@ -594,24 +600,29 @@
594600

595601
<Image x:Name="Img_Type" Width="20px" Height="20px" Stretch="None" Margin="48,5,0,0"
596602
HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" />
597-
<TextBlock x:Name="Tb_Status" HorizontalAlignment="Left" Margin="4,33,0,0"
598603

604+
<TextBlock x:Name="Tb_Status" HorizontalAlignment="Left" Margin="4,33,0,0"
599605
VerticalAlignment="Top" Foreground="White" FontStyle="Italic" Grid.Row="1"
600-
Text="{Binding CurrentQueueItem.Status, UpdateSourceTrigger=PropertyChanged}" />
606+
Text="{Binding CurrentQueueItem.Status, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}" />
601607

602608
<TextBlock x:Name="Tb_Status2" HorizontalAlignment="Left" Margin="115,49,0,0"
603609
VerticalAlignment="Top" Foreground="White" Grid.Row="1" TextDecorations="Underline"
604-
Text="{Binding CurrentQueueItem.Status2, UpdateSourceTrigger=PropertyChanged}" />
610+
Text="{Binding CurrentQueueItem.Status2, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}" />
611+
605612
<Button x:Name="Btn_Filter" Content="Filter" HorizontalAlignment="Left" Margin="501,65,0,0"
606-
VerticalAlignment="Top" Click="Btn_Filter_Click" />
613+
VerticalAlignment="Top" Click="Btn_Filter_Click"
614+
IsEnabled="{Binding CurrentQueueItem.IsComplete}" />
615+
607616
<TextBox x:Name="Tb_Search" HorizontalAlignment="Right" Margin="0,46,499,0" Grid.Row="1"
608617
TextWrapping="Wrap" VerticalAlignment="Top" Width="158"
609618
TextChanged="Tb_Search_TextChanged" Grid.ColumnSpan="2" />
619+
610620
<ComboBox x:Name="Cb_SearchFields" HorizontalAlignment="Right" Margin="0,17,499,0" Grid.Row="1"
611621
VerticalAlignment="Top" Width="148" Grid.ColumnSpan="2" />
622+
612623
<TextBlock x:Name="Tb_Preview" Grid.Column="1" HorizontalAlignment="Right" Margin="0,65,11,0"
613624
Grid.Row="1" VerticalAlignment="Top" TextDecorations="Underline" Foreground="White"
614-
Width="150" />
625+
Width="150" ToolTip="Click preview to stop/close&#x0a;Double click preview to open" />
615626
</Grid>
616627
</TabItem>
617628
<TabItem x:Name="Ti_Config" HorizontalAlignment="Center" Height="20" Header="Config"

0 commit comments

Comments
 (0)