Blender Finder: allow passing the directory instead of the executable
Blender Finder now understands that directory paths should be suffixed with `blender` (Linux, macOS) or `blender.exe` (Windows). Giving the Setup Assistant a path like `C:\Program files\Blender Foundation\Blender 3.2` will now just work. This is considerably simpler for many users, as copy-pasting a directory from a file explorer is simpler than obtaining/typing the path to the executable.
This commit is contained in:
parent
1e3a2b5480
commit
4cb0a6fb14
@ -6,7 +6,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -58,8 +60,8 @@ func CheckBlender(ctx context.Context, exename string) (CheckBlenderResult, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if crosspath.Dir(exename) != "." {
|
if crosspath.Dir(exename) != "." {
|
||||||
// exename is some form of path, see if it works directly as executable.
|
// exename is some form of path, see if it works for us.
|
||||||
return getResultWithVersion(ctx, exename, exename, api.BlenderPathSourceInputPath)
|
return checkBlenderAtPath(ctx, exename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find exename on $PATH
|
// Try to find exename on $PATH
|
||||||
@ -70,6 +72,25 @@ func CheckBlender(ctx context.Context, exename string) (CheckBlenderResult, erro
|
|||||||
return getResultWithVersion(ctx, exename, fullPath, api.BlenderPathSourcePathEnvvar)
|
return getResultWithVersion(ctx, exename, fullPath, api.BlenderPathSourcePathEnvvar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkBlenderAtPath(ctx context.Context, path string) (CheckBlenderResult, error) {
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return CheckBlenderResult{}, err
|
||||||
|
}
|
||||||
|
if !stat.IsDir() {
|
||||||
|
// Simple case, it's not a directory so let's just try and execute it.
|
||||||
|
return getResultWithVersion(ctx, path, path, api.BlenderPathSourceInputPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try appending the Blender executable name.
|
||||||
|
log.Debug().
|
||||||
|
Str("path", path).
|
||||||
|
Str("executable", blenderExeName).
|
||||||
|
Msg("blender finder: given path is directory, going to find Blender executable")
|
||||||
|
exepath := filepath.Join(path, blenderExeName)
|
||||||
|
return getResultWithVersion(ctx, path, exepath, api.BlenderPathSourceInputPath)
|
||||||
|
}
|
||||||
|
|
||||||
// getResultWithVersion tries to run the command to get Blender's version.
|
// getResultWithVersion tries to run the command to get Blender's version.
|
||||||
// The result is returned as a `CheckBlenderResult` struct.
|
// The result is returned as a `CheckBlenderResult` struct.
|
||||||
func getResultWithVersion(
|
func getResultWithVersion(
|
||||||
|
@ -4,6 +4,8 @@ package find_blender
|
|||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
const blenderExeName = "blender"
|
||||||
|
|
||||||
// fileAssociation isn't implemented on non-Windows platforms.
|
// fileAssociation isn't implemented on non-Windows platforms.
|
||||||
func fileAssociation() (string, error) {
|
func fileAssociation() (string, error) {
|
||||||
return "", ErrNotAvailable
|
return "", ErrNotAvailable
|
||||||
|
@ -14,6 +14,8 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const blenderExeName = "blender.exe"
|
||||||
|
|
||||||
// fileAssociation returns the full path of `blender.exe` associated with ".blend" files.
|
// fileAssociation returns the full path of `blender.exe` associated with ".blend" files.
|
||||||
func fileAssociation() (string, error) {
|
func fileAssociation() (string, error) {
|
||||||
exe, err := getFileAssociation(".blend")
|
exe, err := getFileAssociation(".blend")
|
||||||
|
@ -182,7 +182,7 @@
|
|||||||
v-model="customBlenderExe"
|
v-model="customBlenderExe"
|
||||||
:class="{'is-invalid': blenderExeCheckResult != null && !blenderExeCheckResult.is_usable}"
|
:class="{'is-invalid': blenderExeCheckResult != null && !blenderExeCheckResult.is_usable}"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Path to Blender executable"
|
placeholder="Path to Blender"
|
||||||
>
|
>
|
||||||
<p v-if="isBlenderExeChecking" class="is-in-progress">Checking...</p>
|
<p v-if="isBlenderExeChecking" class="is-in-progress">Checking...</p>
|
||||||
<p v-if="blenderExeCheckResult != null && !blenderExeCheckResult.is_usable" class="check-failed">
|
<p v-if="blenderExeCheckResult != null && !blenderExeCheckResult.is_usable" class="check-failed">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user