superfile icon indicating copy to clipboard operation
superfile copied to clipboard

Windows cannot open any files or folders

Open p1g3 opened this issue 1 year ago • 1 comments

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 avatar Oct 31 '24 02:10 p1g3

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.

kjk avatar Nov 10 '24 19:11 kjk

Able to reproduce it with spf v1.1.7.1 and with Windows 11 Home 24H2 - build 26100.2894

For both files and directories, 'e' and 'E' are not working. Right arrow works as expected.

lazysegtree avatar Jan 22 '25 15:01 lazysegtree

@p1g3 Thanks for the bug report. This has been fixed. Can you do a local build spf from the main branch and see if the issue if fixed for you ?

lazysegtree avatar Feb 06 '25 00:02 lazysegtree

@p1g3 Closing this. Please feel free to reopen if you still face the issue.

lazysegtree avatar Feb 09 '25 08:02 lazysegtree