diff --git a/.gitignore b/.gitignore index eed2de186..e1cd73027 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,148 @@ build* cscope.* tags t1.cfg + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +*.pubxml + +# NuGet Packages +packages/* +*.nupkg +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Microsoft Fakes +FakesAssemblies/ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/DllMain.cpp b/shell_integration/windows/OCShellExtensions/OCOverlays/DllMain.cpp new file mode 100644 index 000000000..84b128dd4 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/DllMain.cpp @@ -0,0 +1,156 @@ +/** + * 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 "OCOverlayRegistrationHandler.h" +#include "OCOverlayFactory.h" +#include "stdafx.h" + +HINSTANCE instanceHandle = NULL; + +long dllReferenceCount = 0; + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) +{ + switch (dwReason) + { + case DLL_PROCESS_ATTACH: + instanceHandle = hModule; + DisableThreadLibraryCalls(hModule); + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + + return TRUE; +} + +STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv) +{ + HRESULT hResult = CLASS_E_CLASSNOTAVAILABLE; + GUID guid; + + hResult = CLSIDFromString(OVERLAY_GUID, (LPCLSID)&guid); + + if (hResult != S_OK) { + return hResult; + } + + if (!IsEqualCLSID(guid, rclsid)) { + return hResult; + } + + hResult = E_OUTOFMEMORY; + + wchar_t szModule[MAX_PATH]; + + if (GetModuleFileName(instanceHandle, szModule, ARRAYSIZE(szModule)) == 0) { + hResult = HRESULT_FROM_WIN32(GetLastError()); + + return hResult; + } + + OCOverlayFactory* ocOverlayFactory = new OCOverlayFactory(szModule); + + if (ocOverlayFactory) { + hResult = ocOverlayFactory->QueryInterface(riid, ppv); + ocOverlayFactory->Release(); + } + return hResult; +} + +STDAPI DllCanUnloadNow(void) +{ + return dllReferenceCount > 0 ? S_FALSE : S_OK; + + return S_FALSE; +} + +HRESULT _stdcall DllRegisterServer(void) +{ + HRESULT hResult = S_OK; + + wchar_t szModule[MAX_PATH]; + + if (GetModuleFileName(instanceHandle, szModule, ARRAYSIZE(szModule)) == 0) + { + hResult = HRESULT_FROM_WIN32(GetLastError()); + + return hResult; + } + + GUID guid; + + hResult = CLSIDFromString(OVERLAY_GUID, (LPCLSID)&guid); + + if (hResult != S_OK) + { + return hResult; + } + + hResult = OCOverlayRegistrationHandler::RegisterCOMObject(szModule, guid); + + if(!SUCCEEDED(hResult)) + { + return hResult; + } + + hResult = OCOverlayRegistrationHandler::MakeRegistryEntries(guid, OVERLAY_NAME); + + if(!SUCCEEDED(hResult)) + { + return hResult; + } + + return hResult; +} + +STDAPI DllUnregisterServer(void) +{ + HRESULT hResult = S_OK; + + wchar_t szModule[MAX_PATH]; + + if (GetModuleFileNameW(instanceHandle, szModule, ARRAYSIZE(szModule)) == 0) + { + hResult = HRESULT_FROM_WIN32(GetLastError()); + return hResult; + } + + GUID guid; + + hResult = CLSIDFromString(OVERLAY_GUID, (LPCLSID)&guid); + + if (hResult != S_OK) + { + return hResult; + } + + hResult = OCOverlayRegistrationHandler::UnregisterCOMObject(guid); + + if(!SUCCEEDED(hResult)) + { + return hResult; + } + + hResult = OCOverlayRegistrationHandler::RemoveRegistryEntries(OVERLAY_NAME); + + if (!SUCCEEDED(hResult)) + { + return hResult; + } + + return hResult; +} diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp new file mode 100644 index 000000000..2fc947121 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.cpp @@ -0,0 +1,143 @@ +/** + * 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" + +#include "RegistryUtil.h" +#include "UtilConstants.h" +#include "RemotePathChecker.h" + +#include "resource.h" + +#include +#include +#include + +using namespace std; + +#pragma comment(lib, "shlwapi.lib") + +extern HINSTANCE instanceHandle; + +#define IDM_DISPLAY 0 +#define IDB_OK 101 + +OCOverlay::OCOverlay() + : _communicationSocket(0) + , _referenceCount(1) + , _checker(new RemotePathChecker(PORT)) + +{ +} + +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(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) +{ + pPriority = 0; + + return S_OK; +} + + IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib) +{ + + //if(!_IsOverlaysEnabled()) + //{ + // return MAKE_HRESULT(S_FALSE, 0, 0); + //} + + bool isDir = dwAttrib & FILE_ATTRIBUTE_DIRECTORY; + + if (!_checker->IsMonitoredPath(pwszPath, isDir)) { + return MAKE_HRESULT(S_FALSE, 0, 0); + } + + return MAKE_HRESULT(S_OK, 0, 0); +} + +IFACEMETHODIMP OCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags) +{ + *pIndex = 0; + *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX; + *pIndex = 2; + + 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; +} + diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h new file mode 100644 index 000000000..498800a66 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.h @@ -0,0 +1,49 @@ +/** + * 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. + */ + +#ifndef OCOVERLAY_H +#define OCOVERLAY_H + +#include "stdafx.h" + +#pragma once + +class RemotePathChecker; + +class OCOverlay : public IShellIconOverlayIdentifier + +{ +public: + OCOverlay(); + + IFACEMETHODIMP_(ULONG) AddRef(); + IFACEMETHODIMP GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags); + IFACEMETHODIMP GetPriority(int *pPriority); + IFACEMETHODIMP IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib); + IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv); + IFACEMETHODIMP_(ULONG) Release(); + +protected: + ~OCOverlay(void); + +private: + //bool _GenerateMessage(const wchar_t*, std::wstring*); + + bool _IsOverlaysEnabled(); + long _referenceCount; + CommunicationSocket* _communicationSocket; + RemotePathChecker* _checker; +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.rc b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.rc new file mode 100644 index 000000000..8d4d30b6d Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlay.rc differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.cpp b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.cpp new file mode 100644 index 000000000..f2d344c02 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.cpp @@ -0,0 +1,104 @@ +/** + * 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 "OCOverlayFactory.h" +#include "OCOverlay.h" + +extern long dllReferenceCount; + +OCOverlayFactory::OCOverlayFactory(wchar_t* path) + : _referenceCount(1) +{ + InterlockedIncrement(&dllReferenceCount); +} + +OCOverlayFactory::~OCOverlayFactory() +{ + InterlockedDecrement(&dllReferenceCount); +} + +IFACEMETHODIMP OCOverlayFactory::QueryInterface(REFIID riid, void **ppv) +{ + HRESULT hResult = S_OK; + + if (IsEqualIID(IID_IUnknown, riid) || + IsEqualIID(IID_IClassFactory, riid)) + { + *ppv = static_cast(this); + AddRef(); + } + else + { + hResult = E_NOINTERFACE; + *ppv = NULL; + } + + return hResult; +} + +IFACEMETHODIMP_(ULONG) OCOverlayFactory::AddRef() +{ + return InterlockedIncrement(&_referenceCount); +} + +IFACEMETHODIMP_(ULONG) OCOverlayFactory::Release() +{ + ULONG cRef = InterlockedDecrement(&_referenceCount); + + if (0 == cRef) + { + delete this; + } + return cRef; +} + +IFACEMETHODIMP OCOverlayFactory::CreateInstance( + IUnknown *pUnkOuter, REFIID riid, void **ppv) +{ + HRESULT hResult = CLASS_E_NOAGGREGATION; + + if (pUnkOuter != NULL) + { + return hResult; + } + + hResult = E_OUTOFMEMORY; + + OCOverlay *lrOverlay = + new (std::nothrow) OCOverlay(); + + if (!lrOverlay) + { + return hResult; + } + + hResult = lrOverlay->QueryInterface(riid, ppv); + + lrOverlay->Release(); + + return hResult; +} + +IFACEMETHODIMP OCOverlayFactory::LockServer(BOOL fLock) +{ + if (fLock) + { + InterlockedIncrement(&dllReferenceCount); + } + else + { + InterlockedDecrement(&dllReferenceCount); + } + return S_OK; +} \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.h b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.h new file mode 100644 index 000000000..6751e5b57 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayFactory.h @@ -0,0 +1,41 @@ +/** + * 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. + */ + +#ifndef OCOVERLAYFACTORY_H +#define OCOVERLAYFACTORY_H + +#pragma once + +#include "stdafx.h" + +class OCOverlayFactory : public IClassFactory +{ +public: + OCOverlayFactory(wchar_t* path); + + IFACEMETHODIMP_(ULONG) AddRef(); + IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv); + IFACEMETHODIMP LockServer(BOOL fLock); + IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv); + IFACEMETHODIMP_(ULONG) Release(); + +protected: + ~OCOverlayFactory(); + +private: + long _referenceCount; + wchar_t* _path; +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.cpp b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.cpp new file mode 100644 index 000000000..3fc0729f1 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.cpp @@ -0,0 +1,149 @@ +/** + * 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 "OCOverlayRegistrationHandler.h" +#include "stdafx.h" + +#include +#include + +using namespace std; + +HRESULT OCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PWSTR friendlyName) +{ + HRESULT hResult; + HKEY shellOverlayKey = NULL; + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_OVERLAY_KEY, 0, KEY_WRITE, &shellOverlayKey)); + if (!SUCCEEDED(hResult)) { + hResult = RegCreateKey(HKEY_LOCAL_MACHINE, REGISTRY_OVERLAY_KEY, &shellOverlayKey); + if(!SUCCEEDED(hResult)) { + return hResult; + } + } + + HKEY syncExOverlayKey = NULL; + hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(shellOverlayKey, friendlyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &syncExOverlayKey, NULL)); + + if (!SUCCEEDED(hResult)) { + return hResult; + } + + wchar_t stringCLSID[MAX_PATH]; + StringFromGUID2(clsid, stringCLSID, ARRAYSIZE(stringCLSID)); + LPCTSTR value = stringCLSID; + hResult = RegSetValueEx(syncExOverlayKey, NULL, 0, REG_SZ, (LPBYTE)value, (DWORD)((wcslen(value)+1) * sizeof(TCHAR))); + if (!SUCCEEDED(hResult)) { + return hResult; + } + + return hResult; +} + +HRESULT OCOverlayRegistrationHandler::RemoveRegistryEntries(PWSTR friendlyName) +{ + HRESULT hResult; + HKEY shellOverlayKey = NULL; + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_OVERLAY_KEY, 0, KEY_WRITE, &shellOverlayKey)); + + if (!SUCCEEDED(hResult)) { + return hResult; + } + + HKEY syncExOverlayKey = NULL; + hResult = HRESULT_FROM_WIN32(RegDeleteKeyEx(shellOverlayKey, friendlyName, DELETE, 0)); + if (!SUCCEEDED(hResult)) { + return hResult; + } + + return hResult; +} + +HRESULT OCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, const CLSID& clsid) +{ + if (modulePath == NULL) { + return E_FAIL; + } + + wchar_t stringCLSID[MAX_PATH]; + StringFromGUID2(clsid, stringCLSID, ARRAYSIZE(stringCLSID)); + HRESULT hResult; + HKEY hKey = NULL; + + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CLASSES_ROOT, REGISTRY_CLSID, 0, KEY_WRITE, &hKey)); + if (!SUCCEEDED(hResult)) { + return hResult; + } + + HKEY clsidKey = NULL; + hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(hKey, stringCLSID, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &clsidKey, NULL)); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + HKEY inprocessKey = NULL; + hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(clsidKey, REGISTRY_IN_PROCESS, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &inprocessKey, NULL)); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + DWORD cbData = lstrlen(modulePath) * sizeof(*modulePath); + hResult = HRESULT_FROM_WIN32(RegSetValue(inprocessKey, NULL, REG_SZ, modulePath, cbData)); + + if(!SUCCEEDED(hResult)) { + return hResult; + } + + hResult = HRESULT_FROM_WIN32(RegSetValueEx(inprocessKey, REGISTRY_THREADING, 0, REG_SZ, (LPBYTE)REGISTRY_APARTMENT, (DWORD)((wcslen(REGISTRY_APARTMENT)+1) * sizeof(TCHAR)))); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + hResult = HRESULT_FROM_WIN32(RegSetValueEx(inprocessKey, REGISTRY_VERSION, 0, REG_SZ, (LPBYTE)REGISTRY_VERSION_NUMBER, (DWORD)(wcslen(REGISTRY_VERSION_NUMBER)+1) * sizeof(TCHAR))); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + return S_OK; +} + +HRESULT OCOverlayRegistrationHandler::UnregisterCOMObject(const CLSID& clsid) +{ + wchar_t stringCLSID[MAX_PATH]; + + StringFromGUID2(clsid, stringCLSID, ARRAYSIZE(stringCLSID)); + HRESULT hResult; + HKEY hKey = NULL; + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CLASSES_ROOT, REGISTRY_CLSID, 0, DELETE, &hKey)); + if (!SUCCEEDED(hResult)) { + return hResult; + } + + HKEY clsidKey = NULL; + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(hKey, stringCLSID, 0, DELETE, &clsidKey)); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + hResult = HRESULT_FROM_WIN32(RegDeleteKeyEx(clsidKey, REGISTRY_IN_PROCESS, DELETE, 0)); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + hResult = HRESULT_FROM_WIN32(RegDeleteKeyEx(hKey, stringCLSID, DELETE, 0)); + if(!SUCCEEDED(hResult)) { + return hResult; + } + + return S_OK; +} \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.h b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.h new file mode 100644 index 000000000..1fdef93a7 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlayRegistrationHandler.h @@ -0,0 +1,31 @@ +/** + * 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. + */ + +#ifndef OCOVERLAYREGISTRATIONHANDLER_H +#define OCOVERLAYREGISTRATIONHANDLER_H + +#pragma once + +#include "stdafx.h" + +class __declspec(dllexport) OCOverlayRegistrationHandler +{ + public: + static HRESULT MakeRegistryEntries(const CLSID& clsid, PWSTR fileType); + static HRESULT RegisterCOMObject(PCWSTR modulePath, const CLSID& clsid); + static HRESULT RemoveRegistryEntries(PWSTR friendlyName); + static HRESULT UnregisterCOMObject(const CLSID& clsid); +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.def b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.def new file mode 100644 index 000000000..8cde2bd02 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.def @@ -0,0 +1,6 @@ +LIBRARY +EXPORTS + DllGetClassObject PRIVATE + DllCanUnloadNow PRIVATE + DllRegisterServer PRIVATE + DllUnregisterServer PRIVATE \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj new file mode 100644 index 000000000..b9f352b22 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OCOverlays.vcxproj @@ -0,0 +1,195 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC} + OCOverlays + + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + false + true + Unicode + + + DynamicLibrary + false + true + Unicode + Windows7.1SDK + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x86 + .dll + + + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x64 + .dll + + + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x86 + .dll + + + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x64 + .dll + + + + Level3 + Disabled + ..\OCUtil;%(AdditionalIncludeDirectories) + false + + + true + ..\$(Configuration)\$(Platform); + OCUtil_x86.lib;%(AdditionalDependencies) + OCOverlays.def + + + + + Level3 + Disabled + ..\OCUtil;%(AdditionalIncludeDirectories) + false + + + true + ..\$(Configuration)\$(Platform); + OCUtil_x64.lib;%(AdditionalDependencies) + OCOverlays.def + + + + + Level3 + MaxSpeed + true + true + ..\OCUtil;%(AdditionalIncludeDirectories) + + + true + true + true + ..\$(Configuration)\$(Platform); + OCUtil_x86.lib;%(AdditionalDependencies) + OCOverlays.def + + + + + Level3 + MaxSpeed + true + true + ..\OCUtil;%(AdditionalIncludeDirectories) + + + true + true + true + ..\$(Configuration)\$(Platform); + OCUtil_x64.lib;%(AdditionalDependencies) + OCOverlays.def + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h b/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h new file mode 100644 index 000000000..9df0bc5d0 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h @@ -0,0 +1,32 @@ +/** +* 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. +*/ + +#define OVERLAY_ID 1 +#define OVERLAY_GUID L"{0960F09E-F328-48A3-B746-276B1E3C3722}" +#define OVERLAY_NAME L"OwnCloudStatusOverlay" + +#define REGISTRY_OVERLAY_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers" +#define REGISTRY_CLSID L"CLSID" +#define REGISTRY_IN_PROCESS L"InprocServer32" +#define REGISTRY_THREADING L"ThreadingModel" +#define REGISTRY_APARTMENT L"Apartment" +#define REGISTRY_VERSION L"Version" +#define REGISTRY_VERSION_NUMBER L"1.0" + +//Registry values for running +#define REGISTRY_ENABLE_OVERLAY L"EnableOverlay" + +#define GET_FILE_OVERLAY_ID L"getFileIconId" + +#define PORT 33001 \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h.original b/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h.original new file mode 100644 index 000000000..e244e1515 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/OverlayConstants.h.original @@ -0,0 +1,32 @@ +/** + * 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. + */ + +#define OVERLAY_ID [$overlay.id$] +#define OVERLAY_GUID L"[$overlay.guid$]" +#define OVERLAY_NAME L"[$overlay.name$]" + +#define REGISTRY_OVERLAY_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers" +#define REGISTRY_CLSID L"CLSID" +#define REGISTRY_IN_PROCESS L"InprocServer32" +#define REGISTRY_THREADING L"ThreadingModel" +#define REGISTRY_APARTMENT L"Apartment" +#define REGISTRY_VERSION L"Version" +#define REGISTRY_VERSION_NUMBER L"1.0" + +//Registry values for running +#define REGISTRY_ENABLE_OVERLAY L"EnableOverlay" + +#define GET_FILE_OVERLAY_ID L"getFileIconId" + +#define PORT 33001 diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error.ico new file mode 100644 index 000000000..ebcaa7f98 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error_Shared.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error_Shared.ico new file mode 100644 index 000000000..02c963937 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Error_Shared.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK.ico new file mode 100644 index 000000000..f285d9c75 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK_Shared.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK_Shared.ico new file mode 100644 index 000000000..7c33983c1 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/OK_Shared.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync.ico new file mode 100644 index 000000000..ae1599569 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync_Shared.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync_Shared.ico new file mode 100644 index 000000000..63da185d8 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Sync_Shared.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning.ico new file mode 100644 index 000000000..b7fabc3bf Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning_Shared.ico b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning_Shared.ico new file mode 100644 index 000000000..fc85d46d0 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/ico/Warning_Shared.ico differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/resource.h b/shell_integration/windows/OCShellExtensions/OCOverlays/resource.h new file mode 100644 index 000000000..dbb1edc40 Binary files /dev/null and b/shell_integration/windows/OCShellExtensions/OCOverlays/resource.h differ diff --git a/shell_integration/windows/OCShellExtensions/OCOverlays/stdafx.h b/shell_integration/windows/OCShellExtensions/OCOverlays/stdafx.h new file mode 100644 index 000000000..81121202b --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCOverlays/stdafx.h @@ -0,0 +1,30 @@ +/** + * 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. + */ + +#define WIN32_LEAN_AND_MEAN + +#include "CommunicationSocket.h" +#include "RegistryUtil.h" +#include "OverlayConstants.h" +#include "FileUtil.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/shell_integration/windows/OCShellExtensions/OCShellExtensions.sln b/shell_integration/windows/OCShellExtensions/OCShellExtensions.sln new file mode 100644 index 000000000..979c155fa --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCShellExtensions.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30501.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCUtil", "OCUtil\OCUtil.vcxproj", "{E4F63E19-808D-4234-8DF0-69C5F47C9CD3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCOverlays", "OCOverlays\OCOverlays.vcxproj", "{42EFEC79-5ACA-4F76-955F-15CE4340F6BC}" + ProjectSection(ProjectDependencies) = postProject + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3} = {E4F63E19-808D-4234-8DF0-69C5F47C9CD3} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCUtilTest", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Debug|Win32.ActiveCfg = Debug|Win32 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Debug|Win32.Build.0 = Debug|Win32 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Debug|x64.ActiveCfg = Debug|x64 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Debug|x64.Build.0 = Debug|x64 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Release|Win32.ActiveCfg = Release|Win32 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Release|Win32.Build.0 = Release|Win32 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Release|x64.ActiveCfg = Release|x64 + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3}.Release|x64.Build.0 = Release|x64 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Debug|Win32.ActiveCfg = Debug|Win32 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Debug|Win32.Build.0 = Debug|Win32 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Debug|x64.ActiveCfg = Debug|x64 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Debug|x64.Build.0 = Debug|x64 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Release|Win32.ActiveCfg = Release|Win32 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Release|Win32.Build.0 = Release|Win32 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Release|x64.ActiveCfg = Release|x64 + {42EFEC79-5ACA-4F76-955F-15CE4340F6BC}.Release|x64.Build.0 = Release|x64 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Debug|Win32.ActiveCfg = Debug|Win32 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Debug|Win32.Build.0 = Debug|Win32 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Debug|x64.ActiveCfg = Debug|Win32 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Release|Win32.ActiveCfg = Release|Win32 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Release|Win32.Build.0 = Release|Win32 + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033}.Release|x64.ActiveCfg = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp new file mode 100644 index 000000000..92f404848 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp @@ -0,0 +1,127 @@ +/** + * 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 "CommunicationSocket.h" +#include "UtilConstants.h" +#include "StringUtil.h" + +#include +#include +#include +#include +#include + +#include + +#define BUFSIZE 1024 + +using namespace std; + +#define DEFAULT_BUFLEN 4096 + +CommunicationSocket::CommunicationSocket(int port) + : _port(port), _clientSocket(INVALID_SOCKET) +{ +} + +CommunicationSocket::~CommunicationSocket() +{ + Close(); +} + +bool CommunicationSocket::Close() +{ + WSACleanup(); + bool closed = (closesocket(_clientSocket) == 0); + shutdown(_clientSocket, SD_BOTH); + _clientSocket = INVALID_SOCKET; + return closed; +} + + +bool CommunicationSocket::Connect() +{ + WSADATA wsaData; + + HRESULT iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); + + if (iResult != NO_ERROR) { + int error = WSAGetLastError(); + } + + + _clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (_clientSocket == INVALID_SOCKET) { + //int error = WSAGetLastError(); + Close(); + return false; + } + + struct sockaddr_in clientService; + + clientService.sin_family = AF_INET; + clientService.sin_addr.s_addr = inet_addr(PLUG_IN_SOCKET_ADDRESS); + clientService.sin_port = htons(_port); + + iResult = connect(_clientSocket, (SOCKADDR*)&clientService, sizeof(clientService)); + + if (iResult == SOCKET_ERROR) { + //int error = WSAGetLastError(); + Close(); + return false; + } + return true; +} + +bool CommunicationSocket::SendMsg(const wchar_t* message) +{ + const char* utf8_msg = StringUtil::toUtf8(message); + size_t result = send(_clientSocket, utf8_msg, (int)strlen(utf8_msg), 0); + delete[] utf8_msg; + + if (result == SOCKET_ERROR) { + //int error = WSAGetLastError(); + closesocket(_clientSocket); + return false; + } + + return true; + +} + +bool CommunicationSocket::ReadLine(wstring* response) +{ + if (!response) { + return false; + } + + vector resp_utf8; + char buffer; + while (true) { + int bytesRead = recv(_clientSocket, &buffer, 1, 0); + if (bytesRead <= 0) { + response = 0; + return false; + } + + if (buffer == '\n') { + resp_utf8.push_back(0); + *response = StringUtil::toUtf16(&resp_utf8[0], resp_utf8.size()); + return true; + } else { + resp_utf8.push_back(buffer); + } + } +} diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h new file mode 100644 index 000000000..7bbf1bf63 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h @@ -0,0 +1,42 @@ +/** + * 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. + */ + +#ifndef COMMUNICATIONSOCKET_H +#define COMMUNICATIONSOCKET_H + +#pragma once + +#pragma warning (disable : 4251) + +#include +#include + +class __declspec(dllexport) CommunicationSocket +{ +public: + CommunicationSocket(int port); + ~CommunicationSocket(); + + bool Connect(); + bool Close(); + + bool SendMsg(const wchar_t*); + bool ReadLine(std::wstring*); + +private: + int _port; + SOCKET _clientSocket; +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.cpp new file mode 100644 index 000000000..e0861682b --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.cpp @@ -0,0 +1,84 @@ +/** + * 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 "FileUtil.h" +#include "RegistryUtil.h" +#include "UtilConstants.h" + +using namespace std; + +bool FileUtil::IsChildFile(const wchar_t* rootFolder, vector* files) +{ + for(vector::iterator it = files->begin(); it != files->end(); it++) + { + wstring file = *it; + + size_t found = file.find(rootFolder); + + if(found != string::npos) + { + return true; + } + } + + return false; +} + +bool FileUtil::IsChildFile(const wchar_t* rootFolder, const wchar_t* file) +{ + wstring* f = new wstring(file); + + size_t found = f->find(rootFolder); + + if(found != string::npos) + { + return true; + } + + return false; +} + +bool FileUtil::IsChildFileOfRoot(std::vector* files) +{ + wstring* rootFolder = new wstring(); + bool needed = false; + + if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_FILTER_FOLDER, rootFolder)) + { + if(IsChildFile(rootFolder->c_str(), files)) + { + needed = true; + } + } + + delete rootFolder; + return needed; +} + +bool FileUtil::IsChildFileOfRoot(const wchar_t* filePath) +{ + wstring* rootFolder = new wstring(); + bool needed = false; + + if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_FILTER_FOLDER, rootFolder)) + { + if(FileUtil::IsChildFile(rootFolder->c_str(), filePath)) + { + needed = true; + } + } + + delete rootFolder; + return needed; +} \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.h b/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.h new file mode 100644 index 000000000..650bc471f --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/FileUtil.h @@ -0,0 +1,40 @@ +/** + * 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. + */ + +#ifndef FILEUTIL_H +#define FILEUTIL_H + +#pragma once + +#pragma warning (disable : 4251) + +#include +#include + +class __declspec(dllexport) FileUtil +{ +public: + FileUtil(); + + ~FileUtil(); + + static bool IsChildFile(const wchar_t*, std::vector*); + static bool IsChildFile(const wchar_t*, const wchar_t*); + static bool IsChildFileOfRoot(std::vector*); + static bool IsChildFileOfRoot(const wchar_t*); + +private: +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.cpp new file mode 100644 index 000000000..b86005f71 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.cpp @@ -0,0 +1,74 @@ +/** + * 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 "OCMessage.h" +#include "ParserUtil.h" +#include "UtilConstants.h" + +#include + +#include +#include + +using namespace std; + +OCMessage::OCMessage(void) +{ + _command = new wstring(); + _value = new wstring(); +} + +OCMessage::~OCMessage(void) +{ +} + +bool OCMessage::InitFromMessage(const wstring* message) +{ + if(message->length() == 0) + { + return false; + } + + if(!ParserUtil::GetItem(COMMAND, message, _command)) + { + return false; + } + + if(!ParserUtil::GetItem(VALUE, message, _value)) + { + return false; + } + + return true; +} + +std::wstring* OCMessage::GetCommand() +{ + return _command; +} + +std::wstring* OCMessage::GetValue() +{ + return _value; +} + +void OCMessage::SetCommand(std::wstring* command) +{ + _command = command; +} + +void OCMessage::SetValue(std::wstring* value) +{ + _value = value; +} diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.h b/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.h new file mode 100644 index 000000000..131f3d714 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/OCMessage.h @@ -0,0 +1,42 @@ +/** + * 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. + */ + +#ifndef OCMESSAGE_H +#define OCMESSAGE_H + +#include + +#pragma once + +class __declspec(dllexport) OCMessage +{ +public: + OCMessage(void); + ~OCMessage(void); + + bool InitFromMessage(const std::wstring*); + + std::wstring* GetCommand(); + std::wstring* GetValue(); + + void SetCommand(std::wstring*); + void SetValue(std::wstring*); + +private: + + std::wstring* _command; + std::wstring* _value; +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj b/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj new file mode 100644 index 000000000..fc3b1a31f --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/OCUtil.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E4F63E19-808D-4234-8DF0-69C5F47C9CD3} + OCUtil + + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + false + true + Unicode + + + DynamicLibrary + false + true + Unicode + Windows7.1SDK + + + + + + + + + + + + + + + + + + + .dll + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x86 + + + .dll + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\ + $(ProjectName)_x64 + + + $(ProjectName)_x64 + $(Configuration)\$(Platform)\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + .dll + $(ProjectName)_x86 + $(Configuration)\$(Platform)\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + + Level3 + Disabled + false + + + true + 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) + + + + + Level3 + Disabled + + + true + 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) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + 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) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + 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) + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/ParserUtil.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/ParserUtil.cpp new file mode 100644 index 000000000..ba7d9f101 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/ParserUtil.cpp @@ -0,0 +1,389 @@ +/** + * 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 "ParserUtil.h" +#include "UtilConstants.h" + +#include + +using namespace std; + +bool ParserUtil::GetItem(const wchar_t* item, const wstring* message, wstring* result) +{ + size_t start = message->find(item, 0); + + if(start == string::npos) + { + return false; + } + + size_t end = message->find(COLON, start); + + if(end == string::npos) + { + return false; + } + + //Move to next character after : + end += 1; + + wchar_t c = message->at(end); + + //Move to the next character, which is the start of the value + end += 1; + + if(c == '[') + { + return GetList(end - 1, message, result); + } + else + { + return GetValue(end, message, result); + } +} + +bool ParserUtil::GetList(size_t start, const wstring* message, wstring* result) +{ + size_t end = start + 1; + + int openBraceCount = 1; + + while(openBraceCount > 0) + { + size_t closeBraceLocation = message->find(CLOSE_BRACE, end); + size_t openBraceLocation = message->find(OPEN_BRACE, end); + + if(closeBraceLocation < openBraceLocation) + { + openBraceCount--; + end = closeBraceLocation + 1; + } + else if(openBraceLocation < closeBraceLocation) + { + openBraceCount++; + end = openBraceLocation + 1; + } + + } + + size_t length = end - start; + + return GetString(start, end, message, result); +} + +size_t ParserUtil::GetNextStringItemInList(const wstring* message, size_t start, wstring* result) +{ + size_t end = string::npos; + size_t commaLocation = message->find(COMMA, start); + + if(commaLocation == string::npos) + { + end = message->find(CLOSE_BRACE, start); + if(end == string::npos) + { + end = message->length(); + } + else + { + end = end - 1; + } + } + else + { + end = commaLocation - 1; + } + + if(!GetString(start + 2, end, message, result)) + { + return string::npos; + } + + return end + 2; +} + +size_t ParserUtil::GetNextOCItemInList(const wstring* message, size_t start, wstring* result) +{ + size_t end = message->find(OPEN_CURLY_BRACE, start) + 1; + + int openBraceCount = 1; + + while(openBraceCount > 0) + { + size_t closeBraceLocation = message->find(CLOSE_CURLY_BRACE, end); + size_t openBraceLocation = message->find(OPEN_CURLY_BRACE, end); + + if(closeBraceLocation < openBraceLocation) + { + openBraceCount--; + end = closeBraceLocation + 1; + } + else if(openBraceLocation < closeBraceLocation) + { + openBraceCount++; + end = openBraceLocation + 1; + } + } + + size_t length = end - start; + + if(!GetString(start, end, message, result)) + { + return string::npos; + } + + return end; +} + +bool ParserUtil::GetValue(size_t start, const wstring* message, wstring* result) +{ + if(message->at(start - 1) == '\"') + { + size_t end = message->find(QUOTE, start); + return GetString(start, end, message, result); + } + else + { + start = start - 1; + + size_t end = message->find(COMMA, start); + + result->append(message->substr(start, end-start)); + } + + return true; +} + +bool ParserUtil::GetString(size_t start, size_t end, const wstring* message, wstring* result) +{ + if(end == string::npos) + { + return false; + } + + size_t length = end - start; + + if(length > 0) + { + result->append(message->substr(start, length)); + } + else + { + result->append(L""); + } + + + return true; +} + +bool ParserUtil::IsList(wstring* message) +{ + wchar_t c = message->at(0); + + if(c == '[') + { + return true; + } + + return false; +} + +bool ParserUtil::ParseJsonList(wstring* message, vector* items) +{ + + size_t currentLocation = message->find(OPEN_BRACE, 0); + + while(currentLocation < message->size()) + { + wstring* item = new wstring(); + + currentLocation = ParserUtil::GetNextStringItemInList(message, currentLocation, item); + + if(currentLocation == string::npos) + { + return false; + } + + items->push_back(item); + } + + return true; +} + +bool ParserUtil::ParseOCList(wstring* message, vector* items) +{ + + size_t currentLocation = message->find(OPEN_CURLY_BRACE, 0); + + while(currentLocation < message->size()) + { + wstring* item = new wstring(); + + currentLocation = ParserUtil::GetNextOCItemInList(message, currentLocation, item); + + if(currentLocation == string::npos) + { + return false; + } + + items->push_back(item); + } + + return true; +} + +bool ParserUtil::ParseOCMessageList(wstring* message, vector* messages) +{ + vector* items = new vector(); + + if(!ParseOCList(message, items)) + { + return false; + } + + for(vector::iterator it = items->begin(); it != items->end(); it++) + { + wstring* temp = *it; + + OCMessage* message = new OCMessage(); + message->InitFromMessage(temp); + + messages->push_back(message); + } + + return true; +} + +bool ParserUtil::SerializeList(std::vector* list, std::wstring* result, bool escapeQuotes) +{ + if(result == 0) + { + return false; + } + + result->append(OPEN_BRACE); + + for(vector::iterator it = list->begin(); it != list->end(); it++) + { + wstring value = *it; + + if(escapeQuotes) + { + result->append(BACK_SLASH); + } + + result->append(QUOTE); + result->append(value.c_str()); + + if(escapeQuotes) + { + result->append(BACK_SLASH); + } + + result->append(QUOTE); + result->append(COMMA); + } + + //Erase last comma + result->erase(result->size() - 1, 1); + + result->append(CLOSE_BRACE); + + return true; +} + +bool ParserUtil::SerializeMessage(std::map* arguments, std::wstring* result, bool escapeQuotes) +{ + if(result == 0) + { + return false; + } + + result->append(OPEN_CURLY_BRACE); + + for(map::iterator it = arguments->begin(); it != arguments->end(); it++) + { + wstring key = *it->first; + wstring value = *it->second; + + if(escapeQuotes) + { + result->append(BACK_SLASH); + } + + result->append(QUOTE); + result->append(key.c_str()); + + if(escapeQuotes) + { + result->append(BACK_SLASH); + } + + result->append(QUOTE); + result->append(COLON); + result->append(value.c_str()); + result->append(COMMA); + } + + //Erase last comma + result->erase(result->size() - 1, 1); + + result->append(CLOSE_CURLY_BRACE); + + return true; +} + +bool ParserUtil::SerializeMessage(OCMessage* OCMessage, std::wstring* result) +{ + if(result == 0) + { + return false; + } + + result->append(OPEN_CURLY_BRACE); + + result->append(QUOTE); + result->append(COMMAND); + result->append(QUOTE); + + result->append(COLON); + + result->append(QUOTE); + result->append(OCMessage->GetCommand()->c_str()); + result->append(QUOTE); + + result->append(COMMA); + + result->append(QUOTE); + result->append(VALUE); + result->append(QUOTE); + + result->append(COLON); + + if(!IsList(OCMessage->GetValue())) + { + result->append(QUOTE); + } + + result->append(OCMessage->GetValue()->c_str()); + + if(!IsList(OCMessage->GetValue())) + { + result->append(QUOTE); + } + + result->append(CLOSE_CURLY_BRACE); + + return true; +} + diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.cpp new file mode 100644 index 000000000..5c41bf861 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.cpp @@ -0,0 +1,70 @@ +/** + * 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 "RegistryUtil.h" + +#include + +using namespace std; + +#define SIZE 4096 + +bool RegistryUtil::ReadRegistry(const wchar_t* key, const wchar_t* name, int* result) +{ + wstring* strResult = new wstring(); + + if(!ReadRegistry(key, name, strResult)) + { + return false; + } + + *result = stoi( strResult->c_str() ); + + return true; +} + +bool RegistryUtil::ReadRegistry(const wchar_t* key, const wchar_t* name, wstring* result) +{ + HRESULT hResult; + + HKEY rootKey = NULL; + + hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CURRENT_USER, (LPCWSTR)key, NULL, KEY_READ, &rootKey)); + + if(!SUCCEEDED(hResult)) + { + return false; + } + + wchar_t value[SIZE]; + DWORD value_length = SIZE; + + hResult = RegQueryValueEx(rootKey, (LPCWSTR)name, NULL, NULL, (LPBYTE)value, &value_length ); + + if(!SUCCEEDED(hResult)) + { + return false; + } + + result->append(value); + + HRESULT hResult2 = RegCloseKey(rootKey); + + if (!SUCCEEDED(hResult2)) + { + return false; + } + + return true; +} diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.h b/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.h new file mode 100644 index 000000000..1928d64ce --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/RegistryUtil.h @@ -0,0 +1,35 @@ +/** + * 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. + */ + +#ifndef REGISTRYUTIL_H +#define REGISTRYUTIL_H + +#pragma once + +#pragma warning (disable : 4251) + +#include + +class __declspec(dllexport) RegistryUtil +{ +public: + RegistryUtil(); + + ~RegistryUtil(); + + static bool ReadRegistry(const wchar_t*, const wchar_t*, int*); + static bool ReadRegistry(const wchar_t*, const wchar_t*, std::wstring*); +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp new file mode 100644 index 000000000..2eec3c2ea --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp @@ -0,0 +1,112 @@ +/** +* Copyright (c) 2014 ownCloud, 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; version 2.1 of the License +* +* 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 "CommunicationSocket.h" + +#include "RemotePathChecker.h" + +#include +#include +#include +#include +#include + +using namespace std; + +namespace { + template + 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) +{ +} + +bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, bool isDir) +{ + wstring request; + wstring response; + bool needed = false; + + CommunicationSocket socket(_port); + socket.Connect(); + if (isDir) { + request = L"RETRIEVE_FOLDER_STATUS:"; + } else { + request = L"RETRIEVE_FILE_STATUS:"; + } + request += filePath; + request += L'\n'; + + if (!socket.SendMsg(request.c_str())) { + return false; + } + + while ((socket.ReadLine(&response))) { + // discard broadcast messages + if (begins_with(response, wstring(L"STATUS:"))) { + break; + } + } + + size_t statusBegin = response.find(L':', 0); + if (statusBegin == -1) + return false; + + size_t statusEnd = response.find(L':', statusBegin + 1); + if (statusEnd == -1) + return false; + + + wstring responseStatus = response.substr(statusBegin+1, statusEnd - statusBegin-1); + wstring responsePath = response.substr(statusEnd+1); + if (responsePath == filePath) { + int status = _StrToFileState(responseStatus); + if (status == StateNone) { + return false; + } + needed = true; + } + + return needed; +} + +int RemotePathChecker::_StrToFileState(const std::wstring &str) +{ + if (str == L"NOP" || str == L"NONE") { + return StateNone; + } else if (str == L"SYNC" || str == L"NEW") { + return StateSync; + } else if (str == L"SYNC+SWM" || str == L"NEW+SWM") { + return StateSyncSWM; + } else if (str == L"OK") { + return StateOk; + } else if (str == L"OK+SWM") { + return StateOkSWM; + } else if (str == L"IGNORE") { + return StateWarning; + } else if (str == L"IGNORE+SWM") { + return StateWarningSWM; + } else if (str == L"ERROR") { + return StateError; + } else if (str == L"ERROR+SWM") { + return StateErrorSWM; + } + + return StateNone; +} \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h new file mode 100644 index 000000000..5e58c6d64 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h @@ -0,0 +1,41 @@ +/** +* Copyright (c) 2014 ownCloud, 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; version 2.1 of the License +* +* 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. +*/ + +#ifndef PATHCHECKER_H +#define PATHCHECKER_H + +#include + +#pragma once + +class __declspec(dllexport) RemotePathChecker { +public: + enum FileState { + // Order synced with OCOverlay + StateError = 0, StateErrorSWM, + StateOk, StateOkSWM, + StateSync, StateSyncSWM, + StateWarning, StateWarningSWM, + StateNone + }; + RemotePathChecker(int port); + bool IsMonitoredPath(const wchar_t* filePath, bool isDir); + +private: + int _StrToFileState(const std::wstring &str); + + int _port; + +}; + +#endif \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.cpp new file mode 100644 index 000000000..0c7af0b82 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.cpp @@ -0,0 +1,32 @@ +/** +* Copyright (c) 2014 ownCloud, 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; version 2.1 of the License +* +* 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 + +#include "StringUtil.h" + +char* StringUtil::toUtf8(const wchar_t *utf16, int len) +{ + int newlen = WideCharToMultiByte(CP_UTF8, 0, utf16, len, NULL, 0, NULL, NULL); + char* str = new char[newlen]; + WideCharToMultiByte(CP_UTF8, 0, utf16, -1, str, newlen, NULL, NULL); + return str; +} + +wchar_t* StringUtil::toUtf16(const char *utf8, int len) +{ + int newlen = MultiByteToWideChar(CP_UTF8, 0, utf8, len, NULL, 0); + wchar_t* wstr = new wchar_t[newlen]; + MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, newlen); + return wstr; +} diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h new file mode 100644 index 000000000..d885a89f6 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/StringUtil.h @@ -0,0 +1,27 @@ +/** +* Copyright (c) 2014 ownCloud, 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; version 2.1 of the License +* +* 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. +*/ + +#ifndef STRINGUTIL_H +#define STRINGUTIL_H + +#pragma once + +#include + +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); +}; + +#endif // STRINGUTIL_H diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/UtilConstants.h b/shell_integration/windows/OCShellExtensions/OCUtil/UtilConstants.h new file mode 100644 index 000000000..04ca7d3ba --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtil/UtilConstants.h @@ -0,0 +1,30 @@ +/** + * 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. + */ + +#define PLUG_IN_SOCKET_ADDRESS "127.0.0.1" + +#define BACK_SLASH L"\\" +#define CLOSE_BRACE L"]" +#define CLOSE_CURLY_BRACE L"}" +#define COLON L":" +#define COMMAND L"command" +#define COMMA L"," +#define OPEN_BRACE L"[" +#define OPEN_CURLY_BRACE L"{" +#define QUOTE L"\"" +#define VALUE L"value" + +#define REGISTRY_ROOT_KEY L"SOFTWARE\\ownCloud Inc\\ownCloud" +#define REGISTRY_ENABLE_OVERLAY L"EnableOverlay" +#define REGISTRY_FILTER_FOLDER L"FilterFolder" diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.cpp b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.cpp new file mode 100644 index 000000000..179f8334a --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.cpp @@ -0,0 +1,37 @@ +// ConsoleApplication1.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" + +#include +#include +#include + +#include "RemotePathChecker.h" +#include "StringUtil.h" + +using namespace std; + +int _tmain(int argc, _TCHAR* argv[]) +{ + RemotePathChecker checker(33001); + + vector paths; + + wstring test1(L"C:\\Users\\owncloud\\ownCloud\\wizard2.png"); + wstring test2(L"C:\\Users\\owncloud\\ownCloud\\wizard3.png"); + wstring test3(L"C:\\Users\\owncloud\\ownCloud\\HAMMANET.png"); + paths.push_back(test1); + paths.push_back(test2); + paths.push_back(test3); + +// wstring test3 = StringUtil::toUtf16(StringUtil::toUtf8(test1.c_str())); + + vector::iterator it; + for (it = paths.begin(); it != paths.end(); ++it) { + bool monitored = checker.IsMonitoredPath(it->c_str(), false); + wcout << *it << " " << monitored << " with value " << checker.GetPathType() << endl; + } + return 0; +} + diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.filters b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.filters new file mode 100644 index 000000000..2507d8e20 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.vcxproj b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.vcxproj new file mode 100644 index 000000000..e4c35a3b2 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/OCUtilTest.vcxproj @@ -0,0 +1,97 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {A81E3DAE-8FE7-4BD0-82F9-939B2D59D033} + Win32Proj + OCUtilTest + OCUtilTest + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + $(SolutionDir)$(Configuration)\$(Platform)\ + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + ..\OCUtil + + + Console + true + ..\$(Configuration)\$(Platform); + OCUtil_x86.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) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + Create + Create + + + + + + \ No newline at end of file diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/ReadMe.txt b/shell_integration/windows/OCShellExtensions/OCUtilTest/ReadMe.txt new file mode 100644 index 000000000..4cb8a2f4b --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : ConsoleApplication1 Project Overview +======================================================================== + +AppWizard has created this ConsoleApplication1 application for you. + +This file contains a summary of what you will find in each of the files that +make up your ConsoleApplication1 application. + + +ConsoleApplication1.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +ConsoleApplication1.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +ConsoleApplication1.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named ConsoleApplication1.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.cpp b/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.cpp new file mode 100644 index 000000000..f1d63e0b4 --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// ConsoleApplication1.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.h b/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.h new file mode 100644 index 000000000..b005a839d --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/shell_integration/windows/OCShellExtensions/OCUtilTest/targetver.h b/shell_integration/windows/OCShellExtensions/OCUtilTest/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/shell_integration/windows/OCShellExtensions/OCUtilTest/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include