Skip to content

Commit 657a982

Browse files
committed
WPF 1.0
1 parent 985d1b9 commit 657a982

File tree

5 files changed

+72
-29
lines changed

5 files changed

+72
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public SearchResultItem Convert(SearchResult r)
490490
Url = urls.FirstOrDefault(),
491491
Similarity = Math.Round(Similarity, 2),
492492
// Similarity = Similarity,
493-
Description = Kantan.Text.Strings.NormalizeNull(idxStr),
493+
Description = siteName,
494494
Artist = Kantan.Text.Strings.NormalizeNull(Creator),
495495
Source = Kantan.Text.Strings.NormalizeNull(Material),
496496
Character = Kantan.Text.Strings.NormalizeNull(Character),

SmartImage.Lib 3/SearchClient.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, [CBN] IProgr
150150
var rr = results.SelectMany(rr => rr.AllResults)
151151
.OrderByDescending(rr => rr.Score);
152152

153-
OpenResult(rr.FirstOrDefault()?.Url);
153+
if (Config.OpenRaw) {
154+
OpenResult(results.MaxBy(x => x.AllResults.Sum(xy => xy.Score)));
155+
}
156+
else {
157+
OpenResult(rr.FirstOrDefault()?.Url);
158+
}
154159
}
155160
catch (Exception e) {
156161
Debug.WriteLine($"{e.Message}");
@@ -164,6 +169,7 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, [CBN] IProgr
164169

165170
return results;
166171
}
172+
167173
private void OpenResult(Url url1)
168174
{
169175
#if DEBUG && !TEST
@@ -181,6 +187,7 @@ private void OpenResult(Url url1)
181187
#endif
182188

183189
}
190+
184191
private void OpenResult(SearchResult result)
185192
{
186193
#if DEBUG && !TEST
@@ -199,7 +206,7 @@ private void OpenResult(SearchResult result)
199206
else {
200207
url1 = result.Best?.Url ?? result.RawUrl;
201208
}
202-
209+
203210
OpenResult(url1);
204211
#endif
205212

@@ -214,7 +221,7 @@ public List<Task<SearchResult>> GetSearchTasks(SearchQuery query, CancellationTo
214221
var tasks = Engines.Select(e =>
215222
{
216223
var res = e.GetResultAsync(query, token);
217-
224+
218225
return res;
219226
}).ToList();
220227

@@ -245,9 +252,8 @@ public BaseSearchEngine[] LoadEngines()
245252
}
246253

247254
[CBN]
248-
public BaseSearchEngine TryGetEngine(SearchEngineOptions o) => Engines.FirstOrDefault(e => e.EngineOption == o);
249-
250-
#region
255+
public BaseSearchEngine TryGetEngine(SearchEngineOptions o)
256+
=> Engines.FirstOrDefault(e => e.EngineOption == o);
251257

252258
/*public static ValueTask<IReadOnlyList<SearchResultItem>> Filter(IEnumerable<SearchResultItem> sri)
253259
{
@@ -306,8 +312,6 @@ public static async Task<IReadOnlyList<UniSource>> GetDirectImagesAsync(IEnumera
306312
return di.AsReadOnly();
307313
}*/
308314

309-
#endregion
310-
311315
public void Dispose()
312316
{
313317
foreach (var engine in Engines) {

SmartImage.UI/MainWindow.Handlers.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
using Flurl.Http;
2323
using Kantan.Net.Utilities;
2424
using Kantan.Numeric;
25+
using Kantan.Text;
2526
using Microsoft.VisualBasic.FileIO;
27+
using Microsoft.Win32;
2628
using Novus.FileTypes;
2729
using SmartImage.Lib;
2830
using SmartImage.Lib.Engines.Impl.Search;
2931
using SmartImage.Lib.Engines.Impl.Search.Other;
3032
using SmartImage.Lib.Engines.Impl.Upload;
3133
using SmartImage.Lib.Model;
34+
using SmartImage.Lib.Utilities;
3235
using SmartImage.UI.Model;
3336
using FileSystem = Novus.OS.FileSystem;
3437
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
@@ -80,7 +83,7 @@ private void Tb_Input_Drop(object sender, DragEventArgs e)
8083
{
8184
var files1 = e.GetFilesFromDrop();
8285

83-
AddToQueueAsync(files1);
86+
AddToQueue(files1);
8487
var f1 = files1.FirstOrDefault();
8588

8689
if (!string.IsNullOrWhiteSpace(f1)) {
@@ -124,7 +127,7 @@ private void Lv_Queue_Drop(object sender, DragEventArgs e)
124127
{
125128
var files = e.GetFilesFromDrop();
126129

127-
AddToQueueAsync(files);
130+
AddToQueue(files);
128131
e.Handled = true;
129132
}
130133

@@ -422,17 +425,28 @@ private void Wnd_Main_Loaded(object sender, RoutedEventArgs e)
422425

423426
m_trDispatch.Start();
424427
e.Handled = true;
428+
Debug.WriteLine($"Main loaded");
429+
425430
}
426431

427432
private void Wnd_Main_Unloaded(object sender, RoutedEventArgs e)
428433
{
434+
Debug.WriteLine($"Main unloaded");
429435
e.Handled = true;
430436

431437
}
432438

433-
private void Wnd_Main_Closed(object sender, EventArgs e) { }
439+
private void Wnd_Main_Closed(object sender, EventArgs e)
440+
{
441+
Debug.WriteLine($"Main closed");
442+
443+
}
434444

435-
private void Wnd_Main_Closing(object sender, CancelEventArgs e) { }
445+
private void Wnd_Main_Closing(object sender, CancelEventArgs e)
446+
{
447+
Debug.WriteLine($"Main closing");
448+
449+
}
436450

437451
#endregion
438452

@@ -490,4 +504,19 @@ private void Btn_OpenWiki_Click(object sender, RoutedEventArgs e)
490504
FileSystem.Open(R1.Wiki_Url);
491505
e.Handled = true;
492506
}
507+
508+
private void Btn_Browse_Click(object sender, RoutedEventArgs e)
509+
{
510+
var ofn = new OpenFileDialog();
511+
ofn.Multiselect = true;
512+
ofn.Filter = $"Image files|{ImageHelper.Ext.QuickJoin(";")}";
513+
var d = ofn.ShowDialog(this);
514+
515+
if (d.HasValue && d.Value) {
516+
var fn = ofn.FileNames;
517+
AddToQueue(fn);
518+
}
519+
520+
e.Handled = true;
521+
}
493522
}

SmartImage.UI/MainWindow.xaml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@
205205
<Label x:Name="Lb_Upload" Content="Upload" HorizontalAlignment="Left" Margin="4,32,0,0"
206206
VerticalAlignment="Top" Height="26" FontWeight="Bold" Foreground="White" />
207207

208-
<TextBox x:Name="Tb_Upload" HorizontalAlignment="Left" Margin="57,0,0,0" TextWrapping="Wrap"
209-
VerticalAlignment="Center" Width="437" IsReadOnly="True" Height="20"
208+
<TextBox x:Name="Tb_Upload" HorizontalAlignment="Left" Margin="57,35,0,0" TextWrapping="Wrap"
209+
VerticalAlignment="Top" Width="437" IsReadOnly="True" Height="20"
210210
MouseDoubleClick="Tb_Upload_MouseDoubleClick" Foreground="White" Background="Black" />
211211

212212
<Button x:Name="Btn_Clear" Content="Clear" HorizontalAlignment="Left" Margin="501,38,0,0"
@@ -216,10 +216,12 @@
216216

217217
<Button x:Name="Btn_Restart" Content="Restart" HorizontalAlignment="Left" Margin="537,38,0,0"
218218
VerticalAlignment="Top" Click="Btn_Restart_Click" MouseEnter="Btn_Restart_MouseEnter"
219-
MouseLeave="Btn_Restart_MouseLeave" Width="49" />
219+
MouseLeave="Btn_Restart_MouseLeave" Width="49" Height="20" />
220220

221221
<Button x:Name="Btn_Reset" Content="Reset" HorizontalAlignment="Left" Margin="591,38,0,0"
222-
VerticalAlignment="Top" Click="Btn_Reset_Click" Width="41" />
222+
VerticalAlignment="Top" Click="Btn_Reset_Click" Width="41" Height="20" />
223+
<Button x:Name="Btn_Browse" Content="Browse" HorizontalAlignment="Left" Margin="635,38,0,0"
224+
VerticalAlignment="Top" Click="Btn_Browse_Click" Height="20" />
223225

224226
<Label x:Name="Lb_Info" Content="Info" HorizontalAlignment="Left" Margin="4,62,0,0"
225227
VerticalAlignment="Top" Height="26" FontWeight="Bold" Foreground="White" />
@@ -439,7 +441,7 @@
439441

440442
<CheckBox x:Name="Cb_ContextMenu" Content="Context menu" HorizontalAlignment="Left"
441443
IsChecked="{Binding Path=UseContextMenu, Mode=TwoWay}"
442-
Margin="426,127,0,0" VerticalAlignment="Top" Foreground="White"/>
444+
Margin="426,127,0,0" VerticalAlignment="Top" Foreground="White" />
443445

444446
<Label x:Name="Lbl_SearchEngines" Content="Search Engines" HorizontalAlignment="Left"
445447
Margin="27,2,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="Bold" />
@@ -461,9 +463,12 @@
461463
<TabItem x:Name="Ti_Info" HorizontalAlignment="Center" Height="20" Header="Info" VerticalAlignment="Center"
462464
Width="54">
463465
<Grid Background="{DynamicResource Black1}">
464-
<Label x:Name="Lb_Version" Content="Current version" HorizontalAlignment="Left" Margin="10,21,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="Bold"/>
465-
<TextBlock x:Name="Tb_Version" HorizontalAlignment="Left" Margin="112,26,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" Width="115"/>
466-
<Button x:Name="Btn_OpenFolder" Content="Open program folder" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Click="Btn_OpenFolder_Click"/>
466+
<Label x:Name="Lb_Version" Content="Current version" HorizontalAlignment="Left" Margin="10,21,0,0"
467+
VerticalAlignment="Top" Foreground="White" FontWeight="Bold" />
468+
<TextBlock x:Name="Tb_Version" HorizontalAlignment="Left" Margin="112,26,0,0" TextWrapping="Wrap"
469+
VerticalAlignment="Top" Foreground="White" Width="115" />
470+
<Button x:Name="Btn_OpenFolder" Content="Open program folder" HorizontalAlignment="Left"
471+
Margin="10,162,0,0" VerticalAlignment="Top" Click="Btn_OpenFolder_Click" />
467472
<ListView x:Name="Lv_Logs" ItemsSource="{Binding Logs}"
468473
Foreground="White"
469474
Background="{DynamicResource Black2}"
@@ -475,9 +480,12 @@
475480
</GridView>
476481
</ListView.View>
477482
</ListView>
478-
<Label x:Name="Lb_Version2" Content="Latest version" HorizontalAlignment="Left" Margin="10,52,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="Bold"/>
479-
<TextBlock x:Name="Tb_Version2" HorizontalAlignment="Left" Margin="103,57,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" Width="90"/>
480-
<Button x:Name="Btn_OpenWiki" Content="Open wiki" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Width="70" Click="Btn_OpenWiki_Click"/>
483+
<Label x:Name="Lb_Version2" Content="Latest version" HorizontalAlignment="Left" Margin="10,52,0,0"
484+
VerticalAlignment="Top" Foreground="White" FontWeight="Bold" />
485+
<TextBlock x:Name="Tb_Version2" HorizontalAlignment="Left" Margin="103,57,0,0" TextWrapping="Wrap"
486+
VerticalAlignment="Top" Foreground="White" Width="90" />
487+
<Button x:Name="Btn_OpenWiki" Content="Open wiki" HorizontalAlignment="Left" Margin="10,132,0,0"
488+
VerticalAlignment="Top" Width="70" Click="Btn_OpenWiki_Click" />
481489
</Grid>
482490
</TabItem>
483491
</TabControl>

SmartImage.UI/MainWindow.xaml.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public MainWindow()
116116
RenderOptions.SetBitmapScalingMode(Img_Preview, BitmapScalingMode.HighQuality);
117117

118118
Application.Current.Dispatcher.InvokeAsync(CheckForUpdate);
119+
ResizeMode = ResizeMode.NoResize;//todo
119120
}
120121

121122
#region
@@ -291,7 +292,7 @@ private async Task UpdateQueryAsync()
291292

292293
}
293294

