Kaynağa Gözat

Windows Shell Integration: Unify path lookups

Daniel Molkentin 9 yıl önce
ebeveyn
işleme
0e9170cb36

+ 1 - 15
shell_integration/windows/OCContextMenu/OCClientInterface.cpp

@@ -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)) {

+ 22 - 2
shell_integration/windows/OCUtil/CommunicationSocket.cpp

@@ -24,11 +24,31 @@
 
 #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)

+ 3 - 1
shell_integration/windows/OCUtil/CommunicationSocket.h

@@ -26,6 +26,8 @@
 class __declspec(dllexport) CommunicationSocket
 {
 public:
+	static std::wstring DefaultPipePath();
+
 	CommunicationSocket();
 	~CommunicationSocket();
 
@@ -43,4 +45,4 @@ private:
     bool _connected;
 };
 
-#endif
+#endif

+ 1 - 16
shell_integration/windows/OCUtil/RemotePathChecker.cpp

@@ -31,25 +31,10 @@
 
 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;