This commit is contained in:
2025-07-08 14:54:41 +07:00
commit 644a6f9803
86 changed files with 12422 additions and 0 deletions

44
pkg/sevenzip/sevenzip.go Normal file
View File

@@ -0,0 +1,44 @@
package sevenzip
import (
"bytes"
"firefly-launcher/pkg/constant"
"fmt"
"os"
"os/exec"
"strings"
)
func IsFileIn7z(archivePath, fileInside string) (bool, error) {
cmd := exec.Command(constant.Tool7zaExe.String(), "l", archivePath)
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
if err := cmd.Run(); err != nil {
return false, fmt.Errorf("7za list failed: %v\nOutput: %s", err, out.String())
}
lines := strings.Split(out.String(), "\n")
for _, line := range lines {
if strings.Contains(line, fileInside) {
return true, nil
}
}
return false, fmt.Errorf("%s not found in %s", fileInside, archivePath)
}
func ExtractAFileFromZip(archivePath, fileInside, outDir string) error {
cmd := exec.Command(constant.Tool7zaExe.String(), "e", archivePath, fileInside, "-o"+outDir, "-y")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func ExtractAllFilesFromZip(archivePath, outDir string) error {
cmd := exec.Command(constant.Tool7zaExe.String(), "x", archivePath, "-o"+outDir, "-y")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}