Implement MakeConfigFileName
This commit is contained in:
committed by
Vadim Zeitlin
parent
1bcb30f6d7
commit
8d5d00db9d
@@ -29,6 +29,7 @@ public:
|
|||||||
virtual wxString GetUserLocalDataDir() const wxOVERRIDE;
|
virtual wxString GetUserLocalDataDir() const wxOVERRIDE;
|
||||||
virtual wxString GetPluginsDir() const wxOVERRIDE;
|
virtual wxString GetPluginsDir() const wxOVERRIDE;
|
||||||
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
||||||
|
virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE;
|
||||||
|
|
||||||
|
|
||||||
// MSW-specific methods
|
// MSW-specific methods
|
||||||
|
@@ -32,6 +32,7 @@ public:
|
|||||||
GetLocalizedResourcesDir(const wxString& lang,
|
GetLocalizedResourcesDir(const wxString& lang,
|
||||||
ResourceCat category = ResourceCat_None) const wxOVERRIDE;
|
ResourceCat category = ResourceCat_None) const wxOVERRIDE;
|
||||||
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
||||||
|
virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating
|
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating
|
||||||
|
@@ -155,6 +155,8 @@ public:
|
|||||||
|
|
||||||
virtual wxString GetUserDir(Dir userDir) const;
|
virtual wxString GetUserDir(Dir userDir) const;
|
||||||
|
|
||||||
|
virtual wxString MakeConfigFileName(const wxString& basename, int style) const = 0;
|
||||||
|
|
||||||
// virtual dtor for the base class
|
// virtual dtor for the base class
|
||||||
virtual ~wxStandardPathsBase();
|
virtual ~wxStandardPathsBase();
|
||||||
|
|
||||||
|
@@ -49,6 +49,7 @@ public:
|
|||||||
#ifndef __VMS
|
#ifndef __VMS
|
||||||
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
|
||||||
#endif
|
#endif
|
||||||
|
virtual wxString MakeConfigFileName(const wxString& basename, int style) const wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating
|
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating
|
||||||
|
@@ -444,6 +444,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
void UseAppInfo(int info);
|
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:
|
||||||
/**
|
/**
|
||||||
Protected default constructor.
|
Protected default constructor.
|
||||||
|
@@ -247,26 +247,6 @@ public:
|
|||||||
// static functions
|
// 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()
|
wxString wxFileConfig::GetGlobalDir()
|
||||||
{
|
{
|
||||||
return wxStandardPaths::Get().GetConfigDir();
|
return wxStandardPaths::Get().GetConfigDir();
|
||||||
@@ -286,30 +266,13 @@ wxString wxFileConfig::GetLocalDir(int style)
|
|||||||
|
|
||||||
wxFileName wxFileConfig::GetGlobalFile(const wxString& szFile)
|
wxFileName wxFileConfig::GetGlobalFile(const wxString& szFile)
|
||||||
{
|
{
|
||||||
wxFileName fn(GetGlobalDir(), szFile);
|
wxFileName fn(GetGlobalDir(), wxStandardPaths::Get().MakeConfigFileName(szFile, wxCONFIG_USE_SUBDIR));
|
||||||
|
|
||||||
AddConfFileExtIfNeeded(fn);
|
|
||||||
|
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileName wxFileConfig::GetLocalFile(const wxString& szFile, int style)
|
wxFileName wxFileConfig::GetLocalFile(const wxString& szFile, int style)
|
||||||
{
|
{
|
||||||
wxFileName fn(GetLocalDir(style), szFile);
|
wxFileName fn(GetLocalDir(style), wxStandardPaths::Get().MakeConfigFileName(szFile, style));
|
||||||
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -369,6 +369,14 @@ wxString wxStandardPaths::GetPluginsDir() const
|
|||||||
return GetAppDir();
|
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
|
// wxStandardPathsWin16 implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#if wxUSE_STDPATHS
|
#if wxUSE_STDPATHS
|
||||||
|
|
||||||
|
#include "wx/filename.h"
|
||||||
#include "wx/stdpaths.h"
|
#include "wx/stdpaths.h"
|
||||||
#include "wx/osx/private.h"
|
#include "wx/osx/private.h"
|
||||||
#include "wx/osx/core/cfstring.h"
|
#include "wx/osx/core/cfstring.h"
|
||||||
@@ -129,4 +130,11 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const
|
|||||||
return GetFMDirectory(dirType, NSUserDomainMask);
|
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
|
#endif // wxUSE_STDPATHS
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#endif //WX_PRECOMP
|
#endif //WX_PRECOMP
|
||||||
|
|
||||||
|
#include "wx/fileconf.h"
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/textfile.h"
|
#include "wx/textfile.h"
|
||||||
@@ -308,4 +309,14 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const
|
|||||||
|
|
||||||
#endif // __VMS/!__VMS
|
#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
|
#endif // wxUSE_STDPATHS
|
||||||
|
Reference in New Issue
Block a user