diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af4847..88599a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.2.0 (2024-05-06) + +- Update checker +- More structural changes + +**Full Changelog**: https://github.com/djohts/tpc-truckersmp/compare/v2.1.0...v2.2.0 + ## 2.1.0 (2024-05-06) - Improved logging diff --git a/constants/constants.go b/constants/constants.go index a536ff0..bcf9e5e 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -1,6 +1,12 @@ package constants const ( + APP_VERSION = `2.2.0` + ETS = `Euro Truck Simulator 2` ATS = `American Truck Simulator` ) + +var ( + DocumentsPath string +) diff --git a/constants/variables.go b/constants/variables.go deleted file mode 100644 index f76c96a..0000000 --- a/constants/variables.go +++ /dev/null @@ -1,5 +0,0 @@ -package constants - -var ( - DocumentsPath string -) diff --git a/go.mod b/go.mod index 45b538e..96b0b3e 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,10 @@ require ( git.tcp.direct/kayos/sendkeys v0.0.0-20211216174833-565f782ccf21 github.com/bradhe/stopwatch v0.0.0-20190618212248-a58cccc508ea github.com/charmbracelet/log v0.4.0 + github.com/coreos/go-semver v0.3.1 github.com/creasty/defaults v1.7.0 github.com/fsnotify/fsnotify v1.7.0 + github.com/google/go-github/v61 v61.0.0 golang.org/x/sys v0.20.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -16,6 +18,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/lipgloss v0.10.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.18 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect diff --git a/go.sum b/go.sum index 83add88..10cba5a 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,19 @@ github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMt github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA= github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= +github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= @@ -36,6 +43,7 @@ golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQz golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index f1e9d28..3f214a0 100644 --- a/main.go +++ b/main.go @@ -2,15 +2,19 @@ package main import ( "errors" + "fmt" "github.com/charmbracelet/log" "github.com/djohts/tpc-truckersmp/config" "github.com/djohts/tpc-truckersmp/constants" + "github.com/djohts/tpc-truckersmp/updater" "github.com/djohts/tpc-truckersmp/utils" "github.com/djohts/tpc-truckersmp/watcher" ) func main() { + fmt.Println("tpc-truckersmp", "v"+constants.APP_VERSION, "by djohts") + if !utils.IsFile("SII_Decrypt.exe") { utils.HandleError(errors.New("SII_Decrypt.exe does not exist")) } @@ -21,7 +25,15 @@ func main() { log.Info(" 2. Make a quicksave & reload 1-2 seconds later") log.Info("======================================================") - err := config.Init() + log.Info("Checking for updates...") + needsUpdate, latest, err := updater.CheckUpdates() + if err != nil { + log.Error("Failed to check for updates", "error", err) + } else if needsUpdate { + log.Info("New version available", "current", constants.APP_VERSION, "latest", latest[1:]) + } + + err = config.Init() utils.HandleError(err) DocumentsPath := &constants.DocumentsPath diff --git a/updater/updater.go b/updater/updater.go new file mode 100644 index 0000000..cc69617 --- /dev/null +++ b/updater/updater.go @@ -0,0 +1,26 @@ +package updater + +import ( + "context" + + "github.com/coreos/go-semver/semver" + "github.com/djohts/tpc-truckersmp/constants" + "github.com/google/go-github/v61/github" +) + +func CheckUpdates() (bool, string, error) { + client := github.NewClient(nil) + releases, _, err := client.Repositories.ListReleases(context.Background(), "djohts", "tpc-truckersmp", nil) + if err != nil { + return false, "", err + } + + if len(releases) == 0 { + return false, "", nil + } + + latestRelease := releases[0] + needsUpdate := semver.New(constants.APP_VERSION).LessThan(*semver.New((*latestRelease.TagName)[1:])) + + return needsUpdate, *latestRelease.TagName, nil +}