Browse Source

Added methods to SystemStats to return the user's name.

tags/2021-05-28
Julian Storer 15 years ago
parent
commit
ca0dce68d5
8 changed files with 131 additions and 24 deletions
  1. +21
    -19
      extras/juce demo/src/ApplicationStartup.cpp
  2. +43
    -0
      juce_amalgamated.cpp
  3. +4
    -0
      juce_amalgamated.h
  4. +12
    -0
      src/core/juce_SystemStats.h
  5. +5
    -5
      src/gui/components/code_editor/juce_CodeDocument.cpp
  6. +19
    -0
      src/native/linux/juce_linux_SystemStats.cpp
  7. +11
    -0
      src/native/mac/juce_mac_SystemStats.mm
  8. +16
    -0
      src/native/windows/juce_win32_SystemStats.cpp

+ 21
- 19
extras/juce demo/src/ApplicationStartup.cpp View File

@@ -119,16 +119,18 @@ private:
String systemInfo;
systemInfo
<< T("Time and date: ") << Time::getCurrentTime().toString (true, true)
<< T("\nOperating system: ") << SystemStats::getOperatingSystemName()
<< T("\nCPU vendor: ") << SystemStats::getCpuVendor()
<< T("\nCPU speed: ") << SystemStats::getCpuSpeedInMegaherz() << T("MHz\n")
<< T("\nNumber of CPUs: ") << SystemStats::getNumCpus()
<< T("\nCPU has MMX: ") << (SystemStats::hasMMX() ? T("yes") : T("no"))
<< T("\nCPU has SSE: ") << (SystemStats::hasSSE() ? T("yes") : T("no"))
<< T("\nCPU has SSE2: ") << (SystemStats::hasSSE2() ? T("yes") : T("no"))
<< T("\nCPU has 3DNOW: ") << (SystemStats::has3DNow() ? T("yes") : T("no"))
<< T("\nMemory size: ") << SystemStats::getMemorySizeInMegabytes() << T("MB\n");
<< "Time and date: " << Time::getCurrentTime().toString (true, true)
<< "\nUser logon name: " << SystemStats::getLogonName()
<< "\nFull user name: " << SystemStats::getFullUserName()
<< "\nOperating system: " << SystemStats::getOperatingSystemName()
<< "\nCPU vendor: " << SystemStats::getCpuVendor()
<< "\nCPU speed: " << SystemStats::getCpuSpeedInMegaherz() << "MHz\n"
<< "\nNumber of CPUs: " << SystemStats::getNumCpus()
<< "\nCPU has MMX: " << (SystemStats::hasMMX() ? "yes" : "no")
<< "\nCPU has SSE: " << (SystemStats::hasSSE() ? "yes" : "no")
<< "\nCPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no")
<< "\nCPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no")
<< "\nMemory size: " << SystemStats::getMemorySizeInMegabytes() << "MB\n";
int64 macAddresses[8];
const int numAddresses = SystemStats::getMACAddresses (macAddresses, 8, false);
@@ -136,7 +138,7 @@ private:
for (int i = 0; i < numAddresses; ++i)
{
systemInfo
<< T("Found network card MAC address: ")
<< "Found network card MAC address: "
<< String::formatted (T("%02x-%02x-%02x-%02x-%02x-%02x\n"),
0xff & (int) (macAddresses [i] >> 40),
0xff & (int) (macAddresses [i] >> 32),
@@ -147,21 +149,21 @@ private:
}
systemInfo
<< T("Current executable file: ")
<< "Current executable file: "
<< File::getSpecialLocation (File::currentExecutableFile).getFullPathName()
<< T("\nCurrent application file: ")
<< "\nCurrent application file: "
<< File::getSpecialLocation (File::currentApplicationFile).getFullPathName()
<< T("\nUser home directory: ")
<< "\nUser home directory: "
<< File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
<< T("\nUser documents directory: ")
<< "\nUser documents directory: "
<< File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName()
<< T("\nUser application data directory: ")
<< "\nUser application data directory: "
<< File::getSpecialLocation (File::userApplicationDataDirectory).getFullPathName()
<< T("\nCommon application data directory: ")
<< "\nCommon application data directory: "
<< File::getSpecialLocation (File::commonApplicationDataDirectory).getFullPathName()
<< T("\nTemp directory: ")
<< "\nTemp directory: "
<< File::getSpecialLocation (File::tempDirectory).getFullPathName()
<< T("\n\n");
<< "\n\n";
return systemInfo;
}


+ 43
- 0
juce_amalgamated.cpp View File

@@ -212409,6 +212409,20 @@ int SystemStats::getPageSize() throw()
return systemInfo.dwPageSize;
}

const String SystemStats::getLogonName()
{
TCHAR text [256];
DWORD len = numElementsInArray (text) - 2;
zerostruct (text);
GetUserName (text, &len);
return String (text, len);
}

const String SystemStats::getFullUserName()
{
return getLogonName();
}

#endif
/********* End of inlined file: juce_win32_SystemStats.cpp *********/

@@ -230238,6 +230252,25 @@ int SystemStats::getNumCpus() throw()
return lastCpu + 1;
}

const String SystemStats::getLogonName()
{
const char* user = getenv ("USER");

if (user == 0)
{
struct passwd* const pw = getpwuid (getuid());
if (pw != 0)
user = pw->pw_name;
}

return String::fromUTF8 ((const uint8*) user);
}

const String SystemStats::getFullUserName()
{
return getLogonName();
}

void SystemStats::initialiseStats() throw()
{
// Process starts off as root when running suid
@@ -237564,6 +237597,16 @@ int SystemStats::getNumCpus() throw()
#endif
}

const String SystemStats::getLogonName()
{
return nsStringToJuce (NSUserName());
}

const String SystemStats::getFullUserName()
{
return nsStringToJuce (NSFullUserName());
}

uint32 juce_millisecondsSinceStartup() throw()
{
return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);


+ 4
- 0
juce_amalgamated.h View File

@@ -7088,6 +7088,10 @@ public:

static bool isOperatingSystem64Bit() throw();

static const String getLogonName();

static const String getFullUserName();

// CPU and memory information..

static int getCpuSpeedInMegaherz() throw();


+ 12
- 0
src/core/juce_SystemStats.h View File

@@ -86,6 +86,18 @@ public:
*/
static bool isOperatingSystem64Bit() throw();
//==============================================================================
/** Returns the current user's name, if available.
@see getFullUserName()
*/
static const String getLogonName();
/** Returns the current user's full name, if available.
On some OSes, this may just return the same value as getLogonName().
@see getLogonName()
*/
static const String getFullUserName();
//==============================================================================
// CPU and memory information..


+ 5
- 5
src/gui/components/code_editor/juce_CodeDocument.cpp View File

@@ -116,26 +116,26 @@ public:
//==============================================================================
CodeDocument::Iterator::Iterator (CodeDocument* const document_)
: document (document_),
currentLine (document_->lines[0]),
line (0),
position (0),
currentLine (document_->lines[0])
position (0)
{
}
CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
: document (other.document),
currentLine (other.currentLine),
line (other.line),
position (other.position),
currentLine (other.currentLine)
position (other.position)
{
}
const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
{
document = other.document;
currentLine = other.currentLine;
line = other.line;
position = other.position;
currentLine = other.currentLine;
return *this;
}


+ 19
- 0
src/native/linux/juce_linux_SystemStats.cpp View File

@@ -214,6 +214,25 @@ int SystemStats::getNumCpus() throw()
return lastCpu + 1;
}
//==============================================================================
const String SystemStats::getLogonName()
{
const char* user = getenv ("USER");
if (user == 0)
{
struct passwd* const pw = getpwuid (getuid());
if (pw != 0)
user = pw->pw_name;
}
return String::fromUTF8 ((const uint8*) user);
}
const String SystemStats::getFullUserName()
{
return getLogonName();
}
//==============================================================================
void SystemStats::initialiseStats() throw()


+ 11
- 0
src/native/mac/juce_mac_SystemStats.mm View File

@@ -218,6 +218,17 @@ int SystemStats::getNumCpus() throw()
#endif
}
//==============================================================================
const String SystemStats::getLogonName()
{
return nsStringToJuce (NSUserName());
}
const String SystemStats::getFullUserName()
{
return nsStringToJuce (NSFullUserName());
}
//==============================================================================
uint32 juce_millisecondsSinceStartup() throw()
{


+ 16
- 0
src/native/windows/juce_win32_SystemStats.cpp View File

@@ -390,4 +390,20 @@ int SystemStats::getPageSize() throw()
return systemInfo.dwPageSize;
}
//==============================================================================
const String SystemStats::getLogonName()
{
TCHAR text [256];
DWORD len = numElementsInArray (text) - 2;
zerostruct (text);
GetUserName (text, &len);
return String (text, len);
}
const String SystemStats::getFullUserName()
{
return getLogonName();
}
#endif

Loading…
Cancel
Save