Page 1 of 1

Trouble Opening Files On MacOS

Posted: Sat Sep 28, 2019 1:56 pm
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");
    
}

Re: Trouble Opening Files On MacOS

Posted: Sat Sep 28, 2019 2:42 pm
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.

Re: Trouble Opening Files On MacOS

Posted: Sat Sep 28, 2019 3:11 pm
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.

Re: Trouble Opening Files On MacOS

Posted: Sat Sep 28, 2019 3:37 pm
by doublemax
kestermckinney wrote:
Sat Sep 28, 2019 3:11 pm
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.
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.

Re: Trouble Opening Files On MacOS

Posted: Sun Sep 29, 2019 1:23 am
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.