Skip to content

Commit

Permalink
Added powershell shortcut lnk files with customized font and colors f…
Browse files Browse the repository at this point in the history
…or hstwb installer. Updated setup and run scripts detection and validation of emulators. Added install script executed part of msi installer. Updated hstwb installer wix to include latest changes
  • Loading branch information
henrikstengaard committed Oct 2, 2017
1 parent 5836a64 commit 7d762f9
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 114 deletions.
34 changes: 34 additions & 0 deletions install.ps1
@@ -0,0 +1,34 @@
$currentDir = split-path -parent $MyInvocation.MyCommand.Definition
$hstwbInstallerIconFile = Join-Path $currentDir -ChildPath 'hstwb_installer.ico'

$objShell = New-Object -ComObject WScript.Shell

# install launcher.lnk shortcut
$launcherLinkFile = Join-Path $currentDir -ChildPath 'launcher.lnk'
$launcherLink = $objShell.CreateShortcut($launcherLinkFile)
$launcherLink.WorkingDirectory = $currentDir
$launcherLink.IconLocation = "{0},0" -f $hstwbInstallerIconFile
$launcherLink.Save()

# install setup.lnk shortcut
$setupLinkFile = Join-Path $currentDir -ChildPath 'setup.lnk'
$setupLink = $objShell.CreateShortcut($setupLinkFile)
$setupLink.WorkingDirectory = $currentDir
$setupLink.IconLocation = "{0},0" -f $hstwbInstallerIconFile
$setupLink.Save()

# install run.lnk shortcut
$runLinkFile = Join-Path $currentDir -ChildPath 'run.lnk'
$runLink = $objShell.CreateShortcut($runLinkFile)
$runLink.WorkingDirectory = $currentDir
$runLink.IconLocation = "{0},0" -f $hstwbInstallerIconFile
$runLink.Save()

# install fonts
$fonts = 0x14
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($fonts)
$systemFontsDir = $objFolder.Self.Path
$fontsDir = Join-Path $currentDir -ChildPath 'fonts'

Get-ChildItem -Path $fontsDir *.ttf | Where-Object { !(Test-Path (Join-Path $systemFontsDir -ChildPath $_.Name)) } | ForEach-Object { $objFolder.CopyHere($_.FullName) }
3 changes: 2 additions & 1 deletion launcher.cmd
@@ -1 +1,2 @@
powershell -ExecutionPolicy Bypass -nologo -Noninteractive -WindowStyle Hidden -File launcher.ps1
::powershell -ExecutionPolicy Bypass -nologo -Noninteractive -WindowStyle Hidden -File launcher.ps1
start launcher.lnk
Binary file added launcher.lnk
Binary file not shown.
23 changes: 9 additions & 14 deletions launcher.ps1
Expand Up @@ -41,16 +41,14 @@ function ConfirmDialog($title, $message)
return $false
}

function Run($runFile, $settingsDir)
function Run($runFile)
{
$runArgs = "-ExecutionPolicy Bypass -File ""$runFile"" -settingsDir ""$settingsDir"""
Start-Process "powershell.exe" "$runArgs" -Wait -WindowStyle Maximized
Start-Process $runFile -Wait -WindowStyle Maximized
}

function Setup($setupFile, $settingsDir)
function Setup($setupFile)
{
$setupArgs = "-ExecutionPolicy Bypass -File ""$setupFile"" -settingsDir ""$settingsDir"""
Start-Process "powershell.exe" "$setupArgs" -Wait -WindowStyle Maximized
Start-Process $setupFile -Wait -WindowStyle Maximized
}

function Settings($settingsFile)
Expand Down Expand Up @@ -103,10 +101,7 @@ function GuiMenu($title, $options)
$hash = [hashtable]::Synchronized(@{})
$hash.option = $null

$pfc = New-Object System.Drawing.Text.PrivateFontCollection
$pfc.AddFontFile($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('fonts\TopazPlus_a1200_v1.0.ttf'))

$buttonFont = New-Object System.Drawing.Font($pfc.Families[0],14)
$buttonFont = New-Object System.Drawing.Font('TopazPlus a600a1200a4000',14)

$blueColor = [System.Drawing.Color]::FromArgb(0, 85, 170)

Expand Down Expand Up @@ -198,7 +193,7 @@ function LauncherMenu($hstwb)
$option = GuiMenu "Launcher" @('Setup', 'Advanced', 'Extra', 'Help', 'Exit')
switch ($option)
{
"Setup" { Setup $hstwb.Paths.SetupFile $hstwb.Paths.SettingsDir }
"Setup" { Setup $hstwb.Paths.SetupFile }
"Advanced" { AdvancedMenu $hstwb }
"Extra" { ExtraMenu $hstwb }
"Help" { HelpMenu $hstwb }
Expand All @@ -213,7 +208,7 @@ function AdvancedMenu($hstwb)
$option = GuiMenu "Advanced" @('Run', 'Settings', 'Assigns', 'Back')
switch ($option)
{
"Run" { Run $hstwb.Paths.RunFile $hstwb.Paths.SettingsDir }
"Run" { Run $hstwb.Paths.RunFile }
"Settings" { Settings $hstwb.Paths.SettingsFile }
"Assigns" { Assigns $hstwb.Paths.AssignsFile }
}
Expand Down Expand Up @@ -252,8 +247,8 @@ if (!$settingsDir)
$settingsDir = Join-Path $env:LOCALAPPDATA -ChildPath 'HstWB Installer'
}

$runFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('run.ps1')
$setupFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('setup.ps1')
$runFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('run.lnk')
$setupFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('setup.lnk')
$settingsFile = Join-Path $settingsDir -ChildPath 'hstwb-installer-settings.ini'
$assignsFile = Join-Path $settingsDir -ChildPath 'hstwb-installer-assigns.ini'
$host.ui.RawUI.WindowTitle = "HstWB Installer v{0}" -f (HstwbInstallerVersion)
Expand Down
139 changes: 103 additions & 36 deletions modules/config.psm1
Expand Up @@ -103,30 +103,114 @@ function DefaultSettings($settings)
$settings.Emulator.EmulatorFile = DefaultEmulatorFile
}

function DefaultEmulatorFile()
function IsFsuae64bit($fsuaeFile)
{
$fsuaeBytes = [System.IO.File]::ReadAllBytes($fsuaeFile)
$x64PatternBytes = [System.Text.Encoding]::UTF8.GetBytes("windows-x86-64")

for ($i = 0; $i -lt $fsuaeBytes.Count; $i++)
{
if ($fsuaeBytes[$i] -ne $x64PatternBytes[0])
{
continue
}

$hasX64Pattern = $true

for ($j = 0; $j -lt $x64PatternBytes.Count; $j++)
{
if ($i + $j -ge $fsuaeBytes.Count)
{
return $false
}

if ($fsuaeBytes[$i + $j] -ne $x64PatternBytes[$j])
{
$hasX64Pattern = $false
}
}

if ($hasX64Pattern)
{
return $true
}
}

return $false
}

function DetectEmulatorName($emulatorFile)
{
# return winuae 64-bit, if it exists in program files
$winuaeX64Path = "${Env:ProgramFiles}\WinUAE\winuae64.exe"
if (test-path -path $winuaeX64Path)
if (!$emulatorFile -or !(Test-Path -Path $emulatorFile))
{
return $winuaeX64Path
return $null
}

# return winuae 32-bit, if it exists in program files x86
$winuaeX86Path = "${Env:ProgramFiles(x86)}\WinUAE\winuae.exe"
if (test-path -path $winuaeX86Path)
$version = (get-item $emulatorFile).VersionInfo.FileVersion

if ($emulatorFile -match 'winuae64.exe$')
{
return $winuaeX86Path
return 'WinUAE {0} 64-bit' -f $version
}
elseif ($emulatorFile -match 'winuae.exe$')
{
return 'WinUAE {0} 32-bit' -f $version
}
elseif ($emulatorFile -match 'fs-uae.exe$')
{
# if (IsFsuae64bit $emulatorFile)
# {
# $platform = '64-bit'
# }
# else
# {
# $platform = '32-bit'
# }
# return 'FS-UAE {0} {1}' -f $version, $platform
return 'FS-UAE {0}' -f $version
}

return $null
}

