Skip to content

Commit 3027346

Browse files
committed
Misc improvements
1 parent fc16e0a commit 3027346

File tree

9 files changed

+313
-652
lines changed

9 files changed

+313
-652
lines changed

SmartImage.Lib/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Uri GetRawResultUri(ImageQuery query)
8282
//}
8383

8484
if (!Network.IsAlive(uri, (long) Timeout.TotalMilliseconds)) {
85-
Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g})", C_WARN);
85+
Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g}", C_WARN);
8686
return null;
8787
}
8888

SmartImage.Lib/Searching/ImageResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public void FindDirectImages()
216216
if (ImageHelper.IsDirect(Url.ToString(), DirectImageType.Binary)) {
217217
Direct = Url;
218218
}
219+
219220
else {
220221
try {
221222

SmartImage.Lib/Utilities/ImageHelper.cs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public static Dictionary<string, string> UtilitiesMap
128128
var rg = new Dictionary<string, string>();
129129

130130
foreach (string exe in Utilities) {
131-
var path = FileSystem.SearchInPath(exe);
132-
131+
string path = FileSystem.SearchInPath(exe);
133132

134133
rg.Add(exe, path);
135134
}
@@ -151,14 +150,21 @@ public static string Download(Uri direct)
151150
string filename = Path.GetFileName(direct.AbsolutePath);
152151

153152
if (!Path.HasExtension(filename)) {
153+
154+
// If no format is specified/found, just append a jpg extension
155+
string ext = ".jpg";
156+
154157
// For Pixiv (?)
155158
var kv = HttpUtility.ParseQueryString(direct.Query);
156-
var t = kv["format"];
159+
160+
var t = kv["format"];
157161

158162
if (t != null) {
159-
filename += $".{t}";
163+
ext = $".{t}";
160164
}
161165

166+
filename += ext;
167+
162168
Debug.WriteLine("Fixed file");
163169
}
164170

@@ -323,39 +329,25 @@ public static List<string> FindDirectImages(string url, DirectImageType directTy
323329

324330

325331
/*
326-
* Tasks
327-
* 1 5.19
328-
* 2 4.68
329-
* 3 4.54
330-
* 4 4.42
331-
*
332-
* Parallel
333-
* 1 4.59
334-
* 2 4.37
335-
* 3 4.28
336-
* 4 4.34
337-
* 5 4.38
338-
* 6 4.55
339-
* 7 4.36
340-
* 8 4.45
332+
* Tasks Parallel Parallel 2
333+
* 1 5.19 1 4.59 9 3.84
334+
* 2 4.68 2 4.37 10 3.56
335+
* 3 4.54 3 4.28 11 3.45
336+
* 4 4.42 4 4.34 12 3.52
337+
* 5 4.38 13 3.63
338+
* 6 4.55 14 3.52
339+
* 7 4.36
340+
* 8 4.45
341341
*
342-
* 9 3.84
343-
* 10 3.56
344-
* 11 3.45
345-
* 12 3.52
346-
* 13 3.63
347-
* 14 3.52
348342
*
349-
* 15 3.39
350-
* 16 3.52
351-
* 17 3.58
352-
* 18 3.47
343+
* Parallel 3 Parallel 4
344+
* 15 3.39 20 3.13
345+
* 16 3.52 21 2.89
346+
* 17 3.58 22 2.87
347+
* 18 3.47 23 2.89
353348
* 19 3.33
354-
*
355-
* 20 3.13
356-
* 21 2.89
357-
* 22 2.87
358-
* 23 2.89
349+
*
350+
*
359351
*/
360352

361353
images = imagesCopy;

SmartImage/Core/AppConfig.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void ReadConfigFile()
6464
Debug.WriteLine($"Updated config from {ConfigFile}");
6565
}
6666

67-
public static void SaveConfigFile()
67+
private static void SaveConfigFile()
6868
{
6969
var map = ConfigMap;
7070

@@ -78,5 +78,11 @@ public static void SaveConfigFile()
7878
private const string K_FILTER = "filter";
7979
private const string K_NOTIFICATION = "notification";
8080
private const string K_NOTIFICATION_IMAGE = "notification-image";
81+
82+
public static void UpdateConfig()
83+
{
84+
Program.Client.Reload();
85+
AppConfig.SaveConfigFile();
86+
}
8187
}
8288
}

SmartImage/Core/AppInfo.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Threading;
1717
using Kantan.Cli;
1818
using Kantan.Diagnostics;
19+
1920
// ReSharper disable CognitiveComplexity
2021

2122
// ReSharper disable PossibleNullReferenceException
@@ -61,15 +62,15 @@ public static class AppInfo
6162
/// </summary>
6263
public const string NAME_CFG = "SmartImage.cfg";
6364

64-
public const string Author = "Read Stanton";
65+
public const string AUTHOR = "Read Stanton";
6566

66-
public const string Repo = "https://github.com/Decimation/SmartImage";
67+
public const string URL_REPO = "https://github.com/Decimation/SmartImage";
6768

68-
public const string Readme = "https://github.com/Decimation/SmartImage/blob/master/README.md";
69+
public const string URL_README = "https://github.com/Decimation/SmartImage/blob/master/README.md";
6970

70-
public const string Issue = "https://github.com/Decimation/SmartImage/issues/new";
71+
public const string URL_ISSUE = "https://github.com/Decimation/SmartImage/issues/new";
7172

72-
public const string Wiki = "https://github.com/Decimation/SmartImage/wiki";
73+
public const string URL_WIKI = "https://github.com/Decimation/SmartImage/wiki";
7374

7475
public static string AppFolder => Path.GetDirectoryName(ExeLocation);
7576

@@ -91,8 +92,6 @@ public static string ExeLocation
9192
}
9293
}
9394

