Trouble Opening Files On MacOS

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
kestermckinney
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Sep 28, 2019 1:47 pm

Trouble Opening Files On MacOS

Post by kestermckinney »

I have a strang problem with opening files. I thought at first it was unicode related, but after some research, I believe I've build wxWidgets 3.1.2 correctly and I believe my Xcode project is setup correctly. No matter where I put the code below, I get a file not readable or failure to open the file if I don't select the file with the dialog box??? Any ideas of what I should be looking for? I created this code below to try and figure out why other calls to open files is failing in my application.

Code: Select all

GUIMainFrame::GUIMainFrame( wxWindow* parent ) : MainFrame( parent )
{
    wxString dbname("/Users/paulmckinney/Documents/projectnotes/database/ProjectNotes2.db", wxConvUTF8);
     
    wxFileDialog fdlg(this,wxT("Choose a file to open"), wxEmptyString, wxEmptyString,wxT("Database (*.db)|*.db"), wxFD_OPEN, wxDefaultPosition);
    fdlg.ShowModal();
    
    fprintf(stderr, "\n");
    fprintf(stderr, (const char*) dbname);
    fprintf(stderr, "\n");
    
    if(wxFileName::FileExists(dbname))
        fprintf(stderr, "file exists\n");
    else
        fprintf(stderr, "file does not exist\n");
    
    if (wxFileName::IsFileReadable(dbname))
        fprintf(stderr, "file is readable\n");
    else
        fprintf(stderr, "file is not readable\n");
    
}
Last edited by catalin on Sat Sep 28, 2019 2:16 pm, edited 1 time in total.
Reason: code tags
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trouble Opening Files On MacOS

Post by doublemax »

So, if you use fdlg->GetPath() you can open the file, but with the hard coded string you can't?

If yes, what does fdlg->GetPath() return? There must be a difference.
Use the source, Luke!
kestermckinney
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Sep 28, 2019 1:47 pm

Re: Trouble Opening Files On MacOS

Post by kestermckinney »

Notice the code doesn't call GetPath(). I actually don't want to use the file dialog. The file dialog just does something to allow me to read files once I select it. It's very bizarre. The file name in the string dbname is correct.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trouble Opening Files On MacOS

Post by doublemax »

kestermckinney wrote: Sat Sep 28, 2019 3:11 pmThe file dialog just does something to allow me to read files once I select it. It's very bizarre. The file name in the string dbname is correct.
I doubt that. Please double/triple check and compare it with the output of fdlg->GetPath()

Code: Select all

wxString dbname("/Users/paulmckinney/Documents/projectnotes/database/ProjectNotes2.db", wxConvUTF8);
There are no non-ascii characters in that string, so it shouldn't make any difference. But try without the wxConvUTF8.
Use the source, Luke!
kestermckinney
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Sep 28, 2019 1:47 pm

Re: Trouble Opening Files On MacOS

Post by kestermckinney »

Ok, I figured it out. The dialog box must somehow override the Sandboxing features of MacOS. I went into the .entitlements file and set com.apple.security.files.user-selected.read-only to NO and set App Sandbox to NO. It works perfectly now.
Post Reply