updated spm package
This commit is contained in:
parent
b403befe74
commit
48473f98c5
16 changed files with 1454 additions and 505 deletions
77
installer.go
77
installer.go
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"spitfire-installer/spm"
|
||||
)
|
||||
|
||||
|
@ -19,10 +19,6 @@ type Installer struct {
|
|||
DoneInstall bool
|
||||
LastError error
|
||||
PendingInstall bool
|
||||
|
||||
// Paths
|
||||
DownloadDir string
|
||||
TempDir string
|
||||
}
|
||||
|
||||
// NewInstaller creates a new Installer with initial state.
|
||||
|
@ -36,66 +32,67 @@ func (inst *Installer) StartDownloadDecompress() {
|
|||
go func() {
|
||||
defer func() {
|
||||
inst.IsDownloading = false
|
||||
// Signal that download phase is complete.
|
||||
inst.DoneDownload = (inst.LastError == nil)
|
||||
|
||||
// If user requested install while we were downloading (PendingInstall),
|
||||
// automatically do the install now that we're done decompressing.
|
||||
// If a final install was requested, go ahead.
|
||||
if inst.PendingInstall && inst.DoneDownload && !inst.IsInstalling && !inst.DoneInstall {
|
||||
inst.doFinalInstall()
|
||||
}
|
||||
}()
|
||||
|
||||
spm.UpdateProgress(0, "Preparing to download...")
|
||||
inst.DownloadDir = spm.GetTempDownloadDir()
|
||||
|
||||
// 1) Download APPINDEX
|
||||
appIndexPath := filepath.Join(inst.DownloadDir, "APPINDEX")
|
||||
spm.UpdateProgress(0, "Downloading APPINDEX")
|
||||
if err := spm.DownloadAppIndex(appIndexPath); err != nil {
|
||||
// Define the package specifications.
|
||||
specs := []spm.AppIndexEntry{
|
||||
{
|
||||
Name: "spitfire-luncher",
|
||||
Release: "nightly",
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
Type: "luncher",
|
||||
},
|
||||
{
|
||||
Name: "spitfire-browser",
|
||||
Release: "nightly",
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
Type: "browser",
|
||||
},
|
||||
}
|
||||
|
||||
spm.UpdateProgress(0, "Downloading specified packages...")
|
||||
if err := spm.AutoDownloadSpecified(specs); err != nil {
|
||||
fmt.Println("AutoDownloadSpecifiedPackages failed:", err)
|
||||
inst.LastError = err
|
||||
return
|
||||
}
|
||||
|
||||
// 2) Download package
|
||||
packageName := "spitfire-browser"
|
||||
release := "nightly"
|
||||
spm.UpdateProgress(0, "Downloading package...")
|
||||
if err := spm.DownloadPackageFromAppIndex(appIndexPath, packageName, release, inst.DownloadDir); err != nil {
|
||||
inst.LastError = err
|
||||
return
|
||||
}
|
||||
|
||||
// 3) Decompress
|
||||
spm.UpdateProgress(0, "Decompressing...")
|
||||
tempDir, err := spm.DecompressPackage(inst.DownloadDir)
|
||||
if err != nil {
|
||||
inst.LastError = err
|
||||
return
|
||||
}
|
||||
inst.TempDir = tempDir
|
||||
spm.UpdateProgress(0, "Download and decompression complete!")
|
||||
// Here, update your installer state so FinalInstall() can proceed.
|
||||
inst.DoneDownload = true
|
||||
}()
|
||||
}
|
||||
|
||||
// FinalInstall is called by the UI to request installation.
|
||||
// If download is done, it runs immediately, otherwise sets PendingInstall=true.
|
||||
func (inst *Installer) FinalInstall() {
|
||||
// Already installed or installing => ignore repeated calls
|
||||
// Already installed or installing => ignore repeated calls.
|
||||
if inst.IsInstalling || inst.DoneInstall {
|
||||
return
|
||||
}
|
||||
|
||||
// If not done downloading, just mark that we want to install once finished
|
||||
// If not done downloading, mark that we want to install once finished.
|
||||
if !inst.DoneDownload {
|
||||
fmt.Println("Cannot install now: download and decompression not complete -> pending install.")
|
||||
inst.PendingInstall = true
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, go ahead and install now
|
||||
// Otherwise, go ahead and install now.
|
||||
inst.doFinalInstall()
|
||||
}
|
||||
|
||||
// doFinalInstall does the actual file move and sets states
|
||||
// doFinalInstall does the actual installation by invoking AutoInstallUpdates.
|
||||
func (inst *Installer) doFinalInstall() {
|
||||
inst.IsInstalling = true
|
||||
inst.PendingInstall = false // we are fulfilling the install now
|
||||
|
@ -106,16 +103,8 @@ func (inst *Installer) doFinalInstall() {
|
|||
inst.DoneInstall = (inst.LastError == nil)
|
||||
}()
|
||||
|
||||
// Generate default install directory
|
||||
installDir, err := spm.GetDefaultInstallDir()
|
||||
if err != nil {
|
||||
inst.LastError = fmt.Errorf("failed to determine default install directory: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Move files
|
||||
spm.UpdateProgress(0, "Installing...")
|
||||
if err := spm.MoveFilesToInstallDir(inst.TempDir, installDir); err != nil {
|
||||
spm.UpdateProgress(0, "Installing updates...")
|
||||
if err := spm.AutoInstallUpdates(); err != nil {
|
||||
inst.LastError = err
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue