-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinstaller.go
94 lines (73 loc) · 2.24 KB
/
installer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package installer
import (
"context"
"errors"
"os"
"github.com/itchio/boar"
"github.com/itchio/butler/installer/bfs"
"github.com/itchio/savior"
"github.com/itchio/wharf/eos"
"github.com/itchio/wharf/state"
)
var ErrNeedLocal = errors.New("install source needs to be available locally")
type Manager interface {
Install(params *InstallParams) (*InstallResult, error)
Uninstall(params *UninstallParams) error
Name() string
}
type InstallParams struct {
// An archive file, .exe setup file, .dmg file etc.
File eos.File
// The existing receipt, if any
ReceiptIn *bfs.Receipt
// A folder we can use to store temp files
StageFolderPath string
// The folder we're installing to
InstallFolderPath string
// Listener for progress events, logging etc.
Consumer *state.Consumer
InstallerInfo *InstallerInfo
// For cancellation
Context context.Context
}
type UninstallParams struct {
// The folder we're uninstalling from
InstallFolderPath string
// Listener for progress events, logging etc.
Consumer *state.Consumer
// Receipt at the time we asked for an uninstall
Receipt *bfs.Receipt
}
type InstallResult struct {
// Files is a list of paths, relative to the install folder
Files []string
// optional, installer-specific fields:
MSIProductCode string
}
type InstallerInfo struct {
Type InstallerType
ArchiveInfo *boar.Info
Entries []*savior.Entry
}
type InstallerType string
const (
InstallerTypeNaked InstallerType = "naked"
InstallerTypeArchive InstallerType = "archive"
InstallerTypeDMG InstallerType = "dmg"
InstallerTypeInno InstallerType = "inno"
InstallerTypeNsis InstallerType = "nsis"
InstallerTypeMSI InstallerType = "msi"
InstallerTypeUnknown InstallerType = "unknown"
InstallerTypeUnsupported InstallerType = "unsupported"
)
// AsLocalFile takes an eos.File and tries to cast it to an *os.File.
// If that fails, it returns `ErrNeedLocal`. Consumers of functions that
// call + relay AsLocalFile's errors are expected to know how to
// download a file to disk and call again with an *os.File instance instead
// of, say, an *htfs.File
func AsLocalFile(f eos.File) (*os.File, error) {
if lf, ok := f.(*os.File); ok {
return lf, nil
}
return nil, ErrNeedLocal
}