diff --git a/include/wx/msw/stdpaths.h b/include/wx/msw/stdpaths.h index e9e1e8b231..23564fc9cb 100644 --- a/include/wx/msw/stdpaths.h +++ b/include/wx/msw/stdpaths.h @@ -29,6 +29,7 @@ public: virtual wxString GetUserLocalDataDir() const wxOVERRIDE; virtual wxString GetPluginsDir() const wxOVERRIDE; virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE; + virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE; // MSW-specific methods diff --git a/include/wx/osx/cocoa/stdpaths.h b/include/wx/osx/cocoa/stdpaths.h index 59c33f2019..d361d5f65d 100644 --- a/include/wx/osx/cocoa/stdpaths.h +++ b/include/wx/osx/cocoa/stdpaths.h @@ -32,6 +32,7 @@ public: GetLocalizedResourcesDir(const wxString& lang, ResourceCat category = ResourceCat_None) const wxOVERRIDE; virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE; + virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE; protected: // Ctor is protected, use wxStandardPaths::Get() instead of instantiating diff --git a/include/wx/stdpaths.h b/include/wx/stdpaths.h index 8f7c2d43bb..382a99dfd6 100644 --- a/include/wx/stdpaths.h +++ b/include/wx/stdpaths.h @@ -155,6 +155,8 @@ public: virtual wxString GetUserDir(Dir userDir) const; + virtual wxString MakeConfigFileName(const wxString& basename, int style) const = 0; + // virtual dtor for the base class virtual ~wxStandardPathsBase(); diff --git a/include/wx/unix/stdpaths.h b/include/wx/unix/stdpaths.h index 74f915398c..d0ec1469e5 100644 --- a/include/wx/unix/stdpaths.h +++ b/include/wx/unix/stdpaths.h @@ -49,6 +49,7 @@ public: #ifndef __VMS virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE; #endif + virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE; protected: // Ctor is protected, use wxStandardPaths::Get() instead of instantiating diff --git a/interface/wx/stdpaths.h b/interface/wx/stdpaths.h index 9a1f3cbf9f..6484c94cf1 100644 --- a/interface/wx/stdpaths.h +++ b/interface/wx/stdpaths.h @@ -444,6 +444,18 @@ public: */ void UseAppInfo(int info); + /** + Return the file name which would be used by wxFileConfig as local, + user-specific, file if it were constructed with @a basename. + + @a style has the same meaning as in @ref wxConfigBase::wxConfigBase "wxConfig constructor" + and can contain any combination of styles but only wxCONFIG_USE_SUBDIR bit is + examined by this function. + + Notice that this function cannot be used if @a basename is already a full path name. + */ + virtual wxString MakeConfigFileName(const wxString& basename, int style) const; + protected: /** Protected default constructor. diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index c87bcf82f0..6de548379d 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -247,26 +247,6 @@ public: // static functions // ---------------------------------------------------------------------------- -// this function modifies in place the given wxFileName object if it doesn't -// already have an extension -// -// note that it's slightly misnamed under Mac as there it doesn't add an -// extension but modifies the file name instead, so you shouldn't suppose that -// fn.HasExt() is true after it returns -static void AddConfFileExtIfNeeded(wxFileName& fn) -{ - if ( !fn.HasExt() ) - { -#if defined( __WXMAC__ ) - fn.SetName(fn.GetName() + wxT(" Preferences")); -#elif defined( __UNIX__ ) - fn.SetExt(wxT("conf")); -#else // Windows - fn.SetExt(wxT("ini")); -#endif // UNIX/Win - } -} - wxString wxFileConfig::GetGlobalDir() { return wxStandardPaths::Get().GetConfigDir(); @@ -286,30 +266,13 @@ wxString wxFileConfig::GetLocalDir(int style) wxFileName wxFileConfig::GetGlobalFile(const wxString& szFile) { - wxFileName fn(GetGlobalDir(), szFile); - - AddConfFileExtIfNeeded(fn); - + wxFileName fn(GetGlobalDir(), wxStandardPaths::Get().MakeConfigFileName(szFile, wxCONFIG_USE_SUBDIR)); return fn; } wxFileName wxFileConfig::GetLocalFile(const wxString& szFile, int style) { - wxFileName fn(GetLocalDir(style), szFile); - -#if defined( __UNIX__ ) && !defined( __WXMAC__ ) - if ( !(style & wxCONFIG_USE_SUBDIR) ) - { - // dot-files under Unix start with, well, a dot (but OTOH they usually - // don't have any specific extension) - fn.SetName(wxT('.') + fn.GetName()); - } - else // we do append ".conf" extension to config files in subdirectories -#endif // defined( __UNIX__ ) && !defined( __WXMAC__ ) - { - AddConfFileExtIfNeeded(fn); - } - + wxFileName fn(GetLocalDir(style), wxStandardPaths::Get().MakeConfigFileName(szFile, style)); return fn; } diff --git a/src/msw/stdpaths.cpp b/src/msw/stdpaths.cpp index 29aa6b9192..081ab600a7 100644 --- a/src/msw/stdpaths.cpp +++ b/src/msw/stdpaths.cpp @@ -369,6 +369,14 @@ wxString wxStandardPaths::GetPluginsDir() const return GetAppDir(); } + +wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int WXUNUSED(style)) const +{ + wxFileName fn(wxEmptyString, basename); + fn.SetExt(wxT("ini")); + return fn.GetFullName(); +} + // ============================================================================ // wxStandardPathsWin16 implementation // ============================================================================ diff --git a/src/osx/cocoa/stdpaths.mm b/src/osx/cocoa/stdpaths.mm index a8b8323d2a..cd9b75b46a 100644 --- a/src/osx/cocoa/stdpaths.mm +++ b/src/osx/cocoa/stdpaths.mm @@ -19,6 +19,7 @@ #if wxUSE_STDPATHS +#include "wx/filename.h" #include "wx/stdpaths.h" #include "wx/osx/private.h" #include "wx/osx/core/cfstring.h" @@ -129,4 +130,11 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const return GetFMDirectory(dirType, NSUserDomainMask); } +wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int WXUNUSED(style)) const +{ + wxFileName fn(wxEmptyString, basename); + fn.SetName(fn.GetName() + wxT(" Preferences")); + return fn.GetFullName(); +} + #endif // wxUSE_STDPATHS diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index 5f61f19ecb..fecde0c634 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -33,6 +33,7 @@ #include "wx/utils.h" #endif //WX_PRECOMP +#include "wx/fileconf.h" #include "wx/filename.h" #include "wx/log.h" #include "wx/textfile.h" @@ -308,4 +309,14 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const #endif // __VMS/!__VMS +wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int style) const +{ + wxFileName fn(wxEmptyString, basename); + if (style & wxCONFIG_USE_SUBDIR) + fn.SetExt(wxT("conf")); + else + fn.SetName(wxT('.') + fn.GetName()); + return fn.GetFullName(); +} + #endif // wxUSE_STDPATHS