From 32a9e516cf315a25e9c9c44b2be500308e9673ea Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sat, 15 Dec 2012 15:38:17 -0500
Subject: [PATCH] Added getEnvironmentVariable from latest version of JUCE

---
 .../src/native/common/juce_posix_SharedCode.h      |  8 ++++++++
 .../src/native/linux/juce_linux_Fonts.cpp          |  6 +++---
 .../src/native/windows/juce_win32_SystemStats.cpp  | 14 ++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/JuceLibraryCode/src/native/common/juce_posix_SharedCode.h b/JuceLibraryCode/src/native/common/juce_posix_SharedCode.h
index 34225ba27..a8a3adf89 100755
--- a/JuceLibraryCode/src/native/common/juce_posix_SharedCode.h
+++ b/JuceLibraryCode/src/native/common/juce_posix_SharedCode.h
@@ -557,6 +557,14 @@ const String juce_getOutputFromCommand (const String& command)
     return result;
 }
 
+//=============================================================================
+String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
+{
+    if (const char* s = ::getenv (name.toUTF8()))
+        return String::fromUTF8 (s);
+
+    return defaultValue;
+}
 
 //==============================================================================
 class InterProcessLock::Pimpl
diff --git a/JuceLibraryCode/src/native/linux/juce_linux_Fonts.cpp b/JuceLibraryCode/src/native/linux/juce_linux_Fonts.cpp
index 5f8d8565b..2a5690a52 100755
--- a/JuceLibraryCode/src/native/linux/juce_linux_Fonts.cpp
+++ b/JuceLibraryCode/src/native/linux/juce_linux_Fonts.cpp
@@ -113,10 +113,10 @@ public:
                     {
                         if (e->getStringAttribute ("prefix") == "xdg")
                         {
-                            String xdgDataHome = "~/.local/share";//(SystemStats::getEnvironmentVariable ("XDG_DATA_HOME", String::empty));
+                            String xdgDataHome = (SystemStats::getEnvironmentVariable ("XDG_DATA_HOME", String::empty));
 
-                          //  if (xdgDataHome.trimStart().isEmpty())
-                          //      xdgDataHome = "~/.local/share";
+                            if (xdgDataHome.trimStart().isEmpty())
+                                xdgDataHome = "~/.local/share";
 
                             fontPath = File (xdgDataHome).getChildFile (fontPath).getFullPathName();
                         }
diff --git a/JuceLibraryCode/src/native/windows/juce_win32_SystemStats.cpp b/JuceLibraryCode/src/native/windows/juce_win32_SystemStats.cpp
index 3e41e1d77..69fa9726a 100755
--- a/JuceLibraryCode/src/native/windows/juce_win32_SystemStats.cpp
+++ b/JuceLibraryCode/src/native/windows/juce_win32_SystemStats.cpp
@@ -357,5 +357,19 @@ const String SystemStats::getFullUserName()
     return getLogonName();
 }
 
+String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
+{
+    DWORD len = GetEnvironmentVariableW (name.toWideCharPointer(), 0, 0);
+    if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+        return String (defaultValue);
+
+    HeapBlock<WCHAR> buffer (len);
+    len = GetEnvironmentVariableW (name.toWideCharPointer(), buffer, len);
+
+    return String (CharPointer_wchar_t (buffer),
+                   CharPointer_wchar_t (buffer + len));
+}
+
+
 
 #endif
-- 
GitLab