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

feat: win32 component to redirect file activation to Notepads to open any file types (including restricted file types like .bat .cmd etc.) #755

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2019675
ImplementedWin32 component to redirect activation to UWP app.
soumyamahunt Jan 15, 2021
30c1dc3
Fix github tasks.
soumyamahunt Jan 15, 2021
a53366d
Added assembly info.
soumyamahunt Jan 16, 2021
a09620f
Updated nuget package.
soumyamahunt Feb 8, 2021
5ea92d3
Updated branch.
soumyamahunt Feb 9, 2021
ae97ada
Code refactor.
soumyamahunt Feb 9, 2021
fa5f4a9
code refactor.
soumyamahunt Feb 12, 2021
7185b84
Fix build process.
soumyamahunt Feb 14, 2021
546d1ac
code refactor.
soumyamahunt Feb 15, 2021
ea3f336
Refactor GitHub task.
soumyamahunt Feb 26, 2021
18391c8
Removed trailing spaces.
soumyamahunt Feb 26, 2021
a2a1cc7
Implemented options to copy dektop component path/file.
soumyamahunt Mar 16, 2021
0a103da
Update dependencies.
soumyamahunt Mar 16, 2021
631fb7e
Resolved conflicts.
soumyamahunt Mar 22, 2021
d469859
Resolve conflicts.
soumyamahunt Mar 27, 2021
9a8ceac
Fix typo.
soumyamahunt Mar 27, 2021
526612c
Resolve conflicts.
soumyamahunt Mar 29, 2021
d096c27
Bump Microsoft.Windows.CppWinRT in /src/Notepad
dependabot[bot] Mar 30, 2021
52f090f
Merge pull request #15 from soumyamahunt/dependabot/nuget/src/Notepad…
soumyamahunt Mar 30, 2021
e4dcc50
Use custom target to update nuget imports.
soumyamahunt Apr 4, 2021
6523a05
Merge remote-tracking branch 'JasonStein/master' into advanced-activa…
soumyamahunt Apr 4, 2021
1afe63d
Update nuget imports.
soumyamahunt Apr 4, 2021
5e31882
Refactor code.
soumyamahunt Apr 5, 2021
94c4f5e
Refactor target.
soumyamahunt Apr 6, 2021
4624dc3
Code refactor.
soumyamahunt Apr 6, 2021
1e85677
code refactor
soumyamahunt Apr 24, 2021
f3bc1c9
move to cpp20
soumyamahunt Apr 24, 2021
80da54a
chore: code refactor
soumyamahunt Apr 28, 2021
283ab6f
fix: fix error in debug mode
soumyamahunt Apr 28, 2021
77e24dc
chore: refactor
soumyamahunt Jul 11, 2021
0661eb2
fix: only show activation component for desktop platform
soumyamahunt Jul 18, 2021
f3bdc8c
feat: generate AUMID at build time rather than relying on hardcoded s…
soumyamahunt Jul 19, 2021
d1e41da
chore: refactor project targets
soumyamahunt Jul 23, 2021
dcac9a5
ci: fix build failure
soumyamahunt Jul 23, 2021
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
Prev Previous commit
Next Next commit
Code refactor.
soumyamahunt committed Apr 6, 2021
commit 4624dc376e2c811b20c1910aaff3af48db2132d1
73 changes: 40 additions & 33 deletions src/Notepad/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#pragma comment(lib, "Shell32")
#pragma comment(lib, "shell32")
#define STRICT
#define STRICT_TYPED_ITEMIDS
#include "iostream"
@@ -9,73 +9,80 @@
#include "winrt/base.h"

#ifdef _PRODUCTION
#define AUMID L"19282JackieLiu.Notepads-Beta_echhpq9pdbte8!App"
#define AUMID L"19282JackieLiu.Notepads-Beta_echhpq9pdbte8!App"
#else
#define AUMID L"Notepads-Dev_echhpq9pdbte8!App"
#define AUMID L"Notepads-Dev_echhpq9pdbte8!App"
#endif

#define OPEN L"open"
#define PRINT L"print"
#define OPEN L"open"
#define PRINT L"print"

#define NOTEPADPRINTCOMMAND L"/p"
#define NOTEPADOPENWITHANSIENCODINGCOMMAND L"/a"
#define NOTEPADPRINTCOMMAND L"/p"
#define NOTEPADOPENWITHANSIENCODINGCOMMAND L"/a"
#define NOTEPADOPENWITHUTF16ENCODINGCOMMAND L"/w"

namespace winrt
{
template <typename T, typename F, typename...Args>
impl::com_ref<T> parse(F function, Args&& ...args)
{
T* result{};
check_hresult(function(args..., &result));
return { result, take_ownership_from_abi };
}
}

using namespace std;
using namespace winrt;

#ifndef _DEBUG
INT APIENTRY wWinMain(_In_ HINSTANCE /* hInstance */, _In_opt_ HINSTANCE /* hPrevInstance */, _In_ LPWSTR /* lpCmdLine */, _In_ INT /* nCmdShow */)
INT APIENTRY wWinMain(
_In_ HINSTANCE /* hInstance */,
_In_opt_ HINSTANCE /* hPrevInstance */,
_In_ LPWSTR /* lpCmdLine */,
_In_ INT /* nCmdShow */)
#else
INT main()
#endif
{
init_apartment();

LPWSTR* szArglist = NULL;
INT nArgs;
szArglist = CommandLineToArgvW(GetCommandLine(), &nArgs);
auto nArgs = 0;
auto szArglist = CommandLineToArgvW(GetCommandLine(), &nArgs);
if (szArglist && nArgs > 1)
{
LPCTSTR verb = OPEN;
auto verb = OPEN;
if (wcscmp(NOTEPADPRINTCOMMAND, szArglist[1]) == 0) verb = PRINT;
bool isOpenRequested = (wcscmp(OPEN, verb) == 0);
auto increment = wcscmp(OPEN, verb) == 0 ? 1 : 2;

INT ct = nArgs - isOpenRequested ? 1 : 2;
HRESULT hr = E_OUTOFMEMORY;
com_ptr<IShellItemArray> ppsia = NULL;
PIDLIST_ABSOLUTE* rgpidl = new(std::nothrow) PIDLIST_ABSOLUTE[ct];
auto ct = nArgs - increment;
auto rgpidl = new(std::nothrow) PIDLIST_ABSOLUTE[ct];
if (rgpidl)
{
hr = S_OK;
INT cpidl;
for (cpidl = 0; SUCCEEDED(hr) && cpidl < ct; cpidl++)
auto cpidl = 0;
for (auto hr = S_OK; SUCCEEDED(hr) && cpidl < ct; cpidl++)
{
hr = SHParseDisplayName(szArglist[cpidl + isOpenRequested ? 1 : 2], NULL, &rgpidl[cpidl], 0, NULL);
hr = SHParseDisplayName(szArglist[cpidl + increment], NULL, &rgpidl[cpidl], 0, NULL);
}

if (cpidl > 0 && SUCCEEDED(SHCreateShellItemArrayFromIDLists(cpidl, rgpidl, ppsia.put())))
if (cpidl > 0)
{
com_ptr<IApplicationActivationManager> appActivationMgr = NULL;
if (SUCCEEDED(CoCreateInstance(CLSID_ApplicationActivationManager, NULL, CLSCTX_LOCAL_SERVER, __uuidof(appActivationMgr), appActivationMgr.put_void())))
{
DWORD pid = 0;
appActivationMgr->ActivateForFile(AUMID, ppsia.get(), verb, &pid);
auto pid = DWORD(0);
auto ppsia = parse<IShellItemArray>(SHCreateShellItemArrayFromIDLists, cpidl, rgpidl);
auto appActivationMgr = create_instance<IApplicationActivationManager>(CLSID_ApplicationActivationManager);
appActivationMgr->ActivateForFile(AUMID, ppsia.get(), verb, &pid);
#ifdef _DEBUG
cout << "Launched files with process id: " << pid;
Sleep(2000);
cout << "Launched files with process id: " << pid;
Sleep(2000);
#endif
}
appActivationMgr.~com_ptr();
}

for (INT i = 0; i < cpidl; i++)
for (auto i = 0; i < cpidl; i++)
{
CoTaskMemFree(rgpidl[i]);
}
}

ppsia.~com_ptr();
delete[] rgpidl;
}