Skip to content

Commit 5b444fe

Browse files
committed
Various improvements
1 parent 3f2e8f4 commit 5b444fe

28 files changed

+234
-220
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# HAA0501: Explicit new array type allocation
4+
dotnet_diagnostic.HAA0501.severity = silent

SmartImage/ConsoleMainMenu.cs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using SmartImage.Searching;
1010
using SmartImage.Utilities;
1111

12-
#pragma warning disable IDE0052
12+
#pragma warning disable IDE0052, HAA0502, HAA0505, HAA0601, HAA0502, HAA0101
1313

1414

1515
namespace SmartImage
@@ -43,26 +43,25 @@ private static NConsoleOption[] AllOptions
4343
/// <summary>
4444
/// Main menu console interface
4545
/// </summary>
46-
internal static NConsoleUI Interface => new NConsoleUI(AllOptions, RuntimeInfo.NAME_BANNER, false);
46+
internal static NConsoleUI Interface => new NConsoleUI(AllOptions, RuntimeInfo.NAME_BANNER);
4747

4848
/// <summary>
4949
/// Runs when no arguments are given (and when the executable is double-clicked)
5050
/// </summary>
5151
/// <remarks>
5252
/// More user-friendly menu
5353
/// </remarks>
54-
internal static void Run() => NConsole.IO.HandleOptions(ConsoleMainMenu.Interface);
54+
internal static void Run() => NConsole.IO.HandleOptions(Interface);
5555

56-
private static readonly NConsoleOption RunSelectImage = new NConsoleOption()
56+
private static readonly NConsoleOption RunSelectImage = new NConsoleOption
5757
{
5858
Name = ">>> Select image <<<",
5959
Color = Color.Yellow,
6060
Function = () =>
6161
{
6262
Console.WriteLine("Drag and drop the image here.");
63-
Console.Write("Image: ");
64-
65-
string img = Console.ReadLine();
63+
64+
string img = NConsole.IO.GetInput("Image");
6665
img = Strings.CleanString(img);
6766

6867
SearchConfig.Config.Image = img;
@@ -72,15 +71,15 @@ private static NConsoleOption[] AllOptions
7271
};
7372

7473

75-
private static readonly NConsoleOption ConfigSearchEnginesOption = new NConsoleOption()
74+
private static readonly NConsoleOption ConfigSearchEnginesOption = new NConsoleOption
7675
{
7776
Name = "Configure search engines",
7877
Function = () =>
7978
{
80-
var rgEnum = NConsoleOption.CreateOptionsFromEnum<SearchEngines>();
79+
var rgEnum = NConsoleOption.CreateOptionsFromEnum<SearchEngineOptions>();
8180
var values = NConsole.IO.HandleOptions(rgEnum, true);
8281

83-
var newValues = Enums.ReadEnumFromSet<SearchEngines>(values);
82+
var newValues = Enums.ReadEnumFromSet<SearchEngineOptions>(values);
8483

8584
NConsole.WriteInfo(newValues);
8685

@@ -93,15 +92,15 @@ private static NConsoleOption[] AllOptions
9392
};
9493

9594

96-
private static readonly NConsoleOption ConfigPriorityEnginesOption = new NConsoleOption()
95+
private static readonly NConsoleOption ConfigPriorityEnginesOption = new NConsoleOption
9796
{
9897
Name = "Configure priority engines",
9998
Function = () =>
10099
{
101-
var rgEnum = NConsoleOption.CreateOptionsFromEnum<SearchEngines>();
100+
var rgEnum = NConsoleOption.CreateOptionsFromEnum<SearchEngineOptions>();
102101
var values = NConsole.IO.HandleOptions(rgEnum, true);
103102

104-
var newValues = Enums.ReadEnumFromSet<SearchEngines>(values);
103+
var newValues = Enums.ReadEnumFromSet<SearchEngineOptions>(values);
105104

106105
NConsole.WriteInfo(newValues);
107106

@@ -114,7 +113,7 @@ private static NConsoleOption[] AllOptions
114113
};
115114

116115

117-
private static readonly NConsoleOption ConfigSauceNaoAuthOption = new NConsoleOption()
116+
private static readonly NConsoleOption ConfigSauceNaoAuthOption = new NConsoleOption
118117
{
119118
Name = "Configure SauceNao API authentication",
120119
Function = () =>
@@ -126,7 +125,7 @@ private static NConsoleOption[] AllOptions
126125
}
127126
};
128127

129-
private static readonly NConsoleOption ConfigImgurAuthOption = new NConsoleOption()
128+
private static readonly NConsoleOption ConfigImgurAuthOption = new NConsoleOption
130129
{
131130
Name = "Configure Imgur API authentication",
132131
Function = () =>
@@ -139,7 +138,7 @@ private static NConsoleOption[] AllOptions
139138
}
140139
};
141140

142-
private static readonly NConsoleOption ConfigUpdateOption = new NConsoleOption()
141+
private static readonly NConsoleOption ConfigUpdateOption = new NConsoleOption
143142
{
144143
Name = "Update configuration file",
145144
Function = () =>
@@ -151,7 +150,7 @@ private static NConsoleOption[] AllOptions
151150
}
152151
};
153152

154-
private static readonly NConsoleOption ContextMenuOption = new NConsoleOption()
153+
private static readonly NConsoleOption ContextMenuOption = new NConsoleOption
155154
{
156155
Name = "Add/remove context menu integration",
157156
Function = () =>
@@ -172,7 +171,7 @@ private static NConsoleOption[] AllOptions
172171
}
173172
};
174173

175-
private static readonly NConsoleOption ShowInfoOption = new NConsoleOption()
174+
private static readonly NConsoleOption ShowInfoOption = new NConsoleOption
176175
{
177176
Name = "Show info",
178177
Function = () =>
@@ -184,33 +183,32 @@ private static NConsoleOption[] AllOptions
184183
}
185184
};
186185

187-
private static readonly NConsoleOption CheckForUpdateOption = new NConsoleOption()
186+
187+
private static readonly NConsoleOption CheckForUpdateOption = new NConsoleOption
188188
{
189189
Name = "Check for updates",
190190
Function = () =>
191191
{
192-
// TODO: WIP
193-
194192
var v = UpdateInfo.CheckForUpdates();
195193

196194
if ((v.Status == VersionStatus.Available)) {
197195

198196
UpdateInfo.Update();
199-
197+
200198
// No return
201199
Environment.Exit(0);
202200

203201
}
204202
else {
205-
NConsole.WriteSuccess("{0}", v.Status);
203+
NConsole.WriteInfo("{0}", v.Status);
206204
}
207205

208206
NConsole.IO.WaitForSecond();
209207
return null;
210208
}
211209
};
212210

213-
private static readonly NConsoleOption ResetOption = new NConsoleOption()
211+
private static readonly NConsoleOption ResetOption = new NConsoleOption
214212
{
215213
Name = "Reset all configuration and integrations",
216214
Function = () =>
@@ -222,7 +220,7 @@ private static NConsoleOption[] AllOptions
222220
}
223221
};
224222

225-
private static readonly NConsoleOption UninstallOption = new NConsoleOption()
223+
private static readonly NConsoleOption UninstallOption = new NConsoleOption
226224
{
227225
Name = "Uninstall",
228226
Function = () =>
@@ -252,7 +250,7 @@ private static NConsoleOption[] AllOptions
252250
"Test3.png"
253251
};
254252

255-
private static readonly NConsoleOption DebugTestOption = new NConsoleOption()
253+
private static readonly NConsoleOption DebugTestOption = new NConsoleOption
256254
{
257255
Name = "[DEBUG] Run test",
258256
Function = () =>
@@ -261,13 +259,11 @@ private static NConsoleOption[] AllOptions
261259
var cd2 = cd.Parent.Parent.Parent.Parent.ToString();
262260

263261

264-
var testImg = Collections.GetRandomElement(TestImages);
262+
var testImg = TestImages.GetRandomElement();
265263
var img = Path.Combine(cd2, testImg);
266264

267265
SearchConfig.Config.Image = img;
268-
SearchConfig.Config.PriorityEngines = SearchEngines.None;
269-
//SearchConfig.Config.ImgurAuth = "6c97880bf8754c5";
270-
//SearchConfig.Config.SearchEngines &= ~SearchEngines.TraceMoe;
266+
SearchConfig.Config.PriorityEngines = SearchEngineOptions.None;
271267

272268

273269
return true;

SmartImage/Integration.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
42
using System.Diagnostics.CodeAnalysis;
53
using System.IO;
64
using System.Linq;
7-
using System.Text;
8-
using Microsoft.Win32;
95
using SimpleCore.CommandLine;
106
using SimpleCore.CommandLine.Shell;
117
using SimpleCore.Win32;
12-
using SmartImage.Utilities;
138

149
namespace SmartImage
1510
{
@@ -39,8 +34,8 @@ internal static void HandleContextMenu(IntegrationOption option)
3934
$"reg.exe add {REG_SHELL} /v Icon /d \"{fullPath}\" /f >nul"
4035
};
4136

42-
43-
BatchFileCommand.CreateAndRun(addCode,true);
37+
38+
BatchFileCommand.CreateAndRun(addCode, true);
4439

4540
break;
4641
case IntegrationOption.Remove:
@@ -51,8 +46,8 @@ internal static void HandleContextMenu(IntegrationOption option)
5146
$@"reg.exe delete {REG_SHELL} /f >nul"
5247
};
5348

