Skip to content

Commit 4355631

Browse files
committed
...
1 parent a1007d5 commit 4355631

File tree

13 files changed

+124
-68
lines changed

13 files changed

+124
-68
lines changed

SmartImage 3/App/Integration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ public static bool HandleContextMenu(bool option)
8484

8585
try {
8686
regMenu = Registry.CurrentUser.CreateSubKey(R1.Reg_Shell);
87-
regMenu?.SetValue(String.Empty, Resources.Name);
87+
regMenu?.SetValue(String.Empty, R2.Name);
8888
regMenu?.SetValue("Icon", $"\"{fullPath}\"");
8989

9090
regCmd = Registry.CurrentUser.CreateSubKey(R1.Reg_Shell_Cmd);
9191

9292
regCmd?.SetValue(String.Empty,
93-
$"\"{fullPath}\" {Resources.Arg_Input} \"%1\" {R2.Arg_AutoSearch}");
93+
$"\"{fullPath}\" {R2.Arg_Input} \"%1\" {R2.Arg_AutoSearch}");
9494
}
9595
catch (Exception ex) {
9696
Trace.WriteLine($"{ex.Message}");

SmartImage 3/Mode/CliMode.cs

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,11 @@ public sealed class CliMode : IDisposable, IMode
1919
{
2020
#region
2121

22-
private const double COMPLETE = 100.0D;
23-
24-
private static readonly ProgressColumn[] PrgCol_1 =
22+
static CliMode()
2523
{
26-
new TaskDescriptionColumn()
27-
{
28-
Alignment = Justify.Left
29-
},
30-
new SpinnerColumn(),
31-
new ElapsedTimeColumn(),
32-
new ProgressBarColumn()
33-
};
24+
Debug.WriteLine($"{AConsole.Profile.Capabilities.Unicode} {AConsole.Profile.Capabilities.Links}");
3425

35-
private static readonly Progress Prg_1 = AnsiConsole.Progress()
36-
.AutoClear(true)
37-
.AutoRefresh(true)
38-
.HideCompleted(true)
39-
.Columns(PrgCol_1);
40-
41-
static CliMode() { }
26+
}
4227

4328
#endregion
4429

@@ -54,6 +39,7 @@ static CliMode() { }
5439

5540
private readonly CancellationTokenSource m_cts;
5641

42+
public SearchConfig Config => m_cfg;
5743
public CliMode()
5844
{
5945
m_cfg = new SearchConfig();
@@ -66,31 +52,33 @@ public CliMode()
6652
{
6753

6854
// await Prg_1.StartAsync(ctx => ValidateInputAsync(ctx, c as string));
69-
await ValidateInputAsync(null, c as string);
70-
AnsiConsole.WriteLine($"{m_query}");
55+
await ValidateInputAsync((c as string)!);
56+
AConsole.WriteLine($"{m_query}");
7157

7258
// var url = await Prg_1.StartAsync(UploadInputAsync);
7359

74-
var url = await UploadInputAsync(null);
75-
AnsiConsole.MarkupLine($"[green]{m_query.Upload}[/]");
60+
var url = await UploadInputAsync();
7661

77-
AnsiConsole.WriteLine($"{m_cfg}");
62+
AConsole.MarkupLine($"[green]{m_query.Upload}[/]");
7863

79-
Console.CancelKeyPress += (sender, args) =>
64+
AConsole.WriteLine($"{m_cfg}");
65+
66+
SConsole.CancelKeyPress += (sender, args) =>
8067
{
8168
args.Cancel = false;
8269
m_cts.Cancel();
83-
AnsiConsole.MarkupLine($"[red]Cancellation requested {args}[/]");
70+
AConsole.MarkupLine($"[red]Cancellation requested {args}[/]");
8471
};
8572

8673
// await Prg_1.StartAsync(RunSearchAsync);
8774

88-
await RunSearchAsync(null);
75+
await RunSearchAsync();
76+
8977
return null;
9078

9179
}
9280

93-
private async Task ValidateInputAsync(ProgressContext ctx, string c)
81+
private async Task ValidateInputAsync(string c)
9482
{
9583
// var t = ctx.AddTask("Validating input");
9684
// t.IsIndeterminate = true;
@@ -100,7 +88,7 @@ private async Task ValidateInputAsync(ProgressContext ctx, string c)
10088
// t.Increment(COMPLETE);
10189
}
10290

103-
private async Task<Url> UploadInputAsync(ProgressContext p)
91+
private async Task<Url> UploadInputAsync()
10492
{
10593
// var pt = p.AddTask($"Upload");
10694
// pt.IsIndeterminate = true;
@@ -110,7 +98,7 @@ private async Task<Url> UploadInputAsync(ProgressContext p)
11098

11199
}
112100

113-
private async Task RunSearchAsync(ProgressContext ctx)
101+
private async Task RunSearchAsync()
114102
{
115103
/*var ptMap = new Dictionary<BaseSearchEngine, (ProgressTask, Table)>();
116104
@@ -170,19 +158,21 @@ void OnResult(object sender, SearchResult sr)
170158
while (!pt1.IsFinished) { }*/
171159
var sw = Stopwatch.StartNew();
172160

173-
var sp = AnsiConsole.Status().Spinner(Spinner.Known.Aesthetic).StartAsync("Wait...", async ctx =>
174-
{
175-
// await ttt;
161+
var sp = AConsole.Status()
162+
.Spinner(Spinner.Known.Aesthetic)
163+
.StartAsync("Wait...", async ctx =>
164+
{
165+
// await ttt;
176166

177-
while (!ttt.IsCompleted) {
178-
ctx.Refresh();
179-
await Task.Delay(TimeSpan.FromMilliseconds(300));
167+
while (!ttt.IsCompleted) {
168+
ctx.Refresh();
169+
await Task.Delay(TimeSpan.FromMilliseconds(300));
180170

181-
ctx.Status =
182-
$"{m_results.Count} | {m_results.Sum(c => c.Results.Count)} | {sw.Elapsed.TotalSeconds:3F}";
183-
}
184-
// m_results2 = await ttt;
185-
});
171+
ctx.Status =
172+
$"{m_results.Count} | {m_results.Sum(c => c.Results.Count)} | {sw.Elapsed.TotalSeconds:3F}";
173+
}
174+
// m_results2 = await ttt;
175+
});
186176

187177
await ttt;
188178

@@ -204,7 +194,7 @@ void OnResult(object sender, SearchResult sr)
204194

205195
foreach (var vt in ptMap.Values) {
206196
// vt.Item1.StopTask();
207-
AnsiConsole.Write(vt.Item2);
197+
AConsole.Write(vt.Item2);
208198
}
209199

210200
}

SmartImage 3/Mode/Shell/ShellMain.Handlers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private static void Clear_Clicked()
157157
private void Cancel_Clicked()
158158
{
159159
m_token.Cancel();
160-
Lbl_Status2.Text = Resources.Inf_Cancel;
160+
Lbl_Status2.Text = R2.Inf_Cancel;
161161
Lbl_Status2.SetNeedsDisplay();
162162
Btn_Restart.Enabled = true;
163163
Application.MainLoop.RemoveIdle(m_runIdleTok);

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed partial class ShellMode : IDisposable, IMode
3636

3737
private static readonly Toplevel Top = Application.Top;
3838

39-
private static readonly Window Win = new(Resources.Name)
39+
private static readonly Window Win = new(R2.Name)
4040
{
4141
X = 0,
4242
Y = 1,
@@ -307,7 +307,7 @@ public ShellMode(string[] args)
307307
{
308308
new("Engine", typeof(string)),
309309

310-
new(nameof(SearchResultItem.Url), typeof(Flurl.Url)),
310+
new(nameof(SearchResultItem.Url), typeof(Url)),
311311
new(nameof(SearchResultItem.Score), typeof(int)),
312312
new(nameof(SearchResultItem.Similarity), typeof(double)),
313313
new(nameof(SearchResultItem.Artist), typeof(string)),

SmartImage 3/Program.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable disable
2-
2+
global using AConsole = Spectre.Console.AnsiConsole;
3+
global using SConsole = System.Console;
34
global using static Kantan.Diagnostics.LogCategories;
45
using Console = Spectre.Console.AnsiConsole;
56
using System.CommandLine;
67
using System.Diagnostics;
78
using System.Runtime.CompilerServices;
9+
using System.Text;
810
using Kantan.Threading;
911
// using Windows.UI.Notifications;
1012
// using CommunityToolkit.WinUI.Notifications;
@@ -37,18 +39,20 @@ public static class Program
3739
public static void Init()
3840
{
3941
Global.Setup();
40-
Trace.WriteLine("Init", Resources.Name);
42+
Trace.WriteLine("Init", R2.Name);
4143
// Gui.Init();
4244
System.Console.Title = R2.Name;
4345

4446
if (Compat.IsWin) {
4547
ConsoleUtil.SetConsoleMode();
48+
System.Console.OutputEncoding = Encoding.Unicode;
4649
}
4750

4851
AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
4952
{
5053
Trace.WriteLine($"Exiting", R2.Name);
5154
};
55+
5256
}
5357

5458
public static async Task<int> Main(string[] args)
@@ -64,7 +68,7 @@ public static async Task<int> Main(string[] args)
6468
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
6569

6670
Debug.WriteLine($"TEST");
67-
71+
6872
/*
6973
* & .\bin\Test\net7.0\win10-x64\SmartImage.exe --noui --i C:\Users\Deci\Pictures\lilith___the_maid_i_hired_recently_is_mysterious_by_sciamano240_dfnpdmn.png
7074
*
@@ -74,7 +78,7 @@ public static async Task<int> Main(string[] args)
7478

7579
bool cli = args is { } && args.Any();
7680

77-
if (cli && args.Contains(Resources.Arg_NoUI)) {
81+
if (cli && args.Contains(R2.Arg_NoUI)) {
7882

7983
var main = new CliMode();
8084

@@ -83,14 +87,15 @@ public static async Task<int> Main(string[] args)
8387

8488
var options = new Option[]
8589
{
86-
new Option<string>(Resources.Arg_Input)
90+
new Option<string>(R2.Arg_Input)
8791
{ },
8892

89-
new Option<bool>(Resources.Arg_NoUI)
93+
new Option<bool>(R2.Arg_NoUI)
9094
{
9195
Arity = ArgumentArity.Zero,
9296

93-
}
97+
},
98+
9499
};
95100

96101
foreach (Option option in options) {

SmartImage 3/SmartImage.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
6565
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
6666
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
67+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
6768
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
6869
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
6970
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />

SmartImage.Lib 3/Engines/ILoginEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public interface ILoginEngine
1111

1212
public Task<bool> LoginAsync();
1313

14-
public bool IsLoggedIn { get; }
14+
public bool IsLoggedIn { get; }
1515

1616
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public sealed class EHentaiEngine : WebSearchEngine, ILoginEngine, IConfig,
5555

5656
public override SearchEngineOptions EngineOption => SearchEngineOptions.EHentai;
5757

58-
protected override string NodesSelector => "//table/tbody/tr";
58+
protected override string NodesSelector => Serialization.S_EHentai;
5959

6060
static EHentaiEngine() { }
6161

@@ -188,15 +188,15 @@ protected override async Task<IDocument> GetDocumentAsync(object origin, SearchQ
188188
return await parser.ParseDocumentAsync(content);
189189
}
190190

191-
private async Task<IFlurlResponse> GetSessionAsync()
191+
private Task<IFlurlResponse> GetSessionAsync()
192192
{
193-
return await ExHentaiBase.WithCookies(Cookies)
194-
.WithHeaders(new
195-
{
196-
User_Agent = HttpUtilities.UserAgent
197-
})
198-
.WithAutoRedirect(true)
199-
.GetAsync();
193+
return ExHentaiBase.WithCookies(Cookies)
194+
.WithHeaders(new
195+
{
196+
User_Agent = HttpUtilities.UserAgent
197+
})
198+
.WithAutoRedirect(true)
199+
.GetAsync();
200200
}
201201

202202
protected override ValueTask<INode[]> GetNodes(IDocument d)

SmartImage.Lib 3/SearchClient.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using ICBN = JetBrains.Annotations.ItemCanBeNullAttribute;
2+
using System.Collections;
23
using System.Diagnostics;
34
using System.Text.Json;
45
using Flurl.Http;
@@ -56,7 +57,7 @@ static SearchClient()
5657

5758
var handler = new LoggingHttpMessageHandler(Logger)
5859
{
59-
InnerHandler = new HttpClientLoggingHandler(Logger)
60+
InnerHandler = new HttpLoggingHandler(Logger)
6061
{
6162
InnerHandler = new HttpClientHandler()
6263
}
@@ -193,6 +194,50 @@ public async ValueTask ApplyConfigAsync()
193194
[CBN]
194195
public BaseSearchEngine TryGetEngine(SearchEngineOptions o) => Engines.FirstOrDefault(e => e.EngineOption == o);
195196

197+
public class SearchResultItemCollection : ICollection<SearchResultItem>
198+
{
199+
private readonly ICollection<SearchResultItem> m_value;
200+
201+
public IEnumerator<SearchResultItem> GetEnumerator()
202+
{
203+
return m_value.GetEnumerator();
204+
}
205+
206+
IEnumerator IEnumerable.GetEnumerator()
207+
{
208+
return ((IEnumerable) m_value).GetEnumerator();
209+
}
210+
211+
public void Add(SearchResultItem item)
212+
{
213+
m_value.Add(item);
214+
}
215+
216+
public void Clear()
217+
{
218+
m_value.Clear();
219+
}
220+
221+
public bool Contains(SearchResultItem item)
222+
{
223+
return m_value.Contains(item);
224+
}
225+
226+
public void CopyTo(SearchResultItem[] array, int arrayIndex)
227+
{
228+
m_value.CopyTo(array, arrayIndex);
229+
}
230+
231+
public bool Remove(SearchResultItem item)
232+
{
233+
return m_value.Remove(item);
234+
}
235+
236+
public int Count => m_value.Count;
237+
238+
public bool IsReadOnly => m_value.IsReadOnly;
239+
}
240+
196241
public static IReadOnlyList<SearchResultItem> Optimize(IEnumerable<SearchResultItem> sri)
197242
{
198243
var items = sri.Where(r => SearchQuery.IsValidSourceType(r.Url))

SmartImage.Lib 3/Serialization.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)