Browse Source

Added function: SystemStats::getEnvironmentVariable()

tags/2021-05-28
jules 13 years ago
parent
commit
2d9312ca3e
3 changed files with 30 additions and 0 deletions
  1. +11
    -0
      modules/juce_core/native/juce_posix_SharedCode.h
  2. +14
    -0
      modules/juce_core/native/juce_win32_SystemStats.cpp
  3. +5
    -0
      modules/juce_core/system/juce_SystemStats.h

+ 11
- 0
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -525,6 +525,17 @@ Result FileOutputStream::truncate()
return getResultForReturnValue (ftruncate (getFD (fileHandle), (off_t) currentPosition));
}
//==============================================================================
String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
{
const char* s = ::getenv (name.toUTF8());
if (s != nullptr)
return String::fromUTF8 (s);
return defaultValue;
}
//==============================================================================
MemoryMappedFile::MemoryMappedFile (const File& file, MemoryMappedFile::AccessMode mode)
: address (nullptr),


+ 14
- 0
modules/juce_core/native/juce_win32_SystemStats.cpp View File

@@ -198,6 +198,20 @@ int SystemStats::getMemorySizeInMegabytes()
return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
}
//==============================================================================
String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
{
DWORD len = GetEnvironmentVariableW (name.toWideCharPointer(), nullptr, 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));
}
//==============================================================================
uint32 juce_millisecondsSinceStartup() noexcept
{


+ 5
- 0
modules/juce_core/system/juce_SystemStats.h View File

@@ -94,6 +94,11 @@ public:
static int getOSXMinorVersionNumber();
#endif
/** Returns an environment variable.
If the named value isn't set, this will return the defaultValue string instead.
*/
static String getEnvironmentVariable (const String& name, const String& defaultValue);
//==============================================================================
/** Returns the current user's name, if available.
@see getFullUserName()


Loading…
Cancel
Save