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

Volker Bartheld dr_versaeg at freenet.de
Mon Dec 11 10:04:33 PST 2006


Hi!

[wxMSW 2.8.0rc1]

Is it intended behaviour that wxFileName::AssignCwd() ovewrites a
filename that has been previously set by i. e.
wxFileName::SetFullName()? I noticed that in
wxwidgets\src\common\filename.cpp

void wxFileName::Assign(const wxString& fullpathOrig,
                        const wxString& fullname,
                        wxPathFormat format)

calls Assign(volume, path, name, ext, hasExt, format); which will set

    m_ext = ext;
    m_name = name;

which are - in that case - obviously empty since wxFileName::AssignCwd()
expects a directory rather than a fully qualified path. Moreover, it
seems that the last directory is chopped off somwhere: If I pass
c:\foo\bar\ into AssignCwd(), the static function wxFileName::GetCwd()
returns c:\foo in cwd.

This is probably, because of the

        SetCwd(volume + GetVolumeSeparator());

in wxFileName::GetCwd() which calls SetCwd() with c:\foo\bar\: and
::wxSetWorkingDirectory() cannot cope with the illegal path.

What I don't understand is why the (nonstatic) member function
AssignCwd() calls (static) ::wxSetWorkingDirectory() - thus setting the
cwd for the whole application rather than assigning a working directory
for a relative path that might be stored inside m_name/m_ext of
wxFileName...

My original intention was to have a function that always returns a valid
file reference, either from the parameter's absolute or relative path or
a default (default_file.txt) that points to a file that is shipped with
the binary. Like that:

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

So, if I call foo(wxT("c:\\autoexec.bat")) this should return
wxString(wxT("c:\\autoexec.bat")), if I call foo(wxT("test.txt")) it
should look into and return GetDataFolderOfApplication()+wxT("test.txt")
if the file is readable and default to
GetDataFolderOfApplication()+wxT("default_file.txt") if not.

How can this be done?

Thanks,
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