Page 1 of 1

wxFileConfig doesn't write config file?

Posted: Thu Feb 21, 2008 7:52 pm
by sethjackson
Hey I'm having a really weird problem with wxFileConfig....

I want the config file to be in the user's application data directory. On Windows Vista that would be: C:\Users\user-name\AppData\Local\app-name\settings.txt


So I do:

Code: Select all

conf = new wxFileConfig(_T("Foo"), 
                        wxEmptyString, 
                        wxStandardPaths::Get().GetUserLocalDataDir() + wxFileName::GetPathSeparator() + _T("settings.txt"), 
                        wxEmptyString, 
                        wxCONFIG_USE_LOCAL_FILE);
(where conf is a wxFileConfig* )


This:

Code: Select all

wxStandardPaths::Get().GetUserLocalDataDir() + wxFileName::GetPathSeparator() + _T("settings.txt")
gives:

C:\Users\user-name\AppData\Local\app-name\settings.txt


Reading/Writing settings works (per app instance), but the app-name directory, and the settings file do not exist... :?

So what is the deal? Anyone know what I'm doing wrong?

I'm using wxWidgets 2.8.7 (Unicode), on Windows Vista.

Edit:

Looks like the file isn't being created for some reason... ?

Posted: Fri Feb 22, 2008 12:59 am
by bone
Vista is a bit wierd and I haven't fully plumbed its foibles but your file will be somewhere if it is able to be read and written to. Perhaps in C:\Program Data\myapp.

I know the read/write settings for your app dir are important but you are writing (hopefully) to your user or current user's dir.

Run a file search for "settings.txt" which I think is the name of your config file. I am interested as to where it has ended up.

Posted: Fri Feb 22, 2008 2:12 pm
by Belgabor
Try popping up a wxMessageBox and see what

Code: Select all

wxStandardPaths::Get().GetUserLocalDataDir()
actually returns.

Posted: Fri Feb 22, 2008 6:15 pm
by sethjackson
bone wrote:Vista is a bit wierd and I haven't fully plumbed its foibles but your file will be somewhere if it is able to be read and written to. Perhaps in C:\Program Data\myapp.

I know the read/write settings for your app dir are important but you are writing (hopefully) to your user or current user's dir.

Run a file search for "settings.txt" which I think is the name of your config file. I am interested as to where it has ended up.
Looks like the file isn't being created for some reason...

A couple of times wxWidgets popped up a message box saying the path was invalid (or something like that)....
Belgabor wrote:Try popping up a wxMessageBox and see what

Code: Select all

wxStandardPaths::Get().GetUserLocalDataDir()
actually returns.
Already did that.

I get:

Code: Select all

C:\Users\user-name\AppData\Local\app-name

Posted: Fri Feb 22, 2008 8:24 pm
by Belgabor
I see. You write that the directory does not exist, maybe that is the problem? What happens if you create the dir manually?

Posted: Mon Feb 25, 2008 9:08 pm
by sethjackson
Belgabor wrote:I see. You write that the directory does not exist, maybe that is the problem? What happens if you create the dir manually?
Hmm ok. Actually that turned out to be the problem (had to fix my code first LOL).

So I was under the impression that the directory would be created for me? Is that not the case?

Posted: Mon Feb 25, 2008 10:18 pm
by Belgabor
Well, I think your code proove that indeed it's not the case :)

Here's something I use:

Code: Select all

bool EnsureDir(wxFileName& target) {
    if (target.DirExists()) {
        return true;
    }
    return target.Mkdir(0777, wxPATH_MKDIR_FULL);
}

Posted: Tue Feb 26, 2008 6:51 pm
by sethjackson
Thanks!