Skip to content

Commit

Permalink
Correct path and correctly escape path when running windows install.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluebugs committed Apr 17, 2023
1 parent c23851b commit 152f42f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (i *Installer) install() error {
dirName = p.Name[:len(p.Name)-4]
}
i.installDir = filepath.Join(os.Getenv("ProgramFiles"), dirName)
err := runAsAdminWindows("mkdir", "\"\""+i.installDir+"\"\"")
err := runAsAdminWindows("mkdir", i.installDir)
if err != nil {
fyne.LogError("Failed to run as windows administrator", err)
return err
Expand Down
21 changes: 16 additions & 5 deletions cmd/fyne/internal/commands/package-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,23 @@ func (p *Packager) packageWindows(tags []string) error {
return fmt.Errorf("failed to rebuild after adding metadata: %w", err)
}

appPath := p.exe
appName := filepath.Base(p.exe)
if filepath.Base(p.exe) != p.Name {
appName = p.Name
if filepath.Ext(p.Name) != ".exe" {
appName = appName + ".exe"
}
appPath = filepath.Join(p.dir, appName)
os.Rename(filepath.Base(p.exe), appName)
}

if p.install {
err := runAsAdminWindows("copy", "\"\""+appPath+"\"\"", "\"\""+filepath.Join(p.dir, appName)+"\"\"")
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to locate current working directory")
}
appPath := filepath.Join(wd, appName)

err = runAsAdminWindows("copy", appPath, filepath.Join(p.dir, appName))
if err != nil {
return fmt.Errorf("failed to run as administrator: %w", err)
}
Expand All @@ -131,8 +135,15 @@ func (p *Packager) packageWindows(tags []string) error {
func runAsAdminWindows(args ...string) error {
cmd := "\"/c\""

for _, arg := range args {
cmd += ",\"" + arg + "\""
for idx, arg := range args {
if idx == 0 {
cmd += ",'" + arg
} else {
cmd += " \"" + arg + "\""
}
}
if len(args) != 0 {
cmd += "'"
}

return execabs.Command("powershell.exe", "Start-Process", "cmd.exe", "-Verb", "runAs", "-ArgumentList", cmd).Run()
Expand Down

0 comments on commit 152f42f

Please sign in to comment.