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

Windows cannot open any files or folders #437

Open
p1g3 opened this issue Oct 31, 2024 · 1 comment
Open

Windows cannot open any files or folders #437

p1g3 opened this issue Oct 31, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@p1g3
Copy link

p1g3 commented Oct 31, 2024

Describe the bug
Windows cannot open any files or folders

To Reproduce

Run spf, find a folder, use the E shortcut key to not open

Expected behavior

Open this folder using a file manager

System information (please complete the following information):

  • OS: 10.0.22631 Build 22631
  • Superfile Version v1.1.5
@p1g3 p1g3 added the bug Something isn't working label Oct 31, 2024
@kjk
Copy link

kjk commented Nov 10, 2024

The issue is in openFileWithEditor() / openDirectoryWithEditor()

On windows it should launch default handler app for a file like e.g.:

   cmd := exec.Command("cmd", "/c", "start", absPath)
    if err := cmd.Run(); err != nil {
        return fmt.Errorf("failed to open file: %w", err)
    }

or:

    verb := windows.StringToUTF16Ptr("open")
    file := windows.StringToUTF16Ptr(absPath)
    
    // ShellExecute returns an instance handle, but we don't need it
    ret, err := windows.ShellExecute(0, verb, file, nil, nil, windows.SW_SHOW)
    if ret <= 32 { // According to Windows API documentation, return values <= 32 indicate an error
        if err != nil {
            return fmt.Errorf("failed to open file: %w", err)
        }
        return fmt.Errorf("failed to open file: error code %d", ret)
    }

For folders it's more tricky because the default handler would be file explorer, not an editor.

One option is to detect handler for .txt files by reading registry and launch that program with directory but not editor support directory. E.g. notepad doesn't handle directories but vscode does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants