summaryrefslogtreecommitdiffstats
path: root/src/util/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/util.cpp')
-rwxr-xr-x[-rw-r--r--]src/util/util.cpp62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/util/util.cpp b/src/util/util.cpp
index 946168e..7463ae0 100644..100755
--- a/src/util/util.cpp
+++ b/src/util/util.cpp
@@ -6,7 +6,11 @@
#include <cstdlib>
#include <QStringList>
#include <iostream>
-
+#include <QDir>
+#ifdef __WIN32__
+ #include <windows.h>
+ #include <Lmcons.h>
+#endif //__WIN32__
PVSServerEntry::PVSServerEntry(QString name)
{
@@ -45,7 +49,11 @@ int getRandom(int min, int max)
if (init)
{
init = false;
+ #ifndef __WIN32__
srand ( time(NULL) + getpid() );
+ #else
+ srand ( time(NULL) ); /*might be solved by another random factor*/
+ #endif
}
if (min >= max) return rand();
return rand() % (max-min+1) + min;
@@ -184,12 +192,29 @@ QString colonSplitter(QString line, bool first)
QString getUserName()
{
- struct passwd* passUser = getpwuid(getuid());
QString username;
- if (passUser)
- {
- username = QString(passUser->pw_name);
- }
+ #ifdef __WIN32__
+ WCHAR* lpszSystemInfo; // pointer to system information
+ DWORD cchBuff = 256; // size of user name
+ WCHAR tchBuffer[UNLEN + 1]; // buffer for expanded string
+
+ lpszSystemInfo = tchBuffer;
+
+ // Get and display the user name.
+ GetUserNameW(lpszSystemInfo, &cchBuff);
+
+ //Unicode string needs to be converted
+ username = QString::fromWCharArray(lpszSystemInfo);
+ #elif defined __WIN32__
+ struct passwd* passUser = getpwuid(getuid());
+
+ if (passwd)
+ username = passwd->pw_name;
+ if (passUser)
+ {
+ username = QString(passUser->pw_name);
+ }
+ #endif //#ifdef __WIN32__
if (username.isEmpty())
{
printf("USERNAME COULDNT BE RETRIEVED!\n");
@@ -202,19 +227,21 @@ QString getUserName()
QString getFullUsername()
{
QString fullname = getUserName();
- struct passwd *pd;
+ #ifndef __WIN32__
+ struct passwd *pd;
- if (NULL == (pd = getpwuid(getuid())))
- {ConsoleLog writeError("getpwuid() error.");}
- else
- {
- QString tmp = pd->pw_gecos;
- QStringList userData = tmp.split(",");
- if(userData[0].length() > 0 )
+ if (NULL == (pd = getpwuid(getuid())))
+ {ConsoleLog writeError("getpwuid() error.");}
+ else
{
- fullname = userData[0];
+ QString tmp = pd->pw_gecos;
+ QStringList userData = tmp.split(",");
+ if(userData[0].length() > 0 )
+ {
+ fullname = userData[0];
+ }
}
- }
+ #endif //__WIN32__ //might be completed some time to a full solution for WIN32
return fullname;
}
@@ -266,7 +293,8 @@ bool policyFileExists(QString fileName)
void createPolicyDir()
{
- mkdir(getPolicyDir().toUtf8().data(), 0777);
+ QDir(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).mkdir(".pvs");
+ //assuming PolicyDir is defined like in getPolicyDir()
}
void createPolicyFiles()