-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Build (#87) * adjust build props * rename namespace * remove versions form projects * enable logging * update deps 1 * use new test dl * update tests * change test * update deps 2 * update deps 3 * removed a couple of warnings * Versioning (#88) * add gitversion * nbgv and ci updates * add global json * test * add delay * update projects (#91) * update projects * remove url combine * update projects * Download manager update (#93) * remove net48 target * make dl fully async * start generic verification context * new verification * fix local files get disposed * disposing * make download config immutable * release 4.0 * fix not using io.abstractions * add test cases * Bump Microsoft.NET.Test.Sdk from 17.4.1 to 17.5.0 (#100) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.4.1 to 17.5.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.4.1...v17.5.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump System.IO.Abstractions from 19.1.13 to 19.2.1 (#101) Bumps [System.IO.Abstractions](https://github.com/TestableIO/System.IO.Abstractions) from 19.1.13 to 19.2.1. - [Release notes](https://github.com/TestableIO/System.IO.Abstractions/releases) - [Commits](TestableIO/System.IO.Abstractions@v19.1.13...v19.2.1) --- updated-dependencies: - dependency-name: System.IO.Abstractions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * update deps * New pipeline (#105) * rename and move * move ns * renames * add progress * rename * update progress * added tests * update ref * rename and move * move ns * renames * add progress * rename * update progress * added tests * update ref * use .net 7 sdk * use preview * import parent * add test * update version * add process elevation * ignore test * use config provider * fix build from merge * update and move verification * update deps * to class * update deps * add CurrentProcessInfo * increase version * merge cpi and elevation * remove test * move namespace * don't move ns --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ec3cd2e
commit 7f990a4
Showing
21 changed files
with
136 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#if NET6_0 | ||
using System; | ||
#else | ||
using Vanara.PInvoke; | ||
#endif | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace AnakinRaW.CommonUtilities; | ||
|
||
/// <summary> | ||
/// Provides information about the current process. | ||
/// </summary> | ||
internal sealed class CurrentProcessInfo : ICurrentProcessInfo | ||
{ | ||
/// <summary> | ||
/// Gets an instance of <see cref="CurrentProcessInfo"/> representing the current process. | ||
/// </summary> | ||
public static readonly CurrentProcessInfo Current = new(); | ||
|
||
/// <inheritdoc/> | ||
public bool IsElevated { get; } | ||
|
||
/// <inheritdoc/> | ||
public string? ProcessFilePath { get; } | ||
|
||
/// <inheritdoc/> | ||
public int Id { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CurrentProcessInfo"/> struct representing the current process. | ||
/// </summary> | ||
private CurrentProcessInfo() | ||
{ | ||
var p = Process.GetCurrentProcess(); | ||
Id = p.Id; | ||
#if NET6_0 | ||
var processPath = Environment.ProcessPath; | ||
#else | ||
var processPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
? Kernel32.GetModuleFileName(HINSTANCE.NULL) | ||
: Process.GetCurrentProcess().MainModule.FileName; | ||
#endif | ||
|
||
ProcessFilePath = processPath; | ||
|
||
IsElevated = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
? ProcessElevationWindows.IsProcessElevated() | ||
: ProcessElevationLinux.IsElevated(); | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Provides access to information about the current process. | ||
/// </summary> | ||
public interface ICurrentProcessInfoProvider | ||
{ | ||
/// <summary> | ||
/// Gets the current process information. | ||
/// </summary> | ||
/// <returns>An <see cref="ICurrentProcessInfo"/> instance that contains information about the current process.</returns> | ||
public ICurrentProcessInfo GetCurrentProcessInfo(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public sealed class CurrentProcessInfoProvider : ICurrentProcessInfoProvider | ||
{ | ||
/// <inheritdoc/> | ||
public ICurrentProcessInfo GetCurrentProcessInfo() | ||
{ | ||
return CurrentProcessInfo.Current; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace AnakinRaW.CommonUtilities; | ||
|
||
/// <summary> | ||
/// Service to query whether the current process is elevated. | ||
/// </summary> | ||
public interface ICurrentProcessInfo | ||
{ | ||
/// <summary> | ||
/// Returns <see langword="true"/> if the current process is elevated; <see langword="false"/> otherwise. | ||
/// </summary> | ||
bool IsElevated { get; } | ||
|
||
/// <summary> | ||
/// Gets the file path of the current process, or null if the path could not be determined. | ||
/// </summary> | ||
string? ProcessFilePath { get; } | ||
|
||
/// <summary> | ||
/// Gets the ID of the current process. | ||
/// </summary> | ||
int Id { get; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Xunit; | ||
|
||
namespace AnakinRaW.CommonUtilities.Test; | ||
|
||
public class CurrentProcessInfoTests | ||
{ | ||
[Fact] | ||
public void TestCurrentProcess() | ||
{ | ||
var currentProcessInfo = CurrentProcessInfo.Current; | ||
Assert.NotEqual(0, currentProcessInfo.Id); | ||
Assert.NotNull(currentProcessInfo.ProcessFilePath); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters