Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jul 12, 2022
1 parent 629ee8b commit 1213a51
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 40 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,3 @@ convert.exe
theme.qrc

src/libsync/vfs/cfapi/shellext/Generated
src/libsync/vfs/cfapi/shellext/*.winmd
11 changes: 3 additions & 8 deletions src/common/cfapishellextensionsipcconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
#include "config.h"

#include <QString>
#include <QByteArray>

namespace CfApiShellExtensions {
static constexpr auto IpcServerNamespace = "cfApiShellExtensionsServer";
static const QString IpcMainServerName = APPLICATION_NAME + QStringLiteral(":") + CfApiShellExtensions::IpcServerNamespace;
static constexpr auto ThumbnailProviderServerNamespace = "cfApiShellExtensionsServer";
static const QString ThumbnailProviderMainServerName = APPLICATION_NAME + QStringLiteral(":") + CfApiShellExtensions::ThumbnailProviderServerNamespace;

namespace Protocol {
static constexpr auto ThumbnailProviderRequestKey = "thumbnailProviderRequest";
static constexpr auto ThumbnailProviderRequestAcceptReadyKey = "thumbnailAccepReady";
static constexpr auto ThumbnailProviderRequestFilePathKey = "filePath";
static constexpr auto ThumbnailProviderRequestFileSizeKey = "size";
static constexpr auto ThumbnailFormatKey = "format";
static constexpr auto ThumbnailFormatTagEmptyValue = "empty";
static const QByteArray ThumbnailFormatEmptyMessage = QString("{\"%1\":\"%2\"}").arg(ThumbnailFormatKey).arg(ThumbnailFormatTagEmptyValue).toUtf8();
static constexpr auto ServerNameKey = "serverName";
static constexpr auto ThumbnailProviderServerNameKey = "serverName";
};
}
6 changes: 3 additions & 3 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ FolderMan::FolderMan(QObject *parent)

_socketApi.reset(new SocketApi);

_shellExtensionsServer.listen(CfApiShellExtensions::IpcMainServerName);
_shellExtensionsServer.listen(CfApiShellExtensions::ThumbnailProviderMainServerName);
connect(&_shellExtensionsServer, &QLocalServer::newConnection, this, &FolderMan::slotNewShellExtensionConnection);

ConfigFile cfg;
Expand Down Expand Up @@ -1800,12 +1800,12 @@ void FolderMan::slotNewShellExtensionConnection()
}

if (folderFound) {
const QString serverName = CfApiShellExtensions::IpcMainServerName + QStringLiteral(":")
const QString serverName = CfApiShellExtensions::ThumbnailProviderMainServerName + QStringLiteral(":")
+ folderFound->navigationPaneClsid().toString();
folderFound->startShellExtensionServer(serverName);

const auto sentMessage = QJsonDocument::fromVariant(QVariantMap{
{CfApiShellExtensions::Protocol::ServerNameKey, serverName}}).toJson(QJsonDocument::Compact);
{CfApiShellExtensions::Protocol::ThumbnailProviderServerNameKey, serverName}}).toJson(QJsonDocument::Compact);

newConnection->write(sentMessage);
newConnection->waitForBytesWritten();
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/vfs/cfapi/shellext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ add_library(${CFAPI_SHELL_EXTENSIONS_LIB_NAME} MODULE
dllmain.cpp
cfapishellintegrationclassfactory.cpp
thumbnailprovider.cpp
contextmenus.cpp
vfsexplorercommandhanler.cpp
customstateprovider.cpp
CfApiShellIntegration.def
)
Expand Down
6 changes: 3 additions & 3 deletions src/libsync/vfs/cfapi/shellext/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

#include "cfapishellintegrationclassfactory.h"
#include "contextmenus.h"
#include "vfsexplorercommandhanler.h"
#include "customstateprovider.h"
#include "thumbnailprovider.h"

Expand All @@ -28,7 +28,7 @@ HRESULT TestExplorerCommandHandler_CreateInstance(REFIID riid, void **ppv);
const ClassObjectInit listClassesSupported[] = {
{&__uuidof(ThumbnailProvider), ThumbnailProvider_CreateInstance},
{&__uuidof(winrt::CfApiShellExtensions::implementation::CustomStateProvider), CustomStateProvider_CreateInstance},
{&__uuidof(TestExplorerCommandHandler), TestExplorerCommandHandler_CreateInstance}
{&__uuidof(VfsExplorerCommandHandler), TestExplorerCommandHandler_CreateInstance}
};

STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void *)
Expand Down Expand Up @@ -65,7 +65,7 @@ HRESULT CustomStateProvider_CreateInstance(REFIID riid, void **ppv)

HRESULT TestExplorerCommandHandler_CreateInstance(REFIID riid, void **ppv)
{
auto *testExplorerCommandHandler = new (std::nothrow) TestExplorerCommandHandler();
auto *testExplorerCommandHandler = new (std::nothrow) VfsExplorerCommandHandler();
if (!testExplorerCommandHandler) {
return E_OUTOFMEMORY;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/vfs/cfapi/shellext/thumbnailprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ IFACEMETHODIMP ThumbnailProvider::GetThumbnail(_In_ UINT cx, _Out_ HBITMAP *bitm
};

// #1 Connect to the main server and send a request for a thumbnail
if (!connectSocketToServer(CfApiShellExtensions::IpcMainServerName)) {
if (!connectSocketToServer(CfApiShellExtensions::ThumbnailProviderMainServerName)) {
return E_FAIL;
}

Expand All @@ -160,7 +160,7 @@ IFACEMETHODIMP ThumbnailProvider::GetThumbnail(_In_ UINT cx, _Out_ HBITMAP *bitm

// #2 Get the name of a server for the current syncroot
const auto receivedSyncrootServerNameMessage = QJsonDocument::fromJson(_localSocket.readAll()).toVariant().toMap();
const auto serverNameReceived = receivedSyncrootServerNameMessage.value(CfApiShellExtensions::Protocol::ServerNameKey).toString();
const auto serverNameReceived = receivedSyncrootServerNameMessage.value(CfApiShellExtensions::Protocol::ThumbnailProviderServerNameKey).toString();

if (serverNameReceived.isEmpty()) {
disconnectSocketFromServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,63 @@
* for more details.
*/

