Skip to content

Commit d5bbec1

Browse files
committed
2.0.6
1 parent 327c9be commit d5bbec1

File tree

6 files changed

+55
-68
lines changed

6 files changed

+55
-68
lines changed

SmartImage/Core/Interface.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,9 @@ private static NConsoleOption[] AllOptions
130130
Color = ColorConfig,
131131
Function = () =>
132132
{
133-
var rgEnum = NConsoleOption.FromEnum<SearchEngineOptions>();
134-
var values = NConsole.ReadOptions(rgEnum, true);
135-
136-
var newValues = Enums.ReadFromSet<SearchEngineOptions>(values);
137-
138-
NConsole.WriteSuccess(newValues);
139-
140-
SearchConfig.Config.SearchEngines = newValues;
141-
133+
SearchConfig.Config.SearchEngines = ReadSearchEngineOptions();
134+
SearchConfig.Config.EnsureConfig();
135+
NConsole.WriteSuccess(SearchConfig.Config.SearchEngines);
142136
NConsole.WaitForSecond();
143137
return null;
144138
}
@@ -151,21 +145,26 @@ private static NConsoleOption[] AllOptions
151145
Color = ColorConfig,
152146
Function = () =>
153147
{
154-
var rgEnum = NConsoleOption.FromEnum<SearchEngineOptions>();
155-
var values = NConsole.ReadOptions(rgEnum, true);
156-
157-
var newValues = Enums.ReadFromSet<SearchEngineOptions>(values);
158-
159-
NConsole.WriteSuccess(newValues);
160-
161-
SearchConfig.Config.PriorityEngines = newValues;
162-
148+
SearchConfig.Config.PriorityEngines = ReadSearchEngineOptions();
149+
SearchConfig.Config.EnsureConfig();
150+
NConsole.WriteSuccess(SearchConfig.Config.PriorityEngines);
163151
NConsole.WaitForSecond();
164152
return null;
165153
}
166154
};
167155

168156

157+
private static SearchEngineOptions ReadSearchEngineOptions()
158+
{
159+
var rgEnum = NConsoleOption.FromEnum<SearchEngineOptions>();
160+
var values = NConsole.ReadOptions(rgEnum, true);
161+
162+
var newValues = Enums.ReadFromSet<SearchEngineOptions>(values);
163+
164+
return newValues;
165+
}
166+
167+
169168
private static readonly NConsoleOption ConfigSauceNaoAuthOption = new()
170169
{
171170
Name = "Configure SauceNao API authentication",
@@ -201,17 +200,13 @@ private static NConsoleOption[] AllOptions
201200
{
202201

203202
SearchConfig.Config.FilterResults = !SearchConfig.Config.FilterResults;
204-
ConfigAutoFilter.Name= GetAutoFilterString();
203+
ConfigAutoFilter.Name = GetAutoFilterString();
205204
return null;
206205
}
207206
};
208-
207+
209208
private static string GetAutoFilterString()
210209
{
211-
//var x = SearchConfig.Config.FilterResults
212-
// ? Formatting.CHECK_MARK.ToString()
213-
// : Formatting.BALLOT_X.ToString();
214-
215210
var x = SearchConfig.Config.FilterResults;
216211
return $"Filter results: {x}";
217212
}
@@ -252,10 +247,10 @@ private static string GetAutoFilterString()
252247
bool ctx = Integration.IsContextMenuAdded;
253248

254249
var io = !ctx ? IntegrationOption.Add : IntegrationOption.Remove;
255-
250+
256251
Integration.HandleContextMenu(io);
257252
bool added = io == IntegrationOption.Add;
258-
253+
259254
NConsole.WriteInfo($"Context menu integrated: {added}");
260255

261256
ContextMenuOption.Name = GetContextMenuString(added);

