Skip to content

Commit

Permalink
Merge branch 'dev-plugin-everything'
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Mar 27, 2024
2 parents 9c9ee32 + bbfffbd commit 8b5829d
Show file tree
Hide file tree
Showing 27 changed files with 2,516 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CurvaLauncher.Common/Apis/IImageApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public interface IImageApi
public ImageSource EmptyImage { get; }
public ImageSource? GetEmbededIconImage(string filename, int iconSize, int? iconIndex);
public ImageSource? GetAssociatedIconImage(string filename, int iconSize);
public ImageSource? GetDefaultFileIcon(int iconSize);
public ImageSource? GetDefaultFolderIcon(int iconSize);
public ImageSource? GetFileIcon(string filename, int iconSize);
public ImageSource? CreateFromSvg(string svg);
}
4 changes: 4 additions & 0 deletions src/CurvaLauncher.Common/CurvaLauncherContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace CurvaLauncher
public abstract class CurvaLauncherContext
{
public abstract Dispatcher Dispatcher { get; }

/// <summary>
/// Required query result icon size
/// </summary>
public abstract int RequiredIconSize { get; }

public abstract CultureInfo CurrentCulture { get; }
Expand Down
7 changes: 7 additions & 0 deletions src/CurvaLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AdditionalPlugins", "Additi
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CurvaLauncher.Plugins.SHLoadIndirectStringList", "AdditionalPlugins\CurvaLauncher.Plugins.SHLoadIndirectStringList\CurvaLauncher.Plugins.SHLoadIndirectStringList.fsproj", "{8CFC1C29-51AA-45ED-A91F-01F513182002}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurvaLauncher.Plugins.Everything", "Plugins\CurvaLauncher.Plugins.Everything\CurvaLauncher.Plugins.Everything.csproj", "{C7AC6C75-89C6-42E5-8D2A-D06994949F05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -97,6 +99,10 @@ Global
{8CFC1C29-51AA-45ED-A91F-01F513182002}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CFC1C29-51AA-45ED-A91F-01F513182002}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CFC1C29-51AA-45ED-A91F-01F513182002}.Release|Any CPU.Build.0 = Release|Any CPU
{C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -112,6 +118,7 @@ Global
{3781D17E-F339-4933-85BC-D821C5FCC131} = {BAACD50D-2F94-4A65-8B13-49031D617CAC}
{F3F6F783-4636-457F-80E1-CC489F524B43} = {BAACD50D-2F94-4A65-8B13-49031D617CAC}
{8CFC1C29-51AA-45ED-A91F-01F513182002} = {4A86F98E-B276-4F75-9847-8D0E4280D887}
{C7AC6C75-89C6-42E5-8D2A-D06994949F05} = {BAACD50D-2F94-4A65-8B13-49031D617CAC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3FC4E11A-3D67-43DE-84D8-DCA1841F0D71}
Expand Down
16 changes: 16 additions & 0 deletions src/CurvaLauncher/Apis/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ private ImageApi() { }
}
}

public ImageSource? GetDefaultFileIcon(int iconSize)
{
var path =
System.IO.Path.Combine(Environment.GetEnvironmentVariable("SYSTEMROOT") ?? @"C:\Windows", "System32", "imageres.dll");

return GetEmbededIconImage(path, iconSize, 2);
}

public ImageSource? GetDefaultFolderIcon(int iconSize)
{
var path =
System.IO.Path.Combine(Environment.GetEnvironmentVariable("SYSTEMROOT") ?? @"C:\Windows", "System32", "imageres.dll");

return GetEmbededIconImage(path, iconSize, 3);
}

public ImageSource? CreateFromSvg(string svg)
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<None Include="EverythingSearchClient\EverythingSearchClient.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\CurvaLauncher.Plugins\CurvaLauncher.Plugins.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<Target Name="CopyOutput" AfterTargets="Build">
<Copy SourceFiles="$(OutDir)\$(MSBuildProjectName).dll" DestinationFiles="..\..\CurvaLauncher\bin\$(Configuration)\$(TargetFramework)\Plugins\$(MSBuildProjectName).dll"></Copy>
</Target>

<Target Name="CopyOutputPdb" AfterTargets="Build" Condition="'$(Configuration)'=='Debug'">
<Copy SourceFiles="$(OutDir)\$(MSBuildProjectName).pdb" DestinationFiles="..\..\CurvaLauncher\bin\$(Configuration)\$(TargetFramework)\Plugins\$(MSBuildProjectName).pdb"></Copy>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Windows.Media;

