Fix user configuration path bug on Linux.

Recent versions of wxWidgets wxStandardPaths::GetUserConfigDir() correctly
append ".config" on Linux build which was incorrect as the current code
already appended it to the path.  Add a check to see if ".config" is the
last path and append as required.

Check for XDG_CONFIG_HOME environment variable on all platforms not just
Linux.

Fixes lp:1769145

https://bugs.launchpad.net/kicad/+bug/1769145
This commit is contained in:
Wayne Stambaugh 2018-05-07 11:47:16 -04:00
parent dbc2eea3db
commit 5c5b74b29e
2 changed files with 61 additions and 63 deletions

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -58,14 +58,6 @@ EDA_UNITS_T g_UserUnit;
COLOR4D g_GhostColor; COLOR4D g_GhostColor;
/* Class LOCALE_IO
* is a class that can be instantiated within a scope in which you are expecting
* exceptions to be thrown. Its constructor sets a "C" locale, to read/print files
* with fp numbers.
* Its destructor insures that the default locale is restored if an exception
* is thrown, or not.
*/
std::atomic<unsigned int> LOCALE_IO::m_c_count(0); std::atomic<unsigned int> LOCALE_IO::m_c_count(0);
LOCALE_IO::LOCALE_IO() LOCALE_IO::LOCALE_IO()
@ -80,6 +72,7 @@ LOCALE_IO::LOCALE_IO()
} }
} }
LOCALE_IO::~LOCALE_IO() LOCALE_IO::~LOCALE_IO()
{ {
// use thread safe, atomic operation // use thread safe, atomic operation
@ -222,20 +215,24 @@ wxString GetKicadConfigPath()
// http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0 // http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() ); cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
// GetUserConfigDir() does not default to ~/.config which is the current standard
// configuration file location on Linux. This has been fixed in later versions of wxWidgets.
#if !defined( __WXMSW__ ) && !defined( __WXMAC__ )
wxArrayString dirs = cfgpath.GetDirs();
if( dirs.Last() != ".config" )
cfgpath.AppendDir( ".config" );
#endif
wxString envstr; wxString envstr;
// wxStandardPaths does not default to ~/.config which is the current standard config // This shouldn't cause any issues on Windows or MacOS.
// location on Linux. This has been fixed in wxWidgets 3.1.1.
#if !wxCHECK_VERSION( 3, 1, 1 ) && !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() ) if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
{ {
// Override the assignment above with XDG_CONFIG_HOME // Override the assignment above with XDG_CONFIG_HOME
cfgpath.AssignDir( envstr ); cfgpath.AssignDir( envstr );
} }
cfgpath.AppendDir( wxT( ".config" ) );
#endif
cfgpath.AppendDir( wxT( "kicad" ) ); cfgpath.AppendDir( wxT( "kicad" ) );
// Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path. // Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path.

View File

@ -3,8 +3,8 @@
* *
* Copyright (C) 2014-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -94,9 +94,8 @@ enum pseudokeys {
//-----<KiROUND KIT>------------------------------------------------------------ //-----<KiROUND KIT>------------------------------------------------------------
/** /**
* KiROUND * Round a floating point number to an integer using "round halfway cases away from zero".
* rounds a floating point number to an int using *
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int. * In Debug build an assert fires if will not fit into an int.
*/ */
@ -122,11 +121,13 @@ static inline int kiRound_( double v, int line, const char* filename )
v = v < 0 ? v - 0.5 : v + 0.5; v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 ) if( v > INT_MAX + 0.5 )
{ {
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n",
__FUNCTION__, filename, line, v );
} }
else if( v < INT_MIN - 0.5 ) else if( v < INT_MIN - 0.5 )
{ {
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n",
__FUNCTION__, filename, line, v );
} }
return int( v ); return int( v );
} }
@ -156,12 +157,12 @@ extern KIGFX::COLOR4D g_GhostColor;
/** /**
* Class LOCALE_IO * Instantiate the current locale within a scope in which you are expecting
* is a class that can be instantiated within a scope in which you are expecting * exceptions to be thrown.
* exceptions to be thrown. Its constructor set a "C" laguage locale option, *
* to read/print files with fp numbers. * The constructor sets a "C" language locale option, to read/print files with floating
* Its destructor insures that the default locale is restored if an exception * point numbers. The destructor insures that the default locale is restored if an
* is thrown, or not. * exception is thrown or not.
*/ */
class LOCALE_IO class LOCALE_IO
{ {
@ -180,21 +181,20 @@ private:
std::string m_user_locale; std::string m_user_locale;
}; };
/** /**
* Function GetTextSize * Return the size of @a aSingleLine of text when it is rendered in @a aWindow
* returns the size of @a aSingleLine of text when it is rendered in @a aWindow
* using whatever font is currently set in that window. * using whatever font is currently set in that window.
*/ */
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow ); wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
/** /**
* Function EnsureTextCtrlWidth * Set the minimum pixel width on a text control in order to make a text
* sets the minimum pixel width on a text control in order to make a text * string be fully visible within it.
* string be fully visible within it. The current font within the text *
* control is considered. * The current font within the text control is considered. The text can come either from
* The text can come either from the control or be given as an argument. * the control or be given as an argument. If the text control is larger than needed, then
* If the text control is larger than needed, then nothing is done. * nothing is done.
*
* @param aCtrl the text control to potentially make wider. * @param aCtrl the text control to potentially make wider.
* @param aString the text that is used in sizing the control's pixel width. * @param aString the text that is used in sizing the control's pixel width.
* If NULL, then * If NULL, then
@ -203,10 +203,9 @@ wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
*/ */
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL ); bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
/** /**
* Function ProcessExecute * Run a command in a child process.
* runs a child process. *
* @param aCommandLine The process and any arguments to it all in a single * @param aCommandLine The process and any arguments to it all in a single
* string. * string.
* @param aFlags The same args as allowed for wxExecute() * @param aFlags The same args as allowed for wxExecute()
@ -218,7 +217,6 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC, int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
wxProcess *callback = NULL ); wxProcess *callback = NULL );
/** /**
* @return an unique time stamp that changes after each call * @return an unique time stamp that changes after each call
*/ */
@ -239,8 +237,8 @@ int GetCommandOptions( const int argc, const char** argv,
double RoundTo0( double x, double precision ); double RoundTo0( double x, double precision );
/** /**
* Function wxStringSplit * Split \a aString to a string list separated at \a aSplitter.
* splits \a aString to a string list separated at \a aSplitter. *
* @param aText is the text to split * @param aText is the text to split
* @param aStrings will contain the splitted lines * @param aStrings will contain the splitted lines
* @param aSplitter is the 'split' character * @param aSplitter is the 'split' character
@ -248,8 +246,7 @@ double RoundTo0( double x, double precision );
void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter ); void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter );
/** /**
* Function SearchHelpFileFullPath * Return the help file's full path.
* returns the help file's full path.
* <p> * <p>
* Return the KiCad help file with path and extension. * Return the KiCad help file with path and extension.
* Help files can be html (.html ext) or pdf (.pdf ext) files. * Help files can be html (.html ext) or pdf (.pdf ext) files.
@ -270,27 +267,26 @@ void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSpli
wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName ); wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName );
/** /**
* Helper function EnsureFileDirectoryExists * Make \a aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
* make \a aTargetFullFileName absolute and creates the path of this file if it doesn't yet exist. *
* @param aTargetFullFileName the wxFileName containing the full path and file name to modify. The path * @param aTargetFullFileName the wxFileName containing the full path and file name to modify.
* may be absolute or relative to \a aBaseFilename . * The path may be absolute or relative to \a aBaseFilename .
* @param aBaseFilename a full filename. Only its path is used to set the aTargetFullFileName path. * @param aBaseFilename a full filename. Only its path is used to set the aTargetFullFileName path.
* @param aReporter a point to a REPORTER object use to show messages (can be NULL) * @param aReporter a point to a REPORTER object use to show messages (can be NULL)
* @return true if \a aOutputDir already exists or was successfully created. * @return true if \a aOutputDir already exists or was successfully created.
*/ */
bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName, bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
const wxString& aBaseFilename, const wxString& aBaseFilename,
REPORTER* aReporter = NULL ); REPORTER* aReporter = NULL );
/// Put aPriorityPath in front of all paths in the value of aEnvVar. /// Put aPriorityPath in front of all paths in the value of aEnvVar.
const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath ); const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath );
/** /**
* Function GetNewConfig * Create a new wxConfig so we can put configuration files in a more proper place for each
* platform.
* *
* Use this function instead of creating a new wxConfig so we can put config files in * This is generally $HOME/.config/kicad/ in Linux according to the FreeDesktop specification at
* a more proper place for each platform. This is generally $HOME/.config/kicad/ in Linux
* according to the FreeDesktop specification at
* http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html * http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
* The config object created here should be destroyed by the caller. * The config object created here should be destroyed by the caller.
* *
@ -301,25 +297,30 @@ const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPa
*/ */
wxConfigBase* GetNewConfig( const wxString& aProgName ); wxConfigBase* GetNewConfig( const wxString& aProgName );
/** /**
* Function GetKicadConfigPath * Return the user configuration path used to store KiCad's configuration files.
*
* The configuration path order of precedence is determined by the following criteria:
*
* - The value of the KICAD_CONFIG_HOME environment variable
* - The value of the XDG_CONFIG_HOME environment variable.
* - The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended
* as required on Linux builds.
*
* @return A wxString containing the config path for Kicad * @return A wxString containing the config path for Kicad
*/ */
wxString GetKicadConfigPath(); wxString GetKicadConfigPath();
/** /**
* Function ExpandEnvVarSubstitutions * Replace any environment variable references with their values.
* replaces any environment variable references with their values *
* @param aString = a string containing (perhaps) references to env var * @param aString = a string containing (perhaps) references to env var
* @return a string where env var are replaced by their value * @return a string where env var are replaced by their value
*/ */
const wxString ExpandEnvVarSubstitutions( const wxString& aString ); const wxString ExpandEnvVarSubstitutions( const wxString& aString );
/** /**
* Function ResolveUriByEnvVars * Replace any environment variables in file-path uris (leaving network-path URIs alone).
* replaces any environment variables in file-path uris (leaving network-path
* uris alone).
*/ */
const wxString ResolveUriByEnvVars( const wxString& aUri ); const wxString ResolveUriByEnvVars( const wxString& aUri );