Update progress bar and more embed

This commit is contained in:
2025-08-31 12:53:48 +07:00
parent 612f091ac8
commit cf9d499e91
17 changed files with 269 additions and 201 deletions

View File

@@ -2,18 +2,23 @@ package main
import (
"bufio"
_ "embed"
"encoding/json"
"fmt"
"ldiff-converter/pb"
"os"
"path/filepath"
"strings"
"github.com/schollz/progressbar/v3"
)
func main() {
//go:embed bin/7za.exe
var sevenZip []byte
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter zip ldiff path: ")
fmt.Print("Enter ldiff path: ")
ldiff, _ := reader.ReadString('\n')
ldiff = strings.TrimSpace(ldiff)
if ldiff == "" {
@@ -28,6 +33,9 @@ func main() {
fmt.Fprintln(os.Stderr, "no hdiff output provided")
os.Exit(1)
}
if !strings.HasSuffix(strings.ToLower(hdiff), ".zip") {
hdiff += ".zip"
}
tmpFolderPath := filepath.Join(".", "temp")
if err := os.MkdirAll(tmpFolderPath, 0755); err != nil {
@@ -35,20 +43,24 @@ func main() {
os.Exit(1)
}
if err := Unzip(ldiff, tmpFolderPath); err != nil {
fmt.Println("Unzipping ldiff...")
if err := UnzipWith7za(ldiff, tmpFolderPath); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
fmt.Println("Unzipping ldiff done.")
ldiffPath := filepath.Join(tmpFolderPath, "ldiff")
manifestPath := filepath.Join(tmpFolderPath, "manifest")
hdiffFolderPath := filepath.Join(".", "hdiff")
fmt.Println("Loading manifest proto...")
manifestProto, err := LoadManifestProto(manifestPath)
if err != nil {
fmt.Fprintln(os.Stderr, "error loading manifest proto:", err)
os.Exit(1)
}
fmt.Println("Loading manifest proto done.")
ldiffEntries, err := os.ReadDir(ldiffPath)
if err != nil {
@@ -56,6 +68,13 @@ func main() {
os.Exit(1)
}
bar := progressbar.NewOptions(len(ldiffEntries),
progressbar.OptionSetDescription("📦 Converting ldiff files"),
progressbar.OptionShowCount(),
progressbar.OptionSetWidth(30),
progressbar.OptionSetPredictTime(true),
)
fmt.Println("Converting ldiff files...")
for _, ldiffEntry := range ldiffEntries {
assetName := ldiffEntry.Name()
var matchingAssets []struct {
@@ -77,7 +96,7 @@ func main() {
}
}
}
bar.Add(1)
for _, ma := range matchingAssets {
err := LDiffFile(ma.Asset, ma.AssetName, ma.AssetSize, ldiffPath, hdiffFolderPath)
if err != nil {
@@ -85,12 +104,15 @@ func main() {
}
}
}
bar.Finish()
fmt.Println()
fmt.Println("Converting ldiff files done.")
diffMapNames := make([]string, len(ldiffEntries))
for i, e := range ldiffEntries {
diffMapNames[i] = e.Name()
}
fmt.Println("Making diff map...")
diffMapList, err := MakeDiffMap(manifestProto, diffMapNames)
if err != nil {
fmt.Fprintln(os.Stderr, "error making diff map:", err)
@@ -107,22 +129,31 @@ func main() {
fmt.Fprintln(os.Stderr, "error writing diff map:", err)
os.Exit(1)
}
fmt.Println("Making diff map done.")
if err := os.RemoveAll(tmpFolderPath); err != nil {
fmt.Println("Removing temp ldiff files...")
if err := RemoveFolderWithProgress(tmpFolderPath, "🗑️ Removing temp ldiff files"); err != nil {
fmt.Fprintln(os.Stderr, "error removing temp dir:", err)
os.Exit(1)
}
fmt.Println()
fmt.Println("Removing temp ldiff files done.")
if err := Zip(hdiffFolderPath, hdiff); err != nil {
fmt.Println("Zipping hdiff files...")
if err := ZipWith7za(hdiffFolderPath, hdiff); err != nil {
fmt.Fprintln(os.Stderr, "error zip hdiff:", err)
os.Exit(1)
}
fmt.Println("Zipping hdiff files done.")
if err := os.RemoveAll(hdiffFolderPath); err != nil {
fmt.Println("Removing hdiff temp files...")
if err := RemoveFolderWithProgress(hdiffFolderPath, "🗑️ Removing hdiff temp files"); err != nil {
fmt.Fprintln(os.Stderr, "error removing temp dir:", err)
os.Exit(1)
}
fmt.Println()
fmt.Println("Removing hdiff temp files done.")
fmt.Println("done!")
fmt.Println("Done!")
}