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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "OCOverlay.h"
|
|
|
|
|
2014-08-08 04:39:43 +04:00
|
|
|
#include "OCOverlayFactory.h"
|
2014-07-30 19:20:55 +04:00
|
|
|
#include "RegistryUtil.h"
|
2014-08-05 21:23:40 +04:00
|
|
|
#include "StringUtil.h"
|
|
|
|
|
2014-07-30 19:20:55 +04:00
|
|
|
#include "UtilConstants.h"
|
|
|
|
#include "RemotePathChecker.h"
|
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#pragma comment(lib, "shlwapi.lib")
|
|
|
|
|
|
|
|
extern HINSTANCE instanceHandle;
|
|
|
|
|
|
|
|
#define IDM_DISPLAY 0
|
|
|
|
#define IDB_OK 101
|
|
|
|
|
2014-08-04 17:40:08 +04:00
|
|
|
OCOverlay::OCOverlay(int state)
|
2014-10-14 18:05:48 +04:00
|
|
|
: _referenceCount(1)
|
2014-08-04 17:40:08 +04:00
|
|
|
, _state(state)
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
{
|
2014-10-14 18:05:48 +04:00
|
|
|
static RemotePathChecker s_remotePathChecker;
|
|
|
|
_checker = &s_remotePathChecker;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OCOverlay::~OCOverlay(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP_(ULONG) OCOverlay::AddRef()
|
|
|
|
{
|
|
|
|
return InterlockedIncrement(&_referenceCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP OCOverlay::QueryInterface(REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (IsEqualIID(IID_IUnknown, riid) || IsEqualIID(IID_IShellIconOverlayIdentifier, riid))
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IShellIconOverlayIdentifier *>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = E_NOINTERFACE;
|
|
|
|
*ppv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP_(ULONG) OCOverlay::Release()
|
|
|
|
{
|
|
|
|
ULONG cRef = InterlockedDecrement(&_referenceCount);
|
|
|
|
if (0 == cRef)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
|
|
|
|
{
|
2014-08-08 04:39:43 +04:00
|
|
|
// this defines which handler has prededence, so
|
|
|
|
// we order this in terms of likelyhood
|
|
|
|
switch (_state) {
|
|
|
|
case State_OK:
|
|
|
|
*pPriority = 0;
|
|
|
|
case State_OKShared:
|
|
|
|
*pPriority = 1;
|
|
|
|
case State_Warning:
|
|
|
|
*pPriority = 2;
|
|
|
|
case State_WarningShared:
|
|
|
|
*pPriority = 3;
|
|
|
|
case State_Sync:
|
|
|
|
*pPriority = 4;
|
|
|
|
case State_SyncShared:
|
|
|
|
*pPriority = 5;
|
|
|
|
case State_Error:
|
|
|
|
*pPriority = 6;
|
|
|
|
case State_ErrorShared:
|
|
|
|
*pPriority = 7;
|
|
|
|
default:
|
|
|
|
*pPriority = 8;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
|
|
|
|
{
|
2014-10-14 18:05:48 +04:00
|
|
|
auto watchedDirectories = _checker->WatchedDirectories();
|
2014-08-08 04:39:43 +04:00
|
|
|
|
2014-08-05 21:23:40 +04:00
|
|
|
wstring wpath(pwszPath);
|
2015-01-22 21:12:56 +03:00
|
|
|
wpath.append(L"\\");
|
2014-08-05 21:23:40 +04:00
|
|
|
vector<wstring>::iterator it;
|
|
|
|
bool watched = false;
|
2014-10-14 18:05:48 +04:00
|
|
|
for (it = watchedDirectories.begin(); it != watchedDirectories.end(); ++it) {
|
2014-08-05 21:23:40 +04:00
|
|
|
if (StringUtil::begins_with(wpath, *it)) {
|
|
|
|
watched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!watched) {
|
|
|
|
return MAKE_HRESULT(S_FALSE, 0, 0);
|
|
|
|
}
|
|
|
|
|
2014-08-04 17:40:08 +04:00
|
|
|
int state = 0;
|
|
|
|
if (!_checker->IsMonitoredPath(pwszPath, &state)) {
|
2014-07-30 19:20:55 +04:00
|
|
|
return MAKE_HRESULT(S_FALSE, 0, 0);
|
|
|
|
}
|
2014-08-04 17:40:08 +04:00
|
|
|
return MAKE_HRESULT(state == _state ? S_OK : S_FALSE, 0, 0);
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IFACEMETHODIMP OCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
|
|
|
|
{
|
|
|
|
*pIndex = 0;
|
|
|
|
*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
|
2014-08-04 17:40:08 +04:00
|
|
|
*pIndex = _state;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool OCOverlay::_IsOverlaysEnabled()
|
|
|
|
{
|
|
|
|
//int enable;
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
//if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_ENABLE_OVERLAY, &enable))
|
|
|
|
//{
|
|
|
|
// if(enable) {
|
|
|
|
// success = true;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|