]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Windows Shell Integration: Unify path lookups
authorDaniel Molkentin <danimo@owncloud.com>
Mon, 9 May 2016 13:49:52 +0000 (15:49 +0200)
committerDaniel Molkentin <danimo@owncloud.com>
Tue, 10 May 2016 08:18:53 +0000 (10:18 +0200)
shell_integration/windows/OCContextMenu/OCClientInterface.cpp
shell_integration/windows/OCUtil/CommunicationSocket.cpp
shell_integration/windows/OCUtil/CommunicationSocket.h
shell_integration/windows/OCUtil/RemotePathChecker.cpp

index 7f21292cfa89c0275ff5ea9396345e398dd84ce9..598a10dfdd95afde445895915bbdbae7232cf97c 100644 (file)
@@ -34,23 +34,9 @@ using namespace std;
 #define PIPE_TIMEOUT  5*1000 //ms
 #define SOCK_BUFFER 4096
 
-// TODO: Unify this with RemotePathChecker.cpp
-#define BUFSIZE 512
-std::wstring getUserName() {
-    DWORD  len = BUFSIZE;
-    TCHAR  buf[BUFSIZE];
-    if (GetUserName(buf, &len)) {
-        return std::wstring(&buf[0], len);
-    } else {
-        return std::wstring();
-    }
-}
-
 OCClientInterface::ContextMenuInfo OCClientInterface::FetchInfo()
 {
-       auto pipename = std::wstring(L"\\\\.\\pipe\\");
-       pipename += L"ownCloud\\";
-       pipename += getUserName();
+       auto pipename = CommunicationSocket::DefaultPipePath();
 
        CommunicationSocket socket;
        if (!WaitNamedPipe(pipename.data(), PIPE_TIMEOUT)) {
index a4004f716a9e2f14d78c9c773ec82d456beb25b4..e37487b9162691777facf6b036a73d686b72e427 100644 (file)
 
 #include <fstream> 
 
-#define BUFSIZE 1024
+#define DEFAULT_BUFLEN 4096
 
 using namespace std;
 
-#define DEFAULT_BUFLEN 4096
+namespace {
+
+std::wstring getUserName() {
+       DWORD  len = DEFAULT_BUFLEN;
+       TCHAR  buf[DEFAULT_BUFLEN];
+       if (GetUserName(buf, &len)) {
+               return std::wstring(&buf[0], len);
+       } else {
+               return std::wstring();
+       }
+}
+
+}
+
+std::wstring CommunicationSocket::DefaultPipePath()
+{
+       auto pipename = std::wstring(L"\\\\.\\pipe\\");
+       pipename += L"ownCloud\\";
+       pipename += getUserName();
+       return pipename;
+}
 
 CommunicationSocket::CommunicationSocket()
     : _pipe(INVALID_HANDLE_VALUE)
index 312f47006423a359eb81d71a0e488f4ca0fe60d6..fc06f066886a3f68f22264f7832a78bc8e830c8c 100644 (file)
@@ -26,6 +26,8 @@
 class __declspec(dllexport) CommunicationSocket
 {
 public:
+       static std::wstring DefaultPipePath();
+
        CommunicationSocket();
        ~CommunicationSocket();
 
@@ -43,4 +45,4 @@ private:
     bool _connected;
 };
 
-#endif
\ No newline at end of file
+#endif
index fcca9893ab6c5a77998c7c755afdefbf1e75698a..b0b4df088d05877db8edaf74fdd93fbb026e668d 100644 (file)
 
 using namespace std;
 
-// FIXME: Unify this with OCClientInterface.cpp
-#define BUFSIZE 512
-std::wstring getUserName() {
-    DWORD  len = BUFSIZE;
-    TCHAR  buf[BUFSIZE];
-    if (GetUserName(buf, &len)) {
-        return std::wstring(&buf[0], len);
-    } else {
-        return std::wstring();
-    }
-}
-
 // This code is run in a thread
 void RemotePathChecker::workerThreadLoop()
 {
-    auto pipename = std::wstring(L"\\\\.\\pipe\\");
-    pipename += L"ownCloud\\";
-    pipename += getUserName();
-
+    auto pipename = CommunicationSocket::DefaultPipePath();
     bool connected = false;
     CommunicationSocket socket;
     std::unordered_set<std::wstring> asked;