94-
95-
9695

9796
public static bool IsAppFolderInPath => FileSystem.IsFolderInPath(AppFolder);
9897

SmartImage/Program.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444

4545
namespace SmartImage
4646
{
47+
// ____ _ ___
48+
// / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___
49+
// \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \
50+
// ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/
51+
// |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|
52+
// |___/
53+
4754
public static class Program
4855
{
49-
// ____ _ ___
50-
// / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___
51-
// \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \
52-
// ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/
53-
// |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|
54-
// |___/
55-
5656
#region Core fields
5757

5858
public static readonly SearchConfig Config = new();
@@ -62,7 +62,7 @@ public static class Program
6262
public static readonly NConsoleDialog ResultDialog = new()
6363
{
6464
Options = new List<NConsoleOption>(),
65-
Description = AppInterface.Description
65+
Description = InterfaceElements.Description
6666
};
6767

6868
#endregion
@@ -87,7 +87,7 @@ private static async Task Main(string[] args)
8787
* Register events
8888
*/
8989

90-
ToastNotificationManagerCompat.OnActivated += AppToast.OnActivated;
90+
ToastNotificationManagerCompat.OnActivated += AppInterface.OnToastActivated;
9191

9292
Native.SetConsoleOutputCP(Native.CP_IBM437);
9393

@@ -114,8 +114,7 @@ private static async Task Main(string[] args)
114114
return;
115115

116116

117-
try
118-
{
117+
try {
119118

120119
CancellationTokenSource cts = new();
121120

@@ -126,22 +125,21 @@ private static async Task Main(string[] args)
126125

127126
Client.SearchCompleted += (obj, eventArgs) => OnSearchCompleted(obj, eventArgs, cts);
128127

129-
Client.ExtraResults += AppToast.Show;
128+
Client.ExtraResults += AppInterface.ShowToast;
130129

131130
NConsoleProgress.Queue(cts);
132131

133132
// Show results
134133
var searchTask = Client.RunSearchAsync();
135134

136135
// Add original image
137-
ResultDialog.Options.Add(AppInterface.CreateResultOption(
136+
ResultDialog.Options.Add(InterfaceElements.CreateResultOption(
138137
Config.Query.GetImageResult(), "(Original image)",
139-
AppInterface.ColorMain, -0.1f));
138+
InterfaceElements.ColorMain, -0.1f));
140139

141140

142141
NConsole.ReadOptions(ResultDialog);
143142

144-
145143
await searchTask;
146144
}
147145
catch (Exception exception) {
@@ -156,7 +154,7 @@ private static async Task Main(string[] args)
156154
private static bool HandleArguments(string[] args)
157155
{
158156
if (!args.Any()) {
159-
var options = NConsole.ReadOptions(AppInterface.MainMenuDialog);
157+
HashSet<object> options = NConsole.ReadOptions(AppInterface.MainMenuDialog);
160158

161159
if (!options.Any()) {
162160
return true;
@@ -183,13 +181,13 @@ private static bool HandleArguments(string[] args)
183181

184182
var imageResults = directImages.Select(ImageResult.FromDirectImage);
185183

186-
var directOptions = AppInterface.CreateResultOptions(imageResults, "Image");
184+
var directOptions = InterfaceElements.CreateResultOptions(imageResults, "Image");
187185

188186

189187
NConsole.ReadOptions(new NConsoleDialog
190188
{
191189
Options = directOptions,
192-
Description = AppInterface.Description
190+
Description = InterfaceElements.Description
193191
});
194192

195193
return true;
@@ -215,12 +213,11 @@ private static bool HandleArguments(string[] args)
215213

216214
private static void OnSearchCompleted(object? sender, List<SearchResult> eventArgs, CancellationTokenSource cts)
217215
{
218-
AppInterface.FlashConsoleWindow();
216+
Native.FlashConsoleWindow();
219217

220218
cts.Cancel();
221219
cts.Dispose();
222220

223-
224221
SystemSounds.Exclamation.Play();
225222

226223
}
@@ -230,7 +227,7 @@ private static void OnResultCompleted(object? sender, SearchResultEventArgs even
230227
{
231228
var result = eventArgs.Result;
232229

233-
var option = AppInterface.CreateResultOption(result);
230+
var option = InterfaceElements.CreateResultOption(result);
234231

235232
bool? isFiltered = eventArgs.IsFiltered;
236233

0 commit comments

Comments
 (0)