From 7f990a40b3f7675c833ecbf9af1720b5bc919ca2 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 10 May 2023 13:38:34 +0200 Subject: [PATCH] Release 8 (#120) * 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](https://github.com/microsoft/vstest/compare/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] 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](https://github.com/TestableIO/System.IO.Abstractions/compare/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] 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] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Directory.Build.props | 2 +- ...ommonUtilities.DownloadManager.Test.csproj | 6 +- .../CommonUtilities.FileSystem.Windows.csproj | 8 +- ...onUtilities.FileSystem.Windows.Test.csproj | 2 +- .../src/Commonutilities.FileSystem.csproj | 2 +- .../CommonUtilities.FileSystem.Test.csproj | 6 +- .../CommonUtilities.Registry.Windows.csproj | 5 +- ...mmonUtilities.Registry.Windows.Test.csproj | 2 +- .../test/CommonUtilities.Registry.Test.csproj | 2 +- ...CommonUtilities.SimplePipeline.Test.csproj | 4 +- .../src/CommonUtilities.Xml.csproj | 2 +- .../src/CommonUtilities.csproj | 2 +- .../src/Process/CurrentProcessInfo.cs | 74 +++++++++++++++++++ .../src/Process/ICurrentProcessInfo.cs | 22 ++++++ .../src/Process/IProcessElevation.cs | 12 --- .../src/Process/ProcessElevation.Linux.cs | 2 +- .../src/Process/ProcessElevation.cs | 30 -------- .../test/CommonUtilities.Test.csproj | 7 +- .../test/CurrentProcessInfoTest.cs | 14 ++++ .../test/ProcessElevationTest.cs | 12 --- version.json | 2 +- 21 files changed, 136 insertions(+), 82 deletions(-) create mode 100644 src/CommonUtilities/src/Process/CurrentProcessInfo.cs create mode 100644 src/CommonUtilities/src/Process/ICurrentProcessInfo.cs delete mode 100644 src/CommonUtilities/src/Process/IProcessElevation.cs delete mode 100644 src/CommonUtilities/src/Process/ProcessElevation.cs create mode 100644 src/CommonUtilities/test/CurrentProcessInfoTest.cs delete mode 100644 src/CommonUtilities/test/ProcessElevationTest.cs diff --git a/Directory.Build.props b/Directory.Build.props index 5d64473..c24218b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -24,7 +24,7 @@ all - 3.5.119 + 3.6.128 diff --git a/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj b/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj index f97b1f1..1d761fc 100644 --- a/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj +++ b/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,7 +21,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -36,5 +36,5 @@ - + \ No newline at end of file diff --git a/src/CommonUtilities.FileSystem.Windows/src/CommonUtilities.FileSystem.Windows.csproj b/src/CommonUtilities.FileSystem.Windows/src/CommonUtilities.FileSystem.Windows.csproj index 394611b..8f335b1 100644 --- a/src/CommonUtilities.FileSystem.Windows/src/CommonUtilities.FileSystem.Windows.csproj +++ b/src/CommonUtilities.FileSystem.Windows/src/CommonUtilities.FileSystem.Windows.csproj @@ -5,7 +5,7 @@ - netstandard2.0 + net48;net6.0-windows AnakinRaW.CommonUtilities.FileSystem.Windows AnakinRaW.CommonUtilities.FileSystem.Windows enable @@ -21,13 +21,11 @@ - - - + - + diff --git a/src/CommonUtilities.FileSystem.Windows/test/CommonUtilities.FileSystem.Windows.Test.csproj b/src/CommonUtilities.FileSystem.Windows/test/CommonUtilities.FileSystem.Windows.Test.csproj index 67e6999..41aa086 100644 --- a/src/CommonUtilities.FileSystem.Windows/test/CommonUtilities.FileSystem.Windows.Test.csproj +++ b/src/CommonUtilities.FileSystem.Windows/test/CommonUtilities.FileSystem.Windows.Test.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj b/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj index 87ac76f..01a1971 100644 --- a/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj +++ b/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj @@ -25,7 +25,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj b/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj index 5eaa60e..a7bc026 100644 --- a/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj +++ b/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj @@ -13,12 +13,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -33,5 +33,5 @@ - + diff --git a/src/CommonUtilities.Registry.Windows/src/CommonUtilities.Registry.Windows.csproj b/src/CommonUtilities.Registry.Windows/src/CommonUtilities.Registry.Windows.csproj index 898e461..7fb1fc7 100644 --- a/src/CommonUtilities.Registry.Windows/src/CommonUtilities.Registry.Windows.csproj +++ b/src/CommonUtilities.Registry.Windows/src/CommonUtilities.Registry.Windows.csproj @@ -21,12 +21,11 @@ - - + - + diff --git a/src/CommonUtilities.Registry.Windows/test/CommonUtilities.Registry.Windows.Test.csproj b/src/CommonUtilities.Registry.Windows/test/CommonUtilities.Registry.Windows.Test.csproj index 544fa85..fdb916f 100644 --- a/src/CommonUtilities.Registry.Windows/test/CommonUtilities.Registry.Windows.Test.csproj +++ b/src/CommonUtilities.Registry.Windows/test/CommonUtilities.Registry.Windows.Test.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj b/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj index 986b30d..2d28845 100644 --- a/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj +++ b/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj b/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj index c01a6e6..b3cb29a 100644 --- a/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj +++ b/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj @@ -13,14 +13,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities.Xml/src/CommonUtilities.Xml.csproj b/src/CommonUtilities.Xml/src/CommonUtilities.Xml.csproj index 761725e..0b85f25 100644 --- a/src/CommonUtilities.Xml/src/CommonUtilities.Xml.csproj +++ b/src/CommonUtilities.Xml/src/CommonUtilities.Xml.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/CommonUtilities/src/CommonUtilities.csproj b/src/CommonUtilities/src/CommonUtilities.csproj index a6b198b..d5e47dc 100644 --- a/src/CommonUtilities/src/CommonUtilities.csproj +++ b/src/CommonUtilities/src/CommonUtilities.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/CommonUtilities/src/Process/CurrentProcessInfo.cs b/src/CommonUtilities/src/Process/CurrentProcessInfo.cs new file mode 100644 index 0000000..6450156 --- /dev/null +++ b/src/CommonUtilities/src/Process/CurrentProcessInfo.cs @@ -0,0 +1,74 @@ +#if NET6_0 +using System; +#else +using Vanara.PInvoke; +#endif +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace AnakinRaW.CommonUtilities; + +/// +/// Provides information about the current process. +/// +internal sealed class CurrentProcessInfo : ICurrentProcessInfo +{ + /// + /// Gets an instance of representing the current process. + /// + public static readonly CurrentProcessInfo Current = new(); + + /// + public bool IsElevated { get; } + + /// + public string? ProcessFilePath { get; } + + /// + public int Id { get; } + + /// + /// Initializes a new instance of the struct representing the current process. + /// + 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(); + } +} + + +/// +/// Provides access to information about the current process. +/// +public interface ICurrentProcessInfoProvider +{ + /// + /// Gets the current process information. + /// + /// An instance that contains information about the current process. + public ICurrentProcessInfo GetCurrentProcessInfo(); +} + +/// +public sealed class CurrentProcessInfoProvider : ICurrentProcessInfoProvider +{ + /// + public ICurrentProcessInfo GetCurrentProcessInfo() + { + return CurrentProcessInfo.Current; + } +} \ No newline at end of file diff --git a/src/CommonUtilities/src/Process/ICurrentProcessInfo.cs b/src/CommonUtilities/src/Process/ICurrentProcessInfo.cs new file mode 100644 index 0000000..d906c11 --- /dev/null +++ b/src/CommonUtilities/src/Process/ICurrentProcessInfo.cs @@ -0,0 +1,22 @@ +namespace AnakinRaW.CommonUtilities; + +/// +/// Service to query whether the current process is elevated. +/// +public interface ICurrentProcessInfo +{ + /// + /// Returns if the current process is elevated; otherwise. + /// + bool IsElevated { get; } + + /// + /// Gets the file path of the current process, or null if the path could not be determined. + /// + string? ProcessFilePath { get; } + + /// + /// Gets the ID of the current process. + /// + int Id { get; } +} \ No newline at end of file diff --git a/src/CommonUtilities/src/Process/IProcessElevation.cs b/src/CommonUtilities/src/Process/IProcessElevation.cs deleted file mode 100644 index 295befe..0000000 --- a/src/CommonUtilities/src/Process/IProcessElevation.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace AnakinRaW.CommonUtilities; - -/// -/// Service to query whether the current process is elevated. -/// -public interface IProcessElevation -{ - /// - /// Returns if the current process is elevated; otherwise. - /// - bool IsCurrentProcessElevated { get; } -} \ No newline at end of file diff --git a/src/CommonUtilities/src/Process/ProcessElevation.Linux.cs b/src/CommonUtilities/src/Process/ProcessElevation.Linux.cs index a1fe6af..81ee389 100644 --- a/src/CommonUtilities/src/Process/ProcessElevation.Linux.cs +++ b/src/CommonUtilities/src/Process/ProcessElevation.Linux.cs @@ -2,7 +2,7 @@ namespace AnakinRaW.CommonUtilities; -internal sealed class ProcessElevationLinux +internal static class ProcessElevationLinux { // ReSharper disable once IdentifierTypo [DllImport("libc", SetLastError = true)] diff --git a/src/CommonUtilities/src/Process/ProcessElevation.cs b/src/CommonUtilities/src/Process/ProcessElevation.cs deleted file mode 100644 index ddfc2ae..0000000 --- a/src/CommonUtilities/src/Process/ProcessElevation.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace AnakinRaW.CommonUtilities; - -/// -public sealed class ProcessElevation : IProcessElevation -{ - /// - /// The default instance of the service. - /// - public static readonly IProcessElevation Default = new ProcessElevation(); - - private readonly Lazy _elevatedLazy; - - /// - public bool IsCurrentProcessElevated => _elevatedLazy.Value; - - private ProcessElevation() - { - _elevatedLazy = new Lazy(IsProcessElevated); - } - - private bool IsProcessElevated() - { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? ProcessElevationWindows.IsProcessElevated() - : ProcessElevationLinux.IsElevated(); - } -} \ No newline at end of file diff --git a/src/CommonUtilities/test/CommonUtilities.Test.csproj b/src/CommonUtilities/test/CommonUtilities.Test.csproj index dfe1349..87bd2ff 100644 --- a/src/CommonUtilities/test/CommonUtilities.Test.csproj +++ b/src/CommonUtilities/test/CommonUtilities.Test.csproj @@ -10,10 +10,11 @@ AnakinRaW.CommonUtilities.Test AnakinRaW.CommonUtilities.Test + true - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,7 +22,7 @@ - + @@ -37,5 +38,5 @@ - + diff --git a/src/CommonUtilities/test/CurrentProcessInfoTest.cs b/src/CommonUtilities/test/CurrentProcessInfoTest.cs new file mode 100644 index 0000000..5b51e2d --- /dev/null +++ b/src/CommonUtilities/test/CurrentProcessInfoTest.cs @@ -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); + } +} \ No newline at end of file diff --git a/src/CommonUtilities/test/ProcessElevationTest.cs b/src/CommonUtilities/test/ProcessElevationTest.cs deleted file mode 100644 index d82b34c..0000000 --- a/src/CommonUtilities/test/ProcessElevationTest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Xunit; - -namespace AnakinRaW.CommonUtilities.Test; - -public class ProcessElevationTest -{ - //[Fact] - public void TestNotElevated() - { - Assert.False(ProcessElevation.Default.IsCurrentProcessElevated); - } -} \ No newline at end of file diff --git a/version.json b/version.json index 101cbca..ca26542 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "7.0", + "version": "8.0", "assemblyVersion": { "precision": "major" },