add compatibility mode for NSIS args
This commit is contained in:
@ -2,6 +2,7 @@ At last, an I2P Browser you might want to use
|
||||
=============================================
|
||||
|
||||
1. I2P can only grow if it's easily accessible to people
|
||||
2. I2P and Tor have different, unique strengths
|
||||
2. I2P and Tor have different, unique strengths and can be more powerful when combined in a considered way
|
||||
3. Anonymity is a collaborative effort
|
||||
4. Leeching is rude, if we use something we should try to improve it or give something back
|
||||
4. Leeching is rude, if we use something we should try to improve it or give something back
|
||||
|
||||
|
4
main.go
4
main.go
@ -176,6 +176,10 @@ var snowflake *bool
|
||||
var client *tbserve.Client
|
||||
|
||||
func main() {
|
||||
if err := NSISCompat(); err != nil {
|
||||
log.Println("NSIS compat mode failure", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
filename := filepath.Base(os.Args[0])
|
||||
SnowflakeFlag()
|
||||
usage := flag.Usage
|
||||
|
57
nsis.go
Normal file
57
nsis.go
Normal file
@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NSISCompat() error {
|
||||
// check if no flags(args beginning with '-') were passed
|
||||
if len(os.Args) == 1 {
|
||||
return nil
|
||||
}
|
||||
for _, arg := range os.Args[1:] {
|
||||
if arg[0] == '-' {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
var convertArgs = []string{}
|
||||
// check if any args beginning with /S or /D
|
||||
for _, arg := range os.Args[1:] {
|
||||
if strings.HasPrefix(arg, "/S") {
|
||||
log.Println("/S flag was passed, we're operating in NSIS installer compatibility mode")
|
||||
}
|
||||
if strings.HasPrefix(arg, "/D") {
|
||||
if len(arg) > 3 {
|
||||
return fmt.Errorf("/D flag was passed with a directory argument in NSIS compatibility mode")
|
||||
}
|
||||
log.Println("/D flag was passed, we're operating in NSIS installer compatibility mode")
|
||||
convertArgs = append(convertArgs, "--directory="+arg[2:])
|
||||
}
|
||||
}
|
||||
if len(convertArgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
// if we're here, we're operating in NSIS compatibility mode
|
||||
// re-run ourselves with the converted args
|
||||
// start by getting the path to our executable
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// forumulate our new command
|
||||
cmd := exec.Command(exePath, convertArgs...)
|
||||
// set the current working directory to the same as our executable
|
||||
cmd.Dir = filepath.Dir(exePath)
|
||||
// run the command
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if we're here, we're done
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user