wxFileName::AssignCwd() and wxFileName::SetFullName() problems

Volker Bartheld dr_versaeg at freenet.de
Tue Dec 12 05:24:20 PST 2006


Hi Vadim!

Thanks for your time.

>VB> Is it intended behaviour that wxFileName::AssignCwd() ovewrites a
>VB> filename that has been previously set by i. e.
>VB> wxFileName::SetFullName()?

> I think it is. For me all wxFileName::AssignXXX() methods are supposed to
>fully initialize the object.

OK. No problem. It's all a matter of command order, I could re-assign
the filename via wxFileName::SetFullName() afterwards.

>VB> If I pass c:\foo\bar\ into AssignCwd(),

>Sorry, I don't understand what sense does it make to do this. AssignCwd()
>expects a volume (for Windows, where there are per-volume working
>directories) but "c:\foo\bar\" definitely isn't one.
>What are you trying to achieve?

Actually, I was trying to tell the wxFileName object that it should
consider a relative path it might have been constructed with to be
relative to a directory *I* specify via some kind of member function -
without having to globally (re)set the current working directory because
that might influence the rest of the application.

>VB> What I don't understand is why the (nonstatic) member function
>VB> AssignCwd() calls (static) ::wxSetWorkingDirectory()
>
> There is a comment in wxFileName::GetCwd() explaining this but from
>reading the code I expect AssignCwd() to not change the current working
>directory, of course.

To my knowledge, it does (2.8.0rc1). At least static
::wxSetWorkingDirectory() is called along the way and supposed to make
the change if I trust the documentation.

>VB>   wxString foo(const wxString& s)
>VB>      {
>VB>      wxFileName FileName;
>VB>      FileName.AssignCwd(GetDataFolderOfApplication());

> The above line doesn't do what you think it does (even though I don't know
>what exactly do you think it does). See also wxStandardPaths, you might be
>reinventing what it does with your GetDataFolderOfApplication().

I'm aware of wxStandardPaths. Actually I would need a portable
equivalent of Win32's ::GetModuleFileName(NULL, ...) and add "\\Data\\"
to the returned string. This should be the default path for resolving
relative filenames in wxFileName. As said, I'm using

  wxString foo(const wxString& s)
     {
     wxFileName FileName(s);
     if(FileName.IsRelative())
       {
       FileName.AssignDir(GetDataFolderOfApplication());
       FileName.SetFullName(s);
       }
     if(!wxFileName::IsFileReadable(FileName.GetFullPath()))
       {
       FileName.AssignDir(GetDataFolderOfApplication());
       FileName.SetFullName(wxT("default_file.txt"));
       }
     return FileName.GetFullPath();
     }

which does the trick but seems a little clumsy.


Greets,
Volker

__
Mail replies to/an V B A R T H E L D at G M X dot D E






More information about the wx-users mailing list