From ed6ef1e87c188d217b78496a4f2f900d71c0c650 Mon Sep 17 00:00:00 2001 From: stelzo Date: Wed, 27 Nov 2024 22:52:24 +0100 Subject: [PATCH] mount images and arch detection --- images.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- items.go | 7 +++++-- main.go | 12 ++++++++++++ quests.go | 2 +- update.go | 4 ++-- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/images.go b/images.go index 620f0ff..0e38ca4 100644 --- a/images.go +++ b/images.go @@ -133,6 +133,7 @@ func cleanImages(dir string, resolution int) error { func DownloadImagesLauncher(hashJson *ankabuffer.Manifest, bin int, version int, dir string, headless bool) error { inPath := filepath.Join(dir, "tmp") outPath := filepath.Join(dir, "img", "item") + outPathMounts := filepath.Join(dir, "img", "mount") if version == 2 { fileNames := []HashFile{ @@ -170,15 +171,24 @@ func DownloadImagesLauncher(hashJson *ankabuffer.Manifest, bin int, version int, fileNames := []HashFile{ {Filename: "Dofus_Data/StreamingAssets/Content/Picto/Items/item_assets_1x.bundle", FriendlyName: "item_images_1.imagebundle"}, {Filename: "Dofus_Data/StreamingAssets/Content/Picto/Items/item_assets_2x.bundle", FriendlyName: "item_images_2.imagebundle"}, - //{Filename: "Dofus_Data/StreamingAssets/Content/Picto/UI/mount_.bundle", FriendlyName: "mount_images.bundle"}, + {Filename: "Dofus_Data/StreamingAssets/Content/Picto/UI/mount_assets_.bundle", FriendlyName: "mount_images.imagebundle"}, } - err := PullImages([]string{"stelzo/assetstudio-cli:latest"}, false, headless) + err := PullImages([]string{"stelzo/assetstudio-cli:" + ARCH}, false, headless) if err != nil { return err } - err = DownloadUnpackFiles("Images", bin, hashJson, "picto", fileNames, dir, outPath, true, "", headless, false) + err = DownloadUnpackFiles("Item Images", bin, hashJson, "picto", fileNames, dir, outPath, true, "", headless, false) + if err != nil { + return err + } + + fileNames = []HashFile{ + {Filename: "Dofus_Data/StreamingAssets/Content/Picto/UI/mount_assets_.bundle", FriendlyName: "mount_images.imagebundle"}, + } + + err = DownloadUnpackFiles("Mount Images", bin, hashJson, "picto", fileNames, dir, outPathMounts, true, "", headless, false) if err != nil { return err } @@ -199,6 +209,23 @@ func DownloadImagesLauncher(hashJson *ankabuffer.Manifest, bin int, version int, feedbacks <- "cleaning" + // -- mounts cleaning -- + err = os.Rename(filepath.Join(outPathMounts, "Assets", "BuiltAssets", "mounts", "small"), filepath.Join(outPathMounts, "small")) + if err != nil { + return err + } + + err = os.Rename(filepath.Join(outPathMounts, "Assets", "BuiltAssets", "mounts", "big"), filepath.Join(outPathMounts, "big")) + if err != nil { + return err + } + + err = os.RemoveAll(filepath.Join(outPathMounts, "Assets")) + if err != nil { + return err + } + + // -- items cleaning -- err = os.Rename(filepath.Join(outPath, "Assets", "BuiltAssets", "items", "1x"), filepath.Join(outPath, "1x")) if err != nil { return err @@ -216,6 +243,22 @@ func DownloadImagesLauncher(hashJson *ankabuffer.Manifest, bin int, version int, var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + if cleanImages(filepath.Join(outPathMounts, "small"), 64) != nil { + log.Error("Error cleaning images", "err", err) + } + }() + + wg.Add(1) + go func() { + defer wg.Done() + if cleanImages(filepath.Join(outPathMounts, "big"), 256) != nil { + log.Error("Error cleaning images", "err", err) + } + }() + wg.Add(1) go func() { defer wg.Done() diff --git a/items.go b/items.go index c12c194..12cbc75 100644 --- a/items.go +++ b/items.go @@ -40,14 +40,17 @@ func DownloadItems(hashJson *ankabuffer.Manifest, bin int, version int, dir stri {Filename: "Dofus_Data/StreamingAssets/Content/Data/data_assets_dungeonsroot.asset.bundle", FriendlyName: "dungeons.asset.bundle"}, } - err := PullImages([]string{"stelzo/doduda-umbu:latest"}, false, headless) + err := PullImages([]string{"stelzo/doduda-umbu:" + ARCH}, false, headless) if err != nil { return err } err = DownloadUnpackFiles("Items", bin, hashJson, "data", fileNames, dir, outPath, true, indent, headless, false) - return err + if err != nil { + return err + } + return nil } else if version == 2 { fileNames := []HashFile{ {Filename: "data/common/Items.d2o", FriendlyName: "items.d2o"}, diff --git a/main.go b/main.go index aeca17c..0c4a5b6 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "runtime" "strconv" "strings" "sync" @@ -21,6 +22,7 @@ var ( DodudaShort = "doduda - Unofficial Ankama Launcher CLI" DodudaLong = "The Ankama Launcher Terminal Client for Developers." DodudaVersionHelp = DodudaShort + "\n" + DodudaVersion + "\nhttps://github.com/dofusdude/doduda" + ARCH string rootCmd = &cobra.Command{ Use: "doduda", @@ -70,6 +72,16 @@ var ( ) func main() { + switch runtime.GOARCH { + case "arm64": + ARCH = "arm64" + case "amd64": + ARCH = "amd64" + default: + fmt.Printf("Error: Unsupported architecture %s\n", runtime.GOARCH) + os.Exit(1) + } + viper.SetDefault("LOG_LEVEL", "warn") viper.AutomaticEnv() parsedLevel, err := log.ParseLevel(viper.GetString("LOG_LEVEL")) diff --git a/quests.go b/quests.go index 7177796..babd78e 100644 --- a/quests.go +++ b/quests.go @@ -32,7 +32,7 @@ func DownloadQuests(hashJson *ankabuffer.Manifest, bin int, version int, dir str {Filename: "Dofus_Data/StreamingAssets/Content/Data/data_assets_almanaxcalendarsroot.asset.bundle", FriendlyName: "almanax.asset.bundle"}, } - err := PullImages([]string{"stelzo/doduda-umbu:latest"}, false, headless) + err := PullImages([]string{"stelzo/doduda-umbu:" + ARCH}, false, headless) if err != nil { return err } diff --git a/update.go b/update.go index c1ec866..8b58920 100644 --- a/update.go +++ b/update.go @@ -513,7 +513,7 @@ func UnpackUnityBundle(category string, inputPath string, outputPath string, mut ctx := context.Background() resp, err := cli.ContainerCreate(ctx, &container.Config{ - Image: "stelzo/doduda-umbu:latest", + Image: "stelzo/doduda-umbu:" + ARCH, Cmd: cmd, Volumes: map[string]struct{}{ "/app/data": {}, @@ -585,7 +585,7 @@ func UnpackUnityImages(inputDir string, outputDir string, muteSpinner bool, head } defer cli.Close() - imageName := "stelzo/assetstudio-cli:latest" + imageName := "stelzo/assetstudio-cli:" + ARCH ctx := context.Background() bundles, err := os.ReadDir(inputDir)