feat: 重构
This commit is contained in:
39
scan.go
Normal file
39
scan.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type versionInfo struct {
|
||||
name string
|
||||
path string
|
||||
}
|
||||
|
||||
type versionsFoundMsg []versionInfo
|
||||
type scanErrorMsg struct{ err error }
|
||||
|
||||
func scanVersions(exeDir string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
pattern := filepath.Join(exeDir, ".minecraft", "versions", "*")
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
return scanErrorMsg{err: err}
|
||||
}
|
||||
|
||||
var versions []versionInfo
|
||||
for _, m := range matches {
|
||||
info, err := os.Stat(m)
|
||||
if err != nil || !info.IsDir() {
|
||||
continue
|
||||
}
|
||||
versions = append(versions, versionInfo{
|
||||
name: filepath.Base(m),
|
||||
path: m,
|
||||
})
|
||||
}
|
||||
return versionsFoundMsg(versions)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user