From 2b147f2e19c90ea74a4f96260ef8954a9bfbe2f1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Nov 2007 14:59:13 +0000 Subject: [PATCH] allow to optionally use vendor name component in standard paths (slightly modified patch 1831308) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/stdpaths.tex | 21 ++++++++++++++++ include/wx/msw/stdpaths.h | 7 ++++++ include/wx/stdpaths.h | 34 ++++++++++++++++++++++--- src/common/stdpbase.cpp | 35 +++++++++++++++++++++++--- src/mac/corefoundation/stdpaths_cf.cpp | 10 +++++--- src/msw/stdpaths.cpp | 6 ++--- src/os2/stdpaths.cpp | 2 +- src/unix/stdpaths.cpp | 12 ++++----- 8 files changed, 106 insertions(+), 21 deletions(-) diff --git a/docs/latex/wx/stdpaths.tex b/docs/latex/wx/stdpaths.tex index 6d5da635e8..bd469503f2 100644 --- a/docs/latex/wx/stdpaths.tex +++ b/docs/latex/wx/stdpaths.tex @@ -280,3 +280,24 @@ automatically, portable programs should call this function. Usually the prefix is set during program configuration if using GNU autotools and so it is enough to pass its value defined in \texttt{config.h} to this function. + +\membersection{wxStandardPaths::UseAppInfo}\label{wxstandardpathsuseappinfo} + +\func{void}{UseAppInfo}{\param{int }{info}} + +Controls what application information is used when constructing paths that +should be unique to this program, such as the application data directory, the +plugins directory on Unix, etc. + +Valid values for \arg{info} are \texttt{AppInfo\_None} and either one or +combination of \texttt{AppInfo\_AppName} and \texttt{AppInfo\_VendorName}. The +first one tells this class to not use neither application nor vendor name in +the paths. + +By default, only the application name is used under Unix systems but both +application and vendor names are used under Windows and Mac. + +\wxheading{See also} + +\helpref{wxApp::SetAppName}{wxappsetappname}, \helpref{wxApp::SetVendorName}{wxappsetvendorname} + diff --git a/include/wx/msw/stdpaths.h b/include/wx/msw/stdpaths.h index d8f15d43c9..cb141af92c 100644 --- a/include/wx/msw/stdpaths.h +++ b/include/wx/msw/stdpaths.h @@ -19,6 +19,13 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase { public: + wxStandardPaths() + { + UseAppInfo(AppInfo_AppName | AppInfo_VendorName); + } + + ~wxStandardPaths() { } + // implement base class pure virtuals virtual wxString GetExecutablePath() const; virtual wxString GetConfigDir() const; diff --git a/include/wx/stdpaths.h b/include/wx/stdpaths.h index 9f6c619f63..999720d3ac 100644 --- a/include/wx/stdpaths.h +++ b/include/wx/stdpaths.h @@ -39,6 +39,15 @@ public: ResourceCat_Max }; + // what should we use to construct paths unique to this application: + // (AppInfo_AppName and AppInfo_VendorName can be combined together) + enum + { + AppInfo_None = 0, // nothing + AppInfo_AppName = 1, // the application name + AppInfo_VendorName = 2 // the vendor name + }; + // return the global standard paths object static wxStandardPathsBase& Get(); @@ -126,13 +135,32 @@ public: virtual wxString GetTempDir() const; + // ctor for the base class + wxStandardPathsBase(); + // virtual dtor for the base class virtual ~wxStandardPathsBase(); + // Information used by AppendAppInfo + void UseAppInfo(int info) + { + m_usedAppInfo = info; + } + + bool UsesAppInfo(int info) const { return (m_usedAppInfo & info) != 0; } + + protected: - // append "/appname" suffix if the app name is set (doesn't append the - // slash if dir already ends with a slash or dot) - static wxString AppendAppName(const wxString& dir); + // append the path component, with a leading path seperator if a + // path seperator or dot (.) is not already at the end of dir + static wxString AppendPathComponent(const wxString& dir, const wxString& component); + + // append application information determined by m_usedAppInfo to dir + wxString AppendAppInfo(const wxString& dir) const; + + + // combination of AppInfo_XXX flags used by AppendAppInfo() + int m_usedAppInfo; }; #if wxUSE_STDPATHS diff --git a/src/common/stdpbase.cpp b/src/common/stdpbase.cpp index 6d0609e118..04cebb8587 100644 --- a/src/common/stdpbase.cpp +++ b/src/common/stdpbase.cpp @@ -77,6 +77,15 @@ wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths() return gs_stdPaths; } +wxStandardPathsBase::wxStandardPathsBase() +{ + // Set the default information that is used when + // forming some paths (by AppendAppInfo). + // Derived classes can call this in their constructors + // to set the platform-specific settings + UseAppInfo(AppInfo_AppName); +} + wxStandardPathsBase::~wxStandardPathsBase() { // nothing to do here @@ -104,23 +113,41 @@ wxString wxStandardPathsBase::GetTempDir() const } /* static */ -wxString wxStandardPathsBase::AppendAppName(const wxString& dir) +wxString wxStandardPathsBase::AppendPathComponent(const wxString& dir, const wxString& component) { wxString subdir(dir); // empty string indicates that an error has occurred, don't touch it then if ( !subdir.empty() ) { - const wxString appname = wxTheApp->GetAppName(); - if ( !appname.empty() ) + if ( !component.empty() ) { const wxChar ch = *(subdir.end() - 1); if ( !wxFileName::IsPathSeparator(ch) && ch != _T('.') ) subdir += wxFileName::GetPathSeparator(); - subdir += appname; + subdir += component; } } return subdir; } + + +wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const +{ + wxString subdir(dir); + + if ( UsesAppInfo(AppInfo_VendorName) ) + { + subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName()); + } + + if ( UsesAppInfo(AppInfo_AppName) ) + { + subdir = AppendPathComponent(subdir, wxTheApp->GetAppName()); + } + + return subdir; +} + diff --git a/src/mac/corefoundation/stdpaths_cf.cpp b/src/mac/corefoundation/stdpaths_cf.cpp index 0348da365f..eeaa7453e5 100644 --- a/src/mac/corefoundation/stdpaths_cf.cpp +++ b/src/mac/corefoundation/stdpaths_cf.cpp @@ -49,12 +49,14 @@ wxStandardPathsCF::wxStandardPathsCF() : m_bundle(CFBundleGetMainBundle()) { CFRetain(m_bundle); + UseAppInfo(AppInfo_AppName | AppInfo_VendorName); } wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle) : m_bundle(bundle) { CFRetain(m_bundle); + UseAppInfo(AppInfo_AppName | AppInfo_VendorName); } wxStandardPathsCF::~wxStandardPathsCF() @@ -170,18 +172,18 @@ wxString wxStandardPathsCF::GetExecutablePath() const wxString wxStandardPathsCF::GetLocalDataDir() const { #ifdef __WXMAC__ - return AppendAppName(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder)); + return AppendAppInfo(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder)); #else - return AppendAppName(wxT("/Library/Application Support")); + return AppendAppInfo(wxT("/Library/Application Support")); #endif } wxString wxStandardPathsCF::GetUserDataDir() const { #ifdef __WXMAC__ - return AppendAppName(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder)); + return AppendAppInfo(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder)); #else - return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support")); + return AppendAppInfo(wxFileName::GetHomeDir() + _T("/Library/Application Support")); #endif } diff --git a/src/msw/stdpaths.cpp b/src/msw/stdpaths.cpp index 37c0c9748a..1f21d6d5ae 100644 --- a/src/msw/stdpaths.cpp +++ b/src/msw/stdpaths.cpp @@ -281,7 +281,7 @@ wxString wxStandardPaths::GetExecutablePath() const wxString wxStandardPaths::GetConfigDir() const { - return AppendAppName(DoGetDirectory(CSIDL_COMMON_APPDATA)); + return AppendAppInfo(DoGetDirectory(CSIDL_COMMON_APPDATA)); } wxString wxStandardPaths::GetUserConfigDir() const @@ -298,12 +298,12 @@ wxString wxStandardPaths::GetDataDir() const wxString wxStandardPaths::GetUserDataDir() const { - return AppendAppName(GetUserConfigDir()); + return AppendAppInfo(GetUserConfigDir()); } wxString wxStandardPaths::GetUserLocalDataDir() const { - return AppendAppName(DoGetDirectory(CSIDL_LOCAL_APPDATA)); + return AppendAppInfo(DoGetDirectory(CSIDL_LOCAL_APPDATA)); } wxString wxStandardPaths::GetPluginsDir() const diff --git a/src/os2/stdpaths.cpp b/src/os2/stdpaths.cpp index bd71539125..98cf196f24 100644 --- a/src/os2/stdpaths.cpp +++ b/src/os2/stdpaths.cpp @@ -82,7 +82,7 @@ wxString wxStandardPaths::GetDataDir() const wxString wxStandardPaths::GetUserDataDir() const { - return AppendAppName(wxFileName::GetHomeDir() + _T("\\.")); + return AppendAppInfo(wxFileName::GetHomeDir() + _T("\\.")); } wxString wxStandardPaths::GetPluginsDir() const diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index af3551bf06..f445c2f3d2 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -75,12 +75,12 @@ wxString wxStandardPaths::GetConfigDir() const wxString wxStandardPaths::GetDataDir() const { - return AppendAppName(GetInstallPrefix() + _T("/sys$share")); + return AppendAppInfo(GetInstallPrefix() + _T("/sys$share")); } wxString wxStandardPaths::GetLocalDataDir() const { - return AppendAppName(_T("/sys$manager")); + return AppendAppInfo(_T("/sys$manager")); } wxString wxStandardPaths::GetUserDataDir() const @@ -187,22 +187,22 @@ wxString wxStandardPaths::GetConfigDir() const wxString wxStandardPaths::GetDataDir() const { - return AppendAppName(GetInstallPrefix() + _T("/share")); + return AppendAppInfo(GetInstallPrefix() + _T("/share")); } wxString wxStandardPaths::GetLocalDataDir() const { - return AppendAppName(_T("/etc")); + return AppendAppInfo(_T("/etc")); } wxString wxStandardPaths::GetUserDataDir() const { - return AppendAppName(wxFileName::GetHomeDir() + _T("/.")); + return AppendAppInfo(wxFileName::GetHomeDir() + _T("/.")); } wxString wxStandardPaths::GetPluginsDir() const { - return AppendAppName(GetInstallPrefix() + _T("/lib")); + return AppendAppInfo(GetInstallPrefix() + _T("/lib")); } wxString -- 2.45.2