Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
test: add msi support
Browse files Browse the repository at this point in the history
  • Loading branch information
kjxbyz committed Jul 17, 2024
1 parent d28bfdd commit 1da0be4
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 1 deletion.
144 changes: 144 additions & 0 deletions .github/workflows/test-windows-msi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Test Windows msi

on:
workflow_dispatch:

# Declare default permissions as readonly.
permissions: read-all

jobs:
get_version:
name: Create release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_step.outputs.version }}
steps:
- uses: actions/checkout@v4

- name: Install yq
run: |
if ! command -v yq >/dev/null 2>&1; then
echo "yq not exists"
brew install yq
fi
yq --version
- name: Set version
id: version_step
run: |
VERSION=$(yq '.version' pubspec.yaml)
echo "$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check version
run: echo ${{ steps.version_step.outputs.version }}

msi:
name: Create msi
runs-on: windows-latest
env:
Platform: x64
needs:
- get_version
steps:
- uses: actions/checkout@v4

- name: Check msvc
run: |
$directories = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC" -Directory | Where-Object { $_.Name -match '^[0-9]{1,}' }
# 如果目录列表不为空,则找到最后一个目录
if ($directories.Count -gt 0) {
$lastDirectory = $directories[-1]
Write-Output "最后一个以数字开头的目录是: $($lastDirectory.FullName)"
} else {
Write-Output "未找到以数字开头的目录"
}
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.19.6'

- name: Flutter doctor -v
run: flutter doctor -v

- name: Install yq
shell: pwsh
run: |
choco install yq
yq --version
- name: Install wix toolset
shell: pwsh
run: |
dotnet tool install --global wix
wix --version
- name: Configure .env
run: |
echo "$pwd"
$bytes = echo $env:ENV_KEY | %{[Convert]::FromBase64String($_)}
[IO.File]::WriteAllBytes("$pwd\.env", $bytes)
env:
ENV_KEY: ${{ secrets.ENV_STG_BASE64_WINDOWS }}

- name: Install flutter dependencies
run: flutter pub get

- name: Build windows
run: flutter build windows --dart-define-from-file=.env

- name: Create msi
shell: pwsh
run: |
echo $env:RUNNER_TEMP
$certificatePath = "$env:RUNNER_TEMP\faforever.pfx"
# https://stackoverflow.com/questions/15414678/how-to-decode-a-base64-string
# https://stackoverflow.com/questions/66239147/pfx-encoded-and-back-to-pfx-in-powershell
$bytes = echo $env:WINDOWS_CERTIFICATE | %{[Convert]::FromBase64String($_)}
[IO.File]::WriteAllBytes("$certificatePath", $bytes)
$env:FLUTTER_BUILD_OUTPUT_DIR = "$pwd\build\windows\$env:Platform\runner\Release"
$env:VISUAL_STUDIO_REDIST_DIR = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC\14.40.33807\$env:Platform\Microsoft.VC143.CRT"
dotnet build .\msi\faforever\faforever.wixproj --arch "$env:Platform" --configuration Release
$signtool = "C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe"
& $signtool sign /v /f "$certificatePath" /fd SHA256 /t http://timestamp.comodoca.com/authenticode /p "$env:WINDOWS_CERTIFICATE_PASSWORD" /n "$env:WINDOWS_PUBLISHER_NAME" (get-item ".\msi\faforever\bin\$env:Platform\Release\*\*.msi")
env:
WINDOWS_PUBLISHER_NAME: ${{ secrets.WINDOWS_PUBLISHER_NAME }}
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
WINDOWS_CERTIFICATE_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}

# Package the build.
- name: Copy build for msi
shell: pwsh
run: |
Rename-Item -Path "$pwd\msi\faforever\bin\$env:Platform\Release\en-US\faforever.msi" -NewName "faforever_$env:VERSION`_windows_$env:Platform`_en-US.msi"
Rename-Item -Path "$pwd\msi\faforever\bin\$env:Platform\Release\zh-CN\faforever.msi" -NewName "faforever_$env:VERSION`_windows_$env:Platform`_zh-CN.msi"
env:
VERSION: ${{ needs.get_version.outputs.version }}

