1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-06 04:00:08 +00:00

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

This commit is contained in:
Julian Storer 2010-02-05 18:36:19 +00:00
parent 0d024b3306
commit ca0dce68d5
8 changed files with 131 additions and 24 deletions

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;
}

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);

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();

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..

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;
}

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()

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()
{

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