Skip to content

Commit d71ada7

Browse files
committed
Revert registry interface method, fix SN error, etc
1 parent fd3d6de commit d71ada7

File tree

7 files changed

+48
-102
lines changed

7 files changed

+48
-102
lines changed

SmartImage/Integration.cs

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,26 @@ internal static void HandleContextMenu(IntegrationOption option)
3030
case IntegrationOption.Add:
3131
string fullPath = RuntimeInfo.ExeLocation;
3232

33-
if (!RuntimeInfo.IsExeInAppFolder) {
34-
bool v = CliOutput.ReadConfirm("Could not find exe in system path. Add now?");
33+
// Add command and icon to command
34+
string[] commandCode =
35+
{
36+
"@echo off",
37+
$"reg.exe add {REG_SHELL_CMD} /ve /d \"{fullPath} \"\"%%1\"\"\" /f >nul",
38+
$"reg.exe add {REG_SHELL} /v Icon /d \"{fullPath}\" /f >nul"
39+
};
3540

36-
if (v) {
37-
Setup();
38-
return;
39-
}
40-
}
41-
42-
43-
RegistrySubKey.SetValue("Icon", fullPath);
44-
45-
var cmd = RegistrySubKey.CreateSubKey("command");
46-
cmd.SetValue(null, String.Format("\"{0}\" \"%1\"", fullPath));
41+
Cli.CreateRunBatchFile("add_to_menu.bat", commandCode);
4742

4843
break;
4944
case IntegrationOption.Remove:
5045

51-
Registry.CurrentUser.DeleteSubKeyTree(REG_HKCU_SHELL_SMARTIMAGE);
46+
string[] code =
47+
{
48+
"@echo off",
49+
$@"reg.exe delete {REG_SHELL} /f >nul"
50+
};
51+
52+
Cli.CreateRunBatchFile("rem_from_menu.bat", code);
5253

5354
break;
5455
default:
@@ -88,53 +89,6 @@ internal static void HandlePath(IntegrationOption option)
8889
}
8990
}
9091

91-
/// <summary>
92-
/// Remove old legacy registry integrations
93-
/// </summary>
94-
internal static void RemoveOldRegistry()
95-
{
96-
const string REG_SHELL_LEGACY = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\";
97-
98-
const string REG_SHELL_CMD_LEGACY = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\command";
99-
100-
bool added = IsAdded();
101-
102-
if (added) {
103-
Remove();
104-
}
105-
else {
106-
return;
107-
}
108-
109-
bool success = !IsAdded();
110-
111-
112-
static void Remove()
113-
{
114-
string[] code =
115-
{
116-
"@echo off",
117-
$@"reg.exe delete {REG_SHELL_LEGACY} /f >nul"
118-
};
119-
120-
Cli.CreateRunBatchFile("rem_from_menu.bat", code);
121-
}
122-
123-
static bool IsAdded()
124-
{
125-
string cmdStr = String.Format(@"reg query {0}", REG_SHELL_CMD_LEGACY);
126-
var cmd = Cli.Shell(cmdStr, true);
127-
128-
string[] stdOut = Cli.ReadAllLines(cmd.StandardOutput);
129-
130-
bool b = stdOut.Any(s => s.Contains(RuntimeInfo.NAME));
131-
return b;
132-
}
133-
134-
if (!success) {
135-
throw new SmartImageException();
136-
}
137-
}
13892

13993
internal static void ResetIntegrations()
14094
{
@@ -182,23 +136,27 @@ internal static void Uninstall()
182136

183137
File.WriteAllText(dir, commands.QuickJoin("\n"));
184138

185-
139+
186140
// Runs in background
187141
Process.Start(dir);
188142
}
189143

190-
private const string REG_HKCU_SHELL_ROOT = @"Software\Classes\*\shell\";
144+
private const string REG_SHELL = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\";
191145

192-
private const string REG_HKCU_SHELL_SMARTIMAGE = REG_HKCU_SHELL_ROOT + @"SmartImage\";
146+
private const string REG_SHELL_CMD = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\command";
193147

194-
internal static RegistryKey RegistrySubKey => Registry.CurrentUser.CreateSubKey(REG_HKCU_SHELL_SMARTIMAGE);
195148

196149
internal static bool IsContextMenuAdded
197150
{
198151
get
199152
{
200-
var shell = Registry.CurrentUser.OpenSubKey(REG_HKCU_SHELL_ROOT)!;
201-
return shell.GetSubKeyNames().Contains(RuntimeInfo.NAME);
153+
string cmdStr = String.Format(@"reg query {0}", REG_SHELL_CMD);
154+
var cmd = Cli.Shell(cmdStr, true);
155+
156+
string[] stdOut = Cli.ReadAllLines(cmd.StandardOutput);
157+
158+
bool b = stdOut.Any(s => s.Contains(RuntimeInfo.NAME));
159+
return b;
202160
}
203161
}
204162

SmartImage/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ private static void Main(string[] args)
8484
// return;
8585
// }
8686

87-
using var s = new SearchClient(img);
88-
s.Start();
87+
using var searchClient = new SearchClient(img);
88+
searchClient.Start();
8989

