From 2019675b7c897f110408883d2e2b854138d6e883 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Fri, 15 Jan 2021 17:18:02 +0530 Subject: [PATCH 01/28] ImplementedWin32 component to redirect activation to UWP app. --- src/Notepad/Notepad.vcxproj | 144 ++++++++++++++++++++++++++++ src/Notepad/Notepad.vcxproj.filters | 30 ++++++ src/Notepad/main.cpp | 77 +++++++++++++++ src/Notepad/packages.config | 4 + src/Notepad/pch.h | 8 ++ src/Notepads.sln | 30 ++++++ src/Notepads/Notepads.csproj | 36 +++++++ 7 files changed, 329 insertions(+) create mode 100644 src/Notepad/Notepad.vcxproj create mode 100644 src/Notepad/Notepad.vcxproj.filters create mode 100644 src/Notepad/main.cpp create mode 100644 src/Notepad/packages.config create mode 100644 src/Notepad/pch.h diff --git a/src/Notepad/Notepad.vcxproj b/src/Notepad/Notepad.vcxproj new file mode 100644 index 000000000..2d552528f --- /dev/null +++ b/src/Notepad/Notepad.vcxproj @@ -0,0 +1,144 @@ + + + + + true + true + true + true + 15.0 + {0f39c2eb-f8c6-473e-b26a-0714385798f5} + Win32Proj + Notepad + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + 10.0.19041.0 + 10.0.17134.0 + true + false + false + Windows Store + 10.0 + + + + + Debug + ARM + + + Release + ARM + + + Debug + ARM64 + + + Release + ARM64 + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + Application + v140 + v141 + v142 + Unicode + + + true + true + + + false + true + false + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + _CONSOLE;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions) + Level4 + %(AdditionalOptions) /permissive- /bigobj /FS + + + + + Disabled + _DEBUG;%(PreprocessorDefinitions) + + + Console + false + + + + + WIN32;%(PreprocessorDefinitions) + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + false + + + + + + + + Create + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/src/Notepad/Notepad.vcxproj.filters b/src/Notepad/Notepad.vcxproj.filters new file mode 100644 index 000000000..24ac1a84b --- /dev/null +++ b/src/Notepad/Notepad.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {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 + + + + + Source Files + + + + + + \ No newline at end of file diff --git a/src/Notepad/main.cpp b/src/Notepad/main.cpp new file mode 100644 index 000000000..b9c7aa78c --- /dev/null +++ b/src/Notepad/main.cpp @@ -0,0 +1,77 @@ +#include "pch.h" +#include "iostream" + +#ifndef _DEBUG +#define AUMID L"19282JackieLiu.Notepads-Beta_echhpq9pdbte8!App" +#else +#define AUMID L"Notepads_ezhh5fms182ha!App" +#endif + +#define OPEN L"open" +#define PRINT L"print" + +#define NOTEPADPRINTCOMMAND L"/p" +#define NOTEPADOPENWITHANSIENCODINGCOMMAND L"/a" +#define NOTEPADOPENWITHUTF16ENCODINGCOMMAND L"/w" + +using namespace std; +using namespace winrt; + +#ifndef _DEBUG +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(GetCommandLineW(), &nArgs); + if (szArglist && nArgs > 1) + { + LPCTSTR verb = OPEN; + if (wcscmp(NOTEPADPRINTCOMMAND, szArglist[1]) == 0) verb = PRINT; + bool isOpenRequested = (wcscmp(OPEN, verb) == 0); + + INT ct = nArgs - isOpenRequested ? 1 : 2; + HRESULT hr = E_OUTOFMEMORY; + com_ptr< IShellItemArray> ppsia = NULL; + PIDLIST_ABSOLUTE* rgpidl = new(std::nothrow) PIDLIST_ABSOLUTE[ct]; + if (rgpidl) + { + hr = S_OK; + INT cpidl; + for (cpidl = 0; SUCCEEDED(hr) && cpidl < ct; cpidl++) + { + hr = SHParseDisplayName(szArglist[cpidl + isOpenRequested ? 1 : 2], NULL, &rgpidl[cpidl], 0, NULL); + } + + if (cpidl > 0 && SUCCEEDED(SHCreateShellItemArrayFromIDLists(cpidl, rgpidl, ppsia.put()))) + { + com_ptr 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); +#ifdef _DEBUG + cout << "Launched files with process id: " << pid; + Sleep(2000); +#endif + } + appActivationMgr.~com_ptr(); + } + + for (INT i = 0; i < cpidl; i++) + { + CoTaskMemFree(rgpidl[i]); + } + } + + ppsia.~com_ptr(); + delete[] rgpidl; + } + + LocalFree(szArglist); + uninit_apartment(); +} \ No newline at end of file diff --git a/src/Notepad/packages.config b/src/Notepad/packages.config new file mode 100644 index 000000000..1c90c5bae --- /dev/null +++ b/src/Notepad/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Notepad/pch.h b/src/Notepad/pch.h new file mode 100644 index 000000000..1e77185c1 --- /dev/null +++ b/src/Notepad/pch.h @@ -0,0 +1,8 @@ +#pragma once +#pragma comment(lib, "Shell32") +#define STRICT +#define STRICT_TYPED_ITEMIDS +#include +#include +#include +#include \ No newline at end of file diff --git a/src/Notepads.sln b/src/Notepads.sln index ad5a84593..e61d17beb 100644 --- a/src/Notepads.sln +++ b/src/Notepads.sln @@ -15,16 +15,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Notepad", "Notepad\Notepad.vcxproj", "{0F39C2EB-F8C6-473E-B26A-0714385798F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|ARM = Release|ARM Release|ARM64 = Release|ARM64 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM.ActiveCfg = Debug|ARM + {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM.Build.0 = Debug|ARM + {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM.Deploy.0 = Debug|ARM {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM64.ActiveCfg = Debug|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM64.Build.0 = Debug|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM64.Deploy.0 = Debug|ARM64 @@ -34,6 +41,9 @@ Global {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.ActiveCfg = Debug|x86 {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.Build.0 = Debug|x86 {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.Deploy.0 = Debug|x86 + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM.ActiveCfg = Release|ARM + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM.Build.0 = Release|ARM + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM.Deploy.0 = Release|ARM {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.ActiveCfg = Release|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Build.0 = Release|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Deploy.0 = Release|ARM64 @@ -43,18 +53,38 @@ Global {99274932-9E86-480C-8142-38525F80007D}.Release|x86.ActiveCfg = Release|x86 {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Build.0 = Release|x86 {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Deploy.0 = Release|x86 + {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM.ActiveCfg = Debug|ARM + {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM.Build.0 = Debug|ARM {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM64.ActiveCfg = Debug|ARM64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM64.Build.0 = Debug|ARM64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x64.ActiveCfg = Debug|x64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x64.Build.0 = Debug|x64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x86.ActiveCfg = Debug|x86 {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x86.Build.0 = Debug|x86 + {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM.ActiveCfg = Release|ARM + {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM.Build.0 = Release|ARM {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM64.ActiveCfg = Release|ARM64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM64.Build.0 = Release|ARM64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x64.ActiveCfg = Release|x64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x64.Build.0 = Release|x64 {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x86.ActiveCfg = Release|x86 {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x86.Build.0 = Release|x86 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|ARM.ActiveCfg = Debug|ARM + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|ARM.Build.0 = Debug|ARM + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|ARM64.Build.0 = Debug|ARM64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|x64.ActiveCfg = Debug|x64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|x64.Build.0 = Debug|x64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|x86.ActiveCfg = Debug|Win32 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Debug|x86.Build.0 = Debug|Win32 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|ARM.ActiveCfg = Release|ARM + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|ARM.Build.0 = Release|ARM + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|ARM64.ActiveCfg = Release|ARM64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|ARM64.Build.0 = Release|ARM64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|x64.ActiveCfg = Release|x64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|x64.Build.0 = Release|x64 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|x86.ActiveCfg = Release|Win32 + {0F39C2EB-F8C6-473E-B26A-0714385798F5}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Notepads/Notepads.csproj b/src/Notepads/Notepads.csproj index c408c9458..d7189ed4c 100644 --- a/src/Notepads/Notepads.csproj +++ b/src/Notepads/Notepads.csproj @@ -73,6 +73,30 @@ true true + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP;DISABLE_XAML_GENERATED_MAIN + ;2008 + full + ARM + false + prompt + true + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP;DISABLE_XAML_GENERATED_MAIN + true + ;2008 + pdbonly + ARM + false + prompt + true + true + true bin\x64\Debug\ @@ -860,6 +884,18 @@ 14.0 + + + $(Platform) + Win32 + + + + + + + + Scale|DXFeatureLevel - + @@ -32,7 +32,7 @@ - + From d1e41da2cbb4a3a7f9867be1ac52d62098cea2f2 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Fri, 23 Jul 2021 20:51:39 +0530 Subject: [PATCH 27/28] chore: refactor project targets --- src/Notepad/Notepad.vcxproj | 161 ++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/src/Notepad/Notepad.vcxproj b/src/Notepad/Notepad.vcxproj index a4c22bdb3..b9fa6dd83 100644 --- a/src/Notepad/Notepad.vcxproj +++ b/src/Notepad/Notepad.vcxproj @@ -185,98 +185,98 @@ public class GenerateApplicationUserModeId : Task { - [Required] - public string ManifestPath { get; set; } + [Required] + public string ManifestPath { get; set; } - [Output] - public string ApplicationUserModeId { get; set; } + [Output] + public string ApplicationUserModeId { get; set; } - public override bool Execute() - { - var manifest = new XmlDocument(); - manifest.Load(ManifestPath); - - var packageName = manifest["Package"]["Identity"].GetAttribute("Name"); - var publisher = manifest["Package"]["Identity"].GetAttribute("Publisher"); - var packageId = new PACKAGE_ID - { - name = packageName, - publisher = publisher - }; + public override bool Execute() + { + var manifest = new XmlDocument(); + manifest.Load(ManifestPath); - uint packageFamilyNameLength = 0; - if (PackageFamilyNameFromId(packageId, ref packageFamilyNameLength, null) != 122) - { - throw new Exception("Failed to retrieve Package Family Name length"); - } - - var packageFamilyNameBuilder = new StringBuilder((int)packageFamilyNameLength); - if (PackageFamilyNameFromId(packageId, ref packageFamilyNameLength, packageFamilyNameBuilder) != 0) - { - throw new Exception("Failed to retrieve Package Family Name"); - } + var packageName = manifest["Package"]["Identity"].GetAttribute("Name"); + var publisher = manifest["Package"]["Identity"].GetAttribute("Publisher"); + var packageId = new PACKAGE_ID + { + name = packageName, + publisher = publisher + }; - string packageFamilyName = packageFamilyNameBuilder.ToString(); - string applicationUserModelId = null; - foreach (XmlElement application in manifest["Package"]["Applications"].ChildNodes) - { - if (application.Name != "Application" || application.GetAttribute("EntryPoint") != "Notepads.App") continue; + uint packageFamilyNameLength = 0; + if (PackageFamilyNameFromId(packageId, ref packageFamilyNameLength, null) != 122) + { + throw new Exception("Failed to retrieve Package Family Name length"); + } - var appId = application.GetAttribute("Id"); - uint applicationUserModelIdLength = 0; - if (FormatApplicationUserModelId(packageFamilyName, appId, ref applicationUserModelIdLength, null) != 122) - { - throw new Exception("Failed to retrieve Application User Mode Id length"); - } + var packageFamilyNameBuilder = new StringBuilder((int)packageFamilyNameLength); + if (PackageFamilyNameFromId(packageId, ref packageFamilyNameLength, packageFamilyNameBuilder) != 0) + { + throw new Exception("Failed to retrieve Package Family Name"); + } - var applicationUserModelIdBuilder = new StringBuilder((int)applicationUserModelIdLength); - if (FormatApplicationUserModelId(packageFamilyName, appId, ref applicationUserModelIdLength, applicationUserModelIdBuilder) != 0) - { - throw new Exception("Failed to retrieve Application User Mode Id"); - } + string packageFamilyName = packageFamilyNameBuilder.ToString(); + string applicationUserModelId = null; + foreach (XmlElement application in manifest["Package"]["Applications"].ChildNodes) + { + if (application.Name != "Application" || application.GetAttribute("EntryPoint") != "Notepads.App") continue; - applicationUserModelId = applicationUserModelIdBuilder.ToString(); - break; - } + var appId = application.GetAttribute("Id"); + uint applicationUserModelIdLength = 0; + if (FormatApplicationUserModelId(packageFamilyName, appId, ref applicationUserModelIdLength, null) != 122) + { + throw new Exception("Failed to retrieve Application User Mode Id length"); + } - if (!string.IsNullOrEmpty(applicationUserModelId)) - { - ApplicationUserModeId = applicationUserModelId; - } - else - { - throw new Exception("Couldn't find required Application User Mode Id"); - } + var applicationUserModelIdBuilder = new StringBuilder((int)applicationUserModelIdLength); + if (FormatApplicationUserModelId(packageFamilyName, appId, ref applicationUserModelIdLength, applicationUserModelIdBuilder) != 0) + { + throw new Exception("Failed to retrieve Application User Mode Id"); + } - return true; + applicationUserModelId = applicationUserModelIdBuilder.ToString(); + break; } - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)] - private class PACKAGE_ID + if (!string.IsNullOrEmpty(applicationUserModelId)) + { + ApplicationUserModeId = applicationUserModelId; + } + else { - public uint reserved; - public uint processorArchitecture; - public ulong version; - public string name; - public string publisher; - public string resourceId; - public string publisherId; + throw new Exception("Couldn't find required Application User Mode Id"); } - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] - private static extern uint PackageFamilyNameFromId( - PACKAGE_ID packageId, - ref uint packageFamilyNameLength, - StringBuilder packageFamilyName - ); + return true; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)] + private class PACKAGE_ID + { + public uint reserved; + public uint processorArchitecture; + public ulong version; + public string name; + public string publisher; + public string resourceId; + public string publisherId; + } + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] + private static extern uint PackageFamilyNameFromId( + PACKAGE_ID packageId, + ref uint packageFamilyNameLength, + StringBuilder packageFamilyName + ); - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] - private static extern uint FormatApplicationUserModelId( - string packageFamilyName, - string packageRelativeApplicationId, - ref uint applicationUserModelIdLength, - StringBuilder applicationUserModelId - ); + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] + private static extern uint FormatApplicationUserModelId( + string packageFamilyName, + string packageRelativeApplicationId, + ref uint applicationUserModelIdLength, + StringBuilder applicationUserModelId + ); } ]]> @@ -290,8 +290,11 @@ 19282JackieLiu.Notepads-Beta_echhpq9pdbte8!App Notepads-Dev_echhpq9pdbte8!App + +#pragma once +#define AUMID L"$(ApplicationUserModeId)" + - - + \ No newline at end of file From dcac9a58587851de59ff05b8c4e054950c6b99c2 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Fri, 23 Jul 2021 21:06:11 +0530 Subject: [PATCH 28/28] ci: fix build failure --- src/Notepads/Notepads.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notepads/Notepads.csproj b/src/Notepads/Notepads.csproj index ab5c6d952..d93370095 100644 --- a/src/Notepads/Notepads.csproj +++ b/src/Notepads/Notepads.csproj @@ -503,7 +503,7 @@ $(Platform) Win32 - +