Exemple #1
0
bool CodeBlocksApp::LoadConfig()
{
    if (m_UserDataDir!=wxEmptyString)
    {
        // if --user-data-dir=path was specified we tell
        //ConfigManager (and CfgMgrBldr) about it, which will propagate
        //it through the app and plugins
        if ( !ConfigManager::SetUserDataFolder(m_UserDataDir) )
            return false;
    }

    ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("app"));

    wxString data(wxT(APP_PREFIX));

    if (platform::windows)
        data.assign(GetAppPath());
    else if (platform::macosx)
    {
        data.assign(GetResourcesDir());                 // CodeBlocks.app/Contents/Resources
        if (!data.Contains(wxString(_T("/Resources")))) // not a bundle, use relative path
            data = GetAppPath() + _T("/..");
    }

    if (data.IsEmpty())
    {
        data.assign(GetAppPath());  // fallback
        data.Replace(_T("/bin"),_T(""));
    }


    if (!m_Prefix.IsEmpty())        // --prefix command line switch overrides builtin value
        data = m_Prefix;
    else                            // also, check for environment
    {

        wxString env;
        wxGetEnv(_T("CODEBLOCKS_DATA_DIR"), &env);
        if (!env.IsEmpty())
            data = env;
    }

    data.append(_T("/share/codeblocks"));

    cfg->Write(_T("data_path"), data);

    //m_HasDebugLog = Manager::Get()->GetConfigManager(_T("message_manager"))->ReadBool(_T("/has_debug_log"), false) || m_HasDebugLog;
    //Manager::Get()->GetConfigManager(_T("message_manager"))->Write(_T("/has_debug_log"), m_HasDebugLog);

    return true;
}
// generate config file path
static void get_config_path(wxPathList &path, bool exists = true)
{
	//   local config dir first, then global
	//   locale-specific res first, then main
	wxStandardPathsBase &stdp = wxStandardPaths::Get();
#define add_path(p) do { \
    const wxString& s = stdp.p; \
    wxFileName parent = wxFileName::DirName(s + wxT("//..")); \
    parent.MakeAbsolute(); \
    if((wxDirExists(s) && wxIsWritable(s)) || ((!exists || !wxDirExists(s)) && parent.IsDirWritable())) \
    path.Add(s); \
} while(0)
	// NOTE: this does not support XDG (freedesktop.org) paths
	add_path(GetUserLocalDataDir());
	add_path(GetUserDataDir());
	add_path(GetLocalizedResourcesDir(wxGetApp().locale.GetCanonicalName()));
	add_path(GetResourcesDir());
	add_path(GetDataDir());
	add_path(GetLocalDataDir());
	add_path(GetPluginsDir());
}