From 5932695b5795ba4a3fe65a3a567508ccdc97c283 Mon Sep 17 00:00:00 2001 From: Alissa Rao Date: Fri, 15 Dec 2023 09:41:19 -0800 Subject: [PATCH] Continued refinement work on the Windows installer. --- scripts/ci/build-installer_win32.ps1 | 54 +++++++++++++++---- scripts/ci/install-graalvm.ps1 | 6 +-- .../common-flatlaf-win32/jni-config.json | 2 +- .../predefined-classes-config.json | 0 .../common-flatlaf-win32/proxy-config.json | 0 .../common-flatlaf-win32/reflect-config.json | 0 .../common-flatlaf-win32/resource-config.json | 2 +- .../serialization-config.json | 0 .../native-image-config/win32/jni-config.json | 4 ++ .../win32/resource-config.json | 9 +++- scripts/res/{installer.nsis => installer.nsh} | 17 +----- scripts/res/win32-manifest.xml | 7 +++ scripts/run-agent-flatlaf-cygwin.sh | 31 ----------- scripts/run-agent-flatlaf-linux.sh | 2 +- scripts/run-agent-flatlaf-win32.ps1 | 7 +++ scripts/run-agent-win32.ps1 | 6 +-- 16 files changed, 81 insertions(+), 66 deletions(-) mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/jni-config.json mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/predefined-classes-config.json mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/proxy-config.json mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/reflect-config.json mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/resource-config.json mode change 100644 => 100755 scripts/native-image-config/common-flatlaf-win32/serialization-config.json rename scripts/res/{installer.nsis => installer.nsh} (66%) delete mode 100755 scripts/run-agent-flatlaf-cygwin.sh create mode 100755 scripts/run-agent-flatlaf-win32.ps1 diff --git a/scripts/ci/build-installer_win32.ps1 b/scripts/ci/build-installer_win32.ps1 index bc9576b..34b4b5c 100644 --- a/scripts/ci/build-installer_win32.ps1 +++ b/scripts/ci/build-installer_win32.ps1 @@ -1,6 +1,6 @@ $ErrorActionPreference = "Stop" -$URL_RCEDIT="https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe" +$URL_RCEDIT = "https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe" # Install graalvm scripts/ci/install-graalvm.ps1 @@ -12,20 +12,20 @@ if (Test-Path target/native-bin) { } New-Item target/native-bin -ItemType Directory -ea 0 -Verbose cd target/native-bin - tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz +tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz cd ../.. # Download rcedit if it isn't already downloaded -if (-Not (Test-Path "target/rcedit.exe" -PathType Leaf)) { +if (-Not(Test-Path "target/rcedit.exe" -PathType Leaf)) { echo "Downloading 'rcedit.exe'..." $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri "$URL_RCEDIT" -OutFile "target/rcedit.exe" } # Find the current version -$VERSION="$(sbt "print version" --error)".Trim() -$FILE_VERSION="$VERSION".Split("-")[0] -$FILE_VERSION="$FILE_VERSION.$(git rev-list HEAD --count)" +$VERSION = "$( sbt "print version" --error )".Trim() +$FILE_VERSION = "$VERSION".Split("-")[0] +$FILE_VERSION = "$FILE_VERSION.$( git rev-list HEAD --count )" # Build the native-image echo "Building native-image installer" @@ -47,12 +47,46 @@ editbin /SUBSYSTEM:WINDOWS "target/native-image/mppatch-installer.exe" # Build NSIS image echo "Building NSIS installer wrapper" -$Env:NSIS_VERSION="$VERSION" -$Env:NSIS_FILE_VERSION="$FILE_VERSION" -makensis scripts/res/installer.nsis +makensis scripts/res/installer.nsh + +# Extract NSIS resources partition and run rcedit +[byte[]]$bytes = [System.IO.File]::ReadAllBytes("target/mppatch-installer-unmodified.exe") +[byte[]]$signature = 4, 0, 0, 0, 0xEF, 0xBE, 0xAD, 0xDE, 0x4E, 0x75, 0x6C, 0x6C +$nsisLocation = 0 +for ($i = 0; $i -lt ($bytes.Count - $signature.Count); $i++) { + if ($i % 100000 -eq 0) { + echo "Searching for NSIS signature... $i/$( $bytes.Count )" + } + if ( [Linq.Enumerable]::SequenceEqual([byte[]]@($bytes[$i..($i + $signature.Count - 1)]), $signature)) { + echo "Found NSIS signature at 0x$($i.ToString("X") )" + $nsisLocation = $i + break + } +} +if ($nsisLocation -eq 0) { + echo "NSIS signature not found?" + exit 1 +} + +echo "Writing NSIS split resources..." +[System.IO.File]::WriteAllBytes("target/mppatch-installer-stub.exe", @($bytes[0..($nsisLocation - 1)])) +[System.IO.File]::WriteAllBytes("target/mppatch-installer-data.dat", @($bytes[$nsisLocation..($bytes.Count - 1)])) + +echo "Building final installer..." +target/rcedit.exe "target/mppatch-installer-stub.exe" ` + --set-version-string "FileDescription" "MPPatch Installer" ` + --set-file-version "$FILE_VERSION" ` + --set-version-string "ProductName" "MPPatch" ` + --set-product-version "$VERSION" ` + --set-version-string "LegalCopyright" "©Lymia Kanokawa; available under the MIT License" ` + --set-version-string "OriginalFilename" "MPPatch-Installer_win32_$VERSION.exe" ` + --set-icon "scripts/res/mppatch-installer.ico" ` + --application-manifest "scripts/res/win32-manifest.xml" +Get-Content "target/mppatch-installer-stub.exe", "target/mppatch-installer-data.dat" -Encoding Byte -Read 1024 ` + | Set-Content "target/mppatch-installer.exe" -Encoding Byte # Create tarball echo "Creating Windows installer tarball..." cd target - tar --gzip -cv -f "mppatch_ci_installer-win32.tar.gz" mppatch-installer.exe +tar --gzip -cv -f "mppatch_ci_installer-win32.tar.gz" mppatch-installer.exe cd .. diff --git a/scripts/ci/install-graalvm.ps1 b/scripts/ci/install-graalvm.ps1 index 391b840..79ffc91 100755 --- a/scripts/ci/install-graalvm.ps1 +++ b/scripts/ci/install-graalvm.ps1 @@ -1,10 +1,10 @@ $ErrorActionPreference = "Stop" -$GRAALVM_WIN32="https://download.bell-sw.com/vm/23.1.1/bellsoft-liberica-vm-openjdk21.0.1+12-23.1.1+1-windows-amd64.zip" -$GRAALVM_WIN32_DIR="bellsoft-liberica-vm-openjdk21-23.1.1" +$GRAALVM_WIN32 = "https://download.bell-sw.com/vm/23.1.1/bellsoft-liberica-vm-openjdk21.0.1+12-23.1.1+1-windows-amd64.zip" +$GRAALVM_WIN32_DIR = "bellsoft-liberica-vm-openjdk21-23.1.1" # Install graalvm -if (-Not (Test-Path "target/graalvm-win32" -PathType Container)) { +if (-Not(Test-Path "target/graalvm-win32" -PathType Container)) { echo "Downloading graalvm..." $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri "$GRAALVM_WIN32" -OutFile "target/graalvm-win32.zip" diff --git a/scripts/native-image-config/common-flatlaf-win32/jni-config.json b/scripts/native-image-config/common-flatlaf-win32/jni-config.json old mode 100644 new mode 100755 index 9d7a15a..ae6ae4e --- a/scripts/native-image-config/common-flatlaf-win32/jni-config.json +++ b/scripts/native-image-config/common-flatlaf-win32/jni-config.json @@ -311,7 +311,7 @@ { "name":"sun.awt.windows.WComponentPeer", "fields":[{"name":"hwnd"}, {"name":"winGraphicsConfig"}], - "methods":[{"name":"disposeLater","parameterTypes":[] }, {"name":"handleExpose","parameterTypes":["int","int","int","int"] }, {"name":"postEvent","parameterTypes":["java.awt.AWTEvent"] }, {"name":"replaceSurfaceData","parameterTypes":[] }, {"name":"replaceSurfaceDataLater","parameterTypes":[] }] + "methods":[{"name":"disposeLater","parameterTypes":[] }, {"name":"dynamicallyLayoutContainer","parameterTypes":[] }, {"name":"handleExpose","parameterTypes":["int","int","int","int"] }, {"name":"postEvent","parameterTypes":["java.awt.AWTEvent"] }, {"name":"replaceSurfaceData","parameterTypes":[] }, {"name":"replaceSurfaceDataLater","parameterTypes":[] }] }, { "name":"sun.awt.windows.WDesktopPeer", diff --git a/scripts/native-image-config/common-flatlaf-win32/predefined-classes-config.json b/scripts/native-image-config/common-flatlaf-win32/predefined-classes-config.json old mode 100644 new mode 100755 diff --git a/scripts/native-image-config/common-flatlaf-win32/proxy-config.json b/scripts/native-image-config/common-flatlaf-win32/proxy-config.json old mode 100644 new mode 100755 diff --git a/scripts/native-image-config/common-flatlaf-win32/reflect-config.json b/scripts/native-image-config/common-flatlaf-win32/reflect-config.json old mode 100644 new mode 100755 diff --git a/scripts/native-image-config/common-flatlaf-win32/resource-config.json b/scripts/native-image-config/common-flatlaf-win32/resource-config.json old mode 100644 new mode 100755 index 5c09320..8fda975 --- a/scripts/native-image-config/common-flatlaf-win32/resource-config.json +++ b/scripts/native-image-config/common-flatlaf-win32/resource-config.json @@ -253,7 +253,7 @@ }]}, "bundles":[{ "name":"com.formdev.flatlaf.resources.Bundle", - "locales":[""] + "locales":["", "und"] }, { "name":"com.sun.swing.internal.plaf.basic.resources.basic", "classNames":["com.sun.swing.internal.plaf.basic.resources.basic"] diff --git a/scripts/native-image-config/common-flatlaf-win32/serialization-config.json b/scripts/native-image-config/common-flatlaf-win32/serialization-config.json old mode 100644 new mode 100755 diff --git a/scripts/native-image-config/win32/jni-config.json b/scripts/native-image-config/win32/jni-config.json index e2ec63e..2574f93 100755 --- a/scripts/native-image-config/win32/jni-config.json +++ b/scripts/native-image-config/win32/jni-config.json @@ -1222,6 +1222,10 @@ "name": "disposeLater", "parameterTypes": [] }, + { + "name": "dynamicallyLayoutContainer", + "parameterTypes": [] + }, { "name": "handleExpose", "parameterTypes": [ diff --git a/scripts/native-image-config/win32/resource-config.json b/scripts/native-image-config/win32/resource-config.json index dfed41c..2f08307 100755 --- a/scripts/native-image-config/win32/resource-config.json +++ b/scripts/native-image-config/win32/resource-config.json @@ -70,7 +70,8 @@ { "name": "com.formdev.flatlaf.resources.Bundle", "locales": [ - "" + "", + "und" ] }, { @@ -90,6 +91,12 @@ "classNames": [ "sun.awt.resources.awt" ] + }, + { + "name": "com.formdev.flatlaf.resources.Bundle", + "locales": [ + "" + ] } ] } \ No newline at end of file diff --git a/scripts/res/installer.nsis b/scripts/res/installer.nsh similarity index 66% rename from scripts/res/installer.nsis rename to scripts/res/installer.nsh index 8f69c7e..19df023 100644 --- a/scripts/res/installer.nsis +++ b/scripts/res/installer.nsh @@ -1,20 +1,7 @@ Name "MPPatch" SetCompressor /SOLID /FINAL lzma -OutFile ..\..\target\mppatch-installer.exe -Icon mppatch-installer.ico - -RequestExecutionLevel user -ManifestDPIAware true - -VIProductVersion "$%NSIS_FILE_VERSION%" -VIFileVersion "$%NSIS_FILE_VERSION%" -VIAddVersionKey /LANG=0 "OriginalFilename" "MPPatch-Installer_win32_$%NSIS_VERSION%.exe" - -!define LANG_ENGLISH 1033 -VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "MPPatch" -VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "MPPatch Installer" -VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "(C) Lymia Kanokawa; available under the MIT License" -VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "MPPatch Version $%NSIS_VERSION%" +OutFile ..\..\target\mppatch-installer-unmodified.exe +CRCCheck off ; We will be altering the final binary in a way that invalidates the CRC ; Mutex code, from https://nsis.sourceforge.io/Allow_only_one_installer_instance !define INSTALLERMUTEXNAME "MPPatch NSIS Wrapper / 24d1f759-689d-4707-8fb9-3508574253e7" diff --git a/scripts/res/win32-manifest.xml b/scripts/res/win32-manifest.xml index 77065f5..93fd860 100644 --- a/scripts/res/win32-manifest.xml +++ b/scripts/res/win32-manifest.xml @@ -6,4 +6,11 @@ PerMonitorV2 + + + + + + + diff --git a/scripts/run-agent-flatlaf-cygwin.sh b/scripts/run-agent-flatlaf-cygwin.sh deleted file mode 100755 index e3a072a..0000000 --- a/scripts/run-agent-flatlaf-cygwin.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 2015-2023 Lymia Kanokawa -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -. scripts/ci/install-graalvm.sh -install_for_win32 || exit 1 - -wget https://download.formdev.com/files/flatlaf/flatlaf-demo-3.2.5.jar -O target/flatlaf-demo-3.2.5.jar || exit 1 -target/graalvm-win32/bin/java.exe \ - -agentlib:native-image-agent=config-output-dir=scripts/native-image-config/common-flatlaf-win32 \ - -jar target/flatlaf-demo-3.2.5.jar || exit 1 diff --git a/scripts/run-agent-flatlaf-linux.sh b/scripts/run-agent-flatlaf-linux.sh index d207b67..780a1e7 100755 --- a/scripts/run-agent-flatlaf-linux.sh +++ b/scripts/run-agent-flatlaf-linux.sh @@ -26,5 +26,5 @@ wget https://download.formdev.com/files/flatlaf/flatlaf-demo-3.2.5.jar -O target/flatlaf-demo-3.2.5.jar || exit 1 target/graalvm-linux/bin/java \ - -agentlib:native-image-agent=config-output-dir=scripts/native-image-config/common-flatlaf-linux \ + -agentlib:native-image-agent=config-merge-dir=scripts/native-image-config/common-flatlaf-linux \ -jar target/flatlaf-demo-3.2.5.jar || exit 1 diff --git a/scripts/run-agent-flatlaf-win32.ps1 b/scripts/run-agent-flatlaf-win32.ps1 new file mode 100755 index 0000000..6845a34 --- /dev/null +++ b/scripts/run-agent-flatlaf-win32.ps1 @@ -0,0 +1,7 @@ +scripts/ci/install-graalvm.ps1 + +$ProgressPreference = 'SilentlyContinue' +iwr -Uri "https://download.formdev.com/files/flatlaf/flatlaf-demo-3.2.5.jar" -OutFile "target/flatlaf-demo-3.2.5.jar" +target/graalvm-win32/bin/java.exe ` + -agentlib:native-image-agent=config-merge-dir=scripts/native-image-config/common-flatlaf-win32 ` + -jar target/flatlaf-demo-3.2.5.jar diff --git a/scripts/run-agent-win32.ps1 b/scripts/run-agent-win32.ps1 index fec5a00..3691cd3 100755 --- a/scripts/run-agent-win32.ps1 +++ b/scripts/run-agent-win32.ps1 @@ -1,12 +1,12 @@ scripts/ci/install-graalvm.ps1 -$JAR_NAME="$(sbt "print assembly" --error)".Trim() +$JAR_NAME = "$( sbt "print assembly" --error )".Trim() if (Test-Path target/native-image-config-temp) { - rm -Recurse -Force -Verbose target/native-image-config-temp + rm -Recurse -Force -Verbose target/native-image-config-temp } if (Test-Path scripts/native-image-config/win32) { - rm -Recurse -Force -Verbose scripts/native-image-config/win32 + rm -Recurse -Force -Verbose scripts/native-image-config/win32 } mkdir scripts/native-image-config/win32