#include "contextmenus.h"
#include "vfsexplorercommandhanler.h"
#include <shlwapi.h>

TestExplorerCommandHandler::TestExplorerCommandHandler()
VfsExplorerCommandHandler::VfsExplorerCommandHandler()
: _referenceCount(1)
{
}

IFACEMETHODIMP TestExplorerCommandHandler::GetTitle(_In_opt_ IShellItemArray *items, _Outptr_result_nullonfailure_ PWSTR *name)
IFACEMETHODIMP VfsExplorerCommandHandler::GetTitle(_In_opt_ IShellItemArray *items, _Outptr_result_nullonfailure_ PWSTR *name)
{
*name = nullptr;
return SHStrDup(L"NcTestCommand", name);
}

IFACEMETHODIMP TestExplorerCommandHandler::GetState(_In_opt_ IShellItemArray *, _In_ BOOL, _Out_ EXPCMDSTATE *cmdState)
IFACEMETHODIMP VfsExplorerCommandHandler::GetState(_In_opt_ IShellItemArray *, _In_ BOOL, _Out_ EXPCMDSTATE *cmdState)
{
*cmdState = ECS_ENABLED;
return S_OK;
}

IFACEMETHODIMP TestExplorerCommandHandler::GetFlags(_Out_ EXPCMDFLAGS *flags)
IFACEMETHODIMP VfsExplorerCommandHandler::GetFlags(_Out_ EXPCMDFLAGS *flags)
{
*flags = ECF_DEFAULT;
return S_OK;
}

IFACEMETHODIMP TestExplorerCommandHandler::Invoke(_In_opt_ IShellItemArray *selection, _In_opt_ IBindCtx *)
IFACEMETHODIMP VfsExplorerCommandHandler::Invoke(_In_opt_ IShellItemArray *selection, _In_opt_ IBindCtx *)
{
return S_OK;
}

IFACEMETHODIMP TestExplorerCommandHandler::SetSite(_In_opt_ IUnknown *site)
IFACEMETHODIMP VfsExplorerCommandHandler::SetSite(_In_opt_ IUnknown *site)
{
_site.copy_from(site);
return S_OK;
}
IFACEMETHODIMP TestExplorerCommandHandler::GetSite(_In_ REFIID riid, _COM_Outptr_ void **site)
IFACEMETHODIMP VfsExplorerCommandHandler::GetSite(_In_ REFIID riid, _COM_Outptr_ void **site)
{
return _site->QueryInterface(riid, site);
}

IFACEMETHODIMP TestExplorerCommandHandler::QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP VfsExplorerCommandHandler::QueryInterface(REFIID riid, void **ppv)
{
static const QITAB qit[] = {
QITABENT(TestExplorerCommandHandler, IExplorerCommand),
QITABENT(TestExplorerCommandHandler, IObjectWithSite),
QITABENT(VfsExplorerCommandHandler, IExplorerCommand),
QITABENT(VfsExplorerCommandHandler, IObjectWithSite),
{0},
};
return QISearch(this, qit, riid, ppv);
}

IFACEMETHODIMP_(ULONG) TestExplorerCommandHandler::AddRef()
IFACEMETHODIMP_(ULONG) VfsExplorerCommandHandler::AddRef()
{
return InterlockedIncrement(&_referenceCount);
}

IFACEMETHODIMP_(ULONG) TestExplorerCommandHandler::Release()
IFACEMETHODIMP_(ULONG) VfsExplorerCommandHandler::Release()
{
const auto refCount = InterlockedDecrement(&_referenceCount);
if (refCount == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
/*
* Copyright (C) by Oleksandr Zolotov <alex@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* for more details.
*/

#pragma once
#include "config.h"
#include <winrt/Windows.Foundation.h>
#include <ShlObj_core.h>

class __declspec(uuid(CFAPI_SHELLEXT_COMMAND_HANDLER_CLASS_ID)) TestExplorerCommandHandler
class __declspec(uuid(CFAPI_SHELLEXT_COMMAND_HANDLER_CLASS_ID)) VfsExplorerCommandHandler
: public IExplorerCommand, IObjectWithSite
{
public:
TestExplorerCommandHandler();
virtual ~TestExplorerCommandHandler() = default;
VfsExplorerCommandHandler();
virtual ~VfsExplorerCommandHandler() = default;
// IExplorerCommand
IFACEMETHODIMP GetTitle(_In_opt_ IShellItemArray *items, _Outptr_result_nullonfailure_ PWSTR *name);
IFACEMETHODIMP GetState(_In_opt_ IShellItemArray *, _In_ BOOL, _Out_ EXPCMDSTATE *cmdState);
Expand Down

0 comments on commit 1213a51

Please sign in to comment.