Created
August 22, 2013 01:00
-
-
Save furlmc/6302100 to your computer and use it in GitHub Desktop.
Build dem jars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"fmt" | |
"io" | |
"os" | |
"path" | |
) | |
const archiveName = "FurlMod" | |
func main() { | |
// Called after reobfuscate | |
// mcp = . | |
// jar path = reobf/minecraft/* + src/minecraft/mcmod.info + lol assets | |
files := make(map[string]*os.File) | |
reobf, err := os.Stat("reobf/minecraft") | |
if err != nil { | |
panic(err) | |
} | |
if !reobf.IsDir() { | |
panic("reobf folder not found") | |
} | |
mcmod, err := os.Open("src/minecraft/mcmod.info") | |
if err != nil { | |
panic(err) | |
} | |
files["mcmod.info"] = mcmod | |
var traverse func(fi os.FileInfo, dirPath, zipPath string) | |
traverse = func(fi os.FileInfo, dirPath, zipPath string) { | |
fd, err := os.Open(dirPath) | |
if err != nil { | |
panic(err) | |
} | |
fis, err := fd.Readdir(0) | |
if err != nil { | |
panic(err) | |
} | |
for _, fi := range fis { | |
if fi.IsDir() { | |
traverse(fi, | |
path.Join(dirPath, fi.Name()), | |
path.Join(zipPath, fi.Name()), | |
) | |
} else { | |
fileName := path.Join(dirPath, fi.Name()) | |
zipName := path.Join(zipPath, fi.Name()) | |
f, err := os.Open(fileName) | |
if err != nil { | |
panic(err) | |
} | |
files[zipName] = f | |
} | |
} | |
} | |
traverse(reobf, "reobf/minecraft", "") | |
// ... zip files | |
zipName := "dist/" + archiveName + ".zip" | |
outZip, err := os.Create(zipName) | |
if err != nil { | |
panic(err) | |
} | |
zipWriter := zip.NewWriter(outZip) | |
for zipPath, file := range files { | |
of, err := zipWriter.Create(zipPath) | |
if err != nil { | |
panic(err) | |
} | |
_, err = io.Copy(of, file) | |
if err != nil { | |
panic(err) | |
} | |
} | |
err = zipWriter.Close() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("[=]jar written to " + zipName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment