• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision29473 (tree)
Zeit2022-11-16 02:43:20
Autorstefankueng

Log Message

Add a button to register the sparse package for the current user

Ändern Zusammenfassung

Diff

--- trunk/src/TortoiseProc/Settings/SetWin11ContextMenu.cpp (revision 29472)
+++ trunk/src/TortoiseProc/Settings/SetWin11ContextMenu.cpp (revision 29473)
@@ -1,6 +1,6 @@
11 // TortoiseSVN - a Windows shell extension for easy version control
22
3-// Copyright (C) 2021 - TortoiseSVN
3+// Copyright (C) 2021-2022 - TortoiseSVN
44
55 // This program is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU General Public License
@@ -22,6 +22,17 @@
2222 #include "LoadIconEx.h"
2323 #include "SetWin11ContextMenu.h"
2424
25+#include <winrt/Windows.Management.Deployment.h>
26+#include <winrt/Windows.Foundation.Collections.h>
27+#include <winrt/Windows.ApplicationModel.h>
28+
29+#include "../../Utils/PathUtils.h"
30+#include "../../Utils/MiscUI/ProgressDlg.h"
31+using namespace winrt::Windows::Foundation;
32+using namespace winrt::Windows::Management::Deployment;
33+
34+#pragma comment(lib, "windowsapp.lib")
35+
2536 IMPLEMENT_DYNAMIC(CSetWin11ContextMenu, ISettingsPropPage)
2637 CSetWin11ContextMenu::CSetWin11ContextMenu()
2738 : ISettingsPropPage(CSetWin11ContextMenu::IDD)
@@ -44,6 +55,7 @@
4455
4556 BEGIN_MESSAGE_MAP(CSetWin11ContextMenu, ISettingsPropPage)
4657 ON_NOTIFY(LVN_ITEMCHANGED, IDC_MENULIST, OnLvnItemchangedMenulist)
58+ ON_BN_CLICKED(IDC_REGISTER, &CSetWin11ContextMenu::OnBnClickedRegister)
4759 END_MESSAGE_MAP()
4860
4961 BOOL CSetWin11ContextMenu::OnInitDialog()
@@ -126,3 +138,68 @@
126138 }
127139 *pResult = 0;
128140 }
141+
142+void CSetWin11ContextMenu::OnBnClickedRegister()
143+{
144+ CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
145+ OnOutOfScope(CoUninitialize());
146+ PackageManager manager;
147+
148+ // first unregister if already registered
149+ Collections::IIterable<winrt::Windows::ApplicationModel::Package> packages;
150+ try
151+ {
152+ packages = manager.FindPackagesForUser(L"");
153+ }
154+ catch (winrt::hresult_error const& ex)
155+ {
156+ std::wstring error = L"FindPackagesForUser failed (Errorcode: ";
157+ error += std::to_wstring(ex.code().value);
158+ error += L"):\n";
159+ error += ex.message();
160+ MessageBox(error.c_str(), nullptr, MB_ICONERROR);
161+ return;
162+ }
163+
164+ for (const auto& package : packages)
165+ {
166+ if (package.Id().Name() != L"3A48D7FC-AEE2-4CBC-91D1-0007951B8006")
167+ continue;
168+
169+ winrt::hstring fullName = package.Id().FullName();
170+ auto deploymentOperation = manager.RemovePackageAsync(fullName, RemovalOptions::None);
171+ auto deployResult = deploymentOperation.get();
172+ if (SUCCEEDED(deployResult.ExtendedErrorCode()))
173+ break;
174+
175+ // Undeployment failed
176+ std::wstring error = L"RemovePackageAsync failed (Errorcode: ";
177+ error += std::to_wstring(deployResult.ExtendedErrorCode());
178+ error += L"):\n";
179+ error += deployResult.ErrorText();
180+ MessageBox(error.c_str(), nullptr, MB_ICONERROR);
181+ return;
182+ }
183+
184+ // now register the package
185+ auto appDir = CPathUtils::GetAppParentDirectory();
186+ Uri externalUri(static_cast<LPCWSTR>(appDir));
187+ auto packagePath = appDir + L"bin\\package.msix";
188+ Uri packageUri(static_cast<LPCWSTR>(packagePath));
189+ AddPackageOptions options;
190+ options.ExternalLocationUri(externalUri);
191+ auto deploymentOperation = manager.AddPackageByUriAsync(packageUri, options);
192+
193+ auto deployResult = deploymentOperation.get();
194+
195+ if (!SUCCEEDED(deployResult.ExtendedErrorCode()))
196+ {
197+ std::wstring error = L"AddPackageByUriAsync failed (Errorcode: ";
198+ error += std::to_wstring(deployResult.ExtendedErrorCode());
199+ error += L"):\n";
200+ error += deployResult.ErrorText();
201+ MessageBox(error.c_str(), nullptr, MB_ICONERROR);
202+ return;
203+ }
204+ MessageBox(CString(MAKEINTRESOURCE(IDS_PACKAGE_REGISTERED)));
205+}
--- trunk/src/TortoiseProc/Settings/SetWin11ContextMenu.h (revision 29472)
+++ trunk/src/TortoiseProc/Settings/SetWin11ContextMenu.h (revision 29473)
@@ -1,6 +1,6 @@
11 // TortoiseSVN - a Windows shell extension for easy version control
22
3-// Copyright (C) 2021 - TortoiseSVN
3+// Copyright (C) 2021-2022 - TortoiseSVN
44
55 // This program is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU General Public License
@@ -61,4 +61,7 @@
6161 BOOL m_bModified;
6262 TSVNContextMenuEntries m_topMenu;
6363 bool m_bBlock;
64+
65+public:
66+ afx_msg void OnBnClickedRegister();
6467 };
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Show on old repository browser