Finalized Modpack installation.
This commit is contained in:
parent
f905d617a8
commit
2b372423eb
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -488,6 +489,8 @@ func (i *InstanceManager) ImportModpack(modpack Modpack, name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *InstanceManager) ImportMrpack(data io.Reader, name string) {
|
func (i *InstanceManager) ImportMrpack(data io.Reader, name string) {
|
||||||
|
dir, _ := os.UserConfigDir()
|
||||||
|
InstancePath := filepath.Join(dir, "FCLauncher", "instances", name, "minecraft")
|
||||||
zr := zipstream.NewReader(data)
|
zr := zipstream.NewReader(data)
|
||||||
mrdata := MrData{}
|
mrdata := MrData{}
|
||||||
for {
|
for {
|
||||||
@ -499,7 +502,22 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) {
|
|||||||
file, _ := entry.Open()
|
file, _ := entry.Open()
|
||||||
data, _ := io.ReadAll(file)
|
data, _ := io.ReadAll(file)
|
||||||
json.Unmarshal(data, &mrdata)
|
json.Unmarshal(data, &mrdata)
|
||||||
break
|
} else {
|
||||||
|
prefix := strings.Split(entry.Name, "/")[0]
|
||||||
|
if prefix == "overrides" || prefix == "client-overrides" {
|
||||||
|
path := strings.SplitN(entry.Name, "/", 2)[1]
|
||||||
|
if entry.IsDir() {
|
||||||
|
if _, err := os.Stat(filepath.Join(InstancePath, path)); err != nil {
|
||||||
|
os.MkdirAll(filepath.Join(InstancePath, path), 0755)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
zf, _ := entry.Open()
|
||||||
|
defer zf.Close()
|
||||||
|
file, _ := os.OpenFile(filepath.Join(InstancePath, path), os.O_CREATE|os.O_RDWR, 0755)
|
||||||
|
defer file.Close()
|
||||||
|
io.Copy(file, zf)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("Installing minecraft %s\n", mrdata.Dependencies["minecraft"])
|
fmt.Printf("Installing minecraft %s\n", mrdata.Dependencies["minecraft"])
|
||||||
@ -517,4 +535,27 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) {
|
|||||||
fmt.Printf("Installing quilt %s\n", mrdata.Dependencies["quilt-loader"])
|
fmt.Printf("Installing quilt %s\n", mrdata.Dependencies["quilt-loader"])
|
||||||
i.InstallQuilt(name, mrdata.Dependencies["quilt-loader"])
|
i.InstallQuilt(name, mrdata.Dependencies["quilt-loader"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, f := range mrdata.Files {
|
||||||
|
fmt.Printf("Downloading %s\n", f.Path)
|
||||||
|
resp, err := http.Get(f.Downloads[0])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unable to download file %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
fileDir := ""
|
||||||
|
tokens := strings.Split(f.Path, "/")
|
||||||
|
for ind, token := range tokens {
|
||||||
|
if ind != len(tokens)-1 {
|
||||||
|
fileDir = filepath.Join(fileDir, token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(InstancePath, fileDir)); err != nil {
|
||||||
|
os.MkdirAll(filepath.Join(InstancePath, fileDir), 0755)
|
||||||
|
}
|
||||||
|
file, _ := os.OpenFile(filepath.Join(InstancePath, f.Path), os.O_CREATE|os.O_RDWR, 0755)
|
||||||
|
defer file.Close()
|
||||||
|
io.Copy(file, resp.Body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user