package main import ( "fmt" "path/filepath" "archive/zip" "github.com/arzumify/webview_go-4.1" "net/http" "os" "io" "strconv" ) func upgrade(path string) { err := os.RemoveAll(filepath.Join(path, "website")) if err != nil { fmt.Println("[ERROR] Failed to delete current version:", err) return } err = os.MkdirAll(filepath.Join(path, "website"), os.ModePerm) if err != nil { fmt.Println("[ERROR] Failed to create website directory:", err) return } resp, err := http.Get("https://centrifuge.hectabit.org/HectaBit/Burgernotes-client-web/archive/main.zip") if err != nil { fmt.Println("[ERROR] Cannot fetch latest version:", err) return } defer resp.Body.Close() tempFile, err := os.CreateTemp("", "upgrade_*.zip") if err != nil { fmt.Println("[ERROR] Failed to create temporary file:", err) return } defer os.Remove(tempFile.Name()) _, err = io.Copy(tempFile, resp.Body) if err != nil { fmt.Println("[ERROR] Failed to copy zip content to temporary file:", err) return } zipReader, err := zip.OpenReader(tempFile.Name()) if err != nil { fmt.Println("[ERROR] Failed to open zip file:", err) return } defer zipReader.Close() for _, file := range zipReader.File { dstPath := filepath.Join(filepath.Join(path, "website"), file.Name) if file.FileInfo().IsDir() { os.MkdirAll(dstPath, os.ModePerm) continue } fileReader, err := file.Open() if err != nil { fmt.Println("[ERROR] Failed to open file in zip:", err) return } defer fileReader.Close() dstFile, err := os.Create(dstPath) if err != nil { fmt.Println("[ERROR] Failed to create destination file:", err) return } defer dstFile.Close() _, err = io.Copy(dstFile, fileReader) if err != nil { fmt.Println("[ERROR] Failed to copy file contents:", err) return } } src, err := os.Open(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web")) if err != nil { fmt.Println("[ERROR] Cannot find created folder:", err) return } files, err := src.Readdir(-1) if err != nil { fmt.Println("[ERROR] Failed to read files:", err) return } for _, file := range files { srcPath := filepath.Join(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web"), file.Name()) dstPath := filepath.Join(filepath.Join(path, "website"), file.Name()) err := os.Rename(srcPath, dstPath) if err != nil { fmt.Println("[ERROR] Failed to move files:", err) return } } err = os.Remove(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web")) if err != nil { fmt.Println("[ERROR] Failed to delete source directory:", err) return } file, err := os.OpenFile(filepath.Join(filepath.Join(path, "website"), "index.html"), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) if err != nil { fmt.Println("[ERROR] Failed to open index.html:", err) return } defer file.Close() filecontent := "