Offline installers (roadmap M1.3): - internal/installer drives `reims-util --json offline-installer` and parses its JSON event stream (upstream reims-vgpu 3731afd, reims_util.rs:423-509) - downloads hold installers/.lock like reims-ctl, so the two never write the same file; checked against the real reims-ctl (TestLockExcludesReimsCtl) - pause = stop the process, rerun resumes; deletes go through `reims-ctl downloads delete`, which refuses files in use or downloading - CLI: reims-go installer list | download | cached | delete - Wails bindings: ListOfflineReleases, DownloadInstaller, ListInstallers, DeleteInstaller Task events (ui-redesign B1): - tasks.go tracks long-running work and emits "reims:task" (throttled to 200 ms per task); VM creation turns reims-ctl's progress lines into task progress and logs each step once - the status bar shows the current task with a progress bar, details in a tooltip and a pause button; the frontend regex merging is removed Win10 cold reboot workaround: - host probes whether WinHvPlatform.dll lacks WHvResetPartition (Win10 19045) - internal/qmp watches a dedicated QMP channel for guest resets; with -no-reboot the app restarts the VM in a fresh partition - architecture.md documents download routing and the workaround Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package installer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"unicode"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// Kind is what an Update reports.
|
|
type Kind string
|
|
|
|
const (
|
|
KindStep Kind = "step" // a new stage starts; Message names it
|
|
KindProgress Kind = "progress" // bytes (or percent) of the current stage
|
|
KindNote Kind = "note" // a line worth showing, not a stage
|
|
)
|
|
|
|
// Update is one progress report from reims-util (JSON events) or reims-ctl
|
|
// (text lines that relay reims-util). Total is 0 when the size is unknown;
|
|
// Percent is -1 then.
|
|
type Update struct {
|
|
Kind Kind `json:"kind"`
|
|
Message string `json:"message,omitempty"`
|
|
Step string `json:"step,omitempty"`
|
|
Done int64 `json:"done"`
|
|
Total int64 `json:"total"`
|
|
Percent float64 `json:"percent"`
|
|
}
|
|
|
|
// event mirrors reims-util's `--json` line format. Upstream reims-vgpu
|
|
// 3731afd, crates/reims-ctl/src/reims_util.rs:423-431: each stdout line is
|
|
// {"event":"step"|"progress"|"note"|"done"|"error", ...}; progress carries
|
|
// done and an optional total; done carries the result.
|
|
type event struct {
|
|
Event string `json:"event"`
|
|
Message string `json:"message"`
|
|
Done int64 `json:"done"`
|
|
Total *int64 `json:"total"`
|
|
Result json.RawMessage `json:"result"`
|
|
}
|
|
|
|
// lowerFirst turns "Downloading OpenCore 1.0.8" into "downloading OpenCore
|
|
// 1.0.8" but leaves "OVMF's code" alone, as reims-ctl shows steps
|
|
// (reims_util.rs:511-521). Keeping the same wording means a step reads the same
|
|
// whether it came from reims-util directly or relayed by reims-ctl.
|
|
func lowerFirst(s string) string {
|
|
a, n := utf8.DecodeRuneInString(s)
|
|
if n == 0 {
|
|
return s
|
|
}
|
|
b, _ := utf8.DecodeRuneInString(s[n:])
|
|
if unicode.IsUpper(a) && unicode.IsLower(b) {
|
|
return string(unicode.ToLower(a)) + s[n:]
|
|
}
|
|
return s
|
|
}
|
|
|
|
func percentOf(done, total int64) float64 {
|
|
if total <= 0 {
|
|
return -1
|
|
}
|
|
if done > total {
|
|
done = total
|
|
}
|
|
return float64(done) * 100 / float64(total)
|
|
}
|
|
|
|
// reims-ctl relays reims-util's progress as text (reims_util.rs:480-488):
|
|
// "<step>: <pct>% of <size>" when the total is known, "<step>: <size>" when
|
|
// not, with size "N MB" or "N.N GB" (reims_util.rs:524-530).
|
|
var (
|
|
ctlPercentRE = regexp.MustCompile(`^(.+?): (\d{1,3})% of (\d+(?:\.\d+)?) (MB|GB)$`)
|
|
ctlSizeRE = regexp.MustCompile(`^(.+?): (\d+(?:\.\d+)?) (MB|GB)$`)
|
|
)
|
|
|
|
func sizeBytes(num, unit string) int64 {
|
|
f, err := strconv.ParseFloat(num, 64)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
if unit == "GB" {
|
|
return int64(f * 1e9)
|
|
}
|
|
return int64(f * 1e6)
|
|
}
|
|
|
|
// ParseCtlLine reads one line of reims-ctl output. Progress lines become
|
|
// KindProgress updates; anything else is a KindNote with the line as is.
|
|
// ok is false for blank lines.
|
|
func ParseCtlLine(line string) (u Update, ok bool) {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
return Update{}, false
|
|
}
|
|
if m := ctlPercentRE.FindStringSubmatch(line); m != nil {
|
|
pct, _ := strconv.Atoi(m[2])
|
|
if pct > 100 {
|
|
pct = 100
|
|
}
|
|
total := sizeBytes(m[3], m[4])
|
|
return Update{
|
|
Kind: KindProgress,
|
|
Step: m[1],
|
|
Done: total * int64(pct) / 100,
|
|
Total: total,
|
|
Percent: float64(pct),
|
|
}, true
|
|
}
|
|
if m := ctlSizeRE.FindStringSubmatch(line); m != nil {
|
|
return Update{Kind: KindProgress, Step: m[1], Done: sizeBytes(m[2], m[3]), Percent: -1}, true
|
|
}
|
|
return Update{Kind: KindNote, Message: line, Percent: -1}, true
|
|
}
|