diff --git a/include/wx/msw/stdpaths.h b/include/wx/msw/stdpaths.h index 23564fc9cb..3f733bc67f 100644 --- a/include/wx/msw/stdpaths.h +++ b/include/wx/msw/stdpaths.h @@ -29,7 +29,8 @@ 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; + virtual wxString MakeConfigFileName(const wxString& basename, + ConfigFileConv conv) const wxOVERRIDE; // MSW-specific methods diff --git a/include/wx/osx/cocoa/stdpaths.h b/include/wx/osx/cocoa/stdpaths.h index d361d5f65d..c77713da12 100644 --- a/include/wx/osx/cocoa/stdpaths.h +++ b/include/wx/osx/cocoa/stdpaths.h @@ -32,7 +32,8 @@ 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; + virtual wxString MakeConfigFileName(const wxString& basename, + ConfigFileConv conv) 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 5cadcf1a8b..a7aa61c892 100644 --- a/include/wx/stdpaths.h +++ b/include/wx/stdpaths.h @@ -67,6 +67,14 @@ public: FileLayout_XDG // Recommended: use XDG specification. }; + // Naming convention for the config files under Unix. + enum ConfigFileConv + { + ConfigFileConv_Dot, // Classic Unix dot-file convention. + ConfigFileConv_Ext // Use .conf extension. + }; + + // return the global standard paths object static wxStandardPaths& Get(); @@ -162,7 +170,9 @@ public: virtual wxString GetUserDir(Dir userDir) const; - virtual wxString MakeConfigFileName(const wxString& basename, int style) const = 0; + virtual wxString + MakeConfigFileName(const wxString& basename, + ConfigFileConv conv = ConfigFileConv_Ext) 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 d0ec1469e5..e67d9c6ea2 100644 --- a/include/wx/unix/stdpaths.h +++ b/include/wx/unix/stdpaths.h @@ -49,7 +49,8 @@ public: #ifndef __VMS virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE; #endif - virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE; + virtual wxString MakeConfigFileName(const wxString& basename, + ConfigFileConv conv) 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 e148cf7749..9540770cb4 100644 --- a/interface/wx/stdpaths.h +++ b/interface/wx/stdpaths.h @@ -166,6 +166,35 @@ public: FileLayout_XDG }; + /** + Possible values for MakeConfigFileName() naming convention argument. + + The values in this enum are only used under Unix and only when using + the classic Unix convention for file layout, in XDG mode, XDG naming + convention is used unconditionally. + + @since 3.1.1 + */ + enum ConfigFileConv + { + /** + Use the class Unix dot-file convention. + + Prepend the dot to the file base name. + + This value is ignored when in XDG mode, where MakeConfigFileName() + always behaves as if ConfigFileConv_Ext was specified. + */ + ConfigFileConv_Dot, + + /** + Use @c .conf extension for the file names. + + This convention is always used in XDG mode. + */ + ConfigFileConv_Ext + }; + /** MSW-specific function undoing the effect of IgnoreAppSubDir() calls. @@ -500,16 +529,22 @@ public: FileLayout GetFileLayout() const; /** - Return the file name which would be used by wxFileConfig as local, - user-specific, file if it were constructed with @a basename. + Return the file name which would be used by wxFileConfig 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. + @a conv is used to construct the name of the file under Unix and only + matters when using the class file layout, i.e. if SetFileLayout() had + @e not been called with @c FileLayout_XDG argument. In this case, this + argument is used to determine whether to use an extension or a leading + dot. When following XDG specification, the function always appends the + extension, regardless of @a conv value. Finally, this argument is not + used at all under non-Unix platforms. - Notice that this function cannot be used if @a basename is already a full path name. + @since 3.1.1 */ - virtual wxString MakeConfigFileName(const wxString& basename, int style) const; + virtual wxString + MakeConfigFileName(const wxString& basename, + ConfigFileConv conv = ConfigFileConv_Ext) const; protected: /** diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 6de548379d..77fa9a8103 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -266,14 +266,28 @@ wxString wxFileConfig::GetLocalDir(int style) wxFileName wxFileConfig::GetGlobalFile(const wxString& szFile) { - wxFileName fn(GetGlobalDir(), wxStandardPaths::Get().MakeConfigFileName(szFile, wxCONFIG_USE_SUBDIR)); - return fn; + wxStandardPathsBase& stdp = wxStandardPaths::Get(); + + return wxFileName(GetGlobalDir(), stdp.MakeConfigFileName(szFile)); } wxFileName wxFileConfig::GetLocalFile(const wxString& szFile, int style) { - wxFileName fn(GetLocalDir(style), wxStandardPaths::Get().MakeConfigFileName(szFile, style)); - return fn; + wxStandardPathsBase& stdp = wxStandardPaths::Get(); + + // If the config file is located in a subdirectory, we always use an + // extension for it, but we use just the leading dot if it is located + // directly in the home directory. Note that if wxStandardPaths is + // configured to follow XDG specification, all config files go to a + // subdirectory of XDG_CONFIG_HOME anyhow, so in this case we'll still end + // up using the extension even if wxCONFIG_USE_SUBDIR is not set, but this + // is the correct and expected (if a little confusing) behaviour. + const wxStandardPaths::ConfigFileConv + conv = style & wxCONFIG_USE_SUBDIR + ? wxStandardPaths::ConfigFileConv_Ext + : wxStandardPaths::ConfigFileConv_Dot; + + return wxFileName(GetLocalDir(style), stdp.MakeConfigFileName(szFile, conv)); } // ---------------------------------------------------------------------------- diff --git a/src/msw/stdpaths.cpp b/src/msw/stdpaths.cpp index 081ab600a7..afab737719 100644 --- a/src/msw/stdpaths.cpp +++ b/src/msw/stdpaths.cpp @@ -370,7 +370,9 @@ wxString wxStandardPaths::GetPluginsDir() const } -wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int WXUNUSED(style)) const +wxString +wxStandardPaths::MakeConfigFileName(const wxString& basename, + ConfigFileConv WXUNUSED(conv)) const { wxFileName fn(wxEmptyString, basename); fn.SetExt(wxT("ini")); diff --git a/src/osx/cocoa/stdpaths.mm b/src/osx/cocoa/stdpaths.mm index cd9b75b46a..85418fb5af 100644 --- a/src/osx/cocoa/stdpaths.mm +++ b/src/osx/cocoa/stdpaths.mm @@ -130,7 +130,9 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const return GetFMDirectory(dirType, NSUserDomainMask); } -wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int WXUNUSED(style)) const +wxString +wxStandardPaths::MakeConfigFileName(const wxString& basename, + ConfigFileConv WXUNUSED(conv)) const { wxFileName fn(wxEmptyString, basename); fn.SetName(fn.GetName() + wxT(" Preferences")); diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index c72b47a6f8..51e267916b 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -33,7 +33,6 @@ #include "wx/utils.h" #endif //WX_PRECOMP -#include "wx/fileconf.h" #include "wx/filename.h" #include "wx/log.h" #include "wx/textfile.h" @@ -334,30 +333,38 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const #endif // __VMS/!__VMS -wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int style) const +wxString +wxStandardPaths::MakeConfigFileName(const wxString& basename, + ConfigFileConv conv) const { wxFileName fn(wxEmptyString, basename); + + bool addExt = false; + switch ( GetFileLayout() ) { case FileLayout_Classic: - if ( !(style & wxCONFIG_USE_SUBDIR) ) + switch ( conv ) { - // The standard convention is to not use the extensions for the - // config files in the home directory and just prepend a dot to - // them instead. - fn.SetName(wxT('.') + fn.GetName()); - break; + case ConfigFileConv_Dot: + fn.SetName(wxT('.') + fn.GetName()); + break; + + case ConfigFileConv_Ext: + addExt = true; + break; } - //else: fall through to add the extension - wxFALLTHROUGH; + break; case FileLayout_XDG: - // We always use the extension for the config files when using XDG - // layout as they don't go to the home directory anyhow. - fn.SetExt(wxS("conf")); + // Dot files are never used in XDG mode. + addExt = true; break; } + if ( addExt ) + fn.SetExt(wxS("conf")); + return fn.GetFullName(); }