Skip to content

Commit 2370ee7

Browse files
committed
* Add the context menu for drives
* Improve process handles filtering. Bug fix: PolarGoose/Handle2#4
1 parent 19c67c6 commit 2370ee7

10 files changed

Lines changed: 64 additions & 23 deletions

File tree

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ on: push
22

33
jobs:
44
build:
5-
runs-on: windows-2022
5+
runs-on: windows-2025
66
steps:
77
- uses: actions/checkout@v4
88
- run: ./build.ps1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vs/
33
.idea/
44
launchSettings.json
5+
*.user

ShowWhatProcessLocksFile.sln

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
3-
VisualStudioVersion = 17.4.33205.214
2+
# Visual Studio Version 18
3+
VisualStudioVersion = 18.0.11205.157 d18.0
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShowWhatProcessLocksFile", "src\App\ShowWhatProcessLocksFile.csproj", "{952F82E5-8372-4435-8318-3ED0C114A57C}"
6-
EndProject
7-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\Test\Test.csproj", "{19D889E7-E728-4BFF-A68E-5445454F4417}"
8-
EndProject
9-
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "Installer", "src\Installer\Installer.wixproj", "{8D8AB22B-5677-4A21-B25F-75F2409248EC}"
10-
EndProject
115
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{A8406D94-94FD-4135-875A-1A0FF1E54DC5}"
126
ProjectSection(SolutionItems) = preProject
137
.editorconfig = .editorconfig
@@ -19,6 +13,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{A8406D94
1913
README.md = README.md
2014
EndProjectSection
2115
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShowWhatProcessLocksFile", "src\App\ShowWhatProcessLocksFile.csproj", "{952F82E5-8372-4435-8318-3ED0C114A57C}"
17+
EndProject
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\Test\Test.csproj", "{19D889E7-E728-4BFF-A68E-5445454F4417}"
19+
EndProject
20+
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "Installer", "src\Installer\Installer.wixproj", "{8D8AB22B-5677-4A21-B25F-75F2409248EC}"
21+
EndProject
2222
Global
2323
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2424
Debug|x64 = Debug|x64

src/App/LockFinding/LockFinder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ public static IEnumerable<ProcessInfo> FindWhatProcessesLockPath(string path)
7171
}
7272

7373
lockedFileName = PathUtils.AddTrailingSeparatorIfItIsAFolder(lockedFileName);
74-
if (lockedFileName?.StartsWith(path, StringComparison.InvariantCultureIgnoreCase) == true)
74+
if (path.EndsWith('\\') && lockedFileName.StartsWith(path, StringComparison.InvariantCultureIgnoreCase)
75+
|| string.Equals(lockedFileName, path, StringComparison.InvariantCultureIgnoreCase))
7576
{
7677
currentLockedFiles.Add(lockedFileName);
7778
}
7879
}
7980

8081
var moduleNames = ProcessUtils.GetProcessModules(currentOpenedProcess)
81-
.Where(name => name.StartsWith(path, StringComparison.InvariantCultureIgnoreCase)).ToList();
82+
.Where(name => path.EndsWith('\\') && name.StartsWith(path, StringComparison.InvariantCultureIgnoreCase)
83+
|| string.Equals(name, path, StringComparison.InvariantCultureIgnoreCase)).ToList();
8284

