From 301427ad6b958ca8988573d79894fd48220a4d69 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 1 Nov 2024 15:25:57 +0700 Subject: [PATCH 1/7] .NET8 Windows for SIL.Windows.Forms Updated L10NSharp to 8, which is the version that adds support for .NET8 Windows. Removed some old app.config settings that were causing build warnings. Updated some of the old .NET menu items for the newer style MenuStrip/MenuItem style. Also removed the old CAS-style PermissionSet attributes. This has precedent in FLEx, I believe. Also removed ImageToolbox controls -- they appear to be unused within SIL, and the third-party dependency is Framework 4.6.1 only. The other ancient third-party dependency we have is Enchant, which does appear to be used. But I have marked those two direct references as Obsolete, so we should see build warnings for consumers. --- .../SIL.Windows.Forms.Keyboarding.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj index c4e519ad0..6887ca3b2 100644 --- a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj +++ b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj @@ -13,7 +13,6 @@ All - From e99220688b44a8b4103fc60239b50da8b66b0548 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 1 Nov 2024 15:46:04 +0700 Subject: [PATCH 2/7] Added L10NSharp back to Keyboarding. I thought it was referencing SIL.Windows.Forms like all the others, but it doesn't. --- .../SIL.Windows.Forms.Keyboarding.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj index 6887ca3b2..c4e519ad0 100644 --- a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj +++ b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj @@ -13,6 +13,7 @@ All + From 8fd83bec27e553eb3809cd499fcb5b73a8b25630 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 13 Nov 2024 14:51:23 +0700 Subject: [PATCH 3/7] .NET8 Windows for SIL.Windows.Forms.Keyboarding and .WritingSystems It builds, and the tests appear to be not catastrophic, but I'll wait for the build server to do the actual verification. For .Keyboarding, I completely removed the Linux\ folder on .NET8 Windows. Same for the test files directed at Linux. --- ...SIL.Windows.Forms.Keyboarding.Tests.csproj | 22 ++++++++++++++++++- .../KeyboardController.cs | 4 ++++ .../SIL.Windows.Forms.Keyboarding.csproj | 15 +++++++++++-- ....Windows.Forms.WritingSystems.Tests.csproj | 1 + .../SIL.Windows.Forms.WritingSystems.csproj | 1 + 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj index 0cf57183e..fd4b9c090 100644 --- a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj +++ b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj @@ -4,6 +4,7 @@ SIL.Windows.Forms.Keyboarding.Tests SIL.Windows.Forms.Keyboarding.Tests Unit tests for SIL.Windows.Forms.Keyboarding + $(TargetFrameworks);net8-windows true @@ -25,8 +26,27 @@ - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SIL.Windows.Forms.Keyboarding/KeyboardController.cs b/SIL.Windows.Forms.Keyboarding/KeyboardController.cs index 35ca4b3ad..468ce8368 100644 --- a/SIL.Windows.Forms.Keyboarding/KeyboardController.cs +++ b/SIL.Windows.Forms.Keyboarding/KeyboardController.cs @@ -12,7 +12,9 @@ using SIL.ObjectModel; using SIL.PlatformUtilities; using SIL.Reporting; +#if NETFRAMEWORK using SIL.Windows.Forms.Keyboarding.Linux; +#endif using SIL.Windows.Forms.Keyboarding.Windows; namespace SIL.Windows.Forms.Keyboarding @@ -217,10 +219,12 @@ private void SetDefaultKeyboardAdaptors() } : new IKeyboardRetrievingAdaptor[] { +#if NETFRAMEWORK new XkbKeyboardRetrievingAdaptor(), new IbusKeyboardRetrievingAdaptor(), new UnityXkbKeyboardRetrievingAdaptor(), new UnityIbusKeyboardRetrievingAdaptor(), new CombinedIbusKeyboardRetrievingAdaptor(), new GnomeShellIbusKeyboardRetrievingAdaptor() +#endif } ); } diff --git a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj index c4e519ad0..78662a08a 100644 --- a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj +++ b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj @@ -4,7 +4,15 @@ SIL.Windows.Forms.Keyboarding SIL.Windows.Forms.Keyboarding The SIL.Windows.Forms.Keyboarding library provides cross-platform functionality for keyboard selection and switching in Windows Forms applications. Currently, this library supports system and Keyman keyboards on Windows, and X keyboard extension (XKB) and Intelligent Input Bus (IBus) keyboards on Linux. + $(TargetFrameworks);net8-windows + + + + + + + @@ -23,6 +31,11 @@ + + + + + ..\lib\Keyman10Interop.dll @@ -33,8 +46,6 @@ ..\lib\KeymanLink.dll - - diff --git a/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj b/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj index be2fa479f..f710e7444 100644 --- a/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj +++ b/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj @@ -7,6 +7,7 @@ false true true + $(TargetFrameworks);net8-windows true diff --git a/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj b/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj index bb7abe38c..fe3047c3c 100644 --- a/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj +++ b/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj @@ -4,6 +4,7 @@ SIL.Windows.Forms.WritingSystems SIL.Windows.Forms.WritingSystems SIL.Windows.Forms.WritingSystems contains Windows Forms UI elements for displaying and editing writing systems as defined by the SIL.WritingSystems assembly. + $(TargetFrameworks);net8-windows true true From b34d45aa0a0892997cff0c341fd06360a81f58d7 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 23 Jan 2025 15:02:54 +0700 Subject: [PATCH 4/7] Changed net8 to net8.0 --- .../SIL.Windows.Forms.Keyboarding.Tests.csproj | 4 ++-- .../SIL.Windows.Forms.Keyboarding.csproj | 8 ++++---- .../SIL.Windows.Forms.WritingSystems.Tests.csproj | 2 +- .../SIL.Windows.Forms.WritingSystems.csproj | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj index fd4b9c090..f97db5d91 100644 --- a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj +++ b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj @@ -4,7 +4,7 @@ SIL.Windows.Forms.Keyboarding.Tests SIL.Windows.Forms.Keyboarding.Tests Unit tests for SIL.Windows.Forms.Keyboarding - $(TargetFrameworks);net8-windows + $(TargetFrameworks);net8.0-windows true @@ -31,7 +31,7 @@ - + diff --git a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj index 78662a08a..f598ee43b 100644 --- a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj +++ b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj @@ -4,10 +4,10 @@ SIL.Windows.Forms.Keyboarding SIL.Windows.Forms.Keyboarding The SIL.Windows.Forms.Keyboarding library provides cross-platform functionality for keyboard selection and switching in Windows Forms applications. Currently, this library supports system and Keyman keyboards on Windows, and X keyboard extension (XKB) and Intelligent Input Bus (IBus) keyboards on Linux. - $(TargetFrameworks);net8-windows + $(TargetFrameworks);net8.0-windows - - + + @@ -35,7 +35,7 @@ - + ..\lib\Keyman10Interop.dll diff --git a/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj b/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj index f710e7444..3a08d0405 100644 --- a/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj +++ b/SIL.Windows.Forms.WritingSystems.Tests/SIL.Windows.Forms.WritingSystems.Tests.csproj @@ -7,7 +7,7 @@ false true true - $(TargetFrameworks);net8-windows + $(TargetFrameworks);net8.0-windows true diff --git a/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj b/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj index fe3047c3c..edfbea216 100644 --- a/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj +++ b/SIL.Windows.Forms.WritingSystems/SIL.Windows.Forms.WritingSystems.csproj @@ -4,7 +4,7 @@ SIL.Windows.Forms.WritingSystems SIL.Windows.Forms.WritingSystems SIL.Windows.Forms.WritingSystems contains Windows Forms UI elements for displaying and editing writing systems as defined by the SIL.WritingSystems assembly. - $(TargetFrameworks);net8-windows + $(TargetFrameworks);net8.0-windows true true From d45a1e1158551a8d727332e6c60c071bf162c03f Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 23 Jan 2025 15:47:17 +0700 Subject: [PATCH 5/7] Replaced Rhino.Mocks with Moq --- .../KeyboardControllerTests.cs | 21 +++++++++---------- ...SIL.Windows.Forms.Keyboarding.Tests.csproj | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs b/SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs index 8888487bd..b4c095602 100644 --- a/SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs +++ b/SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs @@ -5,31 +5,30 @@ using System.Globalization; using NUnit.Framework; using SIL.Keyboarding; -using Rhino.Mocks; +using Moq; namespace SIL.Windows.Forms.Keyboarding.Tests { [TestFixture] public class KeyboardControllerTests { - private IKeyboardRetrievingAdaptor _mockKeyboardAdaptor = MockRepository.GenerateMock(); + private Mock _mockKeyboardAdaptor = new Mock(); [SetUp] public void Setup() { // To avoid OS specific behavior in these tests we mock up our own keyboard adaptor returning appropriate values to enable these tests - _mockKeyboardAdaptor.Stub(k => k.IsApplicable).Return(true); - _mockKeyboardAdaptor.Stub(k => k.Type).Return(KeyboardAdaptorType.System); - _mockKeyboardAdaptor.Stub(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Return(true); - _mockKeyboardAdaptor.Stub(k => k.CreateKeyboardDefinition(Arg.Is.Anything)).Return(null) // will be ignored but still the API requires it - .WhenCalled(k => + _mockKeyboardAdaptor.Setup(k => k.IsApplicable).Returns(true); + _mockKeyboardAdaptor.Setup(k => k.Type).Returns(KeyboardAdaptorType.System); + _mockKeyboardAdaptor.Setup(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Returns(true); + _mockKeyboardAdaptor.Setup(k => k.CreateKeyboardDefinition(It.IsAny())).Returns( + id => { - var id = (string)k.Arguments[0]; var idParts = id.Split('_'); var mockKd = new MockKeyboardDescription(id, idParts[0], idParts[1]); - k.ReturnValue = mockKd; + return mockKd; }); - KeyboardController.Initialize(_mockKeyboardAdaptor); + KeyboardController.Initialize(_mockKeyboardAdaptor.Object); } [TearDown] @@ -118,7 +117,7 @@ public void GetKeyboard_FromInputLanguage_NonExistingKeyboard() } /// - /// This mock (less code than a Rhino.Mocks version) provides sufficient IKeyboardDefinition for testing the KeyboardController + /// This mock provides sufficient IKeyboardDefinition for testing the KeyboardController /// private class MockKeyboardDescription : KeyboardDescription { diff --git a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj index f97db5d91..405dd4b75 100644 --- a/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj +++ b/SIL.Windows.Forms.Keyboarding.Tests/SIL.Windows.Forms.Keyboarding.Tests.csproj @@ -17,7 +17,6 @@ - From d115aa08dc15685ae896eb90d2fd2187f18bb0e9 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 24 Jan 2025 13:25:46 +0700 Subject: [PATCH 6/7] Suppress some intentional code that causes a warning --- SIL.Windows.Forms/ImageToolbox/PalasoImage.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/SIL.Windows.Forms/ImageToolbox/PalasoImage.cs b/SIL.Windows.Forms/ImageToolbox/PalasoImage.cs index 39ccb2f11..d7534488a 100644 --- a/SIL.Windows.Forms/ImageToolbox/PalasoImage.cs +++ b/SIL.Windows.Forms/ImageToolbox/PalasoImage.cs @@ -32,27 +32,27 @@ public Metadata Metadata private string _originalFilePath; - + /// /// If false, you get a debug.Fail(). If true, you get a throw. /// public static bool ThrowOnFailureToDisposeAnyPalasoImage = false; /// - /// If the object isn't disposed, the resulting message will give this label. + /// If the object isn't disposed, the resulting message will give this label. /// This can help trace where it was created. /// public string LabelForDebugging = "unlabeled"; - + /// /// Generally, when we load an image, we can happily forget where it came from, because /// the nature of the palaso image system is to deliver images, not file paths, to documents /// (we don't believe in "linking" to files somewhere on the disk which is just asking for problems /// as the document is shared). /// But in one circumstance, we do care: when the user chooses from disk (as opposed to from camera or scanner) - /// and enters metadata, we want to store that metadata in the original. + /// and enters metadata, we want to store that metadata in the original. /// However, there is one circumstance (currently) in which this is not the original path: - /// If we attempt to save metadata and can't (e.g. file is readonly), we create a temp file and + /// If we attempt to save metadata and can't (e.g. file is readonly), we create a temp file and /// store the metadata there, then serve the temp file to the requester. That's why we store this path. /// private string _pathForSavingMetadataChanges; @@ -142,7 +142,7 @@ public static string FileExtForWebFormat(string fileExtension) var format = GetImageFormatForExtension(fileExtension); return format == ImageFormat.Jpeg ? ".jpg" : ".png"; } - + private void SaveInFormat(string path, ImageFormat format) { ThrowIfDisposedOfAlready(); @@ -212,12 +212,12 @@ private static ImageFormat GetImageFormatForExtension(string fileExtension) throw new NotImplementedException(); } } - - + + /// /// If you edit the metadata, call this. If it happens to have an actual file associated, it will save it. /// If not (e.g. the image came from a scanner), it won't do anything. - /// + /// /// Warning. Don't use this on original images. See https://jira.sil.org/browse/BL-1001. /// public void SaveUpdatedMetadataIfItMakesSense() @@ -252,7 +252,7 @@ private static string GetCorrectImageExtension(string path) file.Read(bytes, 0, 10); } }, memo:$"PalasoImage.GetCorrectImageExtension({path})"); - // see http://www.mikekunz.com/image_file_header.html + // see http://www.mikekunz.com/image_file_header.html var bmp = Encoding.ASCII.GetBytes("BM"); // BMP var gif = Encoding.ASCII.GetBytes("GIF"); // GIF var png = new byte[] { 137, 80, 78, 71 }; // PNG @@ -326,8 +326,10 @@ private static Image LoadImageWithoutLocking(string path, out string tempPath) // assume it's a better indication of the problem. var metadata = Metadata.FromFile(path); if (metadata.IsOutOfMemoryPlausible(e)) + #pragma warning disable CA2200 // ReSharper disable once PossibleIntendedRethrow throw e; // Deliberately NOT just "throw", that loses the extra information IsOutOfMemoryPlausible added to the exception. + #pragma warning restore CA2200 throw new TagLib.CorruptFileException("File could not be read and is possible corrupted", e); } } From 42e7154acf5c54a1a84c423884a260e2ba9dcac9 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 24 Jan 2025 13:27:25 +0700 Subject: [PATCH 7/7] Replaced a net8 check with !framework --- .../SIL.Windows.Forms.Keyboarding.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj index f598ee43b..dffd27538 100644 --- a/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj +++ b/SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj @@ -7,7 +7,7 @@ $(TargetFrameworks);net8.0-windows - +