MAC: wxDirDialog doesn't give the real volume name

60 views
Skip to first unread message

Hector

unread,
Jan 19, 2019, 4:15:36 PM1/19/19
to wx-users
On Mac, when I use wxDirDialog  to select a folder from my NAS (Network Attached Storage), wxDirDialog ::GetPath() returns /Volume/... instead of /ls-wsgl27b/...

When I browse for the folder, my NAS appears in the category "Shared" with the correct name. There's no place where Finder doesn't display the real volume name, but wxDirDialog::GetPath() always replaces the real name with just "Volume".

It's a real problem for me as I have to send a command to another computer which needs the real volume name to find it.

Thank you very much for your help!

Igor Korot

unread,
Jan 19, 2019, 4:27:29 PM1/19/19
to wx-u...@googlegroups.com
Hi,
On Sat, Jan 19, 2019 at 3:15 PM Hector <Hec...@coollector.com> wrote:
>
> On Mac, when I use wxDirDialog to select a folder from my NAS (Network Attached Storage), wxDirDialog ::GetPath() returns /Volume/... instead of /ls-wsgl27b/...

1. What version of wx do you use?
2. What OS are you testing it under? What OS is running on the network share?
3. Is dialogs sample behaves the same?

Thank you.

>
> When I browse for the folder, my NAS appears in the category "Shared" with the correct name. There's no place where Finder doesn't display the real volume name, but wxDirDialog::GetPath() always replaces the real name with just "Volume".
>
> It's a real problem for me as I have to send a command to another computer which needs the real volume name to find it.
>
> Thank you very much for your help!
>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Igor Korot

unread,
Jan 19, 2019, 4:28:38 PM1/19/19
to wx-u...@googlegroups.com
Hi,

On Sat, Jan 19, 2019 at 3:15 PM Hector <Hec...@coollector.com> wrote:
>
> On Mac, when I use wxDirDialog to select a folder from my NAS (Network Attached Storage), wxDirDialog ::GetPath() returns /Volume/... instead of /ls-wsgl27b/...

In addirtion - does wxFileDialog behaves properly?

Thank you.

>
> When I browse for the folder, my NAS appears in the category "Shared" with the correct name. There's no place where Finder doesn't display the real volume name, but wxDirDialog::GetPath() always replaces the real name with just "Volume".
>
> It's a real problem for me as I have to send a command to another computer which needs the real volume name to find it.
>
> Thank you very much for your help!
>

Hector

unread,
Jan 19, 2019, 4:42:18 PM1/19/19
to wx-users
Thank you for your response!

I've just moved to wxWdigets 3.1.2, but it was already like that when I used wx2.9. I wasn't bothered until now. I'm using an API to command another app on another computer, and I need to pass the correct file path.

I'm testing with Mac OS 10.13, but it was already the case with all the previous Mac OS versions, except that I didn't care at that time.

I will try to compile the sample, but I'm almost sure of the result.

Other than that, wxFileDialog is working fine and I had never notice that issue because if I ask VLC to play a video file, it plays fine even with "Volume", but now that I'm asking a Kodi box to play a file on TV, it won't recognize the file path.

Hector

unread,
Jan 19, 2019, 4:54:30 PM1/19/19
to wx-users
When I use the dialogs sample, browsing the locations correctly displays the volume name, but returns /Volumes/ too.

If I use the generic dialog, then only "Volumes" is displayed and not the real name. This seems to be an underlying problem with wxWidgets.

Hector

unread,
Jan 19, 2019, 5:30:16 PM1/19/19
to wx-users
Do you get a different result with the sample on your computer?

Stefan Csomor

unread,
Jan 20, 2019, 2:42:24 AM1/20/19
to wx-u...@googlegroups.com

Hi Hector

 

>When I browse for the folder, my NAS appears in the category "Shared" with the correct name. There's no place where Finder doesn't display the real volume >name, but wxDirDialog::GetPath() always replaces the real name with just "Volume".

 

>It's a real problem for me as I have to send a command to another computer which needs the real volume name to find it.

 

As long as /Volume/.. is followed by the share name then this is correct native behaviour, the dir dialog only shows you a nicer user friendly view, if you open a terminal window and drag the volume onto it you should find that the posix name of the volume starts with /Volumes/... that were all the shares are mounted to. This is different from the old HFS System, where the path started with the volume name directly.

 

