Skip to content

Commit

Permalink
Show short commit id in Setting and allow msi to override installatio…
Browse files Browse the repository at this point in the history
…ns of the same main version
  • Loading branch information
ShiinaSekiu committed Aug 20, 2024
1 parent feef424 commit 99e4035
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 22 additions & 1 deletion scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}"
}
}
}
18 changes: 18 additions & 0 deletions scripts/Update-MSI-ProductCode.ps1
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion src/main/kotlin/moe/sekiu/minilpa/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand All @@ -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
}
15 changes: 14 additions & 1 deletion src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 99e4035

Please sign in to comment.