From 1a01d6c6998a95028acbbac08351db22880f1cd9 Mon Sep 17 00:00:00 2001 From: Mindgamesnl Date: Wed, 9 Sep 2020 10:58:32 +0200 Subject: [PATCH] Fixed windows --- gopack/111_pipeline.go | 2 +- gopack/113_pipeline.go | 2 +- gopack/115_pipeline.go | 2 +- gopack/116_pipeline.go | 2 +- gopack/gopack_loader.go | 4 ++-- gopack/out_hasher.go | 4 ++-- gopack/path_util.go | 11 +++++++++++ gopack/pipeline_runner.go | 6 +++--- gopack/task_compress_resources.go | 4 ++-- gopack/task_migrate_language.go | 2 +- gopack/task_name_folders.go | 8 ++++---- gopack/task_rename_items.go | 10 +++++----- gopack/util_archive.go | 4 ++-- 13 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 gopack/path_util.go diff --git a/gopack/111_pipeline.go b/gopack/111_pipeline.go index 0a4a061..a89e625 100644 --- a/gopack/111_pipeline.go +++ b/gopack/111_pipeline.go @@ -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)) diff --git a/gopack/113_pipeline.go b/gopack/113_pipeline.go index d4f7a79..261d5d0 100644 --- a/gopack/113_pipeline.go +++ b/gopack/113_pipeline.go @@ -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 diff --git a/gopack/115_pipeline.go b/gopack/115_pipeline.go index a0030fe..fad22bf 100644 --- a/gopack/115_pipeline.go +++ b/gopack/115_pipeline.go @@ -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)) diff --git a/gopack/116_pipeline.go b/gopack/116_pipeline.go index 7d647c9..7014cde 100644 --- a/gopack/116_pipeline.go +++ b/gopack/116_pipeline.go @@ -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)) diff --git a/gopack/gopack_loader.go b/gopack/gopack_loader.go index 2811c7b..dd6c3ff 100644 --- a/gopack/gopack_loader.go +++ b/gopack/gopack_loader.go @@ -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 { @@ -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 diff --git a/gopack/out_hasher.go b/gopack/out_hasher.go index 305c973..f4e225b 100644 --- a/gopack/out_hasher.go +++ b/gopack/out_hasher.go @@ -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 { @@ -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)) } \ No newline at end of file diff --git a/gopack/path_util.go b/gopack/path_util.go new file mode 100644 index 0000000..53b53ad --- /dev/null +++ b/gopack/path_util.go @@ -0,0 +1,11 @@ +package gopack + +import ( + "os" + "strings" +) + +func TransPath(path string) string { + o := strings.Replace(path,"/", string(os.PathSeparator), -1) + return o +} \ No newline at end of file diff --git a/gopack/pipeline_runner.go b/gopack/pipeline_runner.go index 6138843..83bb8bf 100644 --- a/gopack/pipeline_runner.go +++ b/gopack/pipeline_runner.go @@ -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 @@ -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) @@ -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]) } diff --git a/gopack/task_compress_resources.go b/gopack/task_compress_resources.go index 3e64680..1f498d7 100644 --- a/gopack/task_compress_resources.go +++ b/gopack/task_compress_resources.go @@ -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) { diff --git a/gopack/task_migrate_language.go b/gopack/task_migrate_language.go index 2bd4844..fb38642 100644 --- a/gopack/task_migrate_language.go +++ b/gopack/task_migrate_language.go @@ -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) } diff --git a/gopack/task_name_folders.go b/gopack/task_name_folders.go index 0274c02..fb823ef 100644 --- a/gopack/task_name_folders.go +++ b/gopack/task_name_folders.go @@ -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 @@ -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 diff --git a/gopack/task_rename_items.go b/gopack/task_rename_items.go index 5bb51ce..38d5b9b 100644 --- a/gopack/task_rename_items.go +++ b/gopack/task_rename_items.go @@ -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) @@ -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) } } @@ -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) } } diff --git a/gopack/util_archive.go b/gopack/util_archive.go index 8f327e8..f8095dd 100644 --- a/gopack/util_archive.go +++ b/gopack/util_archive.go @@ -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("/")) } } } \ No newline at end of file