HTH

 

Stefan

Hector

unread,
Jan 20, 2019, 5:22:28 AM1/20/19
to wx-users
Thank you Stefan for your answer!

> the dir dialog only shows you a nicer user friendly view

It's more user friendly and also more computer friendly, because any computer would be able to recognize the network path, not just the Mac you're currently using.

I've searched for a wxWidgets method that would allow me to translate the result of wxDirDialog::GetPath() into a real network path but couldn't find any. Did I miss something or will I have to use native Mac code to do it? Thank you for your help!

Best regards,
  Pascal Baspeyras.

Hector

unread,
Jan 20, 2019, 5:39:46 AM1/20/19
to wx-users
> As long as /Volume/.. is followed by the share name then this is correct
> native behaviour

When you use the finder or when you right click on a file to get its info, Mac OS will always display the network name instead of "Volumes" followed by the share name. In the end, I think it's quite confusing for the user and quite limiting for the programmer.

Gunter Königsmann

unread,
Jan 20, 2019, 5:46:56 AM1/20/19
to wx-u...@googlegroups.com
To me that sounds like windows telling users that all drives are on the desktop while in reality the desktop is a folder in one of the drives. Which is supposed to make things easier for users but tends to cause confusion.

Hector

unread,
Jan 20, 2019, 6:09:19 AM1/20/19
to wx-users
Network drives have a universal network name that any computer on the network can recognize. That's why we have network drives, to access them from several computers. There are some times when, at least as a developer, I need to know the real network name of the drive...

Stefan Csomor

unread,
Jan 20, 2019, 6:27:16 AM1/20/19
to wx-u...@googlegroups.com

Hi

 

> Network drives have a universal network name that any computer on the network can recognize. That's why we have network drives, to access them from
> several computers. There are some times when, at least as a developer, I need to know the real network name of the drive...

 

if you want to know the ‘share’ name, then you just strip /Volumes/ from the name, but this does not give you the host name, nor the protocol used

 

Best,

 

Stefan

Hector

unread,
Jan 20, 2019, 6:38:12 AM1/20/19
to wx-users
> if you want to know the ‘share’ name, then you just strip /Volumes/ from the name,
> but this does not give you the host name, nor the protocol used

For my network drive, I get /Volume/... instead of /ls-wsgl27b/...

It's impossible to use it like that. I need to find a method to get all the network names, then replace all the locations listed inside "Volumes" until I find the right one. Not convenient but I have no choice...

Hector

unread,
Jan 20, 2019, 8:33:41 AM1/20/19
to wx-users
I understand that you won't change the behavior of wxDirDialog. I'm looking for a method to convert the path so I can send it to another computer.

I've found that the terminal command "df /Volumes/share" returns "//GUEST:@ls-wsgl27b/share".

Look like I could make it work... For the moment, it's the only lead that I have. I'll use that technique if I can't find anything better. Any suggestions are welcome ;-)

Best regards,
   Pascal Baspeyras.

Hector

unread,
Jan 20, 2019, 1:10:43 PM1/20/19
to wx-users
I think I've finally found a decent solution with NSFileManager and NSURLVolumeURLForRemountingKey.

I've tested it, it returns "//GUEST:@ls-wsgl27b/share"... Victory!

Stefan Csomor

unread,
Jan 21, 2019, 12:59:56 AM1/21/19
to wx-u...@googlegroups.com

Hi

 

> I think I've finally found a decent solution with NSFileManager and NSURLVolumeURLForRemountingKey.

> I've tested it, it returns "//GUEST:@ls-wsgl27b/share"... Victory!

 

congratulations :-) does this give you the file scheme as well ? or do you just default to smb ?

 

Best,

 

Stefan

Stefan Csomor

unread,
Jan 21, 2019, 1:44:42 AM1/21/19
to wx-u...@googlegroups.com

Hi

 

me again,

 

> I think I've finally found a decent solution with NSFileManager and NSURLVolumeURLForRemountingKey.

> I've tested it, it returns "//GUEST:@ls-wsgl27b/share"... Victory!

 

