-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows installer now installs and does progress correctly. Also adds…
… to registry and creates start menu shortcut. Broken at the moment, though Former-commit-id: fe4e071
- Loading branch information
Showing
17 changed files
with
335 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
id ICON "windows/icons/ico/pod16x16.ico" | ||
id ICON "windows/icons/ico/pod24x24.ico" | ||
id ICON "windows/icons/ico/pod32x32.ico" | ||
id ICON "windows/icons/ico/pod48x48.ico" | ||
id ICON "windows/icons/ico/pod256x256.ico" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func InstallWirePod(is InstallSettings) error { | ||
UpdateInstallStatus("Stopping any wire-pod instances...") | ||
StopWirePodIfRunning() | ||
|
||
UpdateInstallStatus("Removing any wire-pod files (if they exist)...") | ||
os.RemoveAll(is.Where) | ||
|
||
UpdateInstallBar(0) | ||
UpdateInstallStatus("Starting download...") | ||
|
||
// Start downloading the file | ||
resp, err := http.Get(amd64podURL) | ||
if err != nil { | ||
return fmt.Errorf("error getting wire-pod from GitHub: %s", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
totalBytes := resp.ContentLength | ||
var bytesRead int64 = 0 | ||
|
||
// Create a temporary file to store the download | ||
UpdateInstallStatus("Creating temp file...") | ||
tempFile, err := os.CreateTemp("", "wire-pod-*.zip") | ||
if err != nil { | ||
return fmt.Errorf("error creating a temp file: %s", err) | ||
} | ||
defer tempFile.Close() | ||
defer os.Remove(tempFile.Name()) // Clean up | ||
|
||
// Copy the download stream to the temp file with progress tracking | ||
UpdateInstallStatus("Downloading wire-pod from latest release on GitHub...") | ||
progressReader := io.TeeReader(resp.Body, tempFile) | ||
buffer := make([]byte, 32*1024) // 32KB buffer | ||
for { | ||
n, err := progressReader.Read(buffer) | ||
bytesRead += int64(n) | ||
if n == 0 || err != nil { | ||
break | ||
} | ||
UpdateInstallBar(float64(40) * float64(bytesRead) / float64(totalBytes)) | ||
} | ||
|
||
if err != nil && err != io.EOF { | ||
return fmt.Errorf("error while downloading: %s", err) | ||
} | ||
|
||
UpdateInstallBar(40) | ||
UpdateInstallStatus("Starting extraction...") | ||
|
||
// Open the zip file | ||
zipReader, err := zip.OpenReader(tempFile.Name()) | ||
if err != nil { | ||
return fmt.Errorf("error reading zip file: %s", err) | ||
} | ||
defer zipReader.Close() | ||
|
||
// Process each file in the zip | ||
for i, f := range zipReader.File { | ||
// Skip the root directory | ||
if f.Name == "wire-pod/" || strings.HasPrefix(f.Name, "wire-pod/") && f.FileInfo().IsDir() { | ||
continue | ||
} | ||
|
||
// Adjust the file path to exclude the 'wire-pod/' prefix | ||
adjustedPath := strings.TrimPrefix(f.Name, "wire-pod/") | ||
UpdateInstallStatus("Extracting: " + adjustedPath) | ||
fpath := filepath.Join(is.Where, adjustedPath) | ||
|
||
// Check for ZipSlip (Directory traversal) | ||
if !strings.HasPrefix(fpath, filepath.Clean(is.Where)+string(os.PathSeparator)) { | ||
return fmt.Errorf("illegal file path: %s", fpath) | ||
} | ||
|
||
// Create all directories needed for the file path | ||
if f.FileInfo().IsDir() { | ||
os.MkdirAll(fpath, os.ModePerm) | ||
continue | ||
} | ||
|
||
// Create the directories if necessary | ||
if err := os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil { | ||
return fmt.Errorf("error creating directories: %s", err) | ||
} | ||
|
||
// Extract the file | ||
outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) | ||
if err != nil { | ||
return fmt.Errorf("error opening file for writing: %s", err) | ||
} | ||
|
||
rc, err := f.Open() | ||
if err != nil { | ||
outFile.Close() | ||
return fmt.Errorf("error opening zip contents: %s", err) | ||
} | ||
|
||
_, err = io.Copy(outFile, rc) | ||
outFile.Close() | ||
rc.Close() | ||
|
||
if err != nil { | ||
return fmt.Errorf("error writing file: %s", err) | ||
} | ||
|
||
// Update the progress bar for each file processed | ||
UpdateInstallBar(40 + float64(40)*(float64(i)+1)/float64(len(zipReader.File))) | ||
} | ||
|
||
// Update status and progress bar for the final phase | ||
UpdateInstallBar(81) | ||
UpdateInstallStatus("Updating registry...") | ||
|
||
UpdateRegistry(is) | ||
UpdateInstallBar(90) | ||
|
||
UpdateInstallStatus("Creating shortcut...") | ||
CreateShortcut(is) | ||
|
||
UpdateInstallStatus("Done!") | ||
|
||
UpdateInstallBar(100) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
id ICON "cmd/wire-pod-installer/rc/pod.ico" | ||
id ICON "windows/icons/ico/pod16x16.ico" | ||
id ICON "windows/icons/ico/pod24x24.ico" | ||
id ICON "windows/icons/ico/pod32x32.ico" | ||
id ICON "windows/icons/ico/pod48x48.ico" | ||
id ICON "windows/icons/ico/pod256x256.ico" | ||
1 24 "cmd/wire-pod-installer/rc/app.manifest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
func UpdateRegistry(is InstallSettings) { | ||
keyPath := `Software\Microsoft\Windows\CurrentVersion\Uninstall\wire-pod` | ||
appName := "wire-pod" | ||
displayIcon := filepath.Join(is.Where, `\chipper\icons\ico\pod256x256.ico`) | ||
displayVersion := "1.0.0" | ||
publisher := "github.com/kercre123" | ||
uninstallString := filepath.Join(is.Where, `\uninstall.exe`) | ||
installLocation := filepath.Join(is.Where, `\chipper\chipper.exe`) | ||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, keyPath, registry.QUERY_VALUE|registry.SET_VALUE) | ||
if err != nil { | ||
k, _, err = registry.CreateKey(registry.LOCAL_MACHINE, keyPath, registry.ALL_ACCESS) | ||
if err != nil { | ||
fmt.Printf("Error creating registry key: %v\n", err) | ||
return | ||
} | ||
} | ||
defer k.Close() | ||
|
||
err = k.SetStringValue("DisplayName", appName) | ||
if err != nil { | ||
fmt.Printf("Error setting DisplayName: %v\n", err) | ||
return | ||
} | ||
k.SetStringValue("DisplayIcon", displayIcon) | ||
k.SetStringValue("DisplayVersion", displayVersion) | ||
k.SetStringValue("Publisher", publisher) | ||
k.SetStringValue("UninstallString", uninstallString) | ||
k.SetStringValue("InstallLocation", installLocation) | ||
fmt.Println("Registry entries successfully created") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/go-ole/go-ole" | ||
"github.com/go-ole/go-ole/oleutil" | ||
) | ||
|
||
func CreateShortcut(is InstallSettings) { | ||
ole.CoInitialize(0) | ||
defer ole.CoUninitialize() | ||
|
||
unknown, err := oleutil.CreateObject("WScript.Shell") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer unknown.Release() | ||
|
||
wshell, err := unknown.QueryInterface(ole.IID_IDispatch) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer wshell.Release() | ||
|
||
cs, err := oleutil.CallMethod(wshell, "CreateShortcut", "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\wire-pod.lnk") | ||
if err != nil { | ||
panic(err) | ||
} | ||
shortcut := cs.ToIDispatch() | ||
defer shortcut.Release() | ||
|
||
oleutil.PutProperty(shortcut, "TargetPath", filepath.Join(is.Where, "\\chipper\\chipper.exe")) | ||
// Set other properties as needed | ||
oleutil.CallMethod(shortcut, "Save") | ||
} |
Oops, something went wrong.