namespace CurvaLauncher.Plugins.Everything
{
public class EverythingNotRunningQueryResult : IQueryResult
{
public string Title => "Everything";
public string Description => "Everything is not running now!";

public float Weight => 1;

public ImageSource? Icon => null;
}
}
69 changes: 69 additions & 0 deletions src/Plugins/CurvaLauncher.Plugins.Everything/EverythingPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using CurvaLauncher.Plugins.Everything.Properties;
using EverythingSearchClient;

namespace CurvaLauncher.Plugins.Everything
{
public class EverythingPlugin : SyncI18nPlugin
{
public EverythingPlugin(CurvaLauncherContext context) : base(context)
{
Icon = context.ImageApi.CreateFromSvg(Resources.IconSvg)!;
}

public override object NameKey => "StrPluginName";
public override object DescriptionKey => "StrPluginDescription";
public override ImageSource Icon { get; }


[PluginI18nOption("StrPrefix")]
public string Prefix { get; set; } = "*";

[PluginI18nOption("StrResultMaxCount")]
public int ResultMaxCount { get; set; } = 10;

public override IEnumerable<I18nResourceDictionary> GetI18nResourceDictionaries()
{
yield return I18nResourceDictionary.Create(new CultureInfo("en-US"), "I18n/EnUs.xaml");
yield return I18nResourceDictionary.Create(new CultureInfo("zh-Hans"), "I18n/ZhHans.xaml");
yield return I18nResourceDictionary.Create(new CultureInfo("zh-Hant"), "I18n/ZhHant.xaml");
yield return I18nResourceDictionary.Create(new CultureInfo("ja-JP"), "I18n/JaJp.xaml");
yield return I18nResourceDictionary.Create(new CultureInfo("de"), "I18n/De.xaml");
}

public override IEnumerable<IQueryResult> Query(string query)
{
if (!query.StartsWith(Prefix))
yield break;
query = query.Substring(Prefix.Length);

if (!SearchClient.IsEverythingAvailable())
{
yield return new EverythingNotRunningQueryResult();
yield break;
}

if (string.IsNullOrWhiteSpace(query))
{
yield return new EmptyQueryResult("Everything", "Locate files and folders by name instantly.", 1, null);
yield break;
}

var client = new SearchClient();
var result = client.Search(query, (uint)ResultMaxCount);

float weight = 1;
foreach (var item in result.Items)
{
yield return new EverythingQueryResult(this, item, weight);
weight -= float.Epsilon;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Windows.Media;

namespace CurvaLauncher.Plugins.Everything
{
public class EverythingQueryResult : ISyncQueryResult
{
private readonly EverythingPlugin _plugin;
private readonly EverythingSearchClient.Result.Item _searchResult;
private readonly string _itemFullPath;

public EverythingQueryResult(EverythingPlugin plugin, EverythingSearchClient.Result.Item searchResult, float weight)
{
_plugin = plugin;
_searchResult = searchResult;
_itemFullPath = System.IO.Path.Combine(searchResult.Path, searchResult.Name);
Weight = weight;

plugin.HostContext.Dispatcher.Invoke(() =>
{
Icon = plugin.HostContext.ImageApi.GetFileIcon(_itemFullPath, plugin.HostContext.RequiredIconSize);

if (Icon == null)
{
if (System.IO.Directory.Exists(_itemFullPath))
Icon = plugin.HostContext.ImageApi.GetDefaultFolderIcon(plugin.HostContext.RequiredIconSize);
else if (System.IO.File.Exists(_itemFullPath))
Icon = plugin.HostContext.ImageApi.GetDefaultFileIcon(plugin.HostContext.RequiredIconSize);
}
});
}

public string Title => _searchResult.Name;
public string Description => _searchResult.Path;

public float Weight { get; }

public ImageSource? Icon { get; private set; }

public void Invoke()
{
if (_plugin.HostContext.IsAltKeyPressed())
{

}
else if (_plugin.HostContext.IsCtrlKeyPressed())
{

}
else
{
_plugin.HostContext.Api.Open(_itemFullPath);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EverythingSearchClient
{
public class EverythingBusyException: Exception
{
public EverythingBusyException() : base("Everything service is busy") { }
}
}
Loading

0 comments on commit 8b5829d

Please sign in to comment.