Skip to content

Commit

Permalink
Updated to .NET 5 for v0.55.0
Browse files Browse the repository at this point in the history
- Modified icon preview for better stabiliy, esp when file is not local

- Better setting descriptions

- Changed versioning to match PT version built against
  • Loading branch information
lin-ycv committed Feb 3, 2022
1 parent ef2c587 commit d34939c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 40 deletions.
24 changes: 12 additions & 12 deletions Community.PowerToys.Run.Plugin.Everything.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\Version.props" />

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<ProjectGuid>{64467D32-4786-4ADD-9B77-FBF3C965D3D1}</ProjectGuid>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Community.PowerToys.Run.Plugin.Everything</RootNamespace>
<AssemblyName>Community.PowerToys.Run.Plugin.Everything</AssemblyName>
<Version>0.0.2.5</Version>
<Version>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)plugin.json').Split(',')[5].Split(':')[1].Trim().Trim('"'))</Version>
<useWPF>true</useWPF>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Platforms>x64</Platforms>
<NeutralLanguage>en-US</NeutralLanguage>
<Authors>Yu Chieh (Victor) Lin</Authors>
<Company />
<Product />
<AssemblyVersion>0.0.2.5</AssemblyVersion>
<FileVersion>0.0.2.5</FileVersion>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<ApplicationIcon />
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -38,13 +37,15 @@
<OutputPath>..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>

<ItemGroup>
Expand All @@ -59,9 +60,11 @@
<ItemGroup>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</ProjectReference>
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</ProjectReference>
</ItemGroup>

Expand Down Expand Up @@ -106,9 +109,6 @@
<None Update="Images\Everything.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\Everything.ico.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\Everything.light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -121,7 +121,7 @@
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="del /Q &quot;$(TargetDir)*.pdb&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)PowerToys*.dll&quot;" />
<Exec Command="del /Q &quot;$(TargetDir)*.pdb&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)PowerToys*.dll&quot;&#xD;&#xA;rmdir /S /Q &quot;$(TargetDir)\ref&quot;" />
</Target>

</Project>
Binary file removed Images/Everything.ico.png
Binary file not shown.
16 changes: 8 additions & 8 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
{
private const string Wait = nameof(Wait);
private const string Top = nameof(Top);
private const string NoPreview = nameof(NoPreview);
private const string Preview = nameof(Preview);
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
private bool _wait;
private bool _top;
private bool _noPreview;
private bool _preview;

public string Name => Resources.plugin_name;

Expand All @@ -52,8 +52,8 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
},
new PluginAdditionalOption()
{
Key = NoPreview,
DisplayLabel = Resources.NoPreview,
Key = Preview,
DisplayLabel = Resources.Preview,
Value = false,
},
};
Expand Down Expand Up @@ -104,10 +104,10 @@ public List<Result> Query(Query query, bool isFullQuery)
source?.Cancel();
source = new CancellationTokenSource();
CancellationToken token = source.Token;
source.CancelAfter(_wait ? 1000 : 75);
source.CancelAfter(_wait ? 1000 : 120);
try
{
results.AddRange(EverythingSearch(searchQuery, _top, _noPreview, token));
results.AddRange(EverythingSearch(searchQuery, _top, _preview, token));
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -177,12 +177,12 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)
{
wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false;
top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? false;
nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false;
nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Preview)?.Value ?? false;
}

_top = top;
_wait = wait;
_noPreview = nopreview;
_preview = nopreview;
}

protected virtual void Dispose(bool disposing)
Expand Down
60 changes: 57 additions & 3 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Community.PowerToys.Run.Plugin.Everything.Properties;
using Microsoft.Win32;
using Wox.Plugin;

namespace Community.PowerToys.Run.Plugin.Everything
Expand Down Expand Up @@ -97,7 +100,7 @@ public static void EverythingSetup()
Everything_SetMax(max);
}

