[Pkg-owncloud-commits] [owncloud-client] 300/332: Windows Shell extension: Add watched directories
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Aug 14 21:07:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit c7ff1e9b3fc5d1d1ff186390ace1ffd0017109b1
Author: Daniel Molkentin <danimo at owncloud.com>
Date: Tue Aug 5 19:23:40 2014 +0200
Windows Shell extension: Add watched directories
---
.../OCShellExtensions/OCOverlays/OCOverlay.cpp | 21 ++++++++++--
.../OCShellExtensions/OCOverlays/OCOverlay.h | 2 ++
.../OCOverlays/OCOverlays.vcxproj | 2 ++
.../OCUtil/CommunicationSocket.cpp | 2 ++
.../OCShellExtensions/OCUtil/OCUtil.vcxproj | 2 ++
.../OCShellExtensions/OCUtil/RemotePathChecker.cpp | 40 +++++++++++++++-------
.../OCShellExtensions/OCUtil/RemotePathChecker.h | 3 +-
.../windows/OCShellExtensions/OCUtil/StringUtil.h | 8 +++++
8 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp
index a8e3689..20b809b 100644
--- a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp
+++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp
@@ -15,6 +15,8 @@
#include "OCOverlay.h"
#include "RegistryUtil.h"
+#include "StringUtil.h"
+
#include "UtilConstants.h"
#include "RemotePathChecker.h"
@@ -40,6 +42,8 @@ OCOverlay::OCOverlay(int state)
, _state(state)
{
+ // FIXME: Use Registry instead
+ _watchedDirectories = _checker->WatchedDirectories();
}
OCOverlay::~OCOverlay(void)
@@ -99,6 +103,20 @@ IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
// return MAKE_HRESULT(S_FALSE, 0, 0);
//}
+ wstring wpath(pwszPath);
+ wpath.append(L"\\");
+ vector<wstring>::iterator it;
+ bool watched = false;
+ for (it = _watchedDirectories.begin(); it != _watchedDirectories.end(); ++it) {
+ if (StringUtil::begins_with(wpath, *it)) {
+ watched = true;
+ }
+ }
+
+ if (!watched) {
+ return MAKE_HRESULT(S_FALSE, 0, 0);
+ }
+
int state = 0;
if (!_checker->IsMonitoredPath(pwszPath, &state)) {
return MAKE_HRESULT(S_FALSE, 0, 0);
@@ -127,9 +145,6 @@ bool OCOverlay::_IsOverlaysEnabled()
//int enable;
bool success = false;
-
-
-
//if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_ENABLE_OVERLAY, &enable))
//{
// if(enable) {
diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h
index a84bc45..801b303 100644
--- a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h
+++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h
@@ -45,6 +45,8 @@ private:
CommunicationSocket* _communicationSocket;
RemotePathChecker* _checker;
int _state;
+
+ std::vector<std::wstring> _watchedDirectories;
};
#endif
\ No newline at end of file
diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj
index b9f352b..d648d8b 100644
--- a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj
+++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj
@@ -100,6 +100,7 @@
<AdditionalLibraryDirectories>..\$(Configuration)\$(Platform);</AdditionalLibraryDirectories>
<AdditionalDependencies>OCUtil_x86.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>OCOverlays.def</ModuleDefinitionFile>
+ <SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -114,6 +115,7 @@
<AdditionalLibraryDirectories>..\$(Configuration)\$(Platform);</AdditionalLibraryDirectories>
<AdditionalDependencies>OCUtil_x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>OCOverlays.def</ModuleDefinitionFile>
+ <SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
index 92f4048..a2f4a94 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
@@ -76,6 +76,8 @@ bool CommunicationSocket::Connect()
clientService.sin_port = htons(_port);
iResult = connect(_clientSocket, (SOCKADDR*)&clientService, sizeof(clientService));
+ DWORD timeout = 500; // ms
+ setsockopt(_clientSocket, SOL_SOCKET, SO_RCVTIMEO, (const char*) &timeout, sizeof(DWORD));
if (iResult == SOCKET_ERROR) {
//int error = WSAGetLastError();
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj b/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj
index fc3b1a3..a29cc48 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj
@@ -96,6 +96,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -106,6 +107,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
index e2eba1d..a6d9cce 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
@@ -14,29 +14,45 @@
#include "CommunicationSocket.h"
#include "RemotePathChecker.h"
+#include "StringUtil.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iterator>
-#include <vector>
using namespace std;
-namespace {
- template<class TContainer>
- bool begins_with(const TContainer& input, const TContainer& match)
- {
- return input.size() >= match.size()
- && equal(match.begin(), match.end(), input.begin());
- }
-}
-
RemotePathChecker::RemotePathChecker(int port)
: _port(port)
{
}
+vector<wstring> RemotePathChecker::WatchedDirectories()
+{
+ vector<wstring> watchedDirectories;
+ wstring response;
+ bool needed = false;
+
+ CommunicationSocket socket(_port);
+ socket.Connect();
+
+ while (socket.ReadLine(&response)) {
+ if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
+ size_t pathBegin = response.find(L':', 0);
+ if (pathBegin == -1) {
+ continue;
+ }
+
+ // chop trailing '\n'
+ wstring responsePath = response.substr(pathBegin + 1, response.length()-1);
+ watchedDirectories.push_back(responsePath);
+ }
+ }
+
+ return watchedDirectories;
+}
+
bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, int* state)
{
wstring request;
@@ -53,9 +69,9 @@ bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, int* state)
return false;
}
- while ((socket.ReadLine(&response))) {
+ while (socket.ReadLine(&response)) {
// discard broadcast messages
- if (begins_with(response, wstring(L"STATUS:"))) {
+ if (StringUtil::begins_with(response, wstring(L"STATUS:"))) {
break;
}
}
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
index 47b76f2..1fb1ef9 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
@@ -15,6 +15,7 @@
#define PATHCHECKER_H
#include <string>
+#include <vector>
#pragma once
@@ -29,11 +30,11 @@ public:
StateNone
};
RemotePathChecker(int port);
+ std::vector<std::wstring> WatchedDirectories();
bool IsMonitoredPath(const wchar_t* filePath, int* state);
private:
int _StrToFileState(const std::wstring &str);
-
int _port;
};
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h
index d885a89..cf6ec86 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h
@@ -22,6 +22,14 @@ class __declspec(dllexport) StringUtil {
public:
static char* toUtf8(const wchar_t* utf16, int len = -1);
static wchar_t* toUtf16(const char* utf8, int len = -1);
+
+
+ template<class T>
+ static bool begins_with(const T& input, const T& match)
+ {
+ return input.size() >= match.size()
+ && equal(match.begin(), match.end(), input.begin());
+ }
};
#endif // STRINGUTIL_H
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list