Skip to content

Commit 50212ad

Browse files
committed
Various improvements, UI/UX refactoring
1 parent 8a3a91c commit 50212ad

File tree

10 files changed

+149
-173
lines changed

10 files changed

+149
-173
lines changed

SmartImage/Core/Info.cs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,20 @@ public static class Info
3737
@" |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|" + "\n" +
3838
" |___/\n";
3939

40-
// @formatter:off — disable formatter after this line
41-
42-
public const string NAME_BANNER2 = "#############################\n" +
43-
"############**###############\n" +
44-
"#######* ,#########" + " ____ _ ___\n"+
45-
"###### ######## ,.#######" + " / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___\n" +
46-
"#####. ,,#####.,, ,,.,####" + @" \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \" + "\n" +
47-
"##,.,, ,,.,,,., ,,,.,,,##" + " ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/\n" +
48-
"(((((((* (((((((((" + @" |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|" + "\n" +
49-
"((((((((((((**(((( *((((((" + " |___/\n" +
50-
"((((((((((((((((((((, ((((\n" +
51-
"(((((((((((((((((((((((((((((\n" +
52-
"(((((((((((((((((((((((((((((\n";
53-
54-
// @formatter:on — enable formatter after this line
55-
56-
40+
41+
/// <summary>
42+
/// Name
43+
/// </summary>
5744
public const string NAME = "SmartImage";
5845

46+
/// <summary>
47+
/// Executable file name
48+
/// </summary>
5949
public const string NAME_EXE = "SmartImage.exe";
6050

51+
/// <summary>
52+
/// Config file name (<see cref="SearchConfig"/>)
53+
/// </summary>
6154
public const string NAME_CFG = "SmartImage.cfg";
6255

6356
public const string Author = "Read Stanton";
@@ -77,7 +70,7 @@ public static class Info
7770

7871
public static string AppFolder
7972
{
80-
// todo: use ProgramData
73+
// todo: use ProgramData?
8174

8275
get
8376
{
@@ -106,21 +99,6 @@ public static void Setup()
10699
}
107100
}
108101

109-
internal static Stream? GetResource(string resource)
110-
{
111-
Assembly a = Assembly.GetExecutingAssembly();
112-
113-
var n = a.GetName().Name;
114-
115-
//"SmartImage.hint.wav"
116-
117-
// [Assembly].[asset]
118-
119-
resource = n + "." + resource;
120-
121-
return a.GetManifestResourceStream(resource);
122-
}
123-
124102
internal static void ShowInfo()
125103
{
126104

@@ -196,10 +174,5 @@ internal static void ShowInfo()
196174
NConsole.WriteInfo("{0} ({1})", name.Name, name.Version);
197175
}
198176
}
199-
200-
internal static class Resources
201-
{
202-
internal static readonly Stream SndHint = GetResource("hint.wav")!;
203-
}
204177
}
205178
}

