From 80c07b60af1ae4bfa49f955a121ebb478c73ac06 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Thu, 13 Jun 2024 11:59:14 -0500 Subject: [PATCH] Modernize NuGet packages, update dotnet tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fix build warnings --- .github/workflows/validate.yml | 47 +++++++++++++------ SharpShell/Directory.Build.props | 1 + .../GitHubNamespaceExtension.csproj | 2 +- .../DllWithResources/DllWithResources.vcxproj | 2 +- .../ResourceLoaderTests.cs | 36 +++++++------- .../ResourcesPropertySheet.Tests.csproj | 4 +- .../SharpShell.Tests/PidlManagerTests.cs | 8 ++-- .../ServiceRegistry/ServiceRegistryTests.cs | 6 +-- .../SharpShell.Tests/SharpShell.Tests.csproj | 21 +++++---- .../SharpShell.Tests/ShellInteropTests.cs | 4 +- SharpShell/SharpShell/Helpers/Win32Helper.cs | 4 +- .../SharpShell/InitializeWithFileServer.cs | 5 ++ .../SharpShell/InitializeWithItemServer.cs | 5 ++ SharpShell/SharpShell/Interop/Gdi32.cs | 2 +- .../SharpShell/Interop/IObjectWithSite.cs | 2 +- SharpShell/SharpShell/Interop/SHGDNF.cs | 2 +- .../ServerRegistrationManager.cs | 2 +- SharpShell/SharpShell/SharpShell.csproj | 1 + .../ServerRegistrationManager.csproj | 5 +- 19 files changed, 94 insertions(+), 65 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 420e1498..d32e2015 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -6,15 +6,37 @@ concurrency: cancel-in-progress: true jobs: - build: - runs-on: ${{matrix.windows-version}} + sharp-shell: + name: SharpShell + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build SharpShell + run: dotnet build -c Release SharpShell + + - name: Run Tests + run: dotnet test -c Release SharpShell || True + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{github.job}} + path: SharpShell/artifacts + + native-bridge: + name: NativeBridge (VS${{matrix.vs-year}}) + runs-on: windows-${{matrix.vs-year}} strategy: matrix: include: - - windows-version: windows-2019 - visual-studio-version: 16.11 - - windows-version: windows-2022 - visual-studio-version: 17.10 + - vs-year: 2019 + vs-version: 16.11 + - vs-year: 2022 + vs-version: 17.10 steps: - name: Checkout @@ -25,19 +47,14 @@ jobs: - name: Add MSBuild to PATH uses: microsoft/setup-msbuild@v2 with: - vs-version: ${{matrix.visual-studio-version}} + vs-version: ${{matrix.vs-version}} msbuild-architecture: x64 - name: Build Native Bridge - run: msbuild /t:Restore,Build /p:Configuration=Release ./SharpShellNativeBridge/SharpShellNativeBridge.sln - - - name: Build SharpShell - run: msbuild /t:Restore,Build /p:Configuration=Release ./SharpShell/SharpShell.sln + run: msbuild /p:Configuration=Release SharpShellNativeBridge - name: Upload Artifacts uses: actions/upload-artifact@v4 with: - name: ${{matrix.windows-version}} - path: | - ./SharpShellNativeBridge/artifacts - ./SharpShell/artifacts + name: ${{github.job}}-vs${{matrix.vs-year}}) + path: SharpShellNativeBridge/artifacts diff --git a/SharpShell/Directory.Build.props b/SharpShell/Directory.Build.props index 17b86b4f..255d7767 100644 --- a/SharpShell/Directory.Build.props +++ b/SharpShell/Directory.Build.props @@ -10,5 +10,6 @@ $(Version).0 AnyCPU en-US + true diff --git a/SharpShell/Samples/NamespaceExtension/GitHubNamespaceExtension/GitHubNamespaceExtension.csproj b/SharpShell/Samples/NamespaceExtension/GitHubNamespaceExtension/GitHubNamespaceExtension.csproj index a38fd1ee..607dd858 100644 --- a/SharpShell/Samples/NamespaceExtension/GitHubNamespaceExtension/GitHubNamespaceExtension.csproj +++ b/SharpShell/Samples/NamespaceExtension/GitHubNamespaceExtension/GitHubNamespaceExtension.csproj @@ -8,7 +8,7 @@ - + diff --git a/SharpShell/Samples/PropertySheet/DllWithResources/DllWithResources/DllWithResources.vcxproj b/SharpShell/Samples/PropertySheet/DllWithResources/DllWithResources/DllWithResources.vcxproj index b03110db..7562918a 100644 --- a/SharpShell/Samples/PropertySheet/DllWithResources/DllWithResources/DllWithResources.vcxproj +++ b/SharpShell/Samples/PropertySheet/DllWithResources/DllWithResources/DllWithResources.vcxproj @@ -180,4 +180,4 @@ - \ No newline at end of file + diff --git a/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourceLoaderTests.cs b/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourceLoaderTests.cs index eb29d3f0..f5f6fda0 100644 --- a/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourceLoaderTests.cs +++ b/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourceLoaderTests.cs @@ -25,28 +25,28 @@ public void CanLoadResourceTypes() var resourceTypeStrings = resources.Select(rt => rt.ResourceType.ToString()).ToArray(); // Assert we have the expected set of resource types. - Assert.Contains("Bitmap", resourceTypeStrings); - Assert.Contains("Cursor", resourceTypeStrings); - Assert.Contains("Dialog", resourceTypeStrings); - Assert.Contains("HTML", resourceTypeStrings); - Assert.Contains("Group Cursor", resourceTypeStrings); - Assert.Contains("Group Icon", resourceTypeStrings); - Assert.Contains("Icon", resourceTypeStrings); - Assert.Contains("Menu", resourceTypeStrings); - Assert.Contains("\"PNG\"", resourceTypeStrings); - Assert.Contains("RT_MANIFEST", resourceTypeStrings); - Assert.Contains("\"RT_RIBBON_XML\"", resourceTypeStrings); - Assert.Contains("241", resourceTypeStrings); // toolbars - Assert.Contains("Version", resourceTypeStrings); + Assert.That(resourceTypeStrings.Contains("Bitmap")); + Assert.That(resourceTypeStrings.Contains("Cursor")); + Assert.That(resourceTypeStrings.Contains("Dialog")); + Assert.That(resourceTypeStrings.Contains("HTML")); + Assert.That(resourceTypeStrings.Contains("Group Cursor")); + Assert.That(resourceTypeStrings.Contains("Group Icon")); + Assert.That(resourceTypeStrings.Contains("Icon")); + Assert.That(resourceTypeStrings.Contains("Menu")); + Assert.That(resourceTypeStrings.Contains("\"PNG\"")); + Assert.That(resourceTypeStrings.Contains("RT_MANIFEST")); + Assert.That(resourceTypeStrings.Contains("\"RT_RIBBON_XML\"")); + Assert.That(resourceTypeStrings.Contains("241")); // toolbars + Assert.That(resourceTypeStrings.Contains("Version")); // Check we have loaded a bitmap property. var bitmaps = resources.Single(rt => rt.ResourceType.IsKnownResourceType(ResType.RT_BITMAP)); var bitmap103 = bitmaps.Resouces.Single(b => b.ResourceName.IsInt && b.ResourceName.IntValue == 103); - Assert.AreEqual(bitmap103.ResourceName.IsInt, true); - Assert.AreEqual(bitmap103.ResourceName.IntValue, 103); - Assert.AreEqual(bitmap103.ResourceName.ToString(), "103"); - Assert.AreEqual(bitmap103.BitmapData.Width, 48); - Assert.AreEqual(bitmap103.BitmapData.Height, 48); + Assert.That(bitmap103.ResourceName.IsInt); + Assert.That(bitmap103.ResourceName.IntValue, Is.EqualTo(103)); + Assert.That(bitmap103.ResourceName.ToString(), Is.EqualTo("103")); + Assert.That(bitmap103.BitmapData.Width, Is.EqualTo(48)); + Assert.That(bitmap103.BitmapData.Height, Is.EqualTo(48)); } } } diff --git a/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourcesPropertySheet.Tests.csproj b/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourcesPropertySheet.Tests.csproj index 937fc596..e915a24e 100644 --- a/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourcesPropertySheet.Tests.csproj +++ b/SharpShell/Samples/PropertySheet/ResourcesPropertySheet.Tests/ResourcesPropertySheet.Tests.csproj @@ -16,7 +16,9 @@ - + + + diff --git a/SharpShell/SharpShell.Tests/PidlManagerTests.cs b/SharpShell/SharpShell.Tests/PidlManagerTests.cs index d7a0fb49..f0e80db5 100644 --- a/SharpShell/SharpShell.Tests/PidlManagerTests.cs +++ b/SharpShell/SharpShell.Tests/PidlManagerTests.cs @@ -37,7 +37,7 @@ public void CanGetPidlDisplayName() var displayName = PidlManager.GetPidlDisplayName(pidl); Shell32.ILFree(pidl); string expectedName = GetTestKnownFolderDisplayNameForMyCulture(); - Assert.AreEqual(expectedName, displayName); + Assert.That(expectedName, Is.EqualTo(displayName)); } [Test] @@ -52,7 +52,7 @@ public void CanBouncePidl() var pszPath = new StringBuilder(); var displayName = PidlManager.GetPidlDisplayName(pidl); string expectedName = GetTestKnownFolderDisplayNameForMyCulture(); - Assert.AreEqual(expectedName, displayName); + Assert.That(expectedName, Is.EqualTo(displayName)); } [Test] @@ -62,7 +62,7 @@ public void CanIdentifyIdListLength() Shell32.SHGetKnownFolderIDList(KnownFolders.FOLDERID_Downloads, KNOWN_FOLDER_FLAG.KF_NO_FLAGS, IntPtr.Zero, out pidl); var idList = PidlManager.PidlToIdlist(pidl); - Assert.That(idList.Ids.Count, Is.GreaterThan(1)); + Assert.That(idList.Ids.Count, Is.GreaterThan(0)); } [Test] @@ -75,7 +75,7 @@ public void CanFullRoundTripPidl() var pidl2 = PidlManager.IdListToPidl(idList); var idList2 = PidlManager.PidlToIdlist(pidl2); - Assert.IsTrue(idList.Matches(idList2)); + Assert.That(idList.Matches(idList2)); } #region Private Helper Methods diff --git a/SharpShell/SharpShell.Tests/ServiceRegistry/ServiceRegistryTests.cs b/SharpShell/SharpShell.Tests/ServiceRegistry/ServiceRegistryTests.cs index c85de5c2..ee5941bb 100644 --- a/SharpShell/SharpShell.Tests/ServiceRegistry/ServiceRegistryTests.cs +++ b/SharpShell/SharpShell.Tests/ServiceRegistry/ServiceRegistryTests.cs @@ -11,7 +11,7 @@ public void Default_IRegistry_Is_A_WindowsRegistry() { // By default, the service registry should provide a WindowsRegsitry for IRegistry. var registry = SharpShell.ServiceRegistry.ServiceRegistry.GetService(); - Assert.IsInstanceOf(typeof(WindowsRegistry), registry); + Assert.That(registry, Is.InstanceOf()); } [Test] @@ -31,8 +31,8 @@ public void Registered_Service_Provider_Is_Used_To_Get_Service() var service = SharpShell.ServiceRegistry.ServiceRegistry.GetService(); // Assert we called our custom function, and created the service. - Assert.IsTrue(serviceProviderCalled); - Assert.AreSame(windowsRegistry, service); + Assert.That(serviceProviderCalled); + Assert.That(windowsRegistry, Is.EqualTo(service)); } [Test] diff --git a/SharpShell/SharpShell.Tests/SharpShell.Tests.csproj b/SharpShell/SharpShell.Tests/SharpShell.Tests.csproj index 3b2b41c7..ca69e016 100644 --- a/SharpShell/SharpShell.Tests/SharpShell.Tests.csproj +++ b/SharpShell/SharpShell.Tests/SharpShell.Tests.csproj @@ -14,16 +14,17 @@ - - - - - - - - - - + + + + + + + + + + + diff --git a/SharpShell/SharpShell.Tests/ShellInteropTests.cs b/SharpShell/SharpShell.Tests/ShellInteropTests.cs index f19f2991..f065b267 100644 --- a/SharpShell/SharpShell.Tests/ShellInteropTests.cs +++ b/SharpShell/SharpShell.Tests/ShellInteropTests.cs @@ -25,7 +25,7 @@ public void CanGetAndFreeKnownFolderIdList() { IntPtr pidl; Shell32.SHGetKnownFolderIDList(KnownFolders.FOLDERID_Cookies, KNOWN_FOLDER_FLAG.KF_NO_FLAGS, IntPtr.Zero, out pidl); - Assert.IsTrue(pidl != IntPtr.Zero); + Assert.That(pidl, Is.Not.EqualTo(IntPtr.Zero)); Assert.DoesNotThrow(() => Shell32.ILFree(pidl)); } @@ -36,7 +36,7 @@ public void CanGetDesktopFolderLocationAndPath() IntPtr pidl; Shell32.SHGetFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, IntPtr.Zero, 0, out pidl); var sb = new StringBuilder(260); - Assert.IsTrue(Shell32.SHGetPathFromIDList(pidl, sb)); + Assert.That(Shell32.SHGetPathFromIDList(pidl, sb)); Assert.That(sb.ToString(), Is.Not.Null.Or.Empty); Assert.DoesNotThrow(() => Shell32.ILFree(pidl)); } diff --git a/SharpShell/SharpShell/Helpers/Win32Helper.cs b/SharpShell/SharpShell/Helpers/Win32Helper.cs index bd6dd3ad..2d8d3ab9 100644 --- a/SharpShell/SharpShell/Helpers/Win32Helper.cs +++ b/SharpShell/SharpShell/Helpers/Win32Helper.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; -// ReSharper disable IdentifierTypo +// ReSharper disable IdentifierTypo namespace SharpShell.Helpers { @@ -43,7 +43,7 @@ public static int HiWord(IntPtr ptr) /// public static bool IS_INTRESOURCE(IntPtr resource) { - return ((uint)resource) <= ushort.MaxValue; + return (resource.ToInt64() | ushort.MaxValue) == ushort.MaxValue; } } } diff --git a/SharpShell/SharpShell/InitializeWithFileServer.cs b/SharpShell/SharpShell/InitializeWithFileServer.cs index 894f08a5..f360ffef 100644 --- a/SharpShell/SharpShell/InitializeWithFileServer.cs +++ b/SharpShell/SharpShell/InitializeWithFileServer.cs @@ -15,6 +15,11 @@ public abstract class InitializeWithFileServer : SharpShellServer, IInitializeWi { #region Implementation of IInitializeWithFile + /// + /// Initializes a handler with a file. + /// + /// A string representing the file's path. + /// One of the following STGM values that indicates the access mode for grfMode. STGM_READ or STGM_READWRITE. public int Initialize(string pszFilePath, STGM grfMode) { Log($"Intiailising a file based server for '{pszFilePath}' with mode '{grfMode}'."); diff --git a/SharpShell/SharpShell/InitializeWithItemServer.cs b/SharpShell/SharpShell/InitializeWithItemServer.cs index 837f8901..57db54a6 100644 --- a/SharpShell/SharpShell/InitializeWithItemServer.cs +++ b/SharpShell/SharpShell/InitializeWithItemServer.cs @@ -13,6 +13,11 @@ public abstract class InitializeWithItemServer : SharpShellServer, IInitializeWi { #region Implementation of IInitializeWithItem + /// + /// Initializes a handler with a shell. + /// + /// A pointer to an IShellItem interface that represents the stream source. + /// One of the following STGM values that indicates the access mode for shellItem. STGM_READ or STGM_READWRITE. public int Initialize(IShellItem shellItem, STGM accessMode) { Log($"Intiailising a shell item server with mode '{accessMode}'."); diff --git a/SharpShell/SharpShell/Interop/Gdi32.cs b/SharpShell/SharpShell/Interop/Gdi32.cs index dad78409..e8db1281 100644 --- a/SharpShell/SharpShell/Interop/Gdi32.cs +++ b/SharpShell/SharpShell/Interop/Gdi32.cs @@ -89,7 +89,7 @@ internal static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr h /// If the lpvBits parameter is non-NULL and the function succeeds, the return value is the number of scan lines copied from the bitmap. /// If the lpvBits parameter is NULL and GetDIBits successfully fills the structure, the return value is nonzero. /// If the function fails, the return value is zero. - /// This function can return the following value: ERROR_INVALID_PARAMETER (87 (0×57)) + /// This function can return the following value: ERROR_INVALID_PARAMETER (87 (0Ă—57)) [DllImport("gdi32.dll", EntryPoint = "GetDIBits")] internal static extern int GetDIBits([In] IntPtr hdc, [In] IntPtr hbmp, uint uStartScan, uint cScanLines, [Out] byte[] lpvBits, ref BITMAPINFO lpbi, uint uUsage); diff --git a/SharpShell/SharpShell/Interop/IObjectWithSite.cs b/SharpShell/SharpShell/Interop/IObjectWithSite.cs index cab9cfc3..7d77654b 100644 --- a/SharpShell/SharpShell/Interop/IObjectWithSite.cs +++ b/SharpShell/SharpShell/Interop/IObjectWithSite.cs @@ -24,7 +24,7 @@ public interface IObjectWithSite /// Retrieves the latest site passed using SetSite. /// /// The IID of the interface pointer that should be returned in ppvSite. - /// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvSite contains the requested interface pointer to the site last seen in SetSite. The specific interface returned depends on the riid argument—in essence, the two arguments act identically to those in QueryInterface. If the appropriate interface pointer is available, the object must call AddRef on that pointer before returning successfully. If no site is available, or the requested interface is not supported, this method must *ppvSite to NULL and return a failure code. + /// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvSite contains the requested interface pointer to the site last seen in SetSite. The specific interface returned depends on the riid argument—in essence, the two arguments act identically to those in QueryInterface. If the appropriate interface pointer is available, the object must call AddRef on that pointer before returning successfully. If no site is available, or the requested interface is not supported, this method must *ppvSite to NULL and return a failure code. /// This method returns S_OK on success. [PreserveSig] int GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out IntPtr ppvSite); diff --git a/SharpShell/SharpShell/Interop/SHGDNF.cs b/SharpShell/SharpShell/Interop/SHGDNF.cs index 6ed2f74f..d329c4c5 100644 --- a/SharpShell/SharpShell/Interop/SHGDNF.cs +++ b/SharpShell/SharpShell/Interop/SHGDNF.cs @@ -16,7 +16,7 @@ public enum SHGDNF SHGDN_NORMAL = 0x0000, /// - /// The name is relative to the folder from which the request was made. This is the name display to the user when used in the context of the folder. For example, it is used in the view and in the address bar path segment for the folder. This name should not include disambiguation information—for instance "username" instead of "username (on Machine)" for a particular user's folder. + /// The name is relative to the folder from which the request was made. This is the name display to the user when used in the context of the folder. For example, it is used in the view and in the address bar path segment for the folder. This name should not include disambiguation information—for instance "username" instead of "username (on Machine)" for a particular user's folder. /// Use this flag in combinations with SHGDN_FORPARSING and SHGDN_FOREDITING. /// SHGDN_INFOLDER = 0x0001, diff --git a/SharpShell/SharpShell/ServerRegistration/ServerRegistrationManager.cs b/SharpShell/SharpShell/ServerRegistration/ServerRegistrationManager.cs index 45e4d6a2..92c26392 100644 --- a/SharpShell/SharpShell/ServerRegistration/ServerRegistrationManager.cs +++ b/SharpShell/SharpShell/ServerRegistration/ServerRegistrationManager.cs @@ -384,7 +384,7 @@ public static void SetServerDisplayName(Guid classId, string displayName, Regist /// /// Sets the 'DisableProcessIsolation' value of the a COM server. /// - /// + /// /// The class identifier. /// Type of the registration. /// The DisableProcessIsolation value, generally 1 or 0. diff --git a/SharpShell/SharpShell/SharpShell.csproj b/SharpShell/SharpShell/SharpShell.csproj index d002ae86..73aad52e 100644 --- a/SharpShell/SharpShell/SharpShell.csproj +++ b/SharpShell/SharpShell/SharpShell.csproj @@ -27,6 +27,7 @@ + diff --git a/SharpShell/Tools/ServerRegistrationManager/ServerRegistrationManager.csproj b/SharpShell/Tools/ServerRegistrationManager/ServerRegistrationManager.csproj index a41eb4a0..acfecc38 100644 --- a/SharpShell/Tools/ServerRegistrationManager/ServerRegistrationManager.csproj +++ b/SharpShell/Tools/ServerRegistrationManager/ServerRegistrationManager.csproj @@ -12,13 +12,10 @@ - + - - -