Skip to content

Commit

Permalink
Fixed windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Sep 9, 2020
1 parent 01a22a6 commit 1a01d6c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gopack/111_pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gopack

func Make111Pipeline() {
pipeline := CreatePipeline("to 1.11 (remove secrets)", "work/111/", "1.11-1.12.zip")
pipeline := CreatePipeline("to 1.11 (remove secrets)", TransPath("work/111/"), "1.11-1.12.zip")

// update format
pipeline.AddForFileName("pack.mcmeta", SetMetaRevision(3))
Expand Down
2 changes: 1 addition & 1 deletion gopack/113_pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gopack

func Make113Pipeline() {
pipeline := CreatePipeline("to 1.13 (remove secrets, flattening)", "work/113/", "1.13-1.14.zip")
pipeline := CreatePipeline("to 1.13 (remove secrets, flattening)", TransPath("work/113/"), "1.13-1.14.zip")


// update format
Expand Down
2 changes: 1 addition & 1 deletion gopack/115_pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gopack

func Make115Pipeline() {
pipeline := CreatePipeline("to 1.15 (remove secrets, flattening)", "work/115/", "1.15.zip")
pipeline := CreatePipeline("to 1.15 (remove secrets, flattening)", TransPath("work/115/"), "1.15.zip")

// update format
pipeline.AddForFileName("pack.mcmeta", SetMetaRevision(5))
Expand Down
2 changes: 1 addition & 1 deletion gopack/116_pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gopack

func Make116Pipeline() {
pipeline := CreatePipeline("to 1.16 (remove secrets, flattening)", "work/116/", "1.16.zip")
pipeline := CreatePipeline("to 1.16 (remove secrets, flattening)", TransPath("work/116/"), "1.16.zip")

// update format
pipeline.AddForFileName("pack.mcmeta", SetMetaRevision(6))
Expand Down
4 changes: 2 additions & 2 deletions gopack/gopack_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ResourcePack struct {

func FromZip(filename string) ResourcePack {
logrus.Info(filename, " currently is ", readableSize(len(DataFromFile(filename))))
root := "work/original/"
root := TransPath("work/original/")

files, zipErr := Unzip(filename, root)
if zipErr != nil {
Expand All @@ -30,7 +30,7 @@ func FromZip(filename string) ResourcePack {
for i := range files {
path := strings.Replace(files[i], root, "", -1)

elements := strings.Split(path, "/")
elements := strings.Split(path, TransPath("/"))
name := elements[len(elements) - 1]

// duplicate file names can occur within a pack, so we should handle it
Expand Down
4 changes: 2 additions & 2 deletions gopack/out_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var hashes = make(map[string]string)

func HashFile(path string) {
elements := strings.Split(path, "/")
elements := strings.Split(path, TransPath("/"))
name := elements[len(elements) - 1]
file, err := os.Open(path)
if err != nil {
Expand All @@ -33,5 +33,5 @@ func HashFile(path string) {

func SaveHashes() {
hashes := StructToJson(hashes)
WriteToFile("out/hashes.json", []byte(hashes))
WriteToFile(TransPath("out/hashes.json"), []byte(hashes))
}
11 changes: 11 additions & 0 deletions gopack/path_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gopack

import (
"os"
"strings"
)

func TransPath(path string) string {
o := strings.Replace(path,"/", string(os.PathSeparator), -1)
return o
}
6 changes: 3 additions & 3 deletions gopack/pipeline_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func AddPipeline(pipeline *Pipeline) {
}

func RunPipelines(originalPack ResourcePack) {
_ = os.RemoveAll("out/")
_ = os.RemoveAll(TransPath("out/"))
ResetFileCache()
for i := range Pipelines {
pack := originalPack // copy the pack for every pipeline, to prevent destruction
Expand Down Expand Up @@ -91,7 +91,7 @@ func RunPipelines(originalPack ResourcePack) {
}
}

zipName := "out/" + pipe.OutputName
zipName := TransPath("out/") + pipe.OutputName
fer := os.MkdirAll(filepath.Dir(zipName), os.ModePerm)
if fer != nil {
panic(fer)
Expand All @@ -118,7 +118,7 @@ func RunPipelines(originalPack ResourcePack) {
HashFile(zipName)
}

_ = os.RemoveAll("work/")
_ = os.RemoveAll(TransPath("work/"))
for i := range statusReports {
logrus.Info(statusReports[i])
}
Expand Down
4 changes: 2 additions & 2 deletions gopack/task_compress_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "strings"

// don't compress highly visible assets
var compressionWhitelist = []string{
"gui/", // skip inventories etc
TransPath("gui/"), // skip inventories etc
"pack.png", // skip the pack icon
".lang", // skip language files
"lang/", // skip language files
TransPath("lang/"), // skip language files
}

func CompressResources(pipeline *Pipeline) {
Expand Down
2 changes: 1 addition & 1 deletion gopack/task_migrate_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ func MigrateLanguage(pipeline *Pipeline, set map[string]string) {
}

// rename these files
pipeline.AddPathContainsHandler("minecraft/lang/", converter)
pipeline.AddPathContainsHandler(TransPath("minecraft/lang/"), converter)
}
8 changes: 4 additions & 4 deletions gopack/task_name_folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "strings"
func RenamePackFolders(pipeline *Pipeline) {
// flattening part one, rename `textures/blocks` to `/textures/block`
pipeline.AddGlobalHandler(func(originalPack ResourcePack, resource *Resource, pipeline *Pipeline) {
if strings.Contains(resource.Path, "textures/blocks") {
if strings.Contains(resource.Path, TransPath("textures/blocks")) {
delete(pipeline.WriteQueue, pipeline.OutFolder+resource.Path)
resource.Path = strings.Replace(resource.Path, "textures/blocks", "textures/block", 1)
resource.Path = strings.Replace(resource.Path, TransPath("textures/blocks"), TransPath("textures/block"), 1)

// overwrite handler, since we did handle it and don't want the original to be saved because that would be
// silly, since we'd end up with both block and blocks
Expand All @@ -20,9 +20,9 @@ func RenamePackFolders(pipeline *Pipeline) {

// flattening part two, rename `textures/items` to `/textures/item`
pipeline.AddGlobalHandler(func(originalPack ResourcePack, resource *Resource, pipeline *Pipeline) {
if strings.Contains(resource.Path, "textures/items") {
if strings.Contains(resource.Path, TransPath("textures/items")) {
delete(pipeline.WriteQueue, pipeline.OutFolder+resource.Path)
resource.Path = strings.Replace(resource.Path, "textures/items", "textures/item", 1)
resource.Path = strings.Replace(resource.Path, TransPath("textures/items"), TransPath("textures/item"), 1)

// overwrite handler, since we did handle it and don't want the original to be saved because that would be
// silly, since we'd end up with both item and items
Expand Down
10 changes: 5 additions & 5 deletions gopack/task_rename_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ConvertItems(pipeline *Pipeline, set map[string]string) {

converter := func(originalPack ResourcePack, resource *Resource, pipeline *Pipeline) {
// don't save original
if strings.Contains(resource.Path, "/" + oldName + ".") {
if strings.Contains(resource.Path, TransPath("/") + oldName + ".") {
ogContent := resource.GetPipelineContent(pipeline)
delete(pipeline.WriteQueue, pipeline.OutFolder+resource.Path)

Expand Down Expand Up @@ -62,12 +62,12 @@ func ConvertItems(pipeline *Pipeline, set map[string]string) {
// replace references to blocks/ and items/
asString := value.Str

asString = strings.Replace(asString, "items/", "item/", -1)
asString = strings.Replace(asString, "blocks/", "block/", -1)
asString = strings.Replace(asString, TransPath("items/"), TransPath("item/"), -1)
asString = strings.Replace(asString, TransPath("blocks/"), TransPath("block/"), -1)
asString = strings.ToLower(asString)

for s := range set {
if strings.HasSuffix(asString, "/" + s) && !strings.Contains(asString, "custom/") {
if strings.HasSuffix(asString, TransPath("/") + s) && !strings.Contains(asString, TransPath("custom/")) {
asString = strings.Replace(asString, s, set[s], -1)
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func ConvertItems(pipeline *Pipeline, set map[string]string) {

// and translate it, again
for s := range set {
if strings.HasSuffix(asString, "/" + s) && !strings.Contains(asString, "custom/") {
if strings.HasSuffix(asString, TransPath("/") + s) && !strings.Contains(asString, TransPath("custom/")) {
asString = strings.Replace(asString, s, set[s], -1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions gopack/util_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func addFiles(w *zip.Writer, basePath, baseInZip string) {
panic(err)
}
} else if file.IsDir() {
newBase := basePath + file.Name() + "/"
addFiles(w, newBase, baseInZip + file.Name() + "/")
newBase := basePath + file.Name() + TransPath("/")
addFiles(w, newBase, baseInZip + file.Name() + TransPath("/"))
}
}
}

0 comments on commit 1a01d6c

Please sign in to comment.