forked from dmitmel/CCUpdaterUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
warnings.go
63 lines (58 loc) · 2.02 KB
/
warnings.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
package middle
import (
"github.com/CCDirectLink/CCUpdaterCLI"
"github.com/Masterminds/semver"
)
// WarningID represents a kind of warning action.
type WarningID int
const (
// NullActionWarningID cannot be automatically fixed.
NullActionWarningID WarningID = iota
// InstallOrUpdatePackageWarningID warnings can be solved by installing/updating the package Parameter.
InstallOrUpdatePackageWarningID
)
// Warning represents a warning to show the user on the primary view.
type Warning struct {
Text string
Action WarningID
Parameter string
}
// FindWarnings detects issues with the installation to show on the primary view.
func FindWarnings(game *ccmodupdater.GameInstance) []Warning {
warnings := []Warning{}
if InternetConnectionWarning {
warnings = append(warnings, Warning{
Text: "CCUpdaterUI wasn't able to retrieve the mod metadata; downloading mods is not possible.",
})
}
crosscode := game.Packages()["crosscode"]
if crosscode == nil {
warnings = append(warnings, Warning{
Text: "CrossCode is not installed in this installation. (Ok, come on, how'd you manage this? - 20kdc)",
})
} else if crosscode.Metadata().Version().LessThan(semver.MustParse("1.1.0")) {
warnings = append(warnings, Warning{
Text: "The CrossCode version is " + crosscode.Metadata().Version().Original() + "; mods usually expect 1.1.0 or higher.",
})
}
ccloader := game.Packages()["ccloader"]
if ccloader == nil {
warnings = append(warnings, Warning{
Text: "No modloader is installed; thus any mods installed cannot be run.",
Action: InstallOrUpdatePackageWarningID,
Parameter: "ccloader",
})
} else {
remoteCCLoader := GetRemotePackages()["ccloader"]
if remoteCCLoader != nil {
if remoteCCLoader.Metadata().Version().GreaterThan(ccloader.Metadata().Version()) {
warnings = append(warnings, Warning{
Text: "CCLoader is out of date. This may cause buggy behavior, or mods may rely on missing features.",
Action: InstallOrUpdatePackageWarningID,
Parameter: "ccloader",
})
}
}
}
return warnings
}