Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Commander support #1398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions QuickLook.Native/QuickLook.Native32/DllExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Shell32.h"
#include "WoW64HookHelper.h"
#include "DOpus.h"
#include "MultiCommander.h"

#define EXPORT extern "C" __declspec(dllexport)

Expand All @@ -29,6 +30,7 @@ EXPORT void Init()
WoW64HookHelper::Launch();
#endif
DOpus::PrepareMessageWindow();
MultiCommander::PrepareMessageWindow();
}

EXPORT Shell32::FocusedWindowType GetFocusedWindowType()
Expand Down
98 changes: 98 additions & 0 deletions QuickLook.Native/QuickLook.Native32/MultiCommander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// This file is part of QuickLook program.
//
// 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 3 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "stdafx.h"
#include "MultiCommander.h"

HWND MultiCommander::hMsgWnd = nullptr;
HANDLE MultiCommander::hGetResultEvent = nullptr;
PCHAR MultiCommander::pCurrentItemPath = nullptr;

void MultiCommander::GetSelected(PWCHAR buffer)
{
if (false == PrepareMessageWindow()) {
return;
}

COPYDATASTRUCT cds;
cds.dwData = MULTICMD_CPF_GETCURITEMFULL | MULTICMD_CPF_SOURCE;
cds.cbData = 0;
cds.lpData = nullptr;

ResetEvent(hGetResultEvent);

auto ret = SendMessage(
FindWindow(MULTICMD_CLASS, nullptr),
WM_COPYDATA,
reinterpret_cast<WPARAM>(hMsgWnd),
reinterpret_cast<LPARAM>(&cds)
);

if (!ret || WAIT_OBJECT_0 != WaitForSingleObject(hGetResultEvent, 2000)) {
return;
}

auto path = reinterpret_cast<PWCHAR>(pCurrentItemPath);
wcscpy_s(buffer, wcslen(path) + 1, path);

delete[] pCurrentItemPath;
pCurrentItemPath = nullptr;
}

bool MultiCommander::PrepareMessageWindow()
{
if (nullptr == hMsgWnd) {
WNDCLASSEX wx = {};

wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = msgWindowProc;
wx.lpszClassName = MULTICMD_MSGWINDOW_CLASS;

if (RegisterClassEx(&wx))
hMsgWnd = CreateWindowEx(0, MULTICMD_MSGWINDOW_CLASS, L"", 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);

if (nullptr == hMsgWnd) {
return false;
}
}

if (nullptr == hGetResultEvent) {
hGetResultEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
}

return (nullptr != hGetResultEvent);
}

LRESULT CALLBACK MultiCommander::msgWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COPYDATA:
{
delete[] pCurrentItemPath;

auto cds = reinterpret_cast<PCOPYDATASTRUCT>(lParam);
auto buf = static_cast<PCHAR>(cds->lpData);

pCurrentItemPath = new CHAR[cds->cbData + 1]{ '\0' };
memcpy(pCurrentItemPath, buf, cds->cbData);

SetEvent(hGetResultEvent);
return 0;
}
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
37 changes: 37 additions & 0 deletions QuickLook.Native/QuickLook.Native32/MultiCommander.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of QuickLook program.
//
// 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 3 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#define MULTICMD_CPF_GETCURITEMFULL 0x00000010L // Get full path of current item (file or folder) in focus
#define MULTICMD_CPF_SOURCE 0x00000400L // Go to the new path in the source panel side

#define MULTICMD_CLASS L"MultiCommander MainWnd"
#define MULTICMD_MSGWINDOW_CLASS L"QuickLook.Native.MultiCmd.MsgWindow"

class MultiCommander
{
public:
static void GetSelected(PWCHAR buffer);
static bool PrepareMessageWindow();
MultiCommander() = delete;
private:
static HWND hMsgWnd;
static HANDLE hGetResultEvent;
static PCHAR pCurrentItemPath;

static LRESULT CALLBACK msgWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<ClInclude Include="DOpus.h" />
<ClInclude Include="Everything.h" />
<ClInclude Include="HelperMethods.h" />
<ClInclude Include="MultiCommander.h" />
<ClInclude Include="rapidxml.hpp" />
<ClInclude Include="WoW64HookHelper.h" />
<ClInclude Include="Shell32.h" />
Expand All @@ -106,6 +107,7 @@
<ClCompile Include="Everything.cpp" />
<ClCompile Include="HelperMethods.cpp" />
<ClCompile Include="DllExport.cpp" />
<ClCompile Include="MultiCommander.cpp" />
<ClCompile Include="Shell32.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand All @@ -116,4 +118,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ClInclude Include="rapidxml.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MultiCommander.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -71,5 +74,8 @@
<ClCompile Include="DOpus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MultiCommander.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>
8 changes: 8 additions & 0 deletions QuickLook.Native/QuickLook.Native32/Shell32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DialogHook.h"
#include "Everything.h"
#include "DOpus.h"
#include "MultiCommander.h"

using namespace std;

Expand All @@ -36,6 +37,10 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
if (FAILED(GetClassName(hwndfg, classBuffer, MAX_PATH)))
return INVALID;

if (wcscmp(classBuffer, MULTICMD_CLASS) == 0)
{
return MULTICOMMANDER;
}
if (wcscmp(classBuffer, L"dopus.lister") == 0)
{
return DOPUS;
Expand Down Expand Up @@ -91,6 +96,9 @@ void Shell32::GetCurrentSelection(PWCHAR buffer)
case DOPUS:
DOpus::GetSelected(buffer);
break;
case MULTICOMMANDER:
MultiCommander::GetSelected(buffer);
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions QuickLook.Native/QuickLook.Native32/Shell32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Shell32
DIALOG,
EVERYTHING,
DOPUS,
MULTICOMMANDER,
};

static FocusedWindowType GetFocusedWindowType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ClCompile Include="..\QuickLook.Native32\DOpus.cpp" />
<ClCompile Include="..\QuickLook.Native32\Everything.cpp" />
<ClCompile Include="..\QuickLook.Native32\HelperMethods.cpp" />
<ClCompile Include="..\QuickLook.Native32\MultiCommander.cpp" />
<ClCompile Include="..\QuickLook.Native32\Shell32.cpp" />
<ClCompile Include="..\QuickLook.Native32\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -98,4 +99,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<ClCompile Include="..\QuickLook.Native32\WoW64HookHelper.cpp" />
<ClCompile Include="..\QuickLook.Native32\Everything.cpp" />
<ClCompile Include="..\QuickLook.Native32\DOpus.cpp" />
<ClCompile Include="..\QuickLook.Native32\MultiCommander.cpp" />
</ItemGroup>
</Project>
</Project>
5 changes: 3 additions & 2 deletions QuickLook/NativeMethods/QuickLook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ internal enum FocusedWindowType
Explorer,
Dialog,
Everything,
DOpus
DOpus,
MultiCommander
}
}
}
}