SmartImage/Core/Integration.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ internal static void HandlePath(IntegrationOption option)
9393
switch (option) {
9494
case IntegrationOption.Add:
9595
{
96-
string oldValue = OS.EnvironmentPath;
97-
96+
string oldValue = OS.EnvironmentPath;
9897
string appFolder = Info.AppFolder;
9998

10099
if (Info.IsAppFolderInPath) {
101100
return;
102101
}
103102

104-
105103
bool appFolderInPath = oldValue
106104
.Split(OS.PATH_DELIM)
107105
.Any(p => p == appFolder);

SmartImage/Engines/SauceNao/SauceNaoEngine.cs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public override FullSearchResult GetResult(string url)
101101
try {
102102
var orig = GetResults(url);
103103

104-
if (orig == null) {
105-
result.ExtendedInfo.Add($"Timed out after {Timeout}");
106-
return result;
107-
}
108-
109104
var sn = orig
110105
.OrderByDescending(r => r.Similarity)
111106
.ToArray();
@@ -137,33 +132,23 @@ public override FullSearchResult GetResult(string url)
137132

138133
return result;
139134
}
140-
141-
/// <summary>
142-
/// Timeout duration
143-
/// </summary>
144-
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(15);
135+
145136

146137
private IEnumerable<SauceNaoResult>? GetResults(string url)
147138
{
148139

149-
var task = Task.Run(() =>
150-
{
151-
var req = new RestRequest();
152-
req.AddQueryParameter("db", "999");
153-
req.AddQueryParameter("output_type", "2");
154-
req.AddQueryParameter("numres", "16");
155-
req.AddQueryParameter("api_key", m_apiKey);
156-
req.AddQueryParameter("url", url);
157-
158-
var res = m_client.Execute(req);
140+
var req = new RestRequest();
141+
req.AddQueryParameter("db", "999");
142+
req.AddQueryParameter("output_type", "2");
143+
req.AddQueryParameter("numres", "16");
144+
req.AddQueryParameter("api_key", m_apiKey);
145+
req.AddQueryParameter("url", url);
159146

160-
string c = res.Content;
147+
var res = m_client.Execute(req);
161148

162-
return ReadResults(c);
163-
});
149+
string c = res.Content;
164150

165-
// Handle possible timeouts
166-
return task.Wait(Timeout) ? task.Result : null;
151+
return ReadResults(c);
167152
}
168153

169154

SmartImage/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public static class Program
2626
// |___/
2727

2828
/*
29-
* todo: refactor access modifiers
30-
* todo: maybe create a separate unit testing project
29+
* todo: use async/tasks
30+
* todo: timeout handling
3131
*/
3232

3333
/*

SmartImage/Searching/FullSearchResult.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public FullSearchResult(Color color, string name, string url, float? similarity
3737
Similarity = similarity;
3838
ExtendedInfo = new List<string>();
3939
ExtendedResults = new List<FullSearchResult>();
40-
41-
4240
}
4341

4442
/// <summary>
@@ -57,15 +55,6 @@ public override NConsoleFunction? CtrlFunction
5755
{
5856
return () =>
5957
{
60-
// if (!IsImage.HasValue || !IsImage.Value) {
61-
// bool ok = NConsoleIO.ReadConfirmation(
62-
// $"Link may not be an image. Download anyway?");
63-
//
64-
// if (!ok) {
65-
// return null;
66-
// }
67-
// }
68-
6958
Debug.WriteLine("Downloading");
7059

7160
string? path = Network.DownloadUrl(Url);
@@ -75,14 +64,13 @@ public override NConsoleFunction? CtrlFunction
7564
// Open folder with downloaded file selected
7665
FileSystem.ExploreFile(path);
7766

78-
7967
NConsoleIO.WaitForSecond();
8068

8169
return null;
8270
};
8371
}
8472
}
85-
73+
8674

8775
public override string Data => ToString();
8876

@@ -106,6 +94,7 @@ public override NConsoleFunction Function
10694
{
10795
return () =>
10896
{
97+
// Open in browser
10998
Network.OpenUrl(Url);
11099
return null;
111100
};
@@ -185,6 +174,7 @@ public override string ToString()
185174
if (RawUrl != Url) {
186175
sb.Append($"\tResult: {Url}\n");
187176
}
177+
188178
if (RawUrl != null) {
189179
sb.Append($"\tRaw: {RawUrl}\n");
190180
}
@@ -233,5 +223,29 @@ private IList<FullSearchResult> FromExtendedResult(IReadOnlyList<ISearchResult>
233223

234224
return rg;
235225
}
226+
227+
public static int CompareResults(FullSearchResult x, FullSearchResult y)
228+
{
229+
float xSim = x?.Similarity ?? 0;
230+
float ySim = y?.Similarity ?? 0;
231+
232+
if (xSim > ySim) {
233+
return -1;
234+
}
235+
236+
if (xSim < ySim) {
237+
return 1;
238+
}
239+
240+
if (x?.ExtendedResults.Count > y?.ExtendedResults.Count) {
241+
return -1;
242+
}
243+
244+
if (x?.ExtendedInfo.Count > y?.ExtendedInfo.Count) {
245+
return -1;
246+
}
247+
248+
return 0;
249+
}
236250
}
237251
}

0 commit comments

Comments
 (0)