- uses: actions/upload-artifact@v4
with:
name: windows-msi-artifact
path: |
".\msi\faforever\bin\$env:Platform\Release\*\*.msi"
- name: Clean up
if: ${{ always() }}
run: |
ls
if (test-path -Path "$env:RUNNER_TEMP\faforever.pfx") {
echo "$env:RUNNER_TEMP\faforever.pfx"
remove-item -Path "$env:RUNNER_TEMP\faforever.pfx" -Force -ErrorAction SilentlyContinue
} else {
echo "File($env:RUNNER_TEMP\faforever.pfx) doesn't exist."
}
if (test-path -Path "$pwd\.env") {
echo "Remove file($pwd\.env)"
remove-item -Path "$pwd\.env" -Force -ErrorAction SilentlyContinue
} else {
echo "File($pwd\.env) doesn't exist."
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ dist/
.env

# FVM Version Cache
.fvm/
.fvm/

/*.wxs
3 changes: 3 additions & 0 deletions msi/faforever/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs
bin
obj
115 changes: 115 additions & 0 deletions msi/faforever/AppComponents.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<?define FlutterBuildOutputDir = "$(env.FLUTTER_BUILD_OUTPUT_DIR)" ?>

<Fragment>
<!-- Define the icon to use for all shortcuts -->
<Icon Id="FaForever.exe" SourceFile="..\..\windows\runner\resources\app_icon.ico"/>

<ComponentGroup Id="BaseComponents" Directory="INSTALLFOLDER">
<Component>
<!-- We wrap single files in components to let the linker generate the GUIDs -->
<File Id="FaForever.exe" Source="$(FlutterBuildOutputDir)\FaForever.exe" KeyPath="yes" />
<Shortcut Name="FaForever" Description="A third-party music player that replaces Synology DS Audio client." Directory="ProgramMenuFolder" Advertise="yes" Icon="FaForever.exe" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\file_selector_windows_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\flutter_windows.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\permission_handler_windows_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\screen_retriever_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\sentry_flutter_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\url_launcher_windows_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\window_manager_plugin.dll" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\LICENSE" />
</Component>
</ComponentGroup>

<ComponentGroup Id="DataComponents" Directory="DATAFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\app.so" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\icudtl.dat" />
</Component>
</ComponentGroup>

<ComponentGroup Id="FlutterAssetComponents" Directory="FLUTTERASSETSFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\AssetManifest.bin" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\AssetManifest.json" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\FontManifest.json" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\NOTICES.Z" />
</Component>
</ComponentGroup>

<ComponentGroup Id="FlutterFontComponents" Directory="FLUTTERFONTSFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\fonts\MaterialIcons-Regular.otf" />
</Component>
</ComponentGroup>

<ComponentGroup Id="FlutterLogoComponents" Directory="FLUTTERLOGOFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\logo\logo.icns" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\logo\logo.png" />
</Component>
</ComponentGroup>

<ComponentGroup Id="FlutterPackageComponents" Directory="FLUTTERPACKAGEFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\cupertino_icons\assets\CupertinoIcons.ttf" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\fluttertoast\assets\toastify.css" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\fluttertoast\assets\toastify.js" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\window_manager\images\ic_chrome_close.png" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\window_manager\images\ic_chrome_maximize.png" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\window_manager\images\ic_chrome_minimize.png" />
</Component>
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\packages\window_manager\images\ic_chrome_unmaximize.png" />
</Component>
</ComponentGroup>

<ComponentGroup Id="ShaderComponents" Directory="SHADERSFOLDER">
<Component>
<File Source="$(FlutterBuildOutputDir)\data\flutter_assets\shaders\ink_sparkle.frag" />
</Component>
</ComponentGroup>

<!-- Desktop shortcut (user's choice) -->
<Component Id="DesktopShortcutComponent" Directory="DesktopFolder">
<RegistryValue Root="HKCU" Key="SOFTWARE\INSCO LLC\FaForever" Name="EnableDesktopShortcut" Value="1" />
<Shortcut Name="FaForever" Description="A third-party music player that replaces Synology DS Audio client." Directory="DesktopFolder" Target="[#FaForever.exe]" />
</Component>
</Fragment>
</Wix>
18 changes: 18 additions & 0 deletions msi/faforever/Folders.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="CompanyFolder" Name="!(bind.Property.Manufacturer)">
<Directory Id="INSTALLFOLDER" Name="!(bind.Property.ProductName)">
<Directory Id="DATAFOLDER" Name="data">
<Directory Id="FLUTTERASSETSFOLDER" Name="flutter_assets">
<Directory Id="FLUTTERFONTSFOLDER" Name="fonts" />
<Directory Id="FLUTTERLOGOFOLDER" Name="logo" />
<Directory Id="FLUTTERPACKAGEFOLDER" Name="packages" />
<Directory Id="SHADERSFOLDER" Name="shaders" />
</Directory>
</Directory>
</Directory>
</Directory>
</StandardDirectory>
</Fragment>
</Wix>
8 changes: 8 additions & 0 deletions msi/faforever/Package.en-us.wxl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
This file contains the declaration of all the localizable strings.
-->
<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">

<String Id="DowngradeError" Value="A newer version of [ProductName] is already installed." />

</WixLocalization>
49 changes: 49 additions & 0 deletions msi/faforever/Package.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="FaForever" Manufacturer="INSCO LLC" Version="1.0.0.0" UpgradeCode="9e9a6c86-498b-45a3-962a-a8023e749b4a">
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />

<!-- Set an icon for Windows Settings > Apps -->
<Property Id="ARPPRODUCTICON" Value="FaForever.exe" />

<!-- Block 64-bit Win8/WinServer2012 (or earlier) and all 32-bit from installing -->
<Launch Message="FaForever only supports 64-bit Windows 10/11!" Condition="Installed OR VersionNT64 >= 603"/>

<MediaTemplate EmbedCab="yes"/>

<Feature
Id="Main"
Title="FaForever"
Description="A third-party music player that replaces Synology DS Audio client."
AllowAbsent="no"
AllowAdvertise="no">
<!-- Flutter output -->
<ComponentGroupRef Id="BaseComponents" />
<ComponentGroupRef Id="DataComponents" />
<ComponentGroupRef Id="FlutterAssetComponents" />
<ComponentGroupRef Id="FlutterFontComponents" />
<ComponentGroupRef Id="FlutterLogoComponents" />
<ComponentGroupRef Id="FlutterPackageComponents" />
<ComponentGroupRef Id="ShaderComponents" />
</Feature>
<Feature
Id="VCredist"
Title="Visual C++ Redistributable Libraries"
Description="Libraries that FaForever uses. You may not need this if you already have vc_redist installed. You should install these if you're unsure of what this means."
AllowAbsent="yes"
AllowAdvertise="no">
<!-- Visual C++ Redustributable libraries -->
<ComponentGroupRef Id="VCredist" />
</Feature>
<!-- -->
<Feature
Id="Shortcut"
Title="FaForever"
Description="A third-party music player that replaces Synology DS Audio client."
AllowAbsent="yes"
AllowAdvertise="no"
Level="1">
<ComponentGroupRef Id="BaseComponents" />
<ComponentRef Id="DesktopShortcutComponent"/>
</Feature>
</Package>
</Wix>
8 changes: 8 additions & 0 deletions msi/faforever/Package.zh-cn.wxl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
This file contains the declaration of all the localizable strings.
-->
<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="zh-CN">

<String Id="DowngradeError" Value="已安装较新版本的[ProductName]." />

</WixLocalization>
Loading

0 comments on commit 1da0be4

Please sign in to comment.