wxFileConfig doesn't write config file? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

wxFileConfig doesn't write config file?

Post 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... ?
Last edited by sethjackson on Fri Feb 22, 2008 6:13 pm, edited 1 time in total.
bone
Experienced Solver
Experienced Solver
Posts: 74
Joined: Fri Nov 30, 2007 10:11 am
Location: Oz

Post 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.
Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post by Belgabor »

Try popping up a wxMessageBox and see what

Code: Select all

wxStandardPaths::Get().GetUserLocalDataDir()
actually returns.
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post 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
Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post 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?
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post 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?
Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post 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);
}
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

Thanks!
Post Reply