Skip to content

Commit 22bc292

Browse files
committed
Add try catch to encounter dllnotfound issue and move warning string to resource
1 parent acc7d51 commit 22bc292

File tree

5 files changed

+53
-61
lines changed

5 files changed

+53
-61
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<system:String x:Key="plugin_explorer_show_contextmenu_title">Show Windows Context Menu</system:String>
9191

9292
<!-- Everything -->
93+
<system:String x:Key="flowlauncher_plugin_everything_sdk_issue">Everything SDK Loaded Fail</system:String>
9394
<system:String x:Key="flowlauncher_plugin_everything_is_not_running">Warning: Everything service is not running</system:String>
9495
<system:String x:Key="flowlauncher_plugin_everything_query_error">Error while querying Everything</system:String>
9596
<system:String x:Key="flowlauncher_plugin_everything_sort_by">Sort By</system:String>
@@ -110,6 +111,7 @@
110111
<system:String x:Key="flowlauncher_plugin_everything_sort_by_descending">&#x2193;</system:String>
111112
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
112113

114+
<system:String x:Key="flowlauncher_plugin_everything_click_to_launch_or_install">Click to Launch or Install Everything</system:String>
113115
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
114116
<system:String x:Key="flowlauncher_plugin_everything_installing_subtitle">Installing Everything service. Please wait...</system:String>
115117
<system:String x:Key="flowlauncher_plugin_everything_installationsuccess_subtitle">Successfully installed Everything service</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ public static bool IsFastSortOption(SortOption sortOption)
9191

9292
public static async ValueTask<bool> IsEverythingRunningAsync(CancellationToken token = default)
9393
{
94-
await _semaphore.WaitAsync(token);
95-
EverythingApiDllImport.Everything_GetMajorVersion();
96-
var result = EverythingApiDllImport.Everything_GetLastError() != StateCode.IPCError;
97-
_semaphore.Release();
98-
return result;
94+
try
95+
{
96+
await _semaphore.WaitAsync(token);
97+
EverythingApiDllImport.Everything_GetMajorVersion();
98+
var result = EverythingApiDllImport.Everything_GetLastError() != StateCode.IPCError;
99+
return result;
100+
}
101+
finally
102+
{
103+
_semaphore.Release();
104+
}
99105
}
100106

101107
/// <summary>

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingSearchManager.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,40 @@ public EverythingSearchManager(Settings settings)
2424

2525
private async ValueTask ThrowIfEverythingNotAvailableAsync(CancellationToken token = default)
2626
{
27-
if (!await EverythingApi.IsEverythingRunningAsync(token))
28-
throw new EngineNotAvailableException(
29-
Enum.GetName(Settings.IndexSearchEngineOption.Everything),
30-
"Click to Open or Download Everything",
31-
"Everything is not running.",
32-
async _ =>
27+
try
28+
{
29+
if (!await EverythingApi.IsEverythingRunningAsync(token))
30+
throw new EngineNotAvailableException(
31+
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
32+
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_click_to_launch_or_install"),
33+
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running"),
34+
ClickToInstallEverything)
3335
{
34-
var installedPath = await EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, Main.Context.API);
35-
if (installedPath == null)
36-
{
37-
Main.Context.API.ShowMsgError("Unable to find Everything.exe");
38-
return false;
39-
}
40-
Settings.EverythingInstalledPath = installedPath;
41-
Process.Start(installedPath, "-startup");
42-
return true;
43-
})
36+
ErrorIcon = Constants.EverythingErrorImagePath
37+
};
38+
}
39+
catch (DllNotFoundException e)
40+
{
41+
throw new EngineNotAvailableException(
42+
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
43+
"Please check whether your system is x86 or x64",
44+
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue"))
4445
{
45-
ErrorIcon = Constants.EverythingErrorImagePath
46+
ErrorIcon = Constants.GeneralSearchErrorImagePath
4647
};
48+
}
49+
}
50+
private async ValueTask<bool> ClickToInstallEverything(ActionContext _)
51+
{
52+
var installedPath = await EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, Main.Context.API);
53+
if (installedPath == null)
54+
{
55+
Main.Context.API.ShowMsgError("Unable to find Everything.exe");
56+
return false;
57+
}
58+
Settings.EverythingInstalledPath = installedPath;
59+
Process.Start(installedPath, "-startup");
60+
return true;
4761
}
4862

4963
public async IAsyncEnumerable<SearchResult> SearchAsync(string search, [EnumeratorCancellation] CancellationToken token)

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ public Visibility FastSortWarningVisibility
369369
// update the message to let user know in the settings panel.
370370
return Visibility.Visible;
371371
}
372+
catch (DllNotFoundException)
373+
{
374+
return Visibility.Collapsed;
375+
}
372376
}
373377
}
374378
public string SortOptionWarningMessage
@@ -386,6 +390,10 @@ public string SortOptionWarningMessage
386390
{
387391
return Context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running");
388392
}
393+
catch (DllNotFoundException)
394+
{
395+
return Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue");
396+
}
389397
}
390398
}
391399

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
22
using Flow.Launcher.Plugin.Explorer.ViewModels;
3-
using System;
43
using System.Collections.Generic;
54
using System.ComponentModel;
65
using System.IO;
76
using System.Linq;
87
using System.Windows;
98
using System.Windows.Controls;
10-
using System.Windows.Forms;
11-
using System.Windows.Input;
12-
using System.Windows.Media;
139
using DataFormats = System.Windows.DataFormats;
1410
using DragDropEffects = System.Windows.DragDropEffects;
1511
using DragEventArgs = System.Windows.DragEventArgs;
16-
using ListView = System.Windows.Controls.ListView;
17-
using MessageBox = System.Windows.MessageBox;
1812

1913
namespace Flow.Launcher.Plugin.Explorer.Views
2014
{
@@ -92,38 +86,6 @@ private void EverythingSortOptionChanged(object sender, SelectionChangedEventArg
9286
tbFastSortWarning.Text = viewModel.SortOptionWarningMessage;
9387
}
9488
}
95-
private void SettingExpander_OnExpanded(object sender, RoutedEventArgs e)
96-
{
97-
if (sender is not Expander expander)
98-
return;
99-
100-
var parentContainer = VisualTreeHelper.GetParent(expander);
101-
102-
if (parentContainer is not StackPanel stackPanel)
103-
return;
104-
105-
foreach (UIElement child in stackPanel.Children)
106-
{
107-
if (child != expander)
108-
child.Visibility = Visibility.Collapsed;
109-
}
110-
}
111-
private void SettingExpander_OnCollapsed(object sender, RoutedEventArgs e)
112-
{
113-
if (sender is not Expander expander)
114-
return;
115-
116-
var parentContainer = VisualTreeHelper.GetParent(expander);
117-
118-
if (parentContainer is not StackPanel stackPanel)
119-
return;
120-
121-
foreach (UIElement child in stackPanel.Children)
122-
{
123-
if (child != expander)
124-
child.Visibility = Visibility.Visible;
125-
}
126-
}
12789
private void LbxAccessLinks_OnDrop(object sender, DragEventArgs e)
12890
{
12991
AccessLinkDragDrop("QuickAccessLink", e);
@@ -133,4 +95,4 @@ private void LbxExcludedPaths_OnDrop(object sender, DragEventArgs e)
13395
AccessLinkDragDrop("IndexSearchExcludedPath", e);
13496
}
13597
}
136-
}
98+
}

0 commit comments

Comments
 (0)