SmartImage/Core/SearchConfig.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -28,13 +29,6 @@ namespace SmartImage.Core
2829
/// <seealso cref="ConfigComponents" />
2930
public sealed class SearchConfig
3031
{
31-
/// <summary>
32-
/// Illegal <see cref="SearchEngineOptions" /> values for <see cref="SearchEngines" />
33-
/// </summary>
34-
private const SearchEngineOptions IllegalSearchEngineOptions =
35-
SearchEngineOptions.None | SearchEngineOptions.Auto;
36-
37-
3832
private SearchConfig()
3933
{
4034
// Read config from config file
@@ -60,13 +54,13 @@ private SearchConfig()
6054
/// <summary>
6155
/// Engines to use for searching
6256
/// </summary>
63-
[field: ConfigComponent("search_engines", "--search-engines", SearchEngineOptions.All)]
57+
[field: ConfigComponent("search_engines", "--search-engines", SearchEngineOptions.All, true)]
6458
public SearchEngineOptions SearchEngines { get; set; }
6559

6660
/// <summary>
6761
/// Engines whose results should be opened in the browser
6862
/// </summary>
69-
[field: ConfigComponent("priority_engines", "--priority-engines", SearchEngineOptions.Auto)]
63+
[field: ConfigComponent("priority_engines", "--priority-engines", SearchEngineOptions.Auto, true)]
7064
public SearchEngineOptions PriorityEngines { get; set; }
7165

7266
/// <summary>
@@ -82,7 +76,8 @@ private SearchConfig()
8276
public string SauceNaoAuth { get; set; }
8377

8478
/// <summary>
85-
/// Does not open results from priority engines if the result similarity (if available) is below a certain threshold.
79+
/// Does not open results from priority engines if the result similarity (if available) is below a certain threshold,
80+
/// or there are no relevant results.
8681
/// <see cref="ISearchResult.Filter"/> is <c>true</c> if <see cref="ISearchEngine.FilterThreshold"/> is less than <see cref="ISearchResult.Similarity"/>
8782
/// </summary>
8883
[field: ConfigComponent("filter_results", "--filter-results", true, true)]
@@ -155,24 +150,16 @@ public void EnsureConfig()
155150
* Check search engine options
156151
*/
157152

158-
var illegalOptions = SearchEngines & IllegalSearchEngineOptions;
153+
const SearchEngineOptions Illegal = SearchEngineOptions.Auto;
159154

160-
if (illegalOptions != 0) {
161-
NConsole.WriteError($"Search engine option {illegalOptions} cannot be used for search engine options");
162-
163-
NConsole.WaitForSecond();
164-
165-
// Clear illegal options
166-
SearchEngines &= ~illegalOptions;
155+
if (SearchEngines.HasFlag(Illegal)) {
156+
SearchEngines &= ~Illegal;
157+
Debug.WriteLine($"Removed illegal flag -> {SearchEngines}");
167158
}
168159

169-
// Special case
170160
if (SearchEngines == SearchEngineOptions.None) {
171-
NConsole.WriteInfo("Reverting search engine options to default");
172-
NConsole.WaitForSecond();
173161
ConfigComponents.ResetComponent(this, nameof(SearchEngines));
174162
}
175-
176163
}
177164

178165

SmartImage/Engines/Other/IqdbEngine.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public IqdbEngine() : base("https://iqdb.org/?url=") { }
2626

2727
private struct IqdbResult : ISearchResult
2828
{
29-
public bool Filter { get; set; }
30-
29+
public bool Filter { get; set; }
30+
3131
public string? Caption { get; set; }
3232

3333
public string Source { get; }
@@ -141,7 +141,9 @@ public override FullSearchResult GetResult(string url)
141141
bool noMatch = pages.ChildNodes.Any(n => n.GetAttributeValue("class", null) == "nomatch");
142142

143143
if (noMatch) {
144-
sr.ExtendedInfo.Add("No relevant results");
144+
//sr.ExtendedInfo.Add("No relevant results");
145+
// No relevant results
146+
sr.Filter = true;
145147
return sr;
146148
}
147149

SmartImage/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ private static void Main(string[] args)
5050
Console.Title = Info.NAME;
5151

5252
NConsole.Resize(Interface.ConsoleWindowWidth, Interface.ConsoleWindowHeight);
53-
54-
Console.OutputEncoding = Encoding.Unicode;
53+
54+
55+
5556
Console.Clear();
5657

5758
Console.WriteLine(Info.NAME_BANNER);

SmartImage/Searching/FullSearchResult.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Diagnostics;
66
using System.Drawing;
7+
using System.Linq;
78
using System.Text;
89
using Novus.Win32;
910
using SimpleCore.Console.CommandLine;
@@ -138,11 +139,10 @@ public override NConsoleFunction ComboFunction
138139
public string Url { get; set; }
139140

140141
public int? Width { get; set; }
141-
142+
142143

143144
public bool Filter { get; set; }
144-
145-
145+
146146

147147
public void AddExtendedResults(ISearchResult[] bestImages)
148148
{
@@ -164,17 +164,23 @@ public override string ToString()
164164
{
165165
var sb = new StringBuilder();
166166

167-
string attrSuccess = Formatting.CHECK_MARK.ToString();
167+
/*
168+
* Result symbols
169+
*/
168170

171+
if (ExtendedResults.Any()) {
172+
sb.Append($"({ExtendedResults.Count})").Append(Formatting.SPACE);
173+
}
169174

170-
string? ex = ExtendedResults.Count > 0
171-
? String.Format($"({ExtendedResults.Count})")
172-
: String.Empty;
175+
if (Filter) {
176+
sb.Append("-").Append(Formatting.SPACE);
177+
}
173178

174-
var fstr = Filter ? $"{Formatting.BALLOT_X}" : "";
175-
176-
sb.Append($"{attrSuccess} {ex} {fstr}\n");
179+
sb.AppendLine();
177180

181+
/*
182+
* Result details
183+
*/
178184

179185
if (RawUrl != Url) {
180186
sb.Append($"\tResult: {Url}\n");
@@ -200,10 +206,6 @@ public override string ToString()
200206
sb.Append($"\t{s}\n");
201207
}
202208

203-
// if (ExtendedResults.Count > 0) {
204-
// sb.AppendFormat("\tExtended results: {0}\n", ExtendedResults.Count);
205-
// }
206-
207209
return sb.ToString();
208210
}
209211

SmartImage/SmartImage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
<PropertyGroup>
4444
<PackageId>SmartImage</PackageId>
45-
<Version>2.0.5</Version>
45+
<Version>2.0.6</Version>
4646
<Authors>Read Stanton (Decimation)</Authors>
4747
<PackageTags>Image reverse search identification source sauce</PackageTags>
4848
<RepositoryUrl>https://github.com/Decimation/SmartImage</RepositoryUrl>

0 commit comments

Comments
 (0)