miketheprogrammer / go-thrust

Cross Platform UI Kit powered by Blink/V8/Chromium Content Lib
MIT License
445 stars 34 forks source link

Put vendor dir in current dir instead of in / #15

Closed ghost closed 9 years ago

ghost commented 9 years ago

On Linux it tries to put the vendor directory in / Hope this helps.

tehbilly commented 9 years ago

I would recommend starting with os.Getwd() and joining it with vendor like so:

func GetThrustDirectory() string {
    wd, err := os.Getwd()
    if err != nil { // Just in case
        wd = "."
    }
    return filepath.Join(wd, "linux", "x64", common.THRUST_VERSION)
}

This could probably be removed from the os-specific files, as well, as that functionality provided by os.Getwd() and filepath.Join() is already cross-platform.

miketheprogrammer commented 9 years ago

is user.Current() user.Homedir not cross platform?

func SetBaseDirectory(dir string) error {
    if len(dir) == 0 {
        usr, err := user.Current()
        if err != nil {
            fmt.Println(err)
        }
        fmt.Println(usr.HomeDir)
        dir = usr.HomeDir
    }
    dir, err := filepath.Abs(dir)
    if err != nil {
        fmt.Println("Could not calculate absolute path", err)
        return err
    }
    base = dir

    return nil
}
miketheprogrammer commented 9 years ago

And here is the safety check

func Run() {
    if Log == nil {
        InitLogger("debug")
    }
    if base == "" {
        SetBaseDirectory("") // Default to usr.homedir.
    }
miketheprogrammer commented 9 years ago

@tehbilly What do you think, Working Directory or Home Directory as default, definitely however we should use path.join instead of all the windows specific "x\y\z" strings