-
Notifications
You must be signed in to change notification settings - Fork 10
/
types.go
156 lines (129 loc) · 3.59 KB
/
types.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"context"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"time"
)
type UiFile struct {
Filepath string
Progress float64
Bytes int64
Done bool
}
type IndexedFile struct {
Filepath string `json:"path"`
Size int64 `json:"size"`
CRC32 int `json:"crc32"`
RetryCount int
}
type IndexOverview struct {
Name string `json:"name"`
TotalSize int64 `json:"total_size"`
TotalFiles int64 `json:"total_files"`
BaseUrl string `json:"base_url"`
}
type Config struct {
MetaUrl string `json:"meta_url"`
}
type Meta struct {
Current string `json:"current"`
Path string `json:"path"`
Available []string `json:"available"`
}
type InstallerState struct {
Busy bool // Prevent button presses colliding mid-execution
Grabber *Downloader
Repo *SqliteRepo
Config *Config
Meta *Meta
App fyne.App
window fyne.Window
folderPath binding.String
installName binding.String
totalFiles int64
totalSize int64
downloadedSize int64
downloadedFiles int64
downloadSpeed float64
downloadFailures int64
baseUrl string
runningLabel binding.String
formatDownloadedFiles binding.String
formatDownloadedSize binding.String
formatTotalSize binding.String
formatTotalFiles binding.String
formatDownloadSpeed binding.String
formatDownloadFailures binding.String
progressBarTotal binding.Float
fileProgress1 binding.Float
fileProgress2 binding.Float
fileProgress3 binding.Float
fileProgress4 binding.Float
fileTitle1 binding.String
fileTitle2 binding.String
fileTitle3 binding.String
fileTitle4 binding.String
rateLimitEntry binding.String
formatRateLimit binding.String
resumable bool
}
type NoValidPathFoundError struct{}
func (e *NoValidPathFoundError) Error() string {
return "No valid path found"
}
type BrokenResumableState struct {
err error
}
func (e *BrokenResumableState) Error() string {
return fmt.Sprintf("Broken resumable state found, must use a new index\n%s", e.err.Error())
}
type DownloadFailure struct {
err error
}
func (e *DownloadFailure) Error() string {
return fmt.Sprintf("Download failure after 5 retries, retry later.\n%s", e.err.Error())
}
type FatalDownloadFailure struct {
err error
}
func (e *FatalDownloadFailure) Error() string {
return fmt.Sprintf("Fatal download failure\n%s", e.err.Error())
}
type DatabaseError struct {
err error
}
func (e *DatabaseError) Error() string {
return fmt.Sprintf("Fatal database error\n%s", e.err.Error())
}
type BadRateLimit struct{}
func (e *BadRateLimit) Error() string {
return "Invalid rate limit"
}
type ConfigError struct {
err error
}
func (e *ConfigError) Error() string {
return fmt.Sprintf("Failed to load config\n%s", e.err.Error())
}
type MetaError struct {
err error
}
func (e *MetaError) Error() string {
return fmt.Sprintf("Failed to load meta.json from remote, cannot continue\n%s", e.err.Error())
}
type VersionTooOld struct{}
func (e *VersionTooOld) Error() string {
return "Current version too old, you must upgrade to continue install"
}
type DownloadRateLimiter struct {
rate int
total int64
}
func (c *DownloadRateLimiter) WaitN(_ context.Context, bytes int) (err error) {
c.total += int64(bytes)
time.Sleep(
time.Duration(1.00 / float64(c.rate) * float64(bytes) * float64(time.Second)))
return
}