Skip to content

Commit

Permalink
Modernize NuGet packages, update dotnet tests
Browse files Browse the repository at this point in the history
• Fix build warnings
  • Loading branch information
Repiteo committed Jun 13, 2024
1 parent 94ec811 commit 80c07b6
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 65 deletions.
47 changes: 32 additions & 15 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions SharpShell/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<AssemblyVersion>$(Version).0</AssemblyVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Octokit" Version="0.1.7" />
<PackageReference Include="Octokit" Version="12.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions SharpShell/SharpShell.Tests/PidlManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRegistry>();
Assert.IsInstanceOf(typeof(WindowsRegistry), registry);
Assert.That(registry, Is.InstanceOf<WindowsRegistry>());
}

[Test]
Expand All @@ -31,8 +31,8 @@ public void Registered_Service_Provider_Is_Used_To_Get_Service()
var service = SharpShell.ServiceRegistry.ServiceRegistry.GetService<IRegistry>();

// 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]
Expand Down
21 changes: 11 additions & 10 deletions SharpShell/SharpShell.Tests/SharpShell.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit.Console" Version="3.9.0" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.9.0" />
<PackageReference Include="NUnit.Extension.NUnitProjectLoader" Version="3.5.0" />
<PackageReference Include="NUnit.Extension.NUnitV2Driver" Version="3.6.0" />
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter" Version="3.5.0" />
<PackageReference Include="NUnit.Extension.TeamCityEventListener" Version="1.0.3" />
<PackageReference Include="NUnit.Extension.VSProjectLoader" Version="3.8.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Console" Version="3.17.0" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.17.0" />
<PackageReference Include="NUnit.Extension.NUnitProjectLoader" Version="3.7.1" />
<PackageReference Include="NUnit.Extension.NUnitV2Driver" Version="3.9.0" />
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter" Version="3.7.0" />
<PackageReference Include="NUnit.Extension.TeamCityEventListener" Version="1.0.9" />
<PackageReference Include="NUnit.Extension.VSProjectLoader" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="OpenCover" Version="4.7.1221" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions SharpShell/SharpShell.Tests/ShellInteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions SharpShell/SharpShell/Helpers/Win32Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
// ReSharper disable IdentifierTypo
// ReSharper disable IdentifierTypo

namespace SharpShell.Helpers
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public static int HiWord(IntPtr ptr)
/// </returns>
public static bool IS_INTRESOURCE(IntPtr resource)
{
return ((uint)resource) <= ushort.MaxValue;
return (resource.ToInt64() | ushort.MaxValue) == ushort.MaxValue;
}
}
}
5 changes: 5 additions & 0 deletions SharpShell/SharpShell/InitializeWithFileServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public abstract class InitializeWithFileServer : SharpShellServer, IInitializeWi
{
#region Implementation of IInitializeWithFile

/// <summary>
/// Initializes a handler with a file.
/// </summary>
/// <param name="pszFilePath">A string representing the file's path.</param>
/// <param name="grfMode">One of the following STGM values that indicates the access mode for grfMode. STGM_READ or STGM_READWRITE.</param>
public int Initialize(string pszFilePath, STGM grfMode)
{
Log($"Intiailising a file based server for '{pszFilePath}' with mode '{grfMode}'.");
Expand Down
5 changes: 5 additions & 0 deletions SharpShell/SharpShell/InitializeWithItemServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public abstract class InitializeWithItemServer : SharpShellServer, IInitializeWi
{
#region Implementation of IInitializeWithItem

/// <summary>
/// Initializes a handler with a shell.
/// </summary>
/// <param name="shellItem">A pointer to an IShellItem interface that represents the stream source.</param>
/// <param name="accessMode">One of the following STGM values that indicates the access mode for shellItem. STGM_READ or STGM_READWRITE.</param>
public int Initialize(IShellItem shellItem, STGM accessMode)
{
Log($"Intiailising a shell item server with mode '{accessMode}'.");
Expand Down
2 changes: 1 addition & 1 deletion SharpShell/SharpShell/Interop/Gdi32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr h
/// <returns>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 <see cref="BITMAPINFO"/> 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))</returns>
/// This function can return the following value: ERROR_INVALID_PARAMETER (87 (0×57))</returns>
[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);

Expand Down
2 changes: 1 addition & 1 deletion SharpShell/SharpShell/Interop/IObjectWithSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IObjectWithSite
/// Retrieves the latest site passed using SetSite.
/// </summary>
/// <param name="riid">The IID of the interface pointer that should be returned in ppvSite.</param>
/// <param name="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.</param>
/// <param name="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.</param>
/// <returns>This method returns S_OK on success.</returns>
[PreserveSig]
int GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out IntPtr ppvSite);
Expand Down
2 changes: 1 addition & 1 deletion SharpShell/SharpShell/Interop/SHGDNF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum SHGDNF
SHGDN_NORMAL = 0x0000,

/// <summary>
/// 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.
/// </summary>
SHGDN_INFOLDER = 0x0001,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public static void SetServerDisplayName(Guid classId, string displayName, Regist
/// <summary>
/// Sets the 'DisableProcessIsolation' value of the a COM server.
/// </summary>
/// <seealso cref="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144118"/>
/// <seealso href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144118"/>
/// <param name="classId">The class identifier.</param>
/// <param name="registrationType">Type of the registration.</param>
/// <param name="disableProcessIsolationValue">The DisableProcessIsolation value, generally 1 or 0.</param>
Expand Down
1 change: 1 addition & 0 deletions SharpShell/SharpShell/SharpShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)artifacts\build\SharpShell" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Actions\Help.txt" />
<EmbeddedResource Include="EmbeddedReferences\SharpShell.dll" />
<EmbeddedResource Include="..\..\SharpShell\bin\$(Configuration)\$(TargetFramework)\SharpShell.dll" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Copy SourceFiles="$(SolutionDir)artifacts\build\SharpShell\SharpShell.dll" DestinationFolder="$(ProjectDir)EmbeddedReferences" />
</Target>
</Project>

0 comments on commit 80c07b6

Please sign in to comment.