Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PolarGoose committed Apr 30, 2024
0 parents commit 107df2b
Show file tree
Hide file tree
Showing 22 changed files with 1,447 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 150

[*.{xml,wxs,csproj,yaml,props,config,yaml}]
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
18 changes: 18 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on: push

jobs:
build:
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
- run: ./build.ps1
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: build/publish/*.zip
fail_on_unmatched_files: true
- uses: actions/upload-artifact@v4
with:
name: Build artifacts
path: build/publish/*.zip
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build/
.vs/
.idea/
CMakeSettings.json
launchSettings.json
16 changes: 16 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<ProjectRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</ProjectRoot>
<BuildFolder>$(ProjectRoot)build\</BuildFolder>
<OutputPath>$(BuildFolder)$(Configuration)\$(MSBuildProjectName)</OutputPath>
<BaseIntermediateOutputPath>$(BuildFolder)obj\$(MSBuildProjectName)\$(Configuration)\</BaseIntermediateOutputPath>
<TargetFramework>net462</TargetFramework>
<LangVersion>latest</LangVersion>
<Platforms>x64</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningLevel>5</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.0-dev</Version>
</PropertyGroup>
</Project>
52 changes: 52 additions & 0 deletions Handle2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\Test\Test.csproj", "{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{ECE2889E-C492-446E-82C2-022D6029A2BB}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
build.ps1 = build.ps1
Directory.Build.props = Directory.Build.props
.github\workflows\main.yaml = .github\workflows\main.yaml
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Handle2", "src\Handle2\Handle2.csproj", "{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Debug|x64.ActiveCfg = Debug|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Debug|x64.Build.0 = Debug|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Debug|x86.ActiveCfg = Debug|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Debug|x86.Build.0 = Debug|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Release|x64.ActiveCfg = Release|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Release|x64.Build.0 = Release|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Release|x86.ActiveCfg = Release|x64
{D57C5C4B-3FE1-415E-92F8-A345DF5679AC}.Release|x86.Build.0 = Release|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Debug|x64.ActiveCfg = Debug|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Debug|x64.Build.0 = Debug|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Debug|x86.ActiveCfg = Debug|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Debug|x86.Build.0 = Debug|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Release|x64.ActiveCfg = Release|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Release|x64.Build.0 = Release|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Release|x86.ActiveCfg = Release|x64
{FABFDFC5-D060-4A71-B0E7-DC9D339F0856}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {729412BC-986E-47AD-B486-9798934F437F}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 PolarGoose

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Handle2

An open-source alternative to the [Sysinternals Handle](https://learn.microsoft.com/en-us/sysinternals/downloads/handle)<tr>
* Identifies processes that are locking specific files or folders
* Shows information about all handles in the system
* Supports JSON output
* Full Unicode support
* Note: `Sysinternals Handle` doesn't support Unicode file names ([more details](https://superuser.com/questions/1761951/sysinternals-handle-prints-question-marks-instead-of-non-ascii-symbols))

## System requirements

* Windows 7 x64 and higher.

## Usage

```
> Handle2.exe --help
Handle2 1.0
A console utility that displays information about system handles and identifies the processes locking a specific file or folder.
https://github.com/PolarGoose/Handle2
Usage:
Handle2.exe [--json] [--path FILE_OR_FOLDER_FULL_NAME|--dump-all-handles]
Examples:
Handle2.exe --path C:\Windows\System32
Handle2.exe --json --path C:\Windows\System32\ntdll.dll
Handle2.exe --json --path C:\Windows\explorer.exe
Handle2.exe --json --dump-all-handles
Command-line options:
--json (Default: false) Json output
--path Required. (Default: false) path
--dump-all-handles Required. (Default: false) Displays information about all system handles.
--help Display this help screen.
--version Display version information.
```

## How to build

* To work with the codebase, `Visual Studio 2022` can be used.
* To build the project, run `build.ps` script (`git.exe` should be in the PATH)
74 changes: 74 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Function Info($msg) {
Write-Host -ForegroundColor DarkGreen "`nINFO: $msg`n"
}

Function Error($msg) {
Write-Host `n`n
Write-Error $msg
exit 1
}

Function CheckReturnCodeOfPreviousCommand($msg) {
if(-Not $?) {
Error "${msg}. Error code: $LastExitCode"
}
}

Function CreateZipArchive($file, $archiveFile) {
Info "Create a zip archive from `n '$file' `n to `n '$archiveFile'"
Compress-Archive -Force -Path $file -DestinationPath $archiveFile
}

Function GetVersion() {
$gitCommand = Get-Command -Name git

$tag = & $gitCommand describe --exact-match --tags HEAD
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a tag instead"
$tag = "v0.0-dev"
}

$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"

return "$($tag.Substring(1))-$commitHash"
}

Function ForceCopy($srcFile, $dstFile) {
Info "Copy `n '$srcFile' `n to `n '$dstFile'"
New-Item $dstFile -Force -ItemType File > $null
Copy-Item $srcFile -Destination $dstFile -Force
}

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

$root = Resolve-Path $PSScriptRoot
$buildDir = "$root/build"
$publishDir = "$buildDir/publish"
$version = GetVersion

Info "version=$version"

Info "Build the project"
dotnet build `
--nologo `
--configuration Release `
-verbosity:minimal `
/property:DebugType=None `
/property:Version=$version `
"$root/Handle2.sln"
CheckReturnCodeOfPreviousCommand "Cmake generation phase failed"

Info "Run tests"
dotnet test `
--nologo `
--no-build `
--configuration Release `
-verbosity:minimal `
--logger:"console;verbosity=normal" `
"$root/Handle2.sln"
CheckReturnCodeOfPreviousCommand "Tests failed"

ForceCopy "$buildDir/Release/Handle2/net462/Handle2.exe" "$publishDir/Handle2.exe"
CreateZipArchive "$publishDir/Handle2.exe" "$publishDir/Handle2.zip"
5 changes: 5 additions & 0 deletions src/Handle2/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura DisableCompression='false' IncludeDebugSymbols='false' DisableCleanup='true'>
<Unmanaged64Assemblies>Interop</Unmanaged64Assemblies>
</Costura>
</Weavers>
Loading

0 comments on commit 107df2b

Please sign in to comment.