Skip to content

Commit c858e10

Browse files
committed
Bug fixes, refactoring
1 parent f7318e4 commit c858e10

File tree

5 files changed

+25
-52
lines changed

5 files changed

+25
-52
lines changed

SmartImage/Core/Info.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static string AppFolder
9090
public static bool IsExeInAppFolder => File.Exists(Path.Combine(AppFolder, NAME_EXE));
9191

9292
/// <summary>
93-
/// Null if executable is not in path.
93+
/// <c>Null</c> if executable is not in path.
9494
/// </summary>
9595
[CanBeNull]
9696
public static string ExeLocation => FileSystem.FindExecutableLocation(NAME_EXE)!;

SmartImage/Core/Interface.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ internal static NConsoleInterface MainMenu
250250
}
251251
};
252252

253-
private static string GetContextMenuString(bool added)
254-
{
255-
return (!added ? "Add" : "Remove") + " context menu integration";
256-
}
253+
private static string GetContextMenuString(bool added) => (!added ? "Add" : "Remove") + " context menu integration";
257254

258255

259256
private static readonly NConsoleOption CheckForUpdateOption = new()
@@ -262,26 +259,7 @@ private static string GetContextMenuString(bool added)
262259
Color = ColorUtility,
263260
Function = () =>
264261
{
265-
var v = UpdateInfo.GetUpdateInfo();
266-
267-
if (v.Status == VersionStatus.Available) {
268-
Console.WriteLine($"Updating to {v.Latest}...");
269-
270-
try {
271-
UpdateInfo.AutoUpdate();
272-
}
273-
catch (Exception e) {
274-
Console.WriteLine(e);
275-
276-
}
277-
278-
// No return
279-
Environment.Exit(0);
280-
281-
}
282-
else {
283-
NConsole.WriteInfo("{0}", v.Status);
284-
}
262+
UpdateInfo.AutoUpdate();
285263

286264
NConsoleIO.WaitForSecond();
287265
return null;

SmartImage/Program.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ private static void Main(string[] args)
7979
NConsole.WriteError("Could not migrate legacy features");
8080
}
8181

82-
/*
83-
* Check for updates
84-
*/
85-
86-
87-
UpdateInfo.AutoUpdate();
88-
8982
/*
9083
* Run search
9184
*/

SmartImage/Searching/FullSearchResult.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.ComponentModel;
6+
using System.Diagnostics;
67
using System.Drawing;
78
using System.IO;
89
using System.Linq;
@@ -22,8 +23,6 @@ namespace SmartImage.Searching
2223
/// </summary>
2324
public sealed class FullSearchResult : NConsoleOption, ISearchResult
2425
{
25-
26-
2726
public const char ATTR_SUCCESS = Formatting.CHECK_MARK;
2827

2928
public FullSearchResult(ISearchEngine engine, string url, float? similarity = null)
@@ -67,6 +66,8 @@ public override NConsoleFunction? CtrlFunction
6766
// }
6867
// }
6968

69+
Debug.WriteLine("Downloading");
70+
7071
string? path = Network.DownloadUrl(Url);
7172

7273
NConsole.WriteSuccess("Downloaded to {0}", path);
@@ -81,16 +82,8 @@ public override NConsoleFunction? CtrlFunction
8182
};
8283
}
8384
}
84-
85-
// public bool? IsImage
86-
// {
87-
// get;
88-
// internal set;
89-
// }
90-
9185

9286

93-
9487
public override string Data => ToString();
9588

9689
/// <summary>
@@ -125,9 +118,13 @@ public override NConsoleFunction ComboFunction
125118
{
126119
return () =>
127120
{
128-
var u = RawUrl ?? Url;
129-
130-
Network.OpenUrl(u);
121+
if (RawUrl != null) {
122+
Network.OpenUrl(RawUrl);
123+
return null;
124+
}
125+
126+
NConsole.WriteError("Raw result unavailable");
127+
NConsoleIO.WaitForSecond();
131128
return null;
132129
};
133130
}
@@ -177,17 +174,18 @@ public override string ToString()
177174

178175
string attrSuccess = ATTR_SUCCESS.ToString();
179176

180-
177+
181178
var ex = ExtendedResults.Count > 0
182-
? string.Format($"({ExtendedResults.Count})") : string.Empty;
183-
179+
? String.Format($"({ExtendedResults.Count})")
180+
: String.Empty;
181+
184182
sb.Append($"{attrSuccess} {ex}\n");
185183

186184

187185
if (RawUrl != Url) {
188186
sb.Append($"\tResult: {Url}\n");
189187
}
190-
else if (RawUrl != null) {
188+
if (RawUrl != null) {
191189
sb.Append($"\tRaw: {RawUrl}\n");
192190
}
193191

@@ -235,7 +233,5 @@ private IList<FullSearchResult> FromExtendedResult(IReadOnlyList<ISearchResult>
235233

236234
return rg;
237235
}
238-
239-
240236
}
241237
}

SmartImage/Utilities/UpdateInfo.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ public static void AutoUpdate()
8383
NConsole.WriteSuccess($"Update found: {ui.Latest} ");
8484

8585
if (NConsoleIO.ReadConfirmation("Update?")) {
86-
Update(ui);
86+
try {
87+
Update(ui);
88+
}
89+
catch (Exception e) {
90+
Console.WriteLine(e);
91+
return;
92+
}
8793
Environment.Exit(0);
8894
}
8995
}

0 commit comments

Comments
 (0)