This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
forked from dmitmel/CCUpdaterUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remotePkgs.go
50 lines (44 loc) · 1.47 KB
/
remotePkgs.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
package middle
import (
"github.com/CCDirectLink/CCUpdaterCLI"
"github.com/CCDirectLink/CCUpdaterCLI/remote"
"github.com/20kdc/CCUpdaterUI/design"
)
// FakeError should be enabled to prevent internet access by CCUpdaterUI.
const FakeError bool = false
// InternetConnectionWarning is true if the last GetRemotePackages() call actually resulted in error.
var InternetConnectionWarning bool = true
// GetRemotePackages retrieves remote packages from the server. (The CCUpdaterCLI-level cache semantics still apply.)
func GetRemotePackages() map[string]ccmodupdater.RemotePackage {
InternetConnectionWarning = true
if !FakeError {
remote, err := remote.GetRemotePackages()
if err == nil {
InternetConnectionWarning = false
return remote
}
}
return map[string]ccmodupdater.RemotePackage{}
}
// GetLatestOf returns the latest of two possibly-nil packages (returning nil if both are nil)
func GetLatestOf(local ccmodupdater.Package, remote ccmodupdater.Package) ccmodupdater.Package {
if local != nil {
if remote != nil {
if remote.Metadata().Version().GreaterThan(local.Metadata().Version()) {
return remote
}
}
return local
}
return remote
}
// PackageIcon returns the relevant icon ID for a package.
func PackageIcon(pkg ccmodupdater.Package) design.IconID {
typ := pkg.Metadata().Type()
if typ == ccmodupdater.PackageTypeMod {
return design.ModIconID
} else if typ == ccmodupdater.PackageTypeTool {
return design.ToolIconID
}
return design.DirectoryIconID
}