Update progress bar and more embed
This commit is contained in:
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -10,48 +10,12 @@ import (
|
||||
)
|
||||
|
||||
//go:embed bin/hdiffz.exe
|
||||
var hdiffz []byte
|
||||
|
||||
//go:embed bin/7za.exe
|
||||
var embeddedFiles embed.FS
|
||||
|
||||
func ensureBinaries() (map[string]string, error) {
|
||||
binDir := "bin"
|
||||
if _, err := os.Stat(binDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(binDir, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
files := []string{"hdiffz.exe", "7za.exe"}
|
||||
paths := make(map[string]string)
|
||||
|
||||
for _, f := range files {
|
||||
destPath := filepath.Join(binDir, f)
|
||||
paths[f] = destPath
|
||||
|
||||
if _, err := os.Stat(destPath); os.IsNotExist(err) {
|
||||
data, err := embeddedFiles.ReadFile("bin/" + f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(destPath, data, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
}
|
||||
var sevenZip []byte
|
||||
|
||||
func main() {
|
||||
paths, err := ensureBinaries()
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, path := range paths {
|
||||
fmt.Println("Binary ready at:", path)
|
||||
}
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Print("Enter OLD game path: ")
|
||||
@@ -82,31 +46,48 @@ func main() {
|
||||
hdiffName += ".zip"
|
||||
}
|
||||
|
||||
fmt.Println("Diffing folders...")
|
||||
result, err := DiffFolders(oldPath, newPath)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("Diffing folders done.")
|
||||
|
||||
hdiffFolderPath := filepath.Join(".", "hdiff")
|
||||
os.MkdirAll(hdiffFolderPath, 0755)
|
||||
|
||||
fmt.Println("Copying new files...")
|
||||
if err := CopyNewFiles(newPath, result); err != nil {
|
||||
fmt.Println("Error writing diff:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("Copying new files done.")
|
||||
|
||||
fmt.Println("Making hdiff files...")
|
||||
if err := MakeHdiffFile(oldPath, newPath, result.Changed); err != nil {
|
||||
fmt.Println("Error writing diff:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("Making hdiff files done.")
|
||||
|
||||
fmt.Println("Zipping hdiff files...")
|
||||
if err := ZipWith7za(hdiffFolderPath, hdiffName); err != nil {
|
||||
fmt.Println("Error writing diff:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Zipping hdiff files done.")
|
||||
|
||||
if err := RemoveFolderWithProgress(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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user