Implement MakeConfigFileName

This commit is contained in:
Martin Koegler
2016-11-27 14:31:02 +01:00
committed by Vadim Zeitlin
parent 1bcb30f6d7
commit 8d5d00db9d
9 changed files with 46 additions and 39 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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
// ============================================================================

View File

@@ -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

View File

@@ -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