Compare commits
3 commits
main
...
users/davi
Author | SHA1 | Date | |
---|---|---|---|
8fee618ad4 | |||
fda04767bd | |||
5d2b02b3ed |
27
.github/actions/spell-check/advice.md
vendored
Normal file
27
.github/actions/spell-check/advice.md
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<!-- See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples%3A-advice --> <!-- markdownlint-disable MD033 MD041 -->
|
||||||
|
<details><summary>If you see a bunch of garbage</summary>
|
||||||
|
|
||||||
|
If it relates to a ...
|
||||||
|
<details><summary>well-formed pattern</summary>
|
||||||
|
|
||||||
|
See if there's a [pattern](https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns) that would match it.
|
||||||
|
|
||||||
|
If not, try writing one and adding it to the `patterns.txt` file.
|
||||||
|
|
||||||
|
Patterns are Perl 5 Regular Expressions - you can [test](
|
||||||
|
https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your lines.
|
||||||
|
|
||||||
|
Note that patterns can't match multiline strings.
|
||||||
|
</details>
|
||||||
|
<details><summary>binary-ish string</summary>
|
||||||
|
|
||||||
|
Please add a file path to the `excludes.txt` file instead of just accepting the garbage.
|
||||||
|
|
||||||
|
File paths are Perl 5 Regular Expressions - you can [test](
|
||||||
|
https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your files.
|
||||||
|
|
||||||
|
`^` refers to the file's path from the root of the repository, so `^README\.md$` would exclude [README.md](
|
||||||
|
../tree/HEAD/README.md) (on whichever branch you're using).
|
||||||
|
</details>
|
||||||
|
|
||||||
|
</details>
|
35
.github/actions/spell-check/excludes.txt
vendored
35
.github/actions/spell-check/excludes.txt
vendored
|
@ -1,3 +1,13 @@
|
||||||
|
# See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-excludes
|
||||||
|
(?:^|/)(?i)COPYRIGHT
|
||||||
|
(?:^|/)(?i)LICEN[CS]E
|
||||||
|
(?:^|/)package(?:-lock)\.json$
|
||||||
|
(?:^|/)vendor/
|
||||||
|
/package(?:-lock|)\.json$
|
||||||
|
/pinyindb/
|
||||||
|
/settings-html/
|
||||||
|
ignore$
|
||||||
|
[/.][a-z]{2}(?:-[a-zA-Z]{2}|)\.
|
||||||
\.ai$
|
\.ai$
|
||||||
\.bmp$
|
\.bmp$
|
||||||
\.dat$
|
\.dat$
|
||||||
|
@ -7,13 +17,28 @@
|
||||||
\.ico$
|
\.ico$
|
||||||
\.jpg$
|
\.jpg$
|
||||||
\.lcl$
|
\.lcl$
|
||||||
|
\.lock$
|
||||||
|
\.min\.
|
||||||
|
\.mod$
|
||||||
\.pdf$
|
\.pdf$
|
||||||
\.png$
|
|
||||||
\.PNG$
|
\.PNG$
|
||||||
|
\.png$
|
||||||
\.woff$
|
\.woff$
|
||||||
\.zip$
|
\.zip$
|
||||||
|
^doc/devdocs/akaLinks\.md$
|
||||||
|
^src/common/logger/logger\.vcxproj\.filters$
|
||||||
|
^src/common/notifications/BackgroundActivatorDLL/BackgroundActivator\.vcxproj\.filters$
|
||||||
|
^src/common/notifications/BackgroundActivatorDLL/cpp\.hint$
|
||||||
|
^src/modules/colorPicker/ColorPickerUI/Resources/colorPicker\.cur$
|
||||||
|
^src/modules/fancyzones/lib/FancyZonesWinHookEventIDs\.h$
|
||||||
|
^src/modules/imageresizer/dll/ContextMenuHandler\.rgs$
|
||||||
|
^src/modules/imageresizer/dll/ImageResizerExt\.rgs$
|
||||||
|
^src/modules/powerrename/testapp/PowerRenameTest\.vcxproj\.filters$
|
||||||
|
^src/modules/powerrename/UWPui/pch\.h$
|
||||||
|
^src/modules/powerrename/UWPui/PowerRenameUWPUI\.vcxproj\.filters$
|
||||||
|
^src/modules/previewpane/PreviewPaneUnitTests/HelperFiles/MarkdownWithHTMLImageTag\.txt$
|
||||||
|
^tools/CleanUp_tool/CleanUp_tool\.vcxproj\.filters$
|
||||||
|
^\.github/
|
||||||
^\.github/actions/spell-check/
|
^\.github/actions/spell-check/
|
||||||
/package(?:-lock|)\.json$
|
^\.gitmodules$
|
||||||
/pinyindb/
|
(?:^|/)WindowsSettings\.json$
|
||||||
/settings-html/
|
|
||||||
[/.][a-z]{2}(?:-[a-zA-Z]{2}|)\.
|
|
||||||
|
|
808
.github/actions/spell-check/expect.txt
vendored
808
.github/actions/spell-check/expect.txt
vendored
File diff suppressed because it is too large
Load diff
26
.github/actions/spell-check/patterns.txt
vendored
26
.github/actions/spell-check/patterns.txt
vendored
|
@ -1,11 +1,25 @@
|
||||||
|
# See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns
|
||||||
https?://(?:(?:www\.|)youtube\.com|youtu.be)/[-a-zA-Z0-9?&=]*
|
https?://(?:(?:www\.|)youtube\.com|youtu.be)/[-a-zA-Z0-9?&=]*
|
||||||
|
# GitHub SHAs
|
||||||
|
\bapi.github\.com/repos/[^/]+/[^/]+/[^/]+/[0-9a-f]+\b
|
||||||
://github\.(?:com|blog)/[^\w")]+
|
://github\.(?:com|blog)/[^\w")]+
|
||||||
|
(?:\[[0-9a-f]+\]\(https:/|)/github\.com/[^/]+/[^/]+/[^/]+/[0-9a-f]+(?:[-0-9a-zA-Z/#.]*|)\b
|
||||||
|
# githubusercontent
|
||||||
://githubusercontent\.com/[^\w")]+
|
://githubusercontent\.com/[^\w")]+
|
||||||
|
# gist github
|
||||||
|
/gist\.github\.com/[^/]+/[0-9a-f]+
|
||||||
|
|
||||||
|
# msdn
|
||||||
|
\b(?:download\.visualstudio|docs|msdn)\.microsoft\.com/[-_a-zA-Z0-9()=./]*
|
||||||
|
|
||||||
data:[a-zA-Z=;,/0-9+-]+
|
data:[a-zA-Z=;,/0-9+-]+
|
||||||
0x[0-9a-fA-F](?:\.[0-9a-fA-F]*|)[pP]
|
0x[0-9a-fA-F](?:\.[0-9a-fA-F]*|)[pP]
|
||||||
(?:0[Xx]|U\+|#)[a-f0-9A-FGgRr]{2,}[Uu]?[Ll]{0,2}\b
|
(?:0[Xx]|U\+|#)[a-f0-9A-FGgRr]{2,}[Uu]?[Ll]{0,2}\b
|
||||||
[{"][0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}"]
|
# uuid:
|
||||||
\b([A-Za-z])\1{3,}\b
|
[-<({"'>][0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[<'"})>]
|
||||||
|
|
||||||
|
# ignore long runs of a single character:
|
||||||
|
\b([A-Za-z])\g{-1}{3,}\b
|
||||||
(?:L"[abAB]+", ){3}L"[abAB]+"
|
(?:L"[abAB]+", ){3}L"[abAB]+"
|
||||||
"Lorem[^"]+?\."
|
"Lorem[^"]+?\."
|
||||||
TestCase\("[^"]+"
|
TestCase\("[^"]+"
|
||||||
|
@ -17,6 +31,8 @@ TestCase\("[^"]+"
|
||||||
|
|
||||||
# Windows paths
|
# Windows paths
|
||||||
\\native
|
\\native
|
||||||
|
\\netcoreapp
|
||||||
|
\\netstandard
|
||||||
\\notifications
|
\\notifications
|
||||||
\\recyclebin
|
\\recyclebin
|
||||||
\\reinstall
|
\\reinstall
|
||||||
|
@ -27,6 +43,7 @@ TestCase\("[^"]+"
|
||||||
\\restore
|
\\restore
|
||||||
\\result
|
\\result
|
||||||
\\runner
|
\\runner
|
||||||
|
\\runtimes
|
||||||
\\Telemetry
|
\\Telemetry
|
||||||
\\telemetry
|
\\telemetry
|
||||||
\\testapp
|
\\testapp
|
||||||
|
@ -42,6 +59,11 @@ TestCase\("[^"]+"
|
||||||
# Id info inside markdown file (registry.md)
|
# Id info inside markdown file (registry.md)
|
||||||
^\|\s+ID\s+\|\s*\`[0-9A-F]{32}\`
|
^\|\s+ID\s+\|\s*\`[0-9A-F]{32}\`
|
||||||
|
|
||||||
|
# TestCase strings intentionally have non dictionary items
|
||||||
|
\[TestCase\(new string.*\]
|
||||||
|
|
||||||
# marker for ignoring a comment to the end of the line
|
# marker for ignoring a comment to the end of the line
|
||||||
^.*/\* #no-spell-check-line \*/.*$
|
^.*/\* #no-spell-check-line \*/.*$
|
||||||
// #no-spell-check.*$
|
// #no-spell-check.*$
|
||||||
|
|
||||||
|
http://tes/
|
||||||
|
|
20
.github/workflows/spelling.yml
vendored
20
.github/workflows/spelling.yml
vendored
|
@ -1,20 +0,0 @@
|
||||||
name: Spell checking
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
schedule:
|
|
||||||
# * is a special character in YAML so you have to quote this string
|
|
||||||
- cron: '15 * * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Spell checking
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2.0.0
|
|
||||||
with:
|
|
||||||
fetch-depth: 5
|
|
||||||
- uses: check-spelling/check-spelling@0.0.16-alpha
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
bucket: .github/actions
|
|
||||||
project: spell-check
|
|
22
.github/workflows/spelling2.yml
vendored
Normal file
22
.github/workflows/spelling2.yml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# spelling.yml is blocked per https://github.com/check-spelling/check-spelling/security/advisories/GHSA-g86g-chm8-7r2p
|
||||||
|
name: Spell checking
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
spelling:
|
||||||
|
name: Spell checking
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout-merge
|
||||||
|
if: "contains(github.event_name, 'pull_request')"
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: refs/pull/${{github.event.pull_request.number}}/merge
|
||||||
|
- name: checkout
|
||||||
|
if: "!contains(github.event_name, 'pull_request')"
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- uses: check-spelling/check-spelling@v0.0.19
|
||||||
|
with:
|
||||||
|
config: .github/actions/spell-check
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder.Helpers
|
||||||
|
{
|
||||||
|
public static class NativeMethods
|
||||||
|
{
|
||||||
|
[DllImport("netapi32.dll")]
|
||||||
|
internal static extern int NetApiBufferFree(IntPtr Buffer);
|
||||||
|
|
||||||
|
[DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
|
||||||
|
internal static extern int NetShareEnum(StringBuilder servername, int level, ref IntPtr bufptr, uint prefmaxlen, ref int entriesread, ref int totalentries, ref int resume_handle);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder.Helpers
|
||||||
|
{
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Interop")]
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Interop")]
|
||||||
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||||
|
public struct SHARE_INFO_1
|
||||||
|
{
|
||||||
|
public string shi1_netname { get; private set; }
|
||||||
|
|
||||||
|
public uint shi1_type { get; private set; }
|
||||||
|
|
||||||
|
public string shi1_remark { get; private set; }
|
||||||
|
|
||||||
|
public SHARE_INFO_1(string sharename, uint sharetype, string remark)
|
||||||
|
{
|
||||||
|
shi1_netname = sharename;
|
||||||
|
shi1_type = sharetype;
|
||||||
|
shi1_remark = remark;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,11 +27,13 @@ namespace Microsoft.Plugin.Folder
|
||||||
private static readonly FolderSettings _settings = _storage.Load();
|
private static readonly FolderSettings _settings = _storage.Load();
|
||||||
private static readonly IQueryInternalDirectory _internalDirectory = new QueryInternalDirectory(_settings, new QueryFileSystemInfo(_fileSystem.DirectoryInfo), _fileSystem.Directory);
|
private static readonly IQueryInternalDirectory _internalDirectory = new QueryInternalDirectory(_settings, new QueryFileSystemInfo(_fileSystem.DirectoryInfo), _fileSystem.Directory);
|
||||||
private static readonly FolderHelper _folderHelper = new FolderHelper(new DriveInformation(), new FolderLinksSettings(_settings));
|
private static readonly FolderHelper _folderHelper = new FolderHelper(new DriveInformation(), new FolderLinksSettings(_settings));
|
||||||
|
private static readonly IQueryNetworkShare _networkShare = new QueryNetworkShare();
|
||||||
|
|
||||||
private static readonly ICollection<IFolderProcessor> _processors = new IFolderProcessor[]
|
private static readonly ICollection<IFolderProcessor> _processors = new IFolderProcessor[]
|
||||||
{
|
{
|
||||||
new UserFolderProcessor(_folderHelper),
|
new UserFolderProcessor(_folderHelper),
|
||||||
new InternalDirectoryProcessor(_folderHelper, _internalDirectory),
|
new InternalDirectoryProcessor(_folderHelper, _internalDirectory),
|
||||||
|
new NetShareProcessor(_folderHelper, _networkShare),
|
||||||
};
|
};
|
||||||
|
|
||||||
private static PluginInitContext _context;
|
private static PluginInitContext _context;
|
||||||
|
@ -57,10 +59,11 @@ namespace Microsoft.Plugin.Folder
|
||||||
|
|
||||||
var expandedName = FolderHelper.Expand(query.Search);
|
var expandedName = FolderHelper.Expand(query.Search);
|
||||||
|
|
||||||
return _processors.SelectMany(processor => processor.Results(query.ActionKeyword, expandedName))
|
var result = _processors.SelectMany(processor => processor.Results(query.ActionKeyword, expandedName))
|
||||||
.Select(res => res.Create(_context.API))
|
.Select(res => res.Create(_context.API))
|
||||||
.Select(AddScore)
|
.Select(AddScore)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
|
|
|
@ -60,13 +60,13 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\..\settings-ui\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" >
|
<ProjectReference Include="..\..\..\..\settings-ui\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj">
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" >
|
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" >
|
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Plugin.Folder.Sources;
|
||||||
|
using Microsoft.Plugin.Folder.Sources.Result;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder
|
||||||
|
{
|
||||||
|
public class NetShareProcessor : IFolderProcessor
|
||||||
|
{
|
||||||
|
private readonly IFolderHelper _folderHelper;
|
||||||
|
private readonly IQueryNetworkShare _networkShare;
|
||||||
|
|
||||||
|
public NetShareProcessor(IFolderHelper folderHelper, IQueryNetworkShare networkShare)
|
||||||
|
{
|
||||||
|
_folderHelper = folderHelper;
|
||||||
|
_networkShare = networkShare;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IItemResult> Results(string actionKeyword, string search)
|
||||||
|
{
|
||||||
|
if (!_folderHelper.IsNetworkShare(search))
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<IItemResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _networkShare.Query(search);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Plugin.Folder.Sources.Result;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder.Sources
|
||||||
|
{
|
||||||
|
public interface IQueryNetworkShare
|
||||||
|
{
|
||||||
|
IEnumerable<IItemResult> Query(string search);
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,9 +40,8 @@ namespace Microsoft.Plugin.Folder.Sources
|
||||||
throw new ArgumentNullException(nameof(search));
|
throw new ArgumentNullException(nameof(search));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using Ordinal this is internal and we're comparing symbols
|
if (IsSharedFolder(search))
|
||||||
if (search.StartsWith(@"\\", StringComparison.Ordinal))
|
{
|
||||||
{ // share folder
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +68,17 @@ namespace Microsoft.Plugin.Folder.Sources
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsNetworkShare(string search)
|
||||||
|
{
|
||||||
|
if (search == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(search));
|
||||||
|
}
|
||||||
|
|
||||||
|
var levels = search.Trim('\\').Split('\\').Length;
|
||||||
|
return IsSharedFolder(search) && (levels == 1 || levels == 2);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This check is needed because char.IsLetter accepts more than [A-z]
|
/// This check is needed because char.IsLetter accepts more than [A-z]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -92,5 +102,11 @@ namespace Microsoft.Plugin.Folder.Sources
|
||||||
|
|
||||||
return Environment.ExpandEnvironmentVariables(search);
|
return Environment.ExpandEnvironmentVariables(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsSharedFolder(string search)
|
||||||
|
{
|
||||||
|
// Using Ordinal this is internal and we're comparing symbols
|
||||||
|
return search.StartsWith(@"\\", StringComparison.Ordinal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,7 @@ namespace Microsoft.Plugin.Folder.Sources
|
||||||
public interface IFolderHelper
|
public interface IFolderHelper
|
||||||
{
|
{
|
||||||
bool IsDriveOrSharedFolder(string search);
|
bool IsDriveOrSharedFolder(string search);
|
||||||
|
|
||||||
|
bool IsNetworkShare(string search);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Plugin.Folder.Helpers;
|
||||||
|
using Microsoft.Plugin.Folder.Sources.Result;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder.Sources
|
||||||
|
{
|
||||||
|
public class QueryNetworkShare : IQueryNetworkShare
|
||||||
|
{
|
||||||
|
public IEnumerable<IItemResult> Query(string search)
|
||||||
|
{
|
||||||
|
if (search == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(search));
|
||||||
|
}
|
||||||
|
|
||||||
|
var host = @"\\" + search.Substring(2, search.Length - 2).Split('\\')[0];
|
||||||
|
|
||||||
|
var shares = EnumNetShares(host);
|
||||||
|
|
||||||
|
if (!shares.Any())
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new CreateOpenCurrentFolderResult(search);
|
||||||
|
|
||||||
|
var shareResult = BuildShareResult(search, host, shares);
|
||||||
|
|
||||||
|
foreach (var result in shareResult)
|
||||||
|
{
|
||||||
|
yield return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<SHARE_INFO_1> EnumNetShares(string host)
|
||||||
|
{
|
||||||
|
List<SHARE_INFO_1> shareInfos = new List<SHARE_INFO_1>();
|
||||||
|
int entriesRead = 0;
|
||||||
|
int totalEntries = 0;
|
||||||
|
int resumeHandle = 0;
|
||||||
|
int nStructSize = Marshal.SizeOf(typeof(SHARE_INFO_1));
|
||||||
|
IntPtr bufPtr = IntPtr.Zero;
|
||||||
|
StringBuilder hostBuilder = new StringBuilder(host);
|
||||||
|
uint size = 0xFFFFFFFF; // MAX_PREFERRED_LENGTH
|
||||||
|
int result = NativeMethods.NetShareEnum(hostBuilder, 1, ref bufPtr, size, ref entriesRead, ref totalEntries, ref resumeHandle);
|
||||||
|
|
||||||
|
// NERR_Success
|
||||||
|
if (result == 0)
|
||||||
|
{
|
||||||
|
IntPtr currentPtr = bufPtr;
|
||||||
|
for (int i = 0; i < entriesRead; i++)
|
||||||
|
{
|
||||||
|
SHARE_INFO_1 shareInfo = (SHARE_INFO_1)Marshal.PtrToStructure(currentPtr, typeof(SHARE_INFO_1));
|
||||||
|
|
||||||
|
// STYPE_DISKTREE
|
||||||
|
if (shareInfo.shi1_type == 0)
|
||||||
|
{
|
||||||
|
shareInfos.Add(shareInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPtr += nStructSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = NativeMethods.NetApiBufferFree(bufPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shareInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<FolderItemResult> BuildShareResult(string search, string host, IEnumerable<SHARE_INFO_1> shares)
|
||||||
|
{
|
||||||
|
return shares.Select(s => new FolderItemResult(host, s))
|
||||||
|
.Where(s => s.Path.StartsWith(search, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.OrderBy(s => s.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Microsoft.Plugin.Folder.Helpers;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
|
@ -23,6 +24,15 @@ namespace Microsoft.Plugin.Folder.Sources.Result
|
||||||
Path = fileSystemInfo.FullName;
|
Path = fileSystemInfo.FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FolderItemResult(string host, SHARE_INFO_1 shareInfo)
|
||||||
|
{
|
||||||
|
var path = System.IO.Path.Combine(host, shareInfo.shi1_netname);
|
||||||
|
|
||||||
|
Title = shareInfo.shi1_netname;
|
||||||
|
Subtitle = path;
|
||||||
|
Path = path;
|
||||||
|
}
|
||||||
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
public string Subtitle { get; set; }
|
public string Subtitle { get; set; }
|
||||||
|
|
Loading…
Reference in a new issue