Browse Source

GetLoginName() returns the name of the currently logged in user.

Florastamine 8 years ago
parent
commit
de1af331ac

+ 1 - 0
Docs/AngelScriptAPI.h

@@ -15945,6 +15945,7 @@ String GetParentPath(const String&);
 String GetPath(const String&);
 String GetPlatform();
 uint64 GetTotalMemory();
+String GetLoginName(); 
 uint GetRG16Format();
 uint GetRGBA16Format();
 uint GetRGBAFloat16Format();

+ 1 - 0
Docs/LuaScriptAPI.dox

@@ -8655,6 +8655,7 @@ Properties:
 - String GetPath(const String fullPath)
 - String GetPlatform()
 - unsigned long long GetTotalMemory()
+- String GetLoginName()
 - unsigned GetRandomSeed()
 - Renderer* GetRenderer()
 - Time* GetTime()

+ 1 - 0
Docs/ScriptAPI.dox

@@ -16522,6 +16522,7 @@ Properties:
 - String GetPath(const String&)
 - String GetPlatform()
 - uint64 GetTotalMemory() 
+- String GetLoginName() 
 - uint GetRG16Format()
 - uint GetRGBA16Format()
 - uint GetRGBAFloat16Format()

+ 1 - 0
Source/Urho3D/AngelScript/CoreAPI.cpp

@@ -830,6 +830,7 @@ static void RegisterProcessUtils(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("void SetMiniDumpDir(const String&in)", asFUNCTION(SetMiniDumpDir), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetMiniDumpDir()", asFUNCTION(GetMiniDumpDir), asCALL_CDECL);
     engine->RegisterGlobalFunction("uint64 GetTotalMemory()", asFUNCTION(GetTotalMemory), asCALL_CDECL);
+    engine->RegisterGlobalFunction("String GetLoginName()", asFUNCTION(GetLoginName), asCALL_CDECL);
 }
 
 static void ConstructAttributeInfo(AttributeInfo* ptr)

+ 20 - 0
Source/Urho3D/Core/ProcessUtils.cpp

@@ -42,10 +42,12 @@
 #ifdef _WIN32
 #include <windows.h>
 #include <io.h>
+#include <Lmcons.h> // For UNLEN. 
 #if defined(_MSC_VER)
 #include <float.h>
 #endif
 #else
+#include <pwd.h> 
 #include <unistd.h>
 #include <sys/sysinfo.h>
 #endif
@@ -502,4 +504,22 @@ unsigned long long GetTotalMemory()
     return 0ull;
 }
 
+String GetLoginName() 
+{
+#if defined(__linux__)
+    struct passwd *p = getpwuid(getuid());
+    if (p) 
+        return p->pw_name;
+    else 
+        return "(?)"; 
+#elif defined(_WIN32)
+    char name[UNLEN + 1];
+    DWORD len = UNLEN + 1; 
+    if(GetUserName(name, &len)) 
+        return name; 
+#else 
+#endif 
+    return String::EMPTY;
+}
+
 }

+ 2 - 0
Source/Urho3D/Core/ProcessUtils.h

@@ -71,4 +71,6 @@ URHO3D_API void SetMiniDumpDir(const String& pathName);
 URHO3D_API String GetMiniDumpDir();
 /// Return the total amount of useable memory. 
 URHO3D_API unsigned long long GetTotalMemory(); 
+/// Return the name of the currently logged in user. 
+URHO3D_API String GetLoginName(); 
 }

+ 1 - 0
Source/Urho3D/LuaScript/pkgs/Core/ProcessUtils.pkg

@@ -17,3 +17,4 @@ void SetMiniDumpDir(const String pathName);
 String GetMiniDumpDir();
 
 unsigned long long GetTotalMemory(); 
+String GetLoginName();