返回 DeepSeek-Reasonix
open_workspace_windows.go
根目录 / desktop / open_workspace_windows.go
1 //go:build windows
2
3 package main
4
5 import (
6 "os"
7
8 "golang.org/x/sys/windows"
9 )
10
11 func openWorkspacePath(path string) error {
12 info, err := os.Stat(path)
13 if err != nil {
14 return err
15 }
16 return openWorkspacePathWithType(path, info.IsDir())
17 }
18
19 func openWorkspacePathWithType(path string, isDir bool) error {
20 verb, target := shellOpenCommand(path, isDir)
21 verbPtr, err := windows.UTF16PtrFromString(verb)
22 if err != nil {
23 return err
24 }
25 filePtr, err := windows.UTF16PtrFromString(target)
26 if err != nil {
27 return err
28 }
29 return windows.ShellExecute(0, verbPtr, filePtr, nil, nil, windows.SW_SHOWNORMAL)
30 }
31
32 // shellOpenCommand returns the ShellExecute verb and target used to open path.
33 // Folders use "explore" and a trailing separator so the shell cannot confuse
34 // them with a sibling "<folder>.lnk" and launch its target (#7851). Files keep
35 // the "open" verb and their original path.
36 func shellOpenCommand(path string, isDir bool) (verb, target string) {
37 if isDir {
38 target = path
39 if target == "" || !os.IsPathSeparator(target[len(target)-1]) {
40 target += string(os.PathSeparator)
41 }
42 return "explore", target
43 }
44 return "open", path
45 }
46
46 lines GO