public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool noPreview, CancellationToken token)
public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool preview, CancellationToken token)
{
_ = Everything_SetSearchW(qry);
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
Expand All @@ -121,13 +124,14 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool no
path = fullPath;
else
path = Path.GetDirectoryName(fullPath);
string ext = Path.GetExtension(fullPath);

var r = new Result()
{
Title = name,
ToolTipData = new ToolTipData("Name : " + name, "Path : " + path),
SubTitle = Resources.plugin_name + ": " + fullPath,
IcoPath = noPreview ? "Images/Everything.ico.png" : fullPath,
IcoPath = (preview || string.IsNullOrEmpty(ext) || string.IsNullOrEmpty((string)Icons[ext])) ? fullPath : (string)Icons[ext],
ContextData = new SearchResult()
{
Path = fullPath,
Expand All @@ -154,7 +158,7 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool no
},
QueryTextDisplay = isFolder ? path : name,
};
if (top) r.Score = (int)(max - i);
if (top) r.Score = (int)(300 - i);
yield return r;
}

Expand All @@ -169,6 +173,56 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool no
};
}
}

// Credits https://www.codeproject.com/Articles/29137/Get-Registered-File-Types-and-Their-Associated-Ico
[DllImport("shell32.dll", EntryPoint = "ExtractIconA", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex);
internal static readonly Hashtable Icons = GetFileTypeAndIcon();
internal static Hashtable GetFileTypeAndIcon()
{
try
{
RegistryKey rkRoot = Registry.ClassesRoot;
string[] keyNames = rkRoot.GetSubKeyNames();
Hashtable iconsInfo = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
foreach (string keyName in keyNames)
{
if (string.IsNullOrEmpty(keyName))
continue;
int indexOfPoint = keyName.IndexOf(".", StringComparison.CurrentCulture);
if (indexOfPoint != 0)
continue;
RegistryKey rkFileType = rkRoot.OpenSubKey(keyName);
if (rkFileType == null)
continue;
object defaultValue = rkFileType.GetValue(string.Empty);
if (defaultValue == null)
continue;
string defaultIcon = defaultValue.ToString() + "\\DefaultIcon";
RegistryKey rkFileIcon = rkRoot.OpenSubKey(defaultIcon);
if (rkFileIcon != null)
{
object value = rkFileIcon.GetValue(string.Empty);
if (value != null)
{
string fileParam = value.ToString().Replace("\"", string.Empty, StringComparison.CurrentCulture).Split(',')[0].Trim();
iconsInfo.Add(keyName, fileParam);
}

rkFileIcon.Close();
}

rkFileType.Close();
}

rkRoot.Close();
return iconsInfo;
}
catch (Exception)
{
throw;
}
}
#pragma warning restore SA1503 // Braces should not be omitted
}
}
22 changes: 11 additions & 11 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@
<data name="folder_open_failed" xml:space="preserve">
<value>Fail to open folder at</value>
</data>
<data name="NoPreview" xml:space="preserve">
<value>Fast - Disable icon preview, fetching icons for non-local files may cause freezing.</value>
</data>
<data name="open_containing_folder" xml:space="preserve">
<value>Open containing folder (Ctrl+Shift+E)</value>
</data>
Expand All @@ -150,16 +147,19 @@
<data name="plugin_name" xml:space="preserve">
<value>Everything</value>
</data>
<data name="Preview" xml:space="preserve">
<value>Preview - Preview file content as icon, may cause freezing if file not local.</value>
</data>
<data name="run_as_admin" xml:space="preserve">
<value>Run as administrator (Ctrl+Shift+Enter)</value>
</data>
<data name="timeout" xml:space="preserve">
<value>Timed out before finishing the query</value>
</data>
<data name="Top" xml:space="preserve">
<value>Top - Insert result at the top of the list.</value>
<value>Top - Insert result at the top of the list, may cause pre-selection issue.</value>
</data>
<data name="Wait" xml:space="preserve">
<value>Wait - Wait longer for the query to finish.</value>
<value>Wait - Wait longer for the query to finish, enable only if prompted to.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"IsGlobal": true,
"Name": "Everything",
"Author": "Yu Chieh (Victor) Lin",
"Version": "0.2.5",
"Version": "0.55.1.0",
"Language": "csharp",
"Website": "https://github.com/lin-ycv/EverythingPowerToys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
Expand Down

0 comments on commit d34939c

Please sign in to comment.