From 99e40359dd7c27d19ecac3c4b65b8adcc2ccf3e5 Mon Sep 17 00:00:00 2001 From: Shiina_Xi_yu Date: Tue, 20 Aug 2024 22:32:29 +0800 Subject: [PATCH] Show short commit id in Setting and allow msi to override installations of the same main version --- build.gradle.kts | 1 + scripts/Build.ps1 | 23 ++++++++++++++++++- scripts/Update-MSI-ProductCode.ps1 | 18 +++++++++++++++ src/main/kotlin/moe/sekiu/minilpa/Main.kt | 3 ++- .../moe/sekiu/minilpa/ui/SettingPanel.kt | 15 +++++++++++- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 scripts/Update-MSI-ProductCode.ps1 diff --git a/build.gradle.kts b/build.gradle.kts index 29708f83..8e7f4b39 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -86,6 +86,7 @@ buildConfig { && project.findProperty("type") != "app-image" ) buildConfigField("VERSION", "$version") + buildConfigField("SHORT_COMMIT_ID", project.findProperty("short-commit-id") as String? ?: "internal") } application { diff --git a/scripts/Build.ps1 b/scripts/Build.ps1 index 487eec9f..afdde561 100644 --- a/scripts/Build.ps1 +++ b/scripts/Build.ps1 @@ -54,6 +54,12 @@ if ($GithubToken) $BuildArgument += "-Pgithub-token=$GithubToken" } +git diff --no-ext-diff --quiet --exit-code +$IsDirty = $LASTEXITCODE +$ShortCommitId = git rev-parse --short HEAD +if ($IsDirty) { $ShortCommitId = "$ShortCommitId-dirty" } +$BuildArgument += "-Pshort-commit-id=$ShortCommitId" + Push-Location $ProjectRootPath & $GradlewPath $BuildArgument --info --stacktrace Pop-Location @@ -87,5 +93,20 @@ if ($NativeExecutableType -eq 'app-image') } else { - Get-ChildItem -Path $DistFolderPath -File -Filter 'MiniLPA*' | ForEach-Object { Move-Item -Path $_.FullName -Destination "$DistFolderPath$Name$($_.Extension)" -Force } + Get-ChildItem -Path $DistFolderPath -File -Filter "MiniLPA*$NativeExecutableType" | ForEach-Object { + $DistPath = "$DistFolderPath$Name$( $_.Extension )" + Move-Item -Path $_.FullName -Destination $DistPath -Force + if ($NativeExecutableType -eq "msi") + { + if ($IsDirty) { $Guid = [System.Guid]::NewGuid() } + else + { + $CommitId = git rev-parse HEAD + $CommitIdBytes = [System.Text.Encoding]::UTF8.GetBytes($CommitId) + $GuidBytes = $CommitIdBytes[0..15] -as [Byte[]] + $Guid = [System.Guid]::new($guidBytes) + } + & "$PSScriptRoot/Update-MSI-ProductCode.ps1" -Path $DistPath -ProductCode "{$($Guid.Guid)}" + } + } } \ No newline at end of file diff --git a/scripts/Update-MSI-ProductCode.ps1 b/scripts/Update-MSI-ProductCode.ps1 new file mode 100644 index 00000000..04a70de7 --- /dev/null +++ b/scripts/Update-MSI-ProductCode.ps1 @@ -0,0 +1,18 @@ +#!/usr/bin/env pwsh +param( + [String]$Path, + [String]$ProductCode +) + +$WindowsInstaller = New-Object -com WindowsInstaller.Installer +$Database = $WindowsInstaller.OpenDatabase($Path, 2) +$Query = "UPDATE Property SET Property.Value='$ProductCode' WHERE Property.Property='ProductCode'" +$View = $Database.OpenView($Query) +$View.Execute() +$Database.Commit() +$View.Close() + +$View = $null +$Database = $null +[System.GC]::Collect() +[System.GC]::WaitForPendingFinalizers() \ No newline at end of file diff --git a/src/main/kotlin/moe/sekiu/minilpa/Main.kt b/src/main/kotlin/moe/sekiu/minilpa/Main.kt index 2462dcf5..49498ec4 100644 --- a/src/main/kotlin/moe/sekiu/minilpa/Main.kt +++ b/src/main/kotlin/moe/sekiu/minilpa/Main.kt @@ -147,7 +147,7 @@ fun extractResources() if (BuildConfig.LPAC_BUILD_TIME > setting.`lpac-build-time`) { ZipInputStream(bufferedResourceStream("$platform.zip")).unzip(lpacFolder) - setting.update { `lpac-build-time` = BuildConfig.LPAC_BUILD_TIME } + setting.update { `lpac-build-time` = BuildConfig.LPAC_BUILD_TIME } } } @@ -160,6 +160,7 @@ fun setupLogBack() : Logger log.info("Runtime Version: ${SystemUtils.JAVA_VM_VERSION} ${SystemUtils.OS_ARCH}") log.info("VM: ${SystemUtils.JAVA_VM_NAME}, ${SystemUtils.JAVA_VM_VENDOR}") log.info("IS_PACKAGE -> ${BuildConfig.IS_PACKAGED}") + log.info("SHORT_COMMIT_ID -> ${BuildConfig.SHORT_COMMIT_ID}") log.info("AppDataFolder -> ${appDataFolder.canonicalPath}") return log } \ No newline at end of file diff --git a/src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt b/src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt index 7277bb1c..f055c0ec 100644 --- a/src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt +++ b/src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt @@ -6,6 +6,7 @@ import com.formdev.flatlaf.FlatClientProperties import com.formdev.flatlaf.FlatLaf import com.formdev.flatlaf.extras.FlatSVGIcon import com.jthemedetecor.OsThemeDetector +import java.awt.Color import java.io.File import java.util.* import javax.swing.DefaultComboBoxModel @@ -66,7 +67,19 @@ class SettingPanel : MiniPanel() layout = MigLayout("", "[]20[]") val infoPanel = MiniPanel() infoPanel.layout = MigLayout("wrap 1, insets 0") - infoPanel.add(JLabel("MiniLPA ${BuildConfig.VERSION}").apply { putClientProperty(FlatClientProperties.STYLE_CLASS, "h3") }) + infoPanel.add(MiniGroup( + JLabel("MiniLPA ${BuildConfig.VERSION}").apply { putClientProperty(FlatClientProperties.STYLE_CLASS, "h3") }, + MiniPanel().apply { + layout = MigLayout("insets 2") + isOpaque = true + background = Color(128, 128, 128, 64) + putClientProperty(FlatClientProperties.STYLE, "arc: 8") + add(JLabel(BuildConfig.SHORT_COMMIT_ID).apply { + foreground = Color(128, 128, 128, 255) + putClientProperty(FlatClientProperties.STYLE, "font: \$mini.font") + }) + } + )) infoPanel.add(JLabel(language.`runtime-version`.format("${SystemUtils.JAVA_VM_VERSION} ${SystemUtils.OS_ARCH}"))) infoPanel.add(JLabel(language.VM.format("${SystemUtils.JAVA_VM_NAME}, ${SystemUtils.JAVA_VM_VENDOR}"))) add(JLabel(FlatSVGIcon("icons/window.svg", 64, 64)))