294-
private void AddToQueueAsync(string[] files)
295+
private void AddToQueue(string[] files)
295296
{
296297
if (!files.Any()) {
297298
return;
@@ -375,7 +376,7 @@ private void ClipboardListenAsync(object? s, EventArgs e)
375376
enc.Save(ms);
376377
ms.Dispose();
377378

378-
AddToQueueAsync(new[] { fn });
379+
AddToQueue(new[] { fn });
379380
/*Application.Current.Dispatcher.InvokeAsync(() =>
380381
{
381382
return SetQueryAsync(fn);
@@ -393,7 +394,7 @@ private void ClipboardListenAsync(object? s, EventArgs e)
393394
// Queue.Add(txt);
394395
// InputText = txt;
395396

396-
AddToQueueAsync(new[] { txt });
397+
AddToQueue(new[] { txt });
397398

398399
// await SetQueryAsync(txt);
399400
}
@@ -406,7 +407,7 @@ private void ClipboardListenAsync(object? s, EventArgs e)
406407
var rg = new string[files.Count];
407408
files.CopyTo(rg, 0);
408409
rg = rg.Where(x => !m_clipboard.Contains(x) && SearchQuery.IsValidSourceType(x)).ToArray();
409-
AddToQueueAsync(rg);
410+
AddToQueue(rg);
410411

411412
m_clipboard.AddRange(rg);
412413

@@ -724,7 +725,7 @@ private void ParseArgs()
724725
var inp = (string) e.MoveAndGet();
725726

726727
// CurrentQueueItem = inp;
727-
AddToQueueAsync(new[] { inp });
728+
AddToQueue(new[] { inp });
728729
continue;
729730
}
730731

@@ -771,6 +772,7 @@ private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
771772
{
772773
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
773774
}
775+
774776
}
775777

776778
public class ResultModel

0 commit comments

Comments
 (0)