12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package update
- import (
- "fmt"
- "os"
- "strconv"
- "strings"
- v308 "imuslab.com/zoraxy/mod/update/v308"
- "imuslab.com/zoraxy/mod/utils"
- )
- func RunConfigUpdate(fromVersion int, toVersion int) {
- versionFile := "./conf/version"
- if fromVersion == 0 {
-
- fromVersion = 307
- if utils.FileExists(versionFile) {
-
- previousVersionText, err := os.ReadFile(versionFile)
- if err != nil {
- panic("Unable to read version file at " + versionFile)
- }
-
- versionInt, err := strconv.Atoi(strings.TrimSpace(string(previousVersionText)))
- if err != nil {
- panic("Unable to read version file at " + versionFile)
- }
- fromVersion = versionInt
- }
- if fromVersion == toVersion {
-
- return
- }
- }
-
- for i := fromVersion; i < toVersion; i++ {
- oldVersion := fromVersion
- newVersion := fromVersion + 1
- fmt.Println("Updating from v", oldVersion, " to v", newVersion)
- runUpdateRoutineWithVersion(oldVersion, newVersion)
-
- os.WriteFile(versionFile, []byte(strconv.Itoa(newVersion)), 0775)
- }
- fmt.Println("Update completed")
- }
- func GetVersionIntFromVersionNumber(version string) int {
- versionNumberOnly := strings.ReplaceAll(version, ".", "")
- versionInt, _ := strconv.Atoi(versionNumberOnly)
- return versionInt
- }
- func runUpdateRoutineWithVersion(fromVersion int, toVersion int) {
- if fromVersion == 307 && toVersion == 308 {
-
- err := v308.UpdateFrom307To308()
- if err != nil {
- panic(err)
- }
- }
- }
|