-
Notifications
You must be signed in to change notification settings - Fork 28
/
apps.go
76 lines (64 loc) · 1.61 KB
/
apps.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
package steamapi
import (
"errors"
"net/url"
"strconv"
)
type SteamApp struct {
AppId uint64
Name string
}
type appListJson struct {
Applist struct {
Apps []SteamApp
}
}
type upToDateCheckJson struct {
Response struct {
Success bool
UpToDate bool `json:"up_to_date"`
Listable bool `json:"version_is_listable"`
CurrentVersion uint `json:"required_version,omitempty"`
Message string `json:"omitempty"`
Error string `json:"omitempty"`
}
}
func GetAppList() ([]SteamApp, error) {
getAppList := NewSteamMethod("ISteamApps", "GetAppList", 2)
var resp appListJson
err := getAppList.Request(nil, &resp)
if err != nil {
return nil, err
}
return resp.Applist.Apps, nil
}
func IsAppUpToDate(app int, version uint) (bool, error) {
upToDateCheck := NewSteamMethod("ISteamApps", "UpToDateCheck", 1)
vals := url.Values{}
vals.Add("appid", strconv.Itoa(app))
vals.Add("version", strconv.FormatUint(uint64(version), 10))
var resp upToDateCheckJson
err := upToDateCheck.Request(vals, &resp)
if err != nil {
return false, err
}
if !resp.Response.Success {
return false, errors.New(resp.Response.Error)
}
return resp.Response.UpToDate, nil
}
func GetCurrentAppVersion(app int) (uint, error) {
upToDateCheck := NewSteamMethod("ISteamApps", "UpToDateCheck", 1)
vals := url.Values{}
vals.Add("appid", strconv.Itoa(app))
vals.Add("version", "1")
var resp upToDateCheckJson
err := upToDateCheck.Request(vals, &resp)
if err != nil {
return 0, err
}
if !resp.Response.Success {
return 0, errors.New(resp.Response.Error)
}
return resp.Response.CurrentVersion, nil
}