8385
if (currentLockedFiles.Any() || moduleNames.Any())
8486
{

src/App/ShowWhatProcessLocksFile.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
<ItemGroup>
1010
<InternalsVisibleTo Include="Test" />
11-
<PackageReference Include="Polyfill" Version="7.17.0">
11+
<PackageReference Include="Polyfill" Version="8.9.1">
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
1515
<PackageReference Include="PolySharp" Version="1.15.0">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
19-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
19+
<PackageReference Include="System.ValueTuple" Version="4.6.1" />
2020
</ItemGroup>
2121

2222
<ItemGroup>

src/App/Utils/CommandLineParser.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ private static bool Exists(string path)
3030
{
3131
try
3232
{
33-
_ = File.GetAttributes(path);
34-
return true;
33+
return File.Exists(path) || Directory.Exists(path);
3534
}
36-
catch
35+
catch (Exception)
3736
{
3837
return false;
3938
}

src/Installer/Installer.wixproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="WixToolset.Sdk/5.0.1">
1+
<Project Sdk="WixToolset.Sdk/6.0.2">
22
<PropertyGroup>
33
<OutputName>ShowWhatProcessLocksFile</OutputName>
44
<SuppressValidation>True</SuppressValidation>

src/Installer/Product.wxs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<Component Id="ProductComponent" Guid="18A44A77-A0C6-4CE7-9CE5-88ECBEF62B14">
2323
<File Id="ShowWhatProcessLocksFile.exe" Source="$(var.ShowWhatProcessLocksFile.TargetDir)\ShowWhatProcessLocksFile.exe"/>
2424
<File Id="ShowWhatProcessLocksFile.exe.config" Source="$(var.ShowWhatProcessLocksFile.TargetDir)\ShowWhatProcessLocksFile.exe.config"/>
25-
<File Id="System.ValueTuple.dll" Source="$(var.ShowWhatProcessLocksFile.TargetDir)\System.ValueTuple.dll"/>
2625
<File Id="icon.ico" Source="$(var.ShowWhatProcessLocksFile.ProjectDir)\Icon\icon.ico"/>
2726

2827
<!-- https://stackoverflow.com/a/29769228/7585517 -->
@@ -41,6 +40,14 @@
4140
<RegistryValue Type="string" Value="&quot;[INSTALLFOLDER]ShowWhatProcessLocksFile.exe&quot; &quot;%1&quot;"/>
4241
</RegistryKey>
4342
</RegistryKey>
43+
44+
<RegistryKey Root="HKCU" Key="Software\Classes\Drive\shell\ShowWhatProcessLocksFile">
45+
<RegistryValue Type="string" Value="Show what locks this drive"/>
46+
<RegistryValue Type="string" Name="Icon" Value="&quot;[INSTALLFOLDER]icon.ico&quot;"/>
47+
<RegistryKey Key="command">
48+
<RegistryValue Type="string" Value="&quot;[INSTALLFOLDER]ShowWhatProcessLocksFile.exe&quot; %1"/>
49+
</RegistryKey>
50+
</RegistryKey>
4451
</Component>
4552
</ComponentGroup>
4653
</Fragment>

src/Test/LockFinding/LockFinderTest.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class LockFinderTest
1010
{
1111
[TestCase(@"C:\PathThatDoesNotExist")]
1212
[TestCase(@"C:\Windows\system.ini")] // existing but not locked path
13-
public void Returns_empty_list_If_path_does_mot_exist_or_not_locked(string path)
13+
public void Returns_empty_list_If_path_does_not_exist_or_not_locked(string path)
1414
{
1515
var processes = LockFinder.FindWhatProcessesLockPath(path);
1616
ClassicAssert.IsEmpty(processes);
@@ -60,6 +60,38 @@ public void Returns_empty_list_If_path_does_mot_exist_or_not_locked(string path)
6060
@"C:\Windows\en-US\explorer.exe.mUi",
6161
@"C:\Windows\Fonts\StaticCache.dat"
6262
})]
63+
[TestCase(
64+
@"C:\WINDOWS\SYSTEM32\ntdll.dll",
65+
"explorer.exe",
66+
new[]
67+
{
68+
@"C:\WINDOWS\SYSTEM32\ntdll.dll"
69+
})]
70+
[TestCase(
71+
@"C:\Windows\en-US\explorer.exe.mui",
72+
"explorer.exe",
73+
new[]
74+
{
75+
@"C:\Windows\en-US\explorer.exe.mui"
76+
})]
77+
[TestCase(
78+
@"C:\",
79+
"exploRer.exe",
80+
new[]
81+
{
82+
@"C:\Windows\en-US\explorer.exe.mui",
83+
@"C:\Windows\en-US\explorer.exe.mUi",
84+
@"C:\Windows\Fonts\StaticCache.dat"
85+
})]
86+
[TestCase(
87+
@"C:/",
88+
"exploRer.exe",
89+
new[]
90+
{
91+
@"C:\Windows\en-US\explorer.exe.mui",
92+
@"C:\Windows\en-US\explorer.exe.mUi",
93+
@"C:\Windows\Fonts\StaticCache.dat"
94+
})]
6395
public void If_path_is_locked_Returns_information_about_processes_that_lock_this_path(string path, string processName, IEnumerable<string> pathThatShouldBeLocked)
6496
{
6597
var processes = LockFinder.FindWhatProcessesLockPath(path).ToList();

src/Test/Test.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="NUnit" Version="4.3.2" />
9-
<PackageReference Include="NUnit.ConsoleRunner" Version="3.19.2" />
10-
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
8+
<PackageReference Include="NUnit" Version="4.4.0" />
9+
<PackageReference Include="NUnit.ConsoleRunner" Version="3.20.2" />
10+
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)