Commit c9a1b239 authored by Jose Ingnacio's avatar Jose Ingnacio Committed by Wayne Stambaugh

Use XDG_CONFIG_DIR for lock file path on Linux.

* With fixes from Adam Wolf.
parent 547c145a
/* /*
* 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 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 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
...@@ -271,9 +271,9 @@ double RoundTo0( double x, double precision ) ...@@ -271,9 +271,9 @@ double RoundTo0( double x, double precision )
int remainder = ix % 10; // remainder is in precision mm int remainder = ix % 10; // remainder is in precision mm
if ( remainder <= 2 ) if( remainder <= 2 )
ix -= remainder; // truncate to the near number ix -= remainder; // truncate to the near number
else if (remainder >= 8 ) else if( remainder >= 8 )
ix += 10 - remainder; // round to near number ix += 10 - remainder; // round to near number
if ( x < 0 ) if ( x < 0 )
...@@ -305,6 +305,46 @@ wxConfigBase* GetNewConfig( const wxString& aProgName ) ...@@ -305,6 +305,46 @@ wxConfigBase* GetNewConfig( const wxString& aProgName )
return cfg; return cfg;
} }
wxString GetKicadLockFilePath()
{
wxFileName lockpath;
lockpath.AssignDir( wxGetHomeDir() ); // Default wx behavior
#if defined( __WXMAC__ )
// In OSX use the standard per user cache directory
lockpath.AppendDir( wxT( "Library" ) );
lockpath.AppendDir( wxT( "Caches" ) );
lockpath.AppendDir( wxT( "kicad" ) );
#elif defined( __UNIX__ )
wxString envstr;
// Try first the standard XDG_RUNTIME_DIR, falling back to XDG_CACHE_HOME
if( wxGetEnv( wxT( "XDG_RUNTIME_DIR" ), &envstr ) && !envstr.IsEmpty() )
{
lockpath.AssignDir( envstr );
}
else if( wxGetEnv( wxT( "XDG_CACHE_HOME" ), &envstr ) && !envstr.IsEmpty() )
{
lockpath.AssignDir( envstr );
}
else
{
// If all fails, just use ~/.cache
lockpath.AppendDir( wxT( ".cache" ) );
}
lockpath.AppendDir( wxT( "kicad" ) );
#endif
#if defined( __WXMAC__ ) || defined( __UNIX__ )
if( !lockpath.DirExists() )
{
// Lockfiles should be only readable by the user
lockpath.Mkdir( 0700, wxPATH_MKDIR_FULL );
}
#endif
return lockpath.GetPath();
}
wxString GetKicadConfigPath() wxString GetKicadConfigPath()
{ {
......
/* /*
* 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 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2014-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2014-2015 KiCad Developers, see CHANGELOG.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
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/snglinst.h> #include <wx/snglinst.h>
#include <common.h>
wxSingleInstanceChecker* LockFile( const wxString& aFileName ) wxSingleInstanceChecker* LockFile( const wxString& aFileName )
...@@ -41,7 +42,8 @@ wxSingleInstanceChecker* LockFile( const wxString& aFileName ) ...@@ -41,7 +42,8 @@ wxSingleInstanceChecker* LockFile( const wxString& aFileName )
// We can have filenames coming from Windows, so also convert Windows separator // We can have filenames coming from Windows, so also convert Windows separator
lockFileName.Replace( wxT( "\\" ), wxT( "_" ) ); lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
wxSingleInstanceChecker* p = new wxSingleInstanceChecker( lockFileName ); wxSingleInstanceChecker* p = new wxSingleInstanceChecker( lockFileName,
GetKicadLockFilePath() );
if( p->IsAnotherRunning() ) if( p->IsAnotherRunning() )
{ {
......
/* /*
* 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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004-2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 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
...@@ -353,7 +353,7 @@ bool PGM_BASE::initPgm() ...@@ -353,7 +353,7 @@ bool PGM_BASE::initPgm()
wxInitAllImageHandlers(); wxInitAllImageHandlers();
m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId() ); m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId(), GetKicadLockFilePath() );
if( m_pgm_checker->IsAnotherRunning() ) if( m_pgm_checker->IsAnotherRunning() )
{ {
......
/* /*
* 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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 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
...@@ -278,7 +278,7 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL ); ...@@ -278,7 +278,7 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
* wxExecute()) * wxExecute())
*/ */
int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC, int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
wxProcess *callback = NULL ); wxProcess *callback = NULL );
/*******************/ /*******************/
...@@ -433,6 +433,12 @@ const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPa ...@@ -433,6 +433,12 @@ const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPa
*/ */
wxConfigBase* GetNewConfig( const wxString& aProgName ); wxConfigBase* GetNewConfig( const wxString& aProgName );
/**
* Function GetKicadLockFilePath
* @return A wxString containing the path for lockfiles in Kicad
*/
wxString GetKicadLockFilePath();
/** /**
* Function GetKicadConfigPath * Function GetKicadConfigPath
* @return A wxString containing the config path for Kicad * @return A wxString containing the config path for Kicad
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment