summaryrefslogtreecommitdiff
path: root/ExtraSocket.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2017-11-24 23:24:09 +0000
committerThomas Preud'homme <robotux@celest.fr>2017-11-24 23:24:09 +0000
commitb3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (patch)
tree8fce8a51adfb245db8ab2a76831661780c0c713e /ExtraSocket.cpp
parente297dbd8052ef4e66f069e2dd1865ae7fa8af28e (diff)
New upstream version 1.2.3.6
Diffstat (limited to 'ExtraSocket.cpp')
-rw-r--r--ExtraSocket.cpp66
1 files changed, 47 insertions, 19 deletions
diff --git a/ExtraSocket.cpp b/ExtraSocket.cpp
index 08b0979..8175c5f 100644
--- a/ExtraSocket.cpp
+++ b/ExtraSocket.cpp
@@ -1,32 +1,60 @@
/** \file ExtraSocket.h
\brief Define the socket of ultracopier
\author alpha_one_x86
-\version 0.3
-\date 2010
\licence GPL3, see the file COPYING */
#include "ExtraSocket.h"
+#include <QByteArray>
+#include <stdio.h>
QString ExtraSocket::pathSocket(const QString &name)
{
#ifdef Q_OS_UNIX
- return name+"-"+QString::number(getuid());
+ return name+QStringLiteral("-")+QString::number(getuid());
#else
- QString userName;
- DWORD size=0;
- if(GetUserNameW(NULL,&size) || (GetLastError()!=ERROR_INSUFFICIENT_BUFFER))
- {
- }
- else
- {
- WCHAR * userNameW=new WCHAR[size];
- if(GetUserNameW(userNameW,&size))
- {
- userName.fromWCharArray(userNameW,size*2);
- userName=QString(QByteArray((char*)userNameW,size*2-2).toHex());
- }
- delete userNameW;
- }
- return name+"-"+userName;
+ QString userName;
+
+ /* bad way for catchcopy compatibility
+ char uname[1024];
+ DWORD len=1023;
+ if(GetUserNameA(uname, &len)!=FALSE)
+ userName=QString::fromLatin1(toHex(uname));*/
+
+ QChar charTemp;
+ DWORD size=255;
+ WCHAR * userNameW=new WCHAR[size];
+ if(GetUserNameW(userNameW,&size))
+ {
+ QByteArray tempArray;
+ userName=QString::fromWCharArray(userNameW,size-1);
+ int index=0;
+ while(index<userName.size())
+ {
+ tempArray+=userName.at(index).cell();
+ tempArray+=userName.at(index).row();
+ index++;
+ }
+ userName=tempArray.toHex();
+ }
+ delete userNameW;
+ return name+QStringLiteral("-")+userName;
#endif
}
+
+// Dump UTF16 (little endian)
+char * ExtraSocket::toHex(const char *str)
+{
+ char *p, *sz;
+ size_t len;
+ if (str==NULL)
+ return NULL;
+ len= strlen(str);
+ p = sz = (char *) malloc((len+1)*4);
+ for (size_t i=0; i<len; i++)
+ {
+ sprintf(p, "%.2x00", str[i]);
+ p+=4;
+ }
+ *p=0;
+ return sz;
+}