Skip to content

Commit 317e880

Browse files
committed
Refactoring
1 parent 21dd80b commit 317e880

File tree

11 files changed

+76
-81
lines changed

11 files changed

+76
-81
lines changed

SmartImage.Lib/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Uri GetRawResultUrl(ImageQuery query)
7171

7272
//var hostUri = Network.GetHostUri(new Uri(BaseUrl));
7373

74-
bool ok = Network.IsUriAlive(uri, Timeout);
74+
bool ok = Network.IsUriAlive(uri, Timeout);
7575

7676
if (!ok) {
7777
Debug.WriteLine($"{uri} is unavailable", C_WARN);

SmartImage.Lib/Engines/Impl/SauceNaoEngine.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,23 @@ private IEnumerable<SauceNaoDataResult> GetAPIResults(ImageQuery url)
296296

297297
private static ImageResult ConvertToImageResult(SauceNaoDataResult sn)
298298
{
299-
if (sn.Urls != null) {
300-
string url = sn.Urls.FirstOrDefault(u => u != null)!;
301-
302-
string siteName = sn.Index != 0 ? sn.Index.ToString() : null;
303-
304-
// var x = new BasicSearchResult(url, sn.Similarity,
305-
// sn.WebsiteTitle, sn.Creator, sn.Material, sn.Character, siteName);
306-
var imageResult = new ImageResult
307-
{
308-
Url = String.IsNullOrWhiteSpace(url) ? default : new Uri(url),
309-
Similarity = MathF.Round(sn.Similarity, 2),
310-
Description = Strings.NullIfNullOrWhiteSpace(sn.WebsiteTitle),
311-
Artist = Strings.NullIfNullOrWhiteSpace(sn.Creator),
312-
Source = Strings.NullIfNullOrWhiteSpace(sn.Material),
313-
Characters = Strings.NullIfNullOrWhiteSpace(sn.Character),
314-
Site = Strings.NullIfNullOrWhiteSpace(siteName)
315-
};
316-
317-
return imageResult;
318-
}
299+
string url = sn.Urls?.FirstOrDefault(u => u != null);
300+
301+
string siteName = sn.Index != 0 ? sn.Index.ToString() : null;
302+
303+
var imageResult = new ImageResult
304+
{
305+
Url = String.IsNullOrWhiteSpace(url) ? default : new Uri(url),
306+
Similarity = MathF.Round(sn.Similarity, 2),
307+
Description = Strings.NullIfNullOrWhiteSpace(sn.WebsiteTitle),
308+
Artist = Strings.NullIfNullOrWhiteSpace(sn.Creator),
309+
Source = Strings.NullIfNullOrWhiteSpace(sn.Material),
310+
Characters = Strings.NullIfNullOrWhiteSpace(sn.Character),
311+
Site = Strings.NullIfNullOrWhiteSpace(siteName)
312+
};
313+
314+
return imageResult;
319315

320-
return null;
321316
}
322317

323318
private class SauceNaoDataResult

SmartImage.Lib/Engines/Impl/TidderEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using SimpleCore.Net;
99
using SmartImage.Lib.Searching;
1010
using SmartImage.Lib.Utilities;
11+
// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
1112

1213
#nullable enable
1314
namespace SmartImage.Lib.Engines.Impl
@@ -58,7 +59,7 @@ protected override SearchResult Process(IDocument doc, SearchResult sr)
5859
//DeEntize!
5960
string link = titleNode.FirstChild.TryGetAttribute("href");
6061

61-
var bsr = new ImageResult()
62+
var bsr = new ImageResult
6263
{
6364
Artist = author,
6465
Description = title,

SmartImage.Lib/Engines/Impl/TraceMoeEngine.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ private IEnumerable<ImageResult> ConvertResults(TraceMoeRootObject obj)
8888

8989
for (int i = 0; i < results.Length; i++) {
9090
var doc = docs[i];
91-
var sim = MathF.Round((float) (doc.similarity * 100.0f), 2);
91+
float sim = MathF.Round((float) (doc.similarity * 100.0f), 2);
9292

9393

94-
var anilistUrl = ANILIST_URL + doc.anilist;
94+
string anilistUrl = ANILIST_URL + doc.anilist;
9595

96-
var name = m_anilistClient.GetTitle((int) doc.anilist);
96+
string name = m_anilistClient.GetTitle((int) doc.anilist);
9797

9898
results[i] = new ImageResult
9999
{

SmartImage.Lib/Engines/Impl/YandexEngine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using SmartImage.Lib.Searching;
1212
using SmartImage.Lib.Utilities;
1313

14-
#pragma warning disable HAA0101, HAA0601, HAA0502, HAA0401
1514
#nullable enable
1615

1716
namespace SmartImage.Lib.Engines.Impl

SmartImage.Lib/SearchClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public ImageResult[] FindDirectResults()
213213
{
214214
var best = FindBestResults();
215215

216-
216+
217217
best.AsParallel().ForAll(delegate(ImageResult f)
218218
{
219219
f.FindDirectImagesAsync();
@@ -224,7 +224,7 @@ public ImageResult[] FindDirectResults()
224224
//}
225225

226226

227-
best = best.Where(f=>f.Direct!=null).ToArray();
227+
best = best.Where(f => f.Direct != null).ToArray();
228228

229229
//best = best
230230
// .AsParallel()
@@ -234,14 +234,14 @@ public ImageResult[] FindDirectResults()
234234

235235
return best;
236236
}
237-
237+
238238
[CanBeNull]
239239
public ImageResult FindBestResult() => FindBestResults().FirstOrDefault();
240240

241241
/// <summary>
242-
/// Selects the <paramref name="n"/> most detailed results.
242+
/// Selects the most detailed results.
243243
/// </summary>
244-
/// <returns>The <see cref="ImageResult"/>s of the <paramref name="n"/> best <see cref="Results"/></returns>
244+
/// <returns>The <see cref="ImageResult"/>s of the best <see cref="Results"/></returns>
245245
public ImageResult[] FindBestResults()
246246
{
247247
var best = Results.Where(r => r.IsNonPrimitive)

SmartImage.Lib/SearchConfig.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public sealed class SearchConfig
4747
public override string ToString()
4848
{
4949
var sb = new ExtendedStringBuilder();
50-
sb.Append(nameof(SearchEngines), SearchEngines);
51-
sb.Append(nameof(PriorityEngines), PriorityEngines);
52-
sb.Append(nameof(Filtering), Filtering);
53-
sb.Append(nameof(Notification), Notification);
54-
sb.Append(nameof(NotificationImage), NotificationImage);
50+
sb.Append("Search engines", SearchEngines);
51+
sb.Append("Priority engines", PriorityEngines);
52+
sb.Append("Filtering", Filtering);
53+
sb.Append("Notification", Notification);
54+
sb.Append("Notification image", NotificationImage);
5555

5656
return sb.ToString();
5757
}

SmartImage/Core/Info.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
using System;
88
using System.Diagnostics;
99
using System.Diagnostics.CodeAnalysis;
10+
using System.Globalization;
1011
using System.IO;
12+
using System.Linq;
1113
using System.Reflection;
1214
using System.Runtime.CompilerServices;
1315
using System.Text;
16+
using System.Threading;
1417
using SimpleCore.Diagnostics;
1518

1619
// ReSharper disable UnusedMember.Global
@@ -81,13 +84,6 @@ public static string ExeLocation
8184
Guard.AssertNotNull(module);
8285

8386
return module.FileName;
84-
85-
//return FileSystem.FindExecutableLocation(NAME_EXE)!;
86-
87-
//string file = typeof(Info).GetType().Assembly.Location;
88-
// string file = Assembly.GetCallingAssembly().Location;
89-
// string app = System.IO.Path.GetFileNameWithoutExtension(file);
90-
9187
}
9288
}
9389

@@ -104,7 +100,27 @@ public static void Setup()
104100
throw new NotSupportedException();
105101
}
106102

107-
OSIntegration.Setup();
103+
if (!Info.IsAppFolderInPath) {
104+
OSIntegration.HandlePath(IntegrationOption.Add);
105+
}
106+
107+
var languages = Windows.System.UserProfile.GlobalizationPreferences.Languages;
108+
109+
bool zh = languages.Any(l => l.Contains("zh"));
110+
111+
bool ja = languages.Contains("ja");
112+
113+
if (ja || zh) {
114+
115+
Console.WriteLine("Non-Romance language detected!");
116+
Console.WriteLine("If English is not the main IME, things may not work properly!");
117+
118+
NConsole.WaitForInput();
119+
}
120+
121+
//Windows.System.UserProfile.GlobalizationPreferences.Languages
122+
//Thread.CurrentThread.CurrentUICulture
123+
//CultureInfo.CurrentCulture
108124
}
109125
}
110126
}

SmartImage/Core/MainDialog.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace SmartImage.Core
2222
/// <summary>
2323
/// Handles the main menu interface
2424
/// </summary>
25-
public static class MainDialog
25+
internal static class MainDialog
2626
{
2727
#region Colors
2828

@@ -41,10 +41,13 @@ public static class MainDialog
4141

4242
internal static string ToToggleString(this bool b) => b ? Enabled : Disabled;
4343

44-
private static string GetFilterName(bool added) => GetName("Filter", added);
45-
private static string GetNotificationName(bool added) => GetName("Notification", added);
44+
private static string GetFilterName(bool added) => GetName("Filter", added);
45+
46+
private static string GetNotificationName(bool added) => GetName("Notification", added);
47+
4648
private static string GetNotificationImageName(bool added) => GetName("Notification image", added);
47-
private static string GetName(string s, bool added) => $"{s} ({(added.ToToggleString())})";
49+
50+
private static string GetName(string s, bool added) => $"{s} ({(added.ToToggleString())})";
4851

4952

5053
private static string GetContextMenuName(bool added) => GetName("Context menu", added);
@@ -141,7 +144,7 @@ public static class MainDialog
141144
Name = GetContextMenuName(OSIntegration.IsContextMenuAdded),
142145
Function = () =>
143146
{
144-
var added = OSIntegration.IsContextMenuAdded;
147+
bool added = OSIntegration.IsContextMenuAdded;
145148

146149
OSIntegration.HandleContextMenu(added ? IntegrationOption.Remove : IntegrationOption.Add);
147150

@@ -184,10 +187,7 @@ public static class MainDialog
184187
var di = new DirectoryInfo(Info.ExeLocation);
185188

186189
Console.WriteLine($"Executable location: {di.Parent.Name}");
187-
188190
Console.WriteLine($"In path: {Info.IsAppFolderInPath}");
189-
Console.WriteLine($"Context menu added: {OSIntegration.IsContextMenuAdded}");
190-
191191

192192
Console.WriteLine();
193193
Console.WriteLine(Strings.Separator);
@@ -208,7 +208,7 @@ public static class MainDialog
208208
Function = () =>
209209
{
210210
UpdateInfo.AutoUpdate();
211-
211+
212212

213213
return null;
214214
}

SmartImage/Core/OSIntegration.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,6 @@ internal static bool IsContextMenuAdded
201201
}
202202
}
203203

204-
internal static void Setup()
205-
{
206-
if (!Info.IsAppFolderInPath) {
207-
HandlePath(IntegrationOption.Add);
208-
}
209-
210-
//Windows.System.UserProfile.GlobalizationPreferences.Languages
211-
//Thread.CurrentThread.CurrentUICulture
212-
//CultureInfo.CurrentCulture
213-
214-
215-
}
204+
216205
}
217206
}

0 commit comments

Comments
 (0)