kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #26746
Re: KiCad patch: Use XDG_CONFIG_HOME on Windows
Here is my attempt to provide a good patch to use XDG_CONFIG_HOME and
XDG_CACHE_HOME env variables on Windows. I tested it with and without
the env set, it works for me. Let me know what you think. Are there any
other paths who need some adjusting to make it more portable?
>From e92a4b3f4e7f416c971fe21562512e2e730f845d Mon Sep 17 00:00:00 2001
From: mwayne <wodarczykmike@xxxxxxxxx>
Date: Wed, 26 Oct 2016 14:03:17 +0200
Subject: [PATCH] Use XDG_CONFIG_HOME on Windows
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.10.1.windows.1"
This is a multi-part message in MIME format.
--------------2.10.1.windows.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
common/common.cpp | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
--------------2.10.1.windows.1
Content-Type: text/x-patch; name="0001-Use-XDG_CONFIG_HOME-on-Windows.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Use-XDG_CONFIG_HOME-on-Windows.patch"
diff --git a/common/common.cpp b/common/common.cpp
index 976e419..6154948 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -320,7 +320,6 @@ wxString GetKicadLockFilePath()
// 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
@@ -337,17 +336,22 @@ wxString GetKicadLockFilePath()
// If all fails, just use ~/.cache
lockpath.AppendDir( wxT( ".cache" ) );
}
-
- lockpath.AppendDir( wxT( "kicad" ) );
+#elif defined( __WINDOWS__ )
+ wxString envstr;
+
+ if( wxGetEnv( wxT( "XDG_CACHE_HOME" ), &envstr ) && !envstr.IsEmpty() )
+ {
+ lockpath.AssignDir( envstr );
+ }
#endif
-#if defined( __WXMAC__ ) || defined( __UNIX__ )
+ lockpath.AppendDir( wxT( "kicad" ) );
+
if( !lockpath.DirExists() )
{
// Lockfiles should be only readable by the user
lockpath.Mkdir( 0700, wxPATH_MKDIR_FULL );
}
-#endif
return lockpath.GetPath();
}
@@ -362,7 +366,14 @@ wxString GetKicadConfigPath()
// Mac: ~/Library/Preferences
cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
-#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
+#if defined( __WINDOWS__ )
+ wxString envstr;
+
+ if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
+ {
+ cfgpath.AssignDir( envstr );
+ }
+#elif defined( __UNIX__ )
wxString envstr;
if( !wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) || envstr.IsEmpty() )
--------------2.10.1.windows.1--
Follow ups
References