function FindEmulators()
{
$emulators = @()

$winuaeX64File = "${Env:ProgramFiles}\WinUAE\winuae64.exe"
if (test-path -path $winuaeX64File)
{
$version = (get-item $winuaeX64File).VersionInfo.FileVersion
$emulators += @{ 'Name' = (DetectEmulatorName $winuaeX64File); 'File' = $winuaeX64File }
}

$winuaeX86File = "${Env:ProgramFiles(x86)}\WinUAE\winuae.exe"
if (test-path -path $winuaeX86File)
{
$version = (get-item $winuaeX86File).VersionInfo.FileVersion
$emulators += @{ 'Name' = (DetectEmulatorName $winuaeX86File); 'File' = $winuaeX86File }
}

# return fs-uae, if it exists in user's local app data
$fsuaeFile = "${Env:LOCALAPPDATA}\fs-uae\fs-uae.exe"
if (test-path -path $fsuaeFile)
{
return $fsuaeFile
$version = (get-item $fsuaeFile).VersionInfo.FileVersion
$emulators += @{ 'Name' = (DetectEmulatorName $fsuaeFile); 'File' = $fsuaeFile }
}

return $null

return $emulators
}

function DefaultEmulatorFile()
{
$defaultEmulator = FindEmulators | Select-Object -First 1

if (!$defaultEmulator)
{
return $null
}

return $defaultEmulator.File
}


Expand All @@ -148,15 +232,13 @@ function UpgradeSettings($hstwb)
$hstwb.Settings.Installer.Mode = "Install"
}


# create packages section in settings, if it doesn't exist
if (!($hstwb.Settings.Packages))
{
$hstwb.Settings.Packages = @{}
$hstwb.Settings.Packages.InstallPackages = ''
}


# create amiga os 3.9 section in settings, if it doesn't exist
if (!($hstwb.Settings.AmigaOS39))
{
Expand All @@ -165,33 +247,34 @@ function UpgradeSettings($hstwb)
$hstwb.Settings.AmigaOS39.InstallBoingBags = 'No'
}


# set default image dir, if image dir doesn't exist
if ($hstwb.Settings.Image.ImageDir -match '^.+$' -and !(test-path -path $hstwb.Settings.Image.ImageDir))
{
$hstwb.Settings.Image.ImageDir = ''
}


# set default emulator, if not present
# add emulator settings, if not present
if (!$hstwb.Settings.Emulator -or !$hstwb.Settings.Emulator.EmulatorFile)
{
$hstwb.Settings.Emulator = @{}
$hstwb.Settings.Emulator.EmulatorFile = DefaultEmulatorFile
$hstwb.SettingsWinUAE
}

if ($hstwb.Settings.WinUAE)
# upgrade winuae to emulator settings
if ($hstwb.Settings.Winuae -and $hstwb.Settings.Winuae.WinuaePath)
{
$hstwb.Settings.Emulator.EmulatorFile = $hstwb.Settings.Winuae.WinuaePath
$hstwb.Settings.Remove('WinUAE')
}

# upgrade workbench adf path to workbench adf dir
if ($hstwb.Settings.Workbench.WorkbenchAdfPath)
{
$hstwb.Settings.Workbench.WorkbenchAdfDir = $hstwb.Settings.Workbench.WorkbenchAdfPath
$hstwb.Settings.Workbench.Remove('WorkbenchAdfPath')
}

# upgrade kickstart rom path to kickstart rom dir
if ($hstwb.Settings.Kickstart.KickstartRomPath)
{
$hstwb.Settings.Kickstart.KickstartRomDir = $hstwb.Settings.Kickstart.KickstartRomPath
Expand Down Expand Up @@ -449,70 +532,54 @@ function ValidateSettings($settings)
return $false
}


# fail, if InstallWorkbench parameter doesn't exist in settings file or is not valid
if (!$settings.Workbench.InstallWorkbench -or $settings.Workbench.InstallWorkbench -notmatch '(Yes|No)')
{
Write-Host "Error: InstallWorkbench parameter doesn't exist in settings file or is not valid!" -ForegroundColor "Red"
return $false
}


# fail, if WorkbenchAdfPath parameter doesn't exist in settings file or directory doesn't exist
if (!$settings.Workbench.WorkbenchAdfDir -or ($settings.Workbench.WorkbenchAdfDir -match '^.+$' -and !(test-path -path $settings.Workbench.WorkbenchAdfDir)))
{
Write-Host "Error: WorkbenchAdfPath parameter doesn't exist in settings file or directory doesn't exist!" -ForegroundColor "Red"
return $false
}


# fail, if WorkbenchAdfSet parameter doesn't exist settings file or it's not defined
if (!$settings.Workbench.WorkbenchAdfSet -or $settings.Workbench.WorkbenchAdfSet -eq '')
{
Write-Host "Error: WorkbenchAdfSet parameter doesn't exist in settings file or it's not defined!" -ForegroundColor "Red"
return $false
}


# fail, if InstallKickstart parameter doesn't exist in settings file or is not valid
if (!$settings.Kickstart.InstallKickstart -or $settings.Kickstart.InstallKickstart -notmatch '(Yes|No)')
{
Write-Host "Error: InstallKickstart parameter doesn't exist in settings file or is not valid!" -ForegroundColor "Red"
return $false
}


# fail, if KickstartRomPath parameter doesn't exist in settings file or directory doesn't exist
if (!$settings.Kickstart.KickstartRomDir -or ($settings.Kickstart.KickstartRomDir -match '^.+$' -and !(test-path -path $settings.Kickstart.KickstartRomDir)))
{
Write-Host "Error: KickstartRomPath parameter doesn't exist in settings file or directory doesn't exist!" -ForegroundColor "Red"
return $false
}


# fail, if KickstartRomSet parameter doesn't exist in settings file or it's not defined
if (!$settings.Kickstart.KickstartRomSet -or $settings.Kickstart.KickstartRomSet -eq '')
{
Write-Host "Error: KickstartRomSet parameter doesn't exist in settings file or it's not defined!" -ForegroundColor "Red"
return $false
}


# fail, if EmulatorFile parameter doesn't exist in settings file or file doesn't exist
if (!$settings.Emulator.EmulatorFile -or ($settings.Emulator.EmulatorFile -match '^.+$' -and !(test-path -path $settings.Emulator.EmulatorFile)))
{
Write-Host "Error: EmulatorFile parameter doesn't exist in settings file or file doesn't exist!" -ForegroundColor "Red"
return $false
}


# fail, if Mode parameter doesn't exist in settings file or is not valid
if (!$settings.Installer.Mode -or $settings.Installer.Mode -notmatch '(Install|BuildSelfInstall|BuildPackageInstallation|Test)')
{
Write-Host "Error: Mode parameter doesn't exist in settings file or is not valid!" -ForegroundColor "Red"
return $false
}


return $true
}
20 changes: 10 additions & 10 deletions modules/dialog.psm1
Expand Up @@ -71,23 +71,23 @@ function PrintSettings($hstwb)

Write-Host "Emulator"
Write-Host " Emulator File : " -NoNewline -foregroundcolor "Gray"
if (Test-Path -Path $hstwb.Settings.Emulator.EmulatorFile)

if ($hstwb.Settings.Emulator.EmulatorFile -and (Test-Path -Path $hstwb.Settings.Emulator.EmulatorFile))
{
$version = (get-item $hstwb.Settings.Emulator.EmulatorFile).VersionInfo.FileVersion
$emulator = Split-Path $hstwb.Settings.Emulator.EmulatorFile -Leaf
$emulatorName = DetectEmulatorName $hstwb.Settings.Emulator.EmulatorFile

switch ($emulator.ToLower())
if ($emulatorName)
{
"fs-uae.exe" { $emulator = "FS-UAE {0}" -f $version }
"winuae.exe" { $emulator = 'WinUAE {0} 32-bit' -f $version }
"winuae64.exe" { $emulator = 'WinUAE {0} 64-bit' -f $version }
Write-Host ("'{0} ({1})'" -f $emulator, $hstwb.Settings.Emulator.EmulatorFile)
}
else
{
Write-Host ("'{0}'" -f $emulator, $hstwb.Settings.Emulator.EmulatorFile)
}

Write-Host ("'{0} ({1})'" -f $emulator, $hstwb.Settings.Emulator.EmulatorFile)
}
else
{
Write-Host ("'{0}'" -f $hstwb.Settings.Emulator.EmulatorFile)
Write-Host "''"
}

Write-Host "Installer"
Expand Down
Binary file added run.lnk
Binary file not shown.

0 comments on commit 7d762f9

Please sign in to comment.