90-
ConsoleIO.HandleOptions(s.Results);
90+
ConsoleIO.HandleOptions(searchClient.Results);
9191
}
9292
catch (Exception exception) {
9393

SmartImage/Searching/Engines/SauceNao/SauceNaoClient.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ private SearchResult GetBestResultWithApi(string url)
153153
return new SearchResult(this, null);
154154
}
155155

156+
// todo: IExtendedSearchResult
157+
156158
private readonly struct SauceNaoSimpleResult
157159
{
158160
public string Title { get; }
@@ -186,7 +188,7 @@ private static string FindCreator(HtmlNode resultcontent)
186188
return i;
187189

188190
}
189-
191+
190192
// TODO: organize like Yandex
191193

192194

@@ -196,10 +198,8 @@ private static List<SauceNaoSimpleResult> ParseResults(HtmlDocument doc)
196198

197199
var images = new List<SauceNaoSimpleResult>();
198200

199-
foreach (var result in results)
200-
{
201-
if (result.GetAttributeValue("id", string.Empty) == "result-hidden-notification")
202-
{
201+
foreach (var result in results) {
202+
if (result.GetAttributeValue("id", string.Empty) == "result-hidden-notification") {
203203
continue;
204204
}
205205

@@ -232,7 +232,7 @@ private static List<SauceNaoSimpleResult> ParseResults(HtmlDocument doc)
232232

233233
var title = FindCreator(resultcontent);
234234
var similarity = float.Parse(resultsimilarityinfo.InnerText.Replace("%", String.Empty));
235-
235+
236236

237237
var i = new SauceNaoSimpleResult(title, link, similarity);
238238
images.Add(i);
@@ -243,22 +243,21 @@ private static List<SauceNaoSimpleResult> ParseResults(HtmlDocument doc)
243243

244244
private SearchResult GetBestResultWithoutApi(string url)
245245
{
246-
246+
247247

248248
SearchResult? sr = null;
249249

250250
var resUrl = BASIC_RESULT + url;
251251

252252

253-
var sz = Network.GetString(resUrl);
254-
var doc = new HtmlDocument();
255-
doc.LoadHtml(sz);
256-
257253
try {
258-
254+
var sz = Network.GetString(resUrl);
255+
var doc = new HtmlDocument();
256+
doc.LoadHtml(sz);
257+
259258
var img = ParseResults(doc);
260259

261-
var best = img.OrderByDescending(i=>i.Similarity).First(i => i.Url!=null);
260+
var best = img.OrderByDescending(i => i.Similarity).First(i => i.Url != null);
262261

263262
sr = new SearchResult(this, best.Url, best.Similarity);
264263
sr.ExtendedInfo.Add(best.Title);

SmartImage/Searching/SearchClient.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
namespace SmartImage.Searching
1616
{
17+
/// <summary>
18+
/// Searching client
19+
/// </summary>
1720
public class SearchClient : IDisposable
1821
{
1922
/// <summary>
@@ -36,7 +39,7 @@ public class SearchClient : IDisposable
3639

3740
public SearchClient(string img)
3841
{
39-
42+
4043

4144
string auth = SearchConfig.Config.ImgurAuth;
4245
bool useImgur = !String.IsNullOrWhiteSpace(auth);
@@ -55,7 +58,7 @@ public SearchClient(string img)
5558

5659
m_imgUrl = Upload(img, useImgur);
5760

58-
61+
5962
m_threads = CreateSearchThreads();
6063
}
6164

@@ -86,7 +89,7 @@ public void Start()
8689
private Thread[] CreateSearchThreads()
8790
{
8891
// todo: improve
89-
92+
9093

9194
var availableEngines = GetAllEngines()
9295
.Where(e => m_engines.HasFlag(e.Engine))

SmartImage/Shell/ConsoleMainMenu.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,6 @@ private static ConsoleOption[] AllOptions
223223
}
224224
};
225225

226-
227-
private static readonly ConsoleOption LegacyCleanupOption = new ConsoleOption()
228-
{
229-
Name = "Legacy cleanup",
230-
Function = () =>
231-
{
232-
Integration.RemoveOldRegistry();
233-
234-
ConsoleIO.WaitForInput();
235-
236-
return null;
237-
}
238-
};
239-
240226
private static readonly ConsoleOption UninstallOption = new ConsoleOption()
241227
{
242228
Name = "Uninstall",

SmartImage/Shell/ConsoleOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ConsoleOption()
2121
/// </summary>
2222
public static readonly ConsoleOption Wait = new ConsoleOption()
2323
{
24-
Name = "Wait",
24+
Name = "Wait",
2525

2626
Color = ConsoleColor.Yellow,
2727

SmartImage/SmartImage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
<PropertyGroup>
4747
<PackageId>SmartImage</PackageId>
48-
<Version>1.9.5</Version>
48+
<Version>1.9.6</Version>
4949
<Authors>Read Stanton (Decimation)</Authors>
5050
<PackageTags>Image reverse search identification source sauce</PackageTags>
5151
<RepositoryUrl>https://github.com/Decimation/SmartImage</RepositoryUrl>

0 commit comments

Comments
 (0)