install.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $ErrorActionPreference = 'Stop'
  2. $appName = 'ComputerShopWpf'
  3. $displayName = 'Продажа компьютерной техники'
  4. $sourceDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  5. $installDir = Join-Path $env:LOCALAPPDATA $appName
  6. if (-not (Test-Path -LiteralPath $installDir)) {
  7. New-Item -ItemType Directory -Path $installDir | Out-Null
  8. }
  9. Get-ChildItem -LiteralPath $sourceDir -Force |
  10. Where-Object { $_.Name -notin @('install.cmd', 'install.ps1') } |
  11. Copy-Item -Destination $installDir -Recurse -Force
  12. $exePath = Join-Path $installDir 'ComputerShopWpf.exe'
  13. if (-not (Test-Path -LiteralPath $exePath)) {
  14. throw "ComputerShopWpf.exe was not copied to $installDir"
  15. }
  16. $databaseDir = Join-Path $installDir 'Database'
  17. if (-not (Test-Path -LiteralPath $databaseDir)) {
  18. New-Item -ItemType Directory -Path $databaseDir | Out-Null
  19. }
  20. $flatSqlPath = Join-Path $installDir 'create_database.sql'
  21. if (Test-Path -LiteralPath $flatSqlPath) {
  22. Copy-Item -LiteralPath $flatSqlPath -Destination (Join-Path $databaseDir 'create_database.sql') -Force
  23. }
  24. $desktopPath = [Environment]::GetFolderPath('DesktopDirectory')
  25. $shortcutPath = Join-Path $desktopPath "$displayName.lnk"
  26. $shell = New-Object -ComObject WScript.Shell
  27. $shortcut = $shell.CreateShortcut($shortcutPath)
  28. $shortcut.TargetPath = $exePath
  29. $shortcut.WorkingDirectory = $installDir
  30. $shortcut.IconLocation = $exePath
  31. $shortcut.Description = $displayName
  32. $shortcut.Save()
  33. $uninstallShortcutPath = Join-Path $desktopPath "$displayName - удалить.lnk"
  34. $uninstallScript = Join-Path $installDir 'uninstall.ps1'
  35. if (Test-Path -LiteralPath $uninstallScript) {
  36. $uninstallShortcut = $shell.CreateShortcut($uninstallShortcutPath)
  37. $uninstallShortcut.TargetPath = 'powershell.exe'
  38. $uninstallShortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$uninstallScript`""
  39. $uninstallShortcut.WorkingDirectory = $installDir
  40. $uninstallShortcut.Description = "Удалить $displayName"
  41. $uninstallShortcut.Save()
  42. }
  43. $shell.Popup("Приложение установлено в $installDir.`nЯрлык создан на рабочем столе.", 0, $displayName, 64) | Out-Null