do you do the same on MSW, ie do you have a function to get the UNC behind a volume mounted as a letter volume, eg Z:/ ?

 

Best,

 

Stefan

Fabian Cenedese

unread,
Jan 21, 2019, 3:21:29 AM1/21/19
to wx-u...@googlegroups.com

Hector

unread,
Jan 21, 2019, 3:42:16 AM1/21/19
to wx-users
>> I've tested it, it returns "//GUEST:@ls-wsgl27b/share"... Victory!

 >

> congratulations :-) does this give you the file scheme as well ? or do you just default to smb ?

Thank you! In fact, I made a typo, it returns  "smb://GUEST:@ls-wsgl27b/share"

Hector

unread,
Jan 21, 2019, 3:44:54 AM1/21/19
to wx-users
> do you do the same on MSW, ie do you have a function to get the UNC behind a volume
> mounted as a letter volume, eg Z:/ ?

On Windows, I just ask the users to select the folder with its network name (from Networks) rather than the drive letter. On Mac they don't have that choice.

Hector

unread,
Jan 21, 2019, 3:46:51 AM1/21/19
to wx-users
> Probably WNetGetConnectionA or WNetGetUniversalNameA (since Windows 2000): 

Thanks for the tip, I will have a look at it! It could indeed make the feature even more user-friendly :)

Stefan Csomor

unread,
Jan 21, 2019, 4:28:42 AM1/21/19
to wx-u...@googlegroups.com
Hi

At 07:44 21.01.2019, Stefan Csomor wrote:
>Hi
>me again,
>
>> I think I've finally found a decent solution with NSFileManager and NSURLVolumeURLForRemountingKey.
>> I've tested it, it returns "//GUEST:@ls-wsgl27b/share"... Victory!
>
>do you do the same on MSW, ie do you have a function to get the UNC behind a volume mounted as a letter volume, eg Z:/ ?

Probably WNetGetConnectionA or WNetGetUniversalNameA (since Windows 2000):

https://docs.microsoft.com/en-us/windows/desktop/WNet/retrieving-the-connection-name
https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetgetuniversalnamea

Thanks, perhaps we could add have a universal API on wxFilenname or somewhere for that

Best,

Stefan

Hector

unread,
Jan 21, 2019, 7:17:37 AM1/21/19
to wx-users
> perhaps we could add have a universal API on wxFilenname or somewhere for that

Maybe something like wxFilename::ConvertToUNC(wxString LocalName).

I would definitively use it :)


Hector

unread,
Jan 21, 2019, 7:25:57 AM1/21/19
to wx-users
> perhaps we could add have a universal API on wxFileName

The first thing I've done was indeed looking into wxFileName to see if it had a method that could help me.

Hector

unread,
Feb 5, 2019, 4:43:18 AM2/5/19
to wx-users
It all worked fine, I could add the feature to my app, thank you everybody! Here's the code that I've used...

MAC:
----

#include "wx/osx/private.h"

wxString GetNetworkPath(wxString Path)
{
    NSURL *Result = nil;
    
    NSError *Error = nil;

    wxCFStringRef cf(Path, wxFONTENCODING_UTF8);
    
    NSURL *Url = [NSURL fileURLWithPath:cf.AsNSString()];

    BOOL success = [Url getResourceValue:&Result forKey:NSURLVolumeURLForRemountingKey error:&Error];

    if ( success == FALSE || Result == nil )
    {
        return "";
    }
    else
    {
        return wxCFStringRef::AsString(Result.absoluteString);
    }
}


WINDOWS:
--------

wxString GetNetworkPath(wxString Path)
{
DWORD dwRetVal;

WCHAR Buffer[1024];
DWORD dwBufferLength = 1024;
       
UNIVERSAL_NAME_INFO * unameinfo;

unameinfo = (UNIVERSAL_NAME_INFO *) &Buffer;
dwRetVal = WNetGetUniversalName(Path.wc_str(), UNIVERSAL_NAME_INFO_LEVEL, (LPVOID) unameinfo, &dwBufferLength );

if ( dwRetVal == NO_ERROR )
{
return wxString(unameinfo->lpUniversalName);
}
else
{
return "";
}
}
Reply all
Reply to author
Forward
0 new messages