Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add startup shortcut #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ require (
golang.org/x/text v0.3.1-0.20180810153555-6e3c4e7365dd
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
require github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
2 changes: 1 addition & 1 deletion manifest/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (wixFile *WixManifest) check() error {
}
for _, shortcut := range wixFile.Shortcuts {
switch shortcut.Location {
case "program", "desktop":
case "program", "desktop", "startup":
default:
return fmt.Errorf(`Invalid "location" value in shortcut: %s`, shortcut.Location)
}
Expand Down
16 changes: 12 additions & 4 deletions msi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var TPLPATH = "" // non-windows build, use ldflags to tell about that.

// Main exposes the application entry point.
func Main() {

if TPLPATH == "" { // built for windows
b, err := util.GetBinPath()
if err != nil {
Expand Down Expand Up @@ -201,6 +200,10 @@ func Main() {
Name: "msi, m",
Usage: "Path to write resulting msi file to",
},
cli.StringFlag{
Name: "lang",
Usage: "Culture of the localization strings",
},
},
},
{
Expand Down Expand Up @@ -247,6 +250,10 @@ func Main() {
Name: "msi, m",
Usage: "Path to write resulting msi file to",
},
cli.StringFlag{
Name: "lang",
Usage: "Culture of the localization strings",
},
cli.StringFlag{
Name: "version",
Usage: "The version of your program",
Expand Down Expand Up @@ -627,6 +634,7 @@ func generateWixCommands(c *cli.Context) error {
msi := c.String("msi")
arch := c.String("arch")
bin := c.String("bin")
lang := c.String("lang")

if msi == "" {
return cli.NewExitError("--msi parameter must be set", 1)
Expand Down Expand Up @@ -680,8 +688,7 @@ func generateWixCommands(c *cli.Context) error {
return cli.NewExitError(err.Error(), 1)
}
}

cmdStr := wix.GenerateCmd(&wixFile, builtTemplates, msi, arch, bin)
cmdStr := wix.GenerateCmd(&wixFile, builtTemplates, msi, arch, bin, lang)

targetFile := filepath.Join(out, "build.bat")
err = ioutil.WriteFile(targetFile, []byte(cmdStr), 0644)
Expand Down Expand Up @@ -720,6 +727,7 @@ func quickMake(c *cli.Context) error {
arch := c.String("arch")
keep := c.Bool("keep")
bin := c.String("bin")
lang := c.String("lang")

if msi == "" {
return cli.NewExitError("--msi parameter must be set", 1)
Expand Down Expand Up @@ -808,7 +816,7 @@ func quickMake(c *cli.Context) error {
}
}

cmdStr := wix.GenerateCmd(&wixFile, builtTemplates, msi, arch, bin)
cmdStr := wix.GenerateCmd(&wixFile, builtTemplates, msi, arch, bin, lang)

targetFile := filepath.Join(out, "build.bat")
err = ioutil.WriteFile(targetFile, []byte(cmdStr), 0644)
Expand Down
3 changes: 2 additions & 1 deletion templates/product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@

<Directory Id="ProgramMenuFolder"/>
<Directory Id="DesktopFolder"/>
<Directory Id="StartupFolder"/>

{{range $i, $s := .Shortcuts}}
<Component Id="ApplicationShortcuts{{$i}}" Guid="*">
<Shortcut Id="ApplicationShortcut{{$i}}" Name="{{$s.Name}}" Description="{{$s.Description}}" Target="{{$s.Target}}" WorkingDirectory="{{$s.WDir}}"
Directory={{if eq $s.Location "program"}}"ProgramMenuFolder"{{else}}"DesktopFolder"{{end}}
Directory={{if eq $s.Location "program"}}"ProgramMenuFolder"{{ else if eq $s.Location "startup" }}"StartupFolder"{{else}}"DesktopFolder"{{end}}
{{if gt ($s.Arguments | len) 0}}Arguments="{{$s.Arguments}}"{{end}}>
{{if gt ($s.Icon | len) 0}}<Icon Id="Icon{{$i}}" SourceFile="{{$s.Icon}}"/>{{end}}
{{range $j, $p := $s.Properties}}<ShortcutProperty Key="{{$p.Key}}" Value="{{$p.Value}}"/>{{end}}
Expand Down
8 changes: 8 additions & 0 deletions testing/hello/wix.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@
"wdir": "INSTALLDIR",
"icon": "ico.ico",
"condition": "DESKTOPSHORTCUT ~= \"yes\""
},
{
"name": "hello",
"description": "hello web server",
"location": "startup",
"target": "[INSTALLDIR]hello.exe",
"wdir": "INSTALLDIR",
"icon": "ico.ico"
}
],
"choco": {
Expand Down
6 changes: 4 additions & 2 deletions wix/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
var eol = "\r\n"

// GenerateCmd generates required command lines to produce an msi package,
func GenerateCmd(wixFile *manifest.WixManifest, templates []string, msiOutFile, arch, path string) string {

func GenerateCmd(wixFile *manifest.WixManifest, templates []string, msiOutFile, arch, path, lang string) string {
cmd := ""

cmd += filepath.Join(path, "candle")
Expand All @@ -29,6 +28,9 @@ func GenerateCmd(wixFile *manifest.WixManifest, templates []string, msiOutFile,
cmd += eol
cmd += filepath.Join(path, "light") + " -ext WixUIExtension -ext WixUtilExtension -sacl -spdb "
cmd += " -out " + msiOutFile
if lang != "" {
cmd += " -cultures:" + lang
}
for _, tpl := range templates {
cmd += " " + strings.Replace(filepath.Base(tpl), ".wxs", ".wixobj", -1)
}
Expand Down