Skip to content

Commit d015177

Browse files
author
Staffan Gustafsson
committed
Moving SelectEverythingString to a cmdlet.
Updating SDK binaries to fix elevation issue.
1 parent 095d752 commit d015177

10 files changed

Lines changed: 309 additions & 325 deletions

PSEverything/Everything.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ public static void SortResultsByPath()
8989
}
9090

9191

92-
public static bool Query(bool wait)
92+
public static void Query(bool wait)
9393
{
94-
return Is64Bit ? NativeMethods64.Everything_QueryW(wait) : NativeMethods32.Everything_QueryW(wait);
94+
var res = Is64Bit ? NativeMethods64.Everything_QueryW(wait) : NativeMethods32.Everything_QueryW(wait);
95+
if (!res)
96+
{
97+
var err = GetLastError();
98+
Throw(err);
99+
}
95100
}
96101

97102
public static int GetNumberOfResults()
@@ -124,12 +129,20 @@ public static string GetFullPathName(int index, StringBuilder buf)
124129
return buf.ToString();
125130
}
126131

132+
public static void Cleanup()
133+
{
134+
if (Is64Bit)
135+
NativeMethods64.Everything_Cleanup();
136+
else
137+
NativeMethods32.Everything_Cleanup();
138+
}
139+
127140
public static string[] GetAllResults(int count)
128141
{
129142
var retVal = new string[count];
130143
var buf = new StringBuilder(260);
131-
132-
for (int i = 0; i < count ; ++i)
144+
145+
for (int i = 0; i < count; ++i)
133146
{
134147
var path = GetFullPathName(i, buf);
135148
retVal[i] = path;
@@ -138,6 +151,11 @@ public static string[] GetAllResults(int count)
138151
return retVal;
139152
}
140153

154+
static int GetLastError()
155+
{
156+
return Is64Bit ? NativeMethods64.Everything_GetLastError() : NativeMethods32.Everything_GetLastError();
157+
}
158+
141159
static void Throw(int errorCode)
142160
{
143161
switch ((Status)errorCode)

PSEverything/NativeMethods32.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,92 @@ namespace PSEverything
66
{
77
internal class NativeMethods32
88
{
9-
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
9+
const string Everything32Dll = "Everything32.dll";
10+
[DllImport(Everything32Dll, CharSet = CharSet.Unicode)]
1011
public static extern int Everything_SetSearchW(string lpSearchString);
1112

12-
[DllImport("Everything32.dll")]
13+
[DllImport(Everything32Dll)]
1314
public static extern void Everything_SetMatchPath(bool bEnable);
1415

15-
[DllImport("Everything32.dll")]
16+
[DllImport(Everything32Dll)]
1617
public static extern void Everything_SetMatchCase(bool bEnable);
1718

18-
[DllImport("Everything32.dll")]
19+
[DllImport(Everything32Dll)]
1920
public static extern void Everything_SetMatchWholeWord(bool bEnable);
2021

21-
[DllImport("Everything32.dll")]
22+
[DllImport(Everything32Dll)]
2223
public static extern void Everything_SetRegex(bool bEnable);
2324

24-
[DllImport("Everything32.dll")]
25+
[DllImport(Everything32Dll)]
2526
public static extern void Everything_SetMax(int dwMax);
2627

27-
[DllImport("Everything32.dll")]
28+
[DllImport(Everything32Dll)]
2829
public static extern void Everything_SetOffset(int dwOffset);
2930

30-
[DllImport("Everything32.dll")]
31+
[DllImport(Everything32Dll)]
3132
public static extern bool Everything_GetMatchPath();
3233

33-
[DllImport("Everything32.dll")]
34+
[DllImport(Everything32Dll)]
3435
public static extern bool Everything_GetMatchCase();
3536

36-
[DllImport("Everything32.dll")]
37+
[DllImport(Everything32Dll)]
3738
public static extern bool Everything_GetMatchWholeWord();
3839

39-
[DllImport("Everything32.dll")]
40+
[DllImport(Everything32Dll)]
4041
public static extern bool Everything_GetRegex();
4142

42-
[DllImport("Everything32.dll")]
43+
[DllImport(Everything32Dll)]
4344
public static extern UInt32 Everything_GetMax();
4445

45-
[DllImport("Everything32.dll")]
46+
[DllImport(Everything32Dll)]
4647
public static extern UInt32 Everything_GetOffset();
4748

48-
[DllImport("Everything32.dll")]
49+
[DllImport(Everything32Dll)]
4950
public static extern string Everything_GetSearchW();
5051

51-
[DllImport("Everything32.dll")]
52+
[DllImport(Everything32Dll)]
5253
public static extern int Everything_GetLastError();
5354

54-
[DllImport("Everything32.dll")]
55+
[DllImport(Everything32Dll)]
5556
public static extern bool Everything_QueryW(bool bWait);
5657

57-
[DllImport("Everything32.dll")]
58+
[DllImport(Everything32Dll)]
5859
public static extern void Everything_SortResultsByPath();
5960

60-
[DllImport("Everything32.dll")]
61+
[DllImport(Everything32Dll)]
6162
public static extern int Everything_GetNumFileResults();
6263

63-
[DllImport("Everything32.dll")]
64+
[DllImport(Everything32Dll)]
6465
public static extern int Everything_GetNumFolderResults();
6566

66-
[DllImport("Everything32.dll")]
67+
[DllImport(Everything32Dll)]
6768
public static extern int Everything_GetNumResults();
6869

69-
[DllImport("Everything32.dll")]
70+
[DllImport(Everything32Dll)]
7071
public static extern int Everything_GetTotFileResults();
7172

72-
[DllImport("Everything32.dll")]
73+
[DllImport(Everything32Dll)]
7374
public static extern int Everything_GetTotFolderResults();
7475

75-
[DllImport("Everything32.dll")]
76+
[DllImport(Everything32Dll)]
7677
public static extern int Everything_GetTotResults();
7778

78-
[DllImport("Everything32.dll")]
79+
[DllImport(Everything32Dll)]
7980
public static extern bool Everything_IsVolumeResult(int nIndex);
8081

81-
[DllImport("Everything32.dll")]
82+
[DllImport(Everything32Dll)]
8283
public static extern bool Everything_IsFolderResult(int nIndex);
8384

84-
[DllImport("Everything32.dll")]
85+
[DllImport(Everything32Dll)]
8586
public static extern bool Everything_IsFileResult(int nIndex);
8687

87-
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
88+
[DllImport(Everything32Dll, CharSet = CharSet.Unicode)]
8889
public static extern void Everything_GetResultFullPathNameW(int nIndex, StringBuilder lpString, int nMaxCount);
8990

90-
[DllImport("Everything32.dll")]
91+
[DllImport(Everything32Dll)]
9192
public static extern void Everything_Reset();
93+
94+
[DllImport(Everything32Dll)]
95+
public static extern void Everything_Cleanup();
9296
}
9397
}

PSEverything/NativeMethods64.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,92 @@ namespace PSEverything
66
{
77
internal class NativeMethods64
88
{
9-
[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
9+
const string Everything64Dll = "Everything64.dll";
10+
[DllImport(Everything64Dll, CharSet = CharSet.Unicode)]
1011
public static extern int Everything_SetSearchW(string lpSearchString);
1112

12-
[DllImport("Everything64.dll")]
13+
[DllImport(Everything64Dll)]
1314
public static extern void Everything_SetMatchPath(bool bEnable);
1415

15-
[DllImport("Everything64.dll")]
16+
[DllImport(Everything64Dll)]
1617
public static extern void Everything_SetMatchCase(bool bEnable);
1718

18-
[DllImport("Everything64.dll")]
19+
[DllImport(Everything64Dll)]
1920
public static extern void Everything_SetMatchWholeWord(bool bEnable);
2021

21-
[DllImport("Everything64.dll")]
22+
[DllImport(Everything64Dll)]
2223
public static extern void Everything_SetRegex(bool bEnable);
2324

24-
[DllImport("Everything64.dll")]
25+
[DllImport(Everything64Dll)]
2526
public static extern void Everything_SetMax(int dwMax);
2627

27-
[DllImport("Everything64.dll")]
28+
[DllImport(Everything64Dll)]
2829
public static extern void Everything_SetOffset(int dwOffset);
2930

30-
[DllImport("Everything64.dll")]
31+
[DllImport(Everything64Dll)]
3132
public static extern bool Everything_GetMatchPath();
3233

33-
[DllImport("Everything64.dll")]
34+
[DllImport(Everything64Dll)]
3435
public static extern bool Everything_GetMatchCase();
3536

36-
[DllImport("Everything64.dll")]
37+
[DllImport(Everything64Dll)]
3738
public static extern bool Everything_GetMatchWholeWord();
3839

39-
[DllImport("Everything64.dll")]
40+
[DllImport(Everything64Dll)]
4041
public static extern bool Everything_GetRegex();
4142

42-
[DllImport("Everything64.dll")]
43+
[DllImport(Everything64Dll)]
4344
public static extern UInt32 Everything_GetMax();
4445

45-
[DllImport("Everything64.dll")]
46+
[DllImport(Everything64Dll)]
4647
public static extern UInt32 Everything_GetOffset();
4748

48-
[DllImport("Everything64.dll")]
49+
[DllImport(Everything64Dll)]
4950
public static extern string Everything_GetSearchW();
50-
51-
[DllImport("Everything64.dll")]
51+
52+
[DllImport(Everything64Dll)]
5253
public static extern int Everything_GetLastError();
5354

54-
[DllImport("Everything64.dll")]
55+
[DllImport(Everything64Dll)]
5556
public static extern bool Everything_QueryW(bool bWait);
5657

57-
[DllImport("Everything64.dll")]
58+
[DllImport(Everything64Dll)]
5859
public static extern void Everything_SortResultsByPath();
5960

60-
[DllImport("Everything64.dll")]
61+
[DllImport(Everything64Dll)]
6162
public static extern int Everything_GetNumFileResults();
6263

63-
[DllImport("Everything64.dll")]
64+
[DllImport(Everything64Dll)]
6465
public static extern int Everything_GetNumFolderResults();
6566

66-
[DllImport("Everything64.dll")]
67+
[DllImport(Everything64Dll)]
6768
public static extern int Everything_GetNumResults();
6869

69-
[DllImport("Everything64.dll")]
70+
[DllImport(Everything64Dll)]
7071
public static extern int Everything_GetTotFileResults();
7172

72-
[DllImport("Everything64.dll")]
73+
[DllImport(Everything64Dll)]
7374
public static extern int Everything_GetTotFolderResults();
7475

75-
[DllImport("Everything64.dll")]
76+
[DllImport(Everything64Dll)]
7677
public static extern int Everything_GetTotResults();
7778

78-
[DllImport("Everything64.dll")]
79+
[DllImport(Everything64Dll)]
7980
public static extern bool Everything_IsVolumeResult(int nIndex);
8081

81-
[DllImport("Everything64.dll")]
82+
[DllImport(Everything64Dll)]
8283
public static extern bool Everything_IsFolderResult(int nIndex);
8384

84-
[DllImport("Everything64.dll")]
85+
[DllImport(Everything64Dll)]
8586
public static extern bool Everything_IsFileResult(int nIndex);
8687

87-
[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
88+
[DllImport(Everything64Dll, CharSet = CharSet.Unicode)]
8889
public static extern void Everything_GetResultFullPathNameW(int nIndex, StringBuilder lpString, int nMaxCount);
8990

90-
[DllImport("Everything64.dll")]
91+
[DllImport(Everything64Dll)]
9192
public static extern void Everything_Reset();
93+
94+
[DllImport(Everything64Dll)]
95+
public static extern void Everything_Cleanup ();
9296
}
9397
}

PSEverything/PSEverything.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
34+
<SpecificVersion>False</SpecificVersion>
35+
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll</HintPath>
36+
</Reference>
3337
<Reference Include="System" />
3438
<Reference Include="System.Core" />
3539
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -49,6 +53,7 @@
4953
<Compile Include="NativeMethods64.cs" />
5054
<Compile Include="Properties\AssemblyInfo.cs" />
5155
<Compile Include="SearchEverythingCommand.cs" />
56+
<Compile Include="SelectEverythingStringCommand.cs" />
5257
</ItemGroup>
5358
<ItemGroup>
5459
<Content Include="PSEverything.dll-Help.xml">
@@ -63,9 +68,6 @@
6368
<Link>LICENSE</Link>
6469
</Content>
6570
</ItemGroup>
66-
<ItemGroup>
67-
<Content Include="PSEverything.psm1" />
68-
</ItemGroup>
6971
<ItemGroup>
7072
<None Include="packages.config" />
7173
</ItemGroup>

PSEverything/PSEverything.psd1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
@{
1010

1111
# Script module or binary module file associated with this manifest.
12-
RootModule = 'PSEverything.psm1'
12+
RootModule = 'PSEverything.dll'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.0'
15+
ModuleVersion = '2.1'
1616

1717
# ID used to uniquely identify this module
1818
GUID = 'f262ec02-4a88-49e5-94da-e25aab9cbf7a'
@@ -30,7 +30,7 @@ Copyright = '(c) 2016 sgustafsson. All rights reserved.'
3030
Description = 'Powershell access to Everything - Blazingly fast file system searches'
3131

3232
# Minimum version of the Windows PowerShell engine required by this module
33-
PowerShellVersion = '5.0'
33+
PowerShellVersion = '5.0.0'
3434

3535
# Name of the Windows PowerShell host required by this module
3636
# PowerShellHostName = ''
@@ -72,7 +72,7 @@ FunctionsToExport = 'Select-EverythingString'
7272
CmdletsToExport = 'Search-Everything'
7373

7474
# Variables to export from this module
75-
VariablesToExport = '*'
75+
VariablesToExport = ''
7676

7777
# Aliases to export from this module
7878
AliasesToExport = 'se','sles'
@@ -84,7 +84,7 @@ AliasesToExport = 'se','sles'
8484
# ModuleList = @()
8585

8686
# List of all files packaged with this module
87-
FileList = 'Everything32.dll','Everything64.dll','LICENSE','PSEverything.dll','PSEverything.dll-Help.xml','PSEverything.psd1','PSEverything.psm1'
87+
FileList = 'Everything32.dll','Everything64.dll','LICENSE','PSEverything.dll','PSEverything.dll-Help.xml','PSEverything.psd1'
8888

8989
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
9090
PrivateData = @{
@@ -105,6 +105,9 @@ PrivateData = @{
105105

106106
# ReleaseNotes of this module
107107
ReleaseNotes = @'
108+
2.1: Upgrading to SDK matching 1.4.1.809b - Fixing hang when calling from Eleveated powershell
109+
to Everything.
110+
Now works with both eleveated and non-elevated processes as long as Everything is running as admin.
108111
2.0:
109112
Implements tabcompletion.
110113
Quoting filter paths

0 commit comments

Comments
 (0)