From e36babb9f5f697ac2a366be5831b0b1fc4d5c478 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Wed, 23 Aug 2023 19:07:48 +0800 Subject: [PATCH] Check for and add reflex repo during updater launch --- README.md | 2 +- mister/go.mod | 10 +++++----- mister/go.sum | 10 ++++++++++ mister/main.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 07e3252..521cc2e 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,5 @@ Alternatively, manually add the following to your `downloader.ini` file on the S ``` [misteraddons/reflexadapt] -db_url = https://github.com/misteraddons/mappings-reflex_adapt/raw/main/reflexadapt.json.zip +db_url = https://github.com/misteraddons/Reflex-Adapt/raw/main/reflexadapt.json.zip ``` diff --git a/mister/go.mod b/mister/go.mod index 59a8c7c..428f58c 100644 --- a/mister/go.mod +++ b/mister/go.mod @@ -2,7 +2,7 @@ module github.com/wizzomafizzo/misteraddons/reflex/updater go 1.20 -require github.com/wizzomafizzo/mrext v0.0.0-20230805125706-13ef364a1dc9 +require github.com/wizzomafizzo/mrext v0.0.0-20230823092202-e9e36aa31e29 require ( github.com/bendahl/uinput v1.6.2 // indirect @@ -12,12 +12,12 @@ require ( github.com/miekg/dns v1.1.55 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/txn2/txeh v1.4.0 // indirect - golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect - golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.11.0 // indirect + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/term v0.11.0 // indirect - golang.org/x/tools v0.10.0 // indirect + golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect ) diff --git a/mister/go.sum b/mister/go.sum index f0ef5f4..aef5091 100644 --- a/mister/go.sum +++ b/mister/go.sum @@ -30,18 +30,26 @@ github.com/wizzomafizzo/mrext v0.0.0-20230727064047-3a4696e9717b h1:heqfifGOKWK5 github.com/wizzomafizzo/mrext v0.0.0-20230727064047-3a4696e9717b/go.mod h1:hVffvRZS/JL3JqEQOV3pPQYF47gPhNpPZ9j6fEpt02M= github.com/wizzomafizzo/mrext v0.0.0-20230805125706-13ef364a1dc9 h1:A93JgUZsHxqDgpmIiASrZL6lOXgyz6BT6dYuRErGt5A= github.com/wizzomafizzo/mrext v0.0.0-20230805125706-13ef364a1dc9/go.mod h1:08jkztEp9gtPxSnhUKdfSdjmiviHMmm1NyZ3luKegjM= +github.com/wizzomafizzo/mrext v0.0.0-20230823092202-e9e36aa31e29 h1:T+VAxN3cYdwR843GPJf4Vr7qwTYsnaFZhVy2MJBd9pw= +github.com/wizzomafizzo/mrext v0.0.0-20230823092202-e9e36aa31e29/go.mod h1:iNZCxw1JY8bIzWh0L9MfpSe9bYDCLdrPgyqlgqoj7s8= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -62,6 +70,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= +golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 h1:Vve/L0v7CXXuxUmaMGIEK/dEeq7uiqb5qBgQrZzIE7E= +golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= diff --git a/mister/main.go b/mister/main.go index 3819593..77bf22d 100644 --- a/mister/main.go +++ b/mister/main.go @@ -3,6 +3,7 @@ package main import ( "embed" "fmt" + "github.com/wizzomafizzo/mrext/pkg/config" "github.com/wizzomafizzo/mrext/pkg/mister" "github.com/wizzomafizzo/mrext/pkg/utils" "io" @@ -19,6 +20,10 @@ import ( const ( reflexBinName = "reflex-linux-armv7" adaptQuirks = "0x2341:0x8036:0x040" + dbName = "misteraddons/reflexadapt" + dbUrl = "https://github.com/misteraddons/Reflex-Adapt/raw/main/reflexadapt.json.zip" + configFolder = config.ScriptsConfigFolder + "/reflex" + noDbFile = configFolder + "/.no-db-reflexadapt" ) //go:embed _files @@ -131,6 +136,45 @@ func tryUpdateUboot() (bool, error) { return false, nil } +// tryAddDb prompts if the user wants the updater repo db added to their downloader.ini file. Optionally, they can +// say no and the check will be disabled. +func tryAddDb() (bool, error) { + _ = os.MkdirAll(configFolder, 0755) + + if _, err := os.Stat(noDbFile); err == nil { + return false, nil + } + + downloadIni, err := mister.LoadDownloaderIni() + if err != nil { + return false, err + } + if downloadIni.HasDb(dbName) { + return false, nil + } + + answer := utils.YesOrNoPrompt("Do you want Reflex Updater to automatically update with downloader or update_all?") + if !answer { + err := os.WriteFile(noDbFile, []byte{}, 0644) + if err != nil { + return false, err + } + return false, nil + } + + err = downloadIni.AddDb(dbName, dbUrl) + if err != nil { + return false, err + } + + err = downloadIni.Save() + if err != nil { + return false, err + } + + return true, nil +} + func clearTerminal() { fmt.Print("\033[H\033[2J") } @@ -146,6 +190,15 @@ func main() { os.Exit(0) } + updated, err = tryAddDb() + if err != nil { + fmt.Printf("An error occurred while updating downloader.ini: %s\n", err) + os.Exit(1) + } + if updated { + utils.InfoPrompt("Please run downloader or update_all to get controller mappings after configuring Adapt.") + } + updaterDir, err := extractUpdater() if err != nil { fmt.Printf("An error occurred while extracting the updater: %s\n", err)