Skip to content

Commit

Permalink
perf: Improve 7z decompression speed #12
Browse files Browse the repository at this point in the history
  • Loading branch information
libsgh committed Nov 13, 2024
1 parent 120cf09 commit aa0227f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Website = "https://chrome.noki.eu.org"
Icon = "assets/img/chrome.png"
Name = "chrome_updater"
ID = "com.github.libs.chrome"
Version = "2.0"
Version = "2.1"
Build = 0
14 changes: 7 additions & 7 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -211,22 +210,23 @@ func execDownAndUnzip(data *SettingsData, downloadProgress *widget.ProgressBar,
} else {
downloadProgress.SetValue(0.95)
//解压覆盖
UnCompress7z(fileName, parentPath)
UnCompress7z(path.Join(parentPath, "chrome.7z"), parentPath)
p := path.Join(parentPath, "Chrome-bin")
//UUnCompress7z(fileName, parentPath)
UnCompressBy7Zip(fileName, parentPath)
UnCompress7z(filepath.Join(parentPath, "chrome.7z"), parentPath)
p := filepath.Join(parentPath, "Chrome-bin")
targetDir := filepath.Dir(p)
files, _ := os.ReadDir(p)
for _, f := range files {
os.Rename(filepath.Join(p, f.Name()), path.Join(targetDir, f.Name()))
_ = os.Rename(filepath.Join(p, f.Name()), filepath.Join(targetDir, f.Name()))
}
//清理文件
_ = os.Remove(p)
_ = os.Remove(filepath.Join(parentPath, "chrome.7z"))
if !getBool(data.remainInstallFileSettings) {
os.Remove(fileName)
_ = os.Remove(fileName)
}
if !getBool(data.remainHistoryFileSettings) {
os.RemoveAll(filepath.Join(parentPath, getString(data.oldVer)))
_ = os.RemoveAll(filepath.Join(parentPath, getString(data.oldVer)))
}
downloadProgress.SetValue(1)
data.oldVer.Set(getString(data.curVer))
Expand Down
15 changes: 15 additions & 0 deletions bundle.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion chrome_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func installPlus(data *SettingsData, win fyne.Window) {
data.plusProcessStatus.Set(true)
sysInfo := getInfo()
parentPath, _ := data.installPath.Get()
downloadProgress.SetValue(0)
fileName := getFileName(url)
fileName = filepath.Join(parentPath, fileName)
fileSize, _ := getFileSize(url)
Expand Down
31 changes: 31 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,34 @@ func GetVersion(sd *SettingsData, fileName string) string {
}
return "-"
}
func UnCompressBy7Zip(filePath, targetDir string) {
var data []byte
if runtime.GOARCH == "386" {
data = resource7z7za386Exe.Content()
} else if runtime.GOARCH == "amd64" {
data = resource7z7zaamd64Exe.Content()
} else if runtime.GOARCH == "arm64" {
data = resource7z7zaarm64Exe.Content()
}
appDataDir := os.Getenv("APPDATA")
if appDataDir == "" {
appDataDir = os.TempDir()
}
zipExePath := filepath.Join(appDataDir, "chrome_updater", "7za.exe")
if !fileExist(zipExePath) {
err := os.WriteFile(zipExePath, data, 0644)
if err != nil {
logger.Error("write file:", err)
return
}
}
if fileExist(filepath.Join(targetDir, "chrome.7z")) {
_ = os.RemoveAll(filepath.Join(targetDir, "chrome.7z"))
}
cmd := exec.Command("cmd.exe", "/c", zipExePath, "e", filePath, "-o"+targetDir, "-aoa", "-bb0")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
err := cmd.Run()
if err != nil {
logger.Errorf("unzip err: %v\n", err)
}
}

0 comments on commit aa0227f

Please sign in to comment.