54-
55-
BatchFileCommand.CreateAndRun(removeCode,true);
49+
50+
BatchFileCommand.CreateAndRun(removeCode, true);
5651

5752
break;
5853
default:
@@ -69,10 +64,14 @@ internal static void HandlePath(IntegrationOption option)
6964

7065
string appFolder = RuntimeInfo.AppFolder;
7166

72-
if (RuntimeInfo.IsAppFolderInPath) return;
67+
if (RuntimeInfo.IsAppFolderInPath) {
68+
return;
69+
}
7370

7471

75-
bool appFolderInPath = oldValue.Split(Native.PATH_DELIM).Any(p => p == appFolder);
72+
bool appFolderInPath = oldValue
73+
.Split(Native.PATH_DELIM)
74+
.Any(p => p == appFolder);
7675

7776
string cd = Environment.CurrentDirectory;
7877
string exe = Path.Combine(cd, RuntimeInfo.NAME_EXE);
@@ -136,15 +135,12 @@ internal static void Uninstall()
136135
"echo y | del " + DEL_BAT_NAME
137136
};
138137

139-
138+
140139
var bf = new BatchFileCommand(commands, DEL_BAT_NAME);
141140

142141
// Runs in background
143142
bf.Start();
144143

145-
146-
147-
148144
}
149145

150146
private const string REG_SHELL = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\";
@@ -157,11 +153,11 @@ internal static bool IsContextMenuAdded
157153
get
158154
{
159155
string cmdStr = String.Format(@"reg query {0}", REG_SHELL_CMD);
160-
161-
var cmd = ConsoleCommand.Shell(cmdStr);
156+
157+
var cmd = Command.Shell(cmdStr);
162158
cmd.Start();
163159

164-
string[] stdOut = ConsoleCommand.ReadAllLines(cmd.StandardOutput);
160+
string[] stdOut = Command.ReadAllLines(cmd.StandardOutput);
165161

166162
bool b = stdOut.Any(s => s.Contains(RuntimeInfo.NAME));
167163
return b;
@@ -171,7 +167,7 @@ internal static bool IsContextMenuAdded
171167
internal static void Setup()
172168
{
173169
if (!RuntimeInfo.IsAppFolderInPath) {
174-
Integration.HandlePath(IntegrationOption.Add);
170+
HandlePath(IntegrationOption.Add);
175171
}
176172
}
177173
}

SmartImage/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public static class Program
3131
// |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|
3232
// |___/
3333

34-
/**
34+
/*
35+
* todo: refactor access modifiers
36+
*/
37+
38+
/*
3539
* Entry point
3640
*/
3741
private static void Main(string[] args)
@@ -47,6 +51,7 @@ private static void Main(string[] args)
4751

4852
NConsoleUI.DefaultName = RuntimeInfo.NAME_BANNER;
4953

54+
5055
/*
5156
* Run search
5257
*/

SmartImage/RuntimeInfo.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Reflection;
99
using SimpleCore.CommandLine;
1010
using SimpleCore.Win32;
11-
1211
using SmartImage.Utilities;
1312

1413
// ReSharper disable UseStringInterpolation
@@ -17,6 +16,7 @@
1716

1817
#endregion
1918

19+
#pragma warning disable HAA0101, HAA0502, HAA0601
2020

2121
namespace SmartImage
2222
{
@@ -93,13 +93,16 @@ private static string FindExecutableLocation(string exe)
9393

9494
var rg = new List<string>
9595
{
96+
/* Current directory */
97+
Environment.CurrentDirectory,
98+
99+
96100
/* Executing directory */
97101
Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase!
98102
.Replace("file:///", String.Empty)
99103
.Replace("/", "\\"))!,
100104

101-
/* Current directory */
102-
Environment.CurrentDirectory
105+
103106
};
104107

105108
rg.AddRange(Native.PathDirectories);
@@ -112,6 +115,7 @@ private static string FindExecutableLocation(string exe)
112115
}
113116
}
114117

118+
115119
static bool ExistsInFolder(string folder, string exeStr, out string folderExe)
116120
{
117121
string folderExeFull = Path.Combine(folder, exeStr);
@@ -133,7 +137,7 @@ internal static void ShowInfo()
133137
* Config
134138
*/
135139

136-
NConsole.WriteInfo(SearchConfig.Config.Dump());
140+
NConsole.WriteInfo(SearchConfig.Config);
137141

138142

139143
/*

0 commit comments

Comments
 (0)