Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
92c1ce74e5 | |||
8e5a94e8d8 | |||
61e17cffc5 | |||
e7b5215d0f | |||
336340269b | |||
f8ebb74fc9 | |||
ccd2586c8d |
1
go.mod
1
go.mod
@@ -4,6 +4,7 @@ go 1.24.3
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.5.0
|
github.com/BurntSushi/toml v1.5.0
|
||||||
|
github.com/Masterminds/semver/v3 v3.4.0
|
||||||
github.com/go-ole/go-ole v1.3.0
|
github.com/go-ole/go-ole v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
|||||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
|
||||||
|
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
||||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,20 +18,25 @@ type UpdateStats struct {
|
|||||||
Updated int
|
Updated int
|
||||||
Current int
|
Current int
|
||||||
Outdated int
|
Outdated int
|
||||||
LogMessages []string
|
|
||||||
Error error
|
Error error
|
||||||
|
MessageBuf []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) UpdateStats {
|
func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) UpdateStats {
|
||||||
stats := UpdateStats{
|
stats := UpdateStats{
|
||||||
LogMessages: make([]string, 0),
|
|
||||||
Error: nil,
|
Error: nil,
|
||||||
|
MessageBuf: make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msgChan := make(chan string)
|
||||||
|
done := make(chan bool)
|
||||||
|
|
||||||
|
go func() {
|
||||||
manifest, err := GetManifest()
|
manifest, err := GetManifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.Error = fmt.Errorf("Failed to get manifest: %v\n", err)
|
stats.Error = fmt.Errorf("Failed to get manifest: %v\n", err)
|
||||||
return stats
|
done <- true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range manifest.Files {
|
for _, file := range manifest.Files {
|
||||||
@@ -43,7 +49,8 @@ func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) Up
|
|||||||
err = os.MkdirAll(localDir, 0755)
|
err = os.MkdirAll(localDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.Error = fmt.Errorf("failed to create directory %s: %v", localDir, err)
|
stats.Error = fmt.Errorf("failed to create directory %s: %v", localDir, err)
|
||||||
return stats
|
done <- true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +59,13 @@ func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) Up
|
|||||||
data, err := os.ReadFile(localPath)
|
data, err := os.ReadFile(localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.Error = fmt.Errorf("failed to read %s: %v", localPath, err)
|
stats.Error = fmt.Errorf("failed to read %s: %v", localPath, err)
|
||||||
return stats
|
done <- true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
hashBytes := md5.Sum(data)
|
hashBytes := md5.Sum(data)
|
||||||
hash := hex.EncodeToString(hashBytes[:])
|
hash := hex.EncodeToString(hashBytes[:])
|
||||||
if hash == file.Hash {
|
if hash == file.Hash {
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("File %s is up to date", localPath))
|
msgChan <- fmt.Sprintf("File %s is up to date", localPath)
|
||||||
stats.Current += 1
|
stats.Current += 1
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
@@ -67,10 +75,12 @@ func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) Up
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !skipDownload {
|
if !skipDownload {
|
||||||
|
msgChan <- fmt.Sprintf("Downloading %s", localPath)
|
||||||
outFile, err := os.Create(localPath)
|
outFile, err := os.Create(localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.Error = fmt.Errorf("failed to create file %s: %v", localPath, err)
|
stats.Error = fmt.Errorf("failed to create file %s: %v", localPath, err)
|
||||||
return stats
|
done <- true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadSuccess := false
|
downloadSuccess := false
|
||||||
@@ -80,32 +90,33 @@ func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) Up
|
|||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("Failed to download %s: %v", url, err))
|
msgChan <- fmt.Sprintf("Failed to download %s: %v", url, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("HTTP Status %d", resp.StatusCode))
|
msgChan <- fmt.Sprintf("HTTP Status %d", resp.StatusCode)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(outFile, resp.Body)
|
_, err = io.Copy(outFile, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("Failed to write file %s: %v", localPath, err))
|
msgChan <- fmt.Sprintf("Failed to write file %s: %v", localPath, err)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
downloadSuccess = true
|
downloadSuccess = true
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("Successfully downloaded %s", localPath))
|
msgChan <- fmt.Sprintf("Successfully downloaded %s", localPath)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
outFile.Close()
|
outFile.Close()
|
||||||
if !downloadSuccess {
|
if !downloadSuccess {
|
||||||
stats.Error = fmt.Errorf("Failed to download updates, see above messages")
|
stats.Error = fmt.Errorf("Failed to download updates, see above messages")
|
||||||
return stats
|
done <- true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.Updated += 1
|
stats.Updated += 1
|
||||||
@@ -125,27 +136,33 @@ func Update(wowdir string, force bool, removeUnknown bool, skipDownload bool) Up
|
|||||||
err = filepath.WalkDir(filepath.Join(wowdir, "Data"), func(path string, d fs.DirEntry, err error) error {
|
err = filepath.WalkDir(filepath.Join(wowdir, "Data"), func(path string, d fs.DirEntry, err error) error {
|
||||||
if !d.IsDir() && patchreg.MatchString(d.Name()) {
|
if !d.IsDir() && patchreg.MatchString(d.Name()) {
|
||||||
del := true
|
del := true
|
||||||
for _, patch := range patches {
|
if slices.Contains(patches, d.Name()) {
|
||||||
if patch == d.Name() {
|
|
||||||
del = false
|
del = false
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if del {
|
if del {
|
||||||
err = os.Remove(path)
|
err = os.Remove(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stats.LogMessages = append(stats.LogMessages, fmt.Sprintf("Removed unknown patch %s", d.Name()))
|
msgChan <- fmt.Sprintf("Removed unknown patch %s", d.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stats.Error = fmt.Errorf("failed to delete unknown patches: %v", err)
|
stats.Error = fmt.Errorf("failed to delete unknown patches: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done <- true
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case msg := <-msgChan:
|
||||||
|
fmt.Println(msg)
|
||||||
|
stats.MessageBuf = append(stats.MessageBuf, msg)
|
||||||
|
case <-done:
|
||||||
return stats
|
return stats
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
31
version.go
31
version.go
@@ -5,10 +5,14 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "1.0.10"
|
const (
|
||||||
const versionUrl = "https://git.burkey.co/eburk/epochcli/raw/branch/master/version.go"
|
version = "1.1.2"
|
||||||
|
versionUrl = "https://git.burkey.co/eburk/epochcli/raw/branch/master/version.go"
|
||||||
|
)
|
||||||
|
|
||||||
func needUpdate() (bool, error) {
|
func needUpdate() (bool, error) {
|
||||||
resp, err := http.Get(versionUrl)
|
resp, err := http.Get(versionUrl)
|
||||||
@@ -26,11 +30,26 @@ func needUpdate() (bool, error) {
|
|||||||
return false, fmt.Errorf("unable to read response body: %v", err)
|
return false, fmt.Errorf("unable to read response body: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`const version = "([\d.]+)"`)
|
re := regexp.MustCompile(`version\s+=\s+"(\d+.\d+.\d+)"`)
|
||||||
ver := re.FindStringSubmatch(string(b))
|
ver := re.FindStringSubmatch(string(b))
|
||||||
if len(ver) < 2 || ver[1] == "" {
|
if ver[1] == "" {
|
||||||
return false, fmt.Errorf("unable to find version in response")
|
return false, fmt.Errorf("unable to parse version number")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ver[1] != version, nil
|
curVer, err := semver.NewVersion(version)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("unable to parse current version to semver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newVer, err := semver.NewVersion(ver[1])
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("unable to parse new version to semver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if curVer.LessThan(newVer) {
|
||||||
|
fmt.Println("Current Version: ", curVer)
|
||||||
|
fmt.Println("Latest Version: ", newVer)
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user