Windows Shell Integration: fixeWindows Shell Integration: fixe

This commit is contained in:
Olivier Goffart 2014-10-15 15:57:15 +02:00 коммит произвёл Daniel Molkentin
Родитель e66ca267f4
Коммит aa0f2c64ff
3 изменённых файлов: 25 добавлений и 22 удалений

Просмотреть файл

@ -104,12 +104,16 @@ bool CommunicationSocket::ReadLine(wstring* response)
std::array<char, 128> resp_utf8;
DWORD numBytesRead = 0;
DWORD totalBytesAvailable = 0;
PeekNamedPipe(_pipe, NULL, 0, 0, &totalBytesAvailable, 0);
auto result = PeekNamedPipe(_pipe, NULL, 0, 0, &totalBytesAvailable, 0);
if (!result) {
Close();
return false;
}
if (totalBytesAvailable == 0) {
return false;
}
auto result = ReadFile(_pipe, resp_utf8.data(), DWORD(resp_utf8.size()), &numBytesRead, NULL);
result = ReadFile(_pipe, resp_utf8.data(), DWORD(resp_utf8.size()), &numBytesRead, NULL);
if (!result) {
Close();
return false;

Просмотреть файл

@ -39,10 +39,11 @@ void RemotePathChecker::workerThreadLoop()
std::unordered_set<std::wstring> asked;
while(!_stop) {
Sleep(50);
if (!connected) {
asked.clear();
if (!WaitNamedPipe(pipename, 5 * 1000)) {
if (!WaitNamedPipe(pipename.data(), 5 * 1000)) {
continue;
}
if (!socket.Connect(pipename)) {
@ -70,14 +71,14 @@ void RemotePathChecker::workerThreadLoop()
std::wstring response;
while (!_stop && socket.ReadLine(&response)) {
if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
wstring responsePath = response.substr(14); // length of REGISTER_PATH:
if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
wstring responsePath = response.substr(14); // length of REGISTER_PATH:
{ std::unique_lock<std::mutex> lock(_mutex);
_watchedDirectories.push_back(responsePath);
}
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, responsePath.data(), NULL);
if (StringUtil::begins_with(response, wstring(L"UNREGISTER_PATH:"))) {
{ std::unique_lock<std::mutex> lock(_mutex);
_watchedDirectories.push_back(responsePath);
}
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, responsePath.data(), NULL);
} else if (StringUtil::begins_with(response, wstring(L"UNREGISTER_PATH:"))) {
wstring responsePath = response.substr(16); // length of UNREGISTER_PATH:
{ std::unique_lock<std::mutex> lock(_mutex);
@ -87,7 +88,7 @@ void RemotePathChecker::workerThreadLoop()
// Remove any item from the cache
for (auto it = _cache.begin(); it != _cache.end() ; ) {
if (StringUtil::begins_with(it.first, responsePath)) {
if (StringUtil::begins_with(it->first, responsePath)) {
it = _cache.erase(it);
} else {
++it;
@ -119,23 +120,21 @@ void RemotePathChecker::workerThreadLoop()
}
}
if (socket.Event() == INVALID_HANDLE_VALUE) {
std::unique_lock<std::mutex> lock(_mutex);
_cache.clear();
_watchedDirectories.clear();
_connected = connected = false;
}
Sleep(50);
if (socket.Event() == INVALID_HANDLE_VALUE) {
std::unique_lock<std::mutex> lock(_mutex);
_cache.clear();
_watchedDirectories.clear();
_connected = connected = false;
}
}
}
RemotePathChecker::RemotePathChecker()
: _thread([this]{ this->workerThreadLoop(); } )
, _connected(false)
: _connected(false)
, _newQueries(CreateEvent(NULL, true, true, NULL))
, _thread([this]{ this->workerThreadLoop(); })
{
}

Просмотреть файл

@ -43,7 +43,6 @@ public:
private:
FileState _StrToFileState(const std::wstring &str);
std::mutex _mutex;
std::thread _thread;
std::atomic<bool> _stop;
// Everything here is protected by the _mutex
@ -61,6 +60,7 @@ private:
//std::condition_variable _newQueries;
HANDLE _newQueries;
std::thread _thread;
void workerThreadLoop();
};