1 #include "util.h" 2 3 #include <QtGlobal> 4 #include <QtCore/QProcess> 5 6 #ifdef Q_OS_WIN 7 #include <windows.h> 8 #endif 9 10 namespace fso { 11 namespace fred { 12 getUsername()13SCP_string getUsername() { 14 #ifdef Q_OS_WIN 15 char acUserName[256]; 16 DWORD nUserName = sizeof(acUserName); 17 if (GetUserNameA(acUserName, &nUserName)) 18 return SCP_string(acUserName); 19 else 20 return ""; 21 #elif defined(Q_OS_UNIX) 22 QProcess process; 23 QString username; 24 QObject::connect(&process, 25 static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), 26 [&process, &username](int, QProcess::ExitStatus) { 27 username = process.readAllStandardOutput(); 28 }); 29 process.start("whoami", QStringList()); 30 process.waitForFinished(); 31 32 return username.toUtf8().constData(); 33 #else 34 #error No username implementation on this platform! 35 #endif 36 } 37 38 } 39 } 40