2014-07-30 19:20:55 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
#include "NCOverlay.h"
|
|
|
|
#include "NCOverlayFactory.h"
|
2014-08-05 21:23:40 +04:00
|
|
|
#include "StringUtil.h"
|
2014-07-30 19:20:55 +04:00
|
|
|
#include "RemotePathChecker.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2015-02-18 19:19:59 +03:00
|
|
|
#include <memory>
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#pragma comment(lib, "shlwapi.lib")
|
|
|
|
|
|
|
|
extern HINSTANCE instanceHandle;
|
|
|
|
|
|
|
|
#define IDM_DISPLAY 0
|
|
|
|
#define IDB_OK 101
|
|
|
|
|
2015-02-18 19:19:59 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
unique_ptr<RemotePathChecker> s_instance;
|
|
|
|
|
|
|
|
RemotePathChecker *getGlobalChecker()
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
// On Vista we'll run into issue #2680 if we try to create the thread+pipe connection
|
|
|
|
// on any DllGetClassObject of our registered classes.
|
|
|
|
// Work around the issue by creating the static RemotePathChecker only once actually needed.
|
|
|
|
static once_flag s_onceFlag;
|
|
|
|
call_once(s_onceFlag, [] { s_instance.reset(new RemotePathChecker); });
|
2015-02-18 19:19:59 +03:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
return s_instance.get();
|
2015-02-18 19:19:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 20:11:08 +03:00
|
|
|
NCOverlay::NCOverlay(int state)
|
2017-01-05 19:28:28 +03:00
|
|
|
: _referenceCount(1)
|
|
|
|
, _state(state)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
NCOverlay::~NCOverlay(void)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-11 18:35:44 +03:00
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP_(ULONG) NCOverlay::AddRef()
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
|
|
|
return InterlockedIncrement(&_referenceCount);
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP NCOverlay::QueryInterface(REFIID riid, void **ppv)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (IsEqualIID(IID_IUnknown, riid) || IsEqualIID(IID_IShellIconOverlayIdentifier, riid))
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IShellIconOverlayIdentifier *>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = E_NOINTERFACE;
|
2020-06-05 01:51:32 +03:00
|
|
|
*ppv = nullptr;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
AddRef();
|
|
|
|
}
|
2017-01-05 19:28:28 +03:00
|
|
|
|
2014-07-30 19:20:55 +04:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP_(ULONG) NCOverlay::Release()
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
|
|
|
ULONG cRef = InterlockedDecrement(&_referenceCount);
|
|
|
|
if (0 == cRef)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cRef;
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP NCOverlay::GetPriority(int *pPriority)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
// this defines which handler has prededence, so
|
|
|
|
// we order this in terms of likelyhood
|
|
|
|
switch (_state) {
|
|
|
|
case State_OK:
|
|
|
|
*pPriority = 0; break;
|
|
|
|
case State_OKShared:
|
|
|
|
*pPriority = 1; break;
|
|
|
|
case State_Warning:
|
|
|
|
*pPriority = 2; break;
|
|
|
|
case State_Sync:
|
|
|
|
*pPriority = 3; break;
|
|
|
|
case State_Error:
|
|
|
|
*pPriority = 4; break;
|
|
|
|
default:
|
|
|
|
*pPriority = 5; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP NCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
RemotePathChecker* checker = getGlobalChecker();
|
2017-01-09 18:28:26 +03:00
|
|
|
std::shared_ptr<const std::vector<std::wstring>> watchedDirectories = checker->WatchedDirectories();
|
|
|
|
|
|
|
|
if (watchedDirectories->empty()) {
|
|
|
|
return MAKE_HRESULT(S_FALSE, 0, 0);
|
|
|
|
}
|
2017-01-05 19:28:28 +03:00
|
|
|
|
|
|
|
bool watched = false;
|
2017-01-09 18:28:26 +03:00
|
|
|
size_t pathLength = wcslen(pwszPath);
|
|
|
|
for (auto it = watchedDirectories->begin(); it != watchedDirectories->end(); ++it) {
|
|
|
|
if (StringUtil::isDescendantOf(pwszPath, pathLength, *it)) {
|
2017-01-05 19:28:28 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
return MAKE_HRESULT(state == _state ? S_OK : S_FALSE, 0, 0);
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
2020-08-18 20:11:08 +03:00
|
|
|
IFACEMETHODIMP NCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
|
2014-07-30 19:20:55 +04:00
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
*pIndex = 0;
|
|
|
|
*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
|
|
|
|
*pIndex = _state;
|
|
|
|
|
|
|
|
if (GetModuleFileName(instanceHandle, pwszIconFile, cchMax) == 0) {
|
|
|
|
HRESULT hResult = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
wcerr << L"IsOK? " << (hResult == S_OK) << L" with path " << pwszIconFile << L", index " << *pIndex << endl;
|
|
|
|
return hResult;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
return S_OK;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|