Skip to content

Commit db8cccf

Browse files
committed
Added project
1 parent 80c74a0 commit db8cccf

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!.gitignore
3+
!main.go
4+
!README.md
5+
!example.ccip

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# MultiMC-CCIP
2+
3+
A simple Go program that reads CurseForge CCIP files for MultiMC
4+
1. Reads the [CurseForge] `.ccip` file
5+
2. Requests the [TwitchAPI] to get the zip url
6+
3. Launches [MultiMC] with the `--import` flag, with the url
7+
8+
[Download](https://github.com/ShayBox/MultiMC-CCIP/releases)
9+
10+
[CurseForge]: https://www.curseforge.com/
11+
[TwitchAPI]: https://twitchappapi.docs.apiary.io/
12+
[MultiMC]: https://multimc.org/

example.ccip

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2+
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3+
<project id="225080" file="2246179" />
4+
</package>

main.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"os"
9+
"os/exec"
10+
)
11+
12+
// Package - XML structure the CurseForge CCIP files
13+
type Package struct {
14+
XMLName xml.Name `xml:"package"`
15+
Project struct {
16+
ID string `xml:"id,attr"`
17+
File string `xml:"file,attr"`
18+
} `xml:"project"`
19+
}
20+
21+
func main() {
22+
if len(os.Args) < 2 {
23+
fmt.Println("No path provided")
24+
os.Exit(128)
25+
}
26+
27+
pkg := LoadXML(os.Args[1])
28+
url := GetURL(pkg)
29+
30+
LoadMultiMC(url)
31+
}
32+
33+
// LoadXML - Load XML from disk into variable
34+
func LoadXML(fileName string) Package {
35+
xmlFile, err := os.Open(fileName)
36+
if err != nil {
37+
fmt.Println(err)
38+
os.Exit(1)
39+
}
40+
41+
defer xmlFile.Close()
42+
43+
byteValue, _ := ioutil.ReadAll(xmlFile)
44+
45+
var pkg Package
46+
xml.Unmarshal(byteValue, &pkg)
47+
48+
return pkg
49+
}
50+
51+
// GetURL - Request the download url from Twitch's API
52+
func GetURL(pkg Package) string {
53+
url := "https://addons-ecs.forgesvc.net/api/v2/addon/" + pkg.Project.ID + "/file/" + pkg.Project.File + "/download-url"
54+
resp, err := http.Get(url)
55+
if err != nil {
56+
fmt.Println(err)
57+
os.Exit(1)
58+
}
59+
60+
defer resp.Body.Close()
61+
62+
body, err := ioutil.ReadAll(resp.Body)
63+
if err != nil {
64+
fmt.Println(err)
65+
os.Exit(1)
66+
}
67+
68+
return string(body)
69+
}
70+
71+
// LoadMultiMC - Execute MultiMC with --import (url)
72+
func LoadMultiMC(url string) {
73+
cmd := exec.Command("multimc", "--import", url)
74+
cmd.Stdout = os.Stdout
75+
cmd.Stderr = os.Stderr
76+
77+
err := cmd.Run()
78+
if err != nil {
79+
fmt.Println(err)
80+
}
81+
82+
cmd.Wait()
83+
}

0 commit comments

Comments
 (0)