Skip to content

Commit

Permalink
Continued refinement work on the Windows installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Dec 15, 2023
1 parent 3bab891 commit 5932695
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 66 deletions.
54 changes: 44 additions & 10 deletions scripts/ci/build-installer_win32.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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 ..
6 changes: 3 additions & 3 deletions scripts/ci/install-graalvm.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/native-image-config/common-flatlaf-win32/jni-config.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion scripts/native-image-config/common-flatlaf-win32/resource-config.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions scripts/native-image-config/win32/jni-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,10 @@
"name": "disposeLater",
"parameterTypes": []
},
{
"name": "dynamicallyLayoutContainer",
"parameterTypes": []
},
{
"name": "handleExpose",
"parameterTypes": [
Expand Down
9 changes: 8 additions & 1 deletion scripts/native-image-config/win32/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
{
"name": "com.formdev.flatlaf.resources.Bundle",
"locales": [
""
"",
"und"
]
},
{
Expand All @@ -90,6 +91,12 @@
"classNames": [
"sun.awt.resources.awt"
]
},
{
"name": "com.formdev.flatlaf.resources.Bundle",
"locales": [
""
]
}
]
}
17 changes: 2 additions & 15 deletions scripts/res/installer.nsis → scripts/res/installer.nsh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 7 additions & 0 deletions scripts/res/win32-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
31 changes: 0 additions & 31 deletions scripts/run-agent-flatlaf-cygwin.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/run-agent-flatlaf-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions scripts/run-agent-flatlaf-win32.ps1
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions scripts/run-agent-win32.ps1
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 5932695

Please sign in to comment.