Skip to content

[macOS] Files cannot be opened via Finder when path contains non-ASCII characters #71

Description

@JasonWayne2023

Hi,

Thank you for developing TreeViewer — it's a great tool for phylogenetic tree visualisation.

I noticed an issue on macOS when opening tree files by double-clicking them in Finder. If the file path contains non-ASCII characters (such as Chinese characters) or spaces, TreeViewer shows the following error:

The file type is not supported by any of the current installed modules!

The same file opens correctly when placed in an ASCII-only path, or when opened from the command line with treeviewer /path/to/file.tree.

Steps to reproduce:

  1. Place a valid .tree, .nex, or .tre file in a path like /Users/username/下载/test.tree or /Users/username/test folder/test.tree.
  2. Double-click the file in Finder.
  3. TreeViewer launches and shows the unsupported file type error.

Expected behavior:
The file should open normally, since the format itself is valid.

Root cause:
In src/TreeViewer/CoreClasses/MacOSFileOpener.cs, the file URL is converted using uri.AbsolutePath, which URL-encodes non-ASCII characters. For example, /Users/username/下载/test.tree becomes /Users/username/%E4%B8%8B%E8%BD%BD/test.tree, which does not exist on the filesystem. The file type detection modules then fail to read the file and return a support score of 0, leading to the misleading error message.

Suggested fix:
Replace uri.AbsolutePath with uri.LocalPath in both LoadFile calls within MacOSFileOpener.cs. uri.LocalPath returns the properly decoded local filesystem path.

Uri uri = new Uri(url);
if (uri.IsFile)
{
    string localPath = uri.LocalPath;

    if (GlobalSettings.Settings.MainWindows.Count > 0)
    {
        await GlobalSettings.Settings.MainWindows[0].LoadFile(localPath, false);
    }
    else
    {
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
        await mainWindow.LoadFile(localPath, false);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions