X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de303444986fc3894e258708b2390b03937b57ed..7e3204b45cf8e1bb882b314d456e75f2a22850d7:/src/msw/stdpaths.cpp diff --git a/src/msw/stdpaths.cpp b/src/msw/stdpaths.cpp index 611d49a198..4f2cfd65c5 100644 --- a/src/msw/stdpaths.cpp +++ b/src/msw/stdpaths.cpp @@ -50,7 +50,7 @@ typedef HRESULT (WINAPI *SHGetSpecialFolderPath_t)(HWND, LPTSTR, int, BOOL); // ---------------------------------------------------------------------------- // used in our wxLogTrace messages -static const wxChar *TRACE_MASK = _T("stdpaths"); +#define TRACE_MASK _T("stdpaths") #ifndef CSIDL_APPDATA #define CSIDL_APPDATA 0x001a @@ -79,10 +79,14 @@ static const wxChar *TRACE_MASK = _T("stdpaths"); #ifndef SHGFP_TYPE_DEFAULT #define SHGFP_TYPE_DEFAULT 1 #endif + // ---------------------------------------------------------------------------- // module globals // ---------------------------------------------------------------------------- +namespace +{ + struct ShellFunctions { ShellFunctions() @@ -101,13 +105,13 @@ struct ShellFunctions // in spite of using a static variable, this is MT-safe as in the worst case it // results in initializing the function pointer several times -- but this is // harmless -static ShellFunctions gs_shellFuncs; +ShellFunctions gs_shellFuncs; // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- -static void ResolveShellFunctions() +void ResolveShellFunctions() { #if wxUSE_DYNLIB_CLASS @@ -161,6 +165,8 @@ static void ResolveShellFunctions() #endif } +} // anonymous namespace + // ============================================================================ // wxStandardPaths implementation // ============================================================================ @@ -245,24 +251,14 @@ wxString wxStandardPaths::DoGetDirectory(int csidl) return dir; } -/* static */ -wxString wxStandardPaths::GetAppDir() +wxString wxStandardPaths::GetAppDir() const { - wxFileName fn(wxGetFullModuleName()); - - // allow running the apps directly from build directory in debug builds -#ifdef __WXDEBUG__ - wxString lastdir; - if ( fn.GetDirCount() ) + if ( m_appDir.empty() ) { - lastdir = fn.GetDirs().Last(); - lastdir.MakeLower(); - if ( lastdir.Matches(_T("debug*")) || lastdir.Matches(_T("vc_msw*")) ) - fn.RemoveLastDir(); + m_appDir = wxFileName(wxGetFullModuleName()).GetPath(); } -#endif // __WXDEBUG__ - return fn.GetPath(); + return m_appDir; } wxString wxStandardPaths::GetDocumentsDir() const @@ -270,13 +266,82 @@ wxString wxStandardPaths::GetDocumentsDir() const return DoGetDirectory(CSIDL_PERSONAL); } +// ---------------------------------------------------------------------------- +// MSW-specific functions +// ---------------------------------------------------------------------------- + +void wxStandardPaths::IgnoreAppSubDir(const wxString& subdirPattern) +{ + wxFileName fn = wxFileName::DirName(GetAppDir()); + + if ( !fn.GetDirCount() ) + { + // no last directory to ignore anyhow + return; + } + + const wxString lastdir = fn.GetDirs().Last().Lower(); + if ( lastdir.Matches(subdirPattern.Lower()) ) + { + fn.RemoveLastDir(); + + // store the cached value so that subsequent calls to GetAppDir() will + // reuse it instead of using just the program binary directory + m_appDir = fn.GetPath(); + } +} + +void wxStandardPaths::IgnoreAppBuildSubDirs() +{ + IgnoreAppSubDir("debug"); + IgnoreAppSubDir("release"); + + wxString compilerPrefix; +#ifdef __VISUALC__ + compilerPrefix = "vc"; +#elif defined(__GNUG__) + compilerPrefix = "gcc"; +#elif defined(__BORLANDC__) + compilerPrefix = "bcc"; +#elif defined(__DIGITALMARS__) + compilerPrefix = "dmc"; +#elif defined(__WATCOMC__) + compilerPrefix = "wat"; +#else + return; +#endif + + IgnoreAppSubDir(compilerPrefix + "_msw*"); +} + +void wxStandardPaths::DontIgnoreAppSubDir() +{ + // this will force the next call to GetAppDir() to use the program binary + // path as the application directory + m_appDir.clear(); +} + // ---------------------------------------------------------------------------- // public functions // ---------------------------------------------------------------------------- +wxStandardPaths::wxStandardPaths() +{ + // under MSW it's common to use both the applicatio nand vendor + UseAppInfo(AppInfo_AppName | AppInfo_VendorName); + + // make it possible to run uninstalled application from the build directory + IgnoreAppBuildSubDirs(); +} + +wxString wxStandardPaths::GetExecutablePath() const +{ + return wxGetFullModuleName(); +} + wxString wxStandardPaths::GetConfigDir() const { - return AppendAppName(DoGetDirectory(CSIDL_COMMON_APPDATA)); + return AppendAppInfo(DoGetDirectory(CSIDL_COMMON_APPDATA)); } wxString wxStandardPaths::GetUserConfigDir() const @@ -293,12 +358,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