mirror of
https://github.com/modernw/App-Installer-For-Windows-8.x-Reset.git
synced 2026-04-11 17:57:19 +10:00
Update Shell
This commit is contained in:
@@ -10,13 +10,13 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
CoInitializeEx (NULL, COINIT_MULTITHREADED | COINIT_APARTMENTTHREADED);
|
||||
RoInitialize (RO_INIT_MULTITHREADED);
|
||||
// CoInitializeEx (NULL, COINIT_MULTITHREADED | COINIT_APARTMENTTHREADED);
|
||||
// RoInitialize (RO_INIT_MULTITHREADED);
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
CoUninitialize ();
|
||||
RoUninitialize ();
|
||||
// CoUninitialize ();
|
||||
// RoUninitialize ();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -20,7 +20,33 @@ std::wstring GetFullPathName (const std::wstring &lpFileName)
|
||||
|
||||
std::wstring g_swExceptionCode = L"";
|
||||
std::wstring g_swExceptionDetail = L"";
|
||||
bool g_enableIterDeps = false;
|
||||
|
||||
LPWSTR AllocWideString (const std::wstring &str)
|
||||
{
|
||||
size_t size = (str.length () + 1) * sizeof (WCHAR);
|
||||
LPWSTR buf = (LPWSTR)CoTaskMemAlloc (size);
|
||||
if (!buf) return nullptr;
|
||||
ZeroMemory (buf, size);
|
||||
wcscpy (buf, str.c_str ());
|
||||
return buf;
|
||||
}
|
||||
// 测试用
|
||||
LPWSTR AllocWideString (LPCWSTR str)
|
||||
{
|
||||
if (!str) return nullptr;
|
||||
size_t size = (wcslen (str) + 1) * sizeof (WCHAR);
|
||||
LPWSTR buf = (LPWSTR)CoTaskMemAlloc (size);
|
||||
if (!buf) return nullptr;
|
||||
ZeroMemory (buf, size);
|
||||
wcscpy (buf, str);
|
||||
return buf;
|
||||
}
|
||||
#define _wcsdup AllocWideString
|
||||
#define free CoTaskMemFree
|
||||
#define malloc CoTaskMemAlloc
|
||||
#define realloc CoTaskMemRealloc
|
||||
#define calloc(_cnt_, _size_) CoTaskMemAlloc (_cnt_ * _size_)
|
||||
struct destruct
|
||||
{
|
||||
std::function <void ()> endtask = nullptr;
|
||||
@@ -57,15 +83,15 @@ template <typename TAsyncOpCreator> HRESULT RunPackageManagerOperation (TAsyncOp
|
||||
depopt->Progress = ref new onprogress ([pfCallback, pCustom] (progressopt operation, DeploymentProgress progress) {
|
||||
if (pfCallback) pfCallback ((DWORD)progress.percentage, pCustom);
|
||||
});
|
||||
depopt->Completed = ref new onprogresscomp ([&hCompEvt] (progressopt, AsyncStatus) {
|
||||
depopt->Completed = ref new onprogresscomp ([&hCompEvt] (progressopt, Windows::Foundation::AsyncStatus) {
|
||||
SetEvent (hCompEvt);
|
||||
});
|
||||
WaitForSingleObject (hCompEvt, INFINITE);
|
||||
switch (depopt->Status)
|
||||
{
|
||||
case AsyncStatus::Completed:
|
||||
case Windows::Foundation::AsyncStatus::Completed:
|
||||
return S_OK;
|
||||
case AsyncStatus::Error:
|
||||
case Windows::Foundation::AsyncStatus::Error:
|
||||
{
|
||||
auto depresult = depopt->GetResults ();
|
||||
auto errorcode = depopt->ErrorCode;
|
||||
@@ -77,11 +103,11 @@ template <typename TAsyncOpCreator> HRESULT RunPackageManagerOperation (TAsyncOp
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (HRESULT)errorcode.Value;
|
||||
}
|
||||
case AsyncStatus::Canceled:
|
||||
case Windows::Foundation::AsyncStatus::Canceled:
|
||||
g_swExceptionDetail = L"Installation Canceled";
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_ABORT;
|
||||
case AsyncStatus::Started:
|
||||
case Windows::Foundation::AsyncStatus::Started:
|
||||
g_swExceptionDetail = L"Installation is Running";
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_PENDING;
|
||||
@@ -185,7 +211,8 @@ void SidToAccountName (const std::wstring &sidString, std::wstring &stringSid)
|
||||
if (LookupAccountSidW (nullptr, sid, namebuf.data (), &nameCharCount, domainNameBuf.data (), &domainNameCharCount, &sidType))
|
||||
{
|
||||
stringSid = domainNameBuf.data ();
|
||||
stringSid += stringSid + L"\\" + namebuf.data ();
|
||||
if (!stringSid.empty ()) stringSid += L"\\";
|
||||
stringSid += namebuf.data ();
|
||||
}
|
||||
}
|
||||
if (stringSid.length () == 0) stringSid = sidString;
|
||||
@@ -218,7 +245,7 @@ struct pkg_info
|
||||
std::wstring users = L"";
|
||||
std::wstring sids = L"";
|
||||
std::vector <pkg_info> dependencies;
|
||||
static pkg_info parse (Windows::ApplicationModel::Package ^pkg, Windows::Management::Deployment::PackageManager ^mgr)
|
||||
static pkg_info parse (Windows::ApplicationModel::Package ^pkg, Windows::Management::Deployment::PackageManager ^mgr, bool iterdeps = true)
|
||||
{
|
||||
pkg_info pi;
|
||||
if (!pkg) throw ref new InvalidArgumentException ("No package found.");
|
||||
@@ -259,23 +286,30 @@ struct pkg_info
|
||||
std::wstring sid;
|
||||
WAPParseSetStringValue (sid, it->UserSecurityId);
|
||||
if (i) pi.sids += L';';
|
||||
pi.users += sid;
|
||||
pi.sids += sid;
|
||||
}
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
if (g_enableIterDeps && iterdeps)
|
||||
{
|
||||
auto deps = pkg->Dependencies;
|
||||
for (auto it : deps)
|
||||
try
|
||||
{
|
||||
auto deppkg = pkg_info::parse (it, mgr);
|
||||
deppkg.dependencies.clear ();
|
||||
pi.dependencies.push_back (deppkg);
|
||||
auto deps = pkg->Dependencies;
|
||||
if (deps && deps->Size)
|
||||
{
|
||||
for (size_t i = 0; i < deps->Size; i ++)
|
||||
{
|
||||
auto it = deps->GetAt (i);
|
||||
auto deppkg = pkg_info::parse (it, mgr, false);
|
||||
deppkg.dependencies.clear ();
|
||||
pi.dependencies.push_back (deppkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
catch (...) {}
|
||||
return pi;
|
||||
#ifdef WAPParseSetStringValue
|
||||
#undef WAPParseSetStringValue
|
||||
@@ -319,6 +353,49 @@ struct pkg_info
|
||||
}
|
||||
};
|
||||
[STAThread]
|
||||
HRESULT ProcessFoundAppxPackages (Windows::Foundation::Collections::IIterable <Windows::ApplicationModel::Package ^> ^pkgarr, PackageManager ^pkgmgr, std::function <void (pkg_info &)> pfCallback, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
g_swExceptionCode = L"";
|
||||
g_swExceptionDetail = L"";
|
||||
try
|
||||
{
|
||||
if (pkgarr)
|
||||
{
|
||||
for each (auto pkg in pkgarr)
|
||||
{
|
||||
auto pkginfo = pkg_info::parse (pkg, pkgmgr);
|
||||
if (pfCallback) pfCallback (pkginfo);
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
catch (AccessDeniedException ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
g_swExceptionDetail = StringToWString (e.what () ? e.what () : "Unknown exception.");
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
g_swExceptionDetail = L"Unknown exception";
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
[STAThread]
|
||||
HRESULT FindAppxPackageByCallback (std::function <void (pkg_info &)> pfCallback, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
g_swExceptionCode = L"";
|
||||
@@ -327,12 +404,7 @@ HRESULT FindAppxPackageByCallback (std::function <void (pkg_info &)> pfCallback,
|
||||
{
|
||||
auto pkgmgr = ref new PackageManager ();
|
||||
auto pkgarr = pkgmgr->FindPackages ();
|
||||
for (auto pkg : pkgarr)
|
||||
{
|
||||
auto pkginfo = pkg_info::parse (pkg, pkgmgr);
|
||||
if (pfCallback) pfCallback (pkginfo);
|
||||
}
|
||||
return S_OK;
|
||||
return ProcessFoundAppxPackages (pkgarr, pkgmgr, pfCallback, pErrorCode, pDetailMsg);
|
||||
}
|
||||
catch (AccessDeniedException ^e)
|
||||
{
|
||||
@@ -632,6 +704,7 @@ LPCWSTR GetPackageManagerLastErrorDetailMessage () { return g_swExceptionDetail.
|
||||
|
||||
HRESULT ActivateAppxApplication (LPCWSTR lpAppUserId, PDWORD pdwProcessId)
|
||||
{
|
||||
if (FAILED (CoInitializeEx (NULL, COINIT_APARTMENTTHREADED))) return E_INVALIDARG;
|
||||
if (!lpAppUserId) return E_INVALIDARG;
|
||||
std::wstring strAppUserModelId (L"");
|
||||
if (lpAppUserId) strAppUserModelId += lpAppUserId;
|
||||
@@ -649,9 +722,112 @@ HRESULT ActivateAppxApplication (LPCWSTR lpAppUserId, PDWORD pdwProcessId)
|
||||
{
|
||||
// This call ensures that the app is launched as the foreground window
|
||||
hResult = CoAllowSetForegroundWindow (spAppActivationManager, NULL);
|
||||
DWORD dwProgressId = 0;
|
||||
// Launch the app
|
||||
if (SUCCEEDED (hResult)) hResult = spAppActivationManager->ActivateApplication (strAppUserModelId.c_str (), NULL, AO_NONE, pdwProcessId);
|
||||
if (SUCCEEDED (hResult))
|
||||
hResult = spAppActivationManager->ActivateApplication (strAppUserModelId.c_str (), NULL, AO_NONE, &dwProgressId);
|
||||
if (pdwProcessId) *pdwProcessId = dwProgressId;
|
||||
}
|
||||
}
|
||||
return hResult;
|
||||
}
|
||||
}
|
||||
[STAThread]
|
||||
HRESULT FindAppxPackageByCallback (LPCWSTR lpPkgName, LPCWSTR lpPublisher, std::function <void (pkg_info &)> pfCallback, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
g_swExceptionCode = L"";
|
||||
g_swExceptionDetail = L"";
|
||||
try
|
||||
{
|
||||
auto pkgmgr = ref new PackageManager ();
|
||||
std::wstring pkgname = lpPkgName ? lpPkgName : L"";
|
||||
std::wstring pkgpublisher = lpPublisher ? lpPublisher : L"";
|
||||
auto refname = ref new Platform::String (pkgname.c_str ()),
|
||||
refpublisher = ref new Platform::String (pkgpublisher.c_str ());
|
||||
auto pkgarr = pkgmgr->FindPackages (refname, refpublisher);
|
||||
return ProcessFoundAppxPackages (pkgarr, pkgmgr, pfCallback, pErrorCode, pDetailMsg);
|
||||
}
|
||||
catch (AccessDeniedException ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
g_swExceptionDetail = StringToWString (e.what () ? e.what () : "Unknown exception.");
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
g_swExceptionDetail = L"Unknown exception";
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
[STAThread]
|
||||
HRESULT FindAppxPackagesByIdentity (LPCWSTR lpPkgName, LPCWSTR lpPkgPublisher, PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
return FindAppxPackageByCallback (lpPkgName, lpPkgPublisher, [&pCustom, &pfCallback] (pkg_info &pi) {
|
||||
std::vector <BYTE> bytes;
|
||||
pi.to_c_struct (bytes);
|
||||
if (pfCallback) pfCallback ((FIND_PACKAGE_INFO *)bytes.data (), pCustom);
|
||||
}, pErrorCode, pDetailMsg);
|
||||
}
|
||||
[STAThread]
|
||||
HRESULT FindAppxPackageByCallback (LPCWSTR lpPkgFamilyName, std::function <void (pkg_info &)> pfCallback, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
g_swExceptionCode = L"";
|
||||
g_swExceptionDetail = L"";
|
||||
try
|
||||
{
|
||||
auto pkgmgr = ref new PackageManager ();
|
||||
std::wstring familyname = L"";
|
||||
familyname += lpPkgFamilyName ? lpPkgFamilyName : L"";
|
||||
auto reffamily = ref new Platform::String (familyname.c_str ());
|
||||
auto pkgarr = pkgmgr->FindPackages (reffamily);
|
||||
return ProcessFoundAppxPackages (pkgarr, pkgmgr, pfCallback, pErrorCode, pDetailMsg);
|
||||
}
|
||||
catch (AccessDeniedException ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
g_swExceptionDetail = e->ToString ()->Data ();
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return (SUCCEEDED ((HRESULT)e->HResult) ? E_FAIL : (HRESULT)e->HResult);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
g_swExceptionDetail = StringToWString (e.what () ? e.what () : "Unknown exception.");
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
g_swExceptionDetail = L"Unknown exception";
|
||||
if (pDetailMsg) *pDetailMsg = _wcsdup (g_swExceptionDetail.c_str ());
|
||||
return E_FAIL;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
[STAThread]
|
||||
HRESULT FindAppxPackagesByFamilyName (LPCWSTR lpPkgFamilyName, PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom, LPWSTR *pErrorCode, LPWSTR *pDetailMsg)
|
||||
{
|
||||
return FindAppxPackageByCallback (lpPkgFamilyName, [&pCustom, &pfCallback] (pkg_info &pi) {
|
||||
std::vector <BYTE> bytes;
|
||||
pi.to_c_struct (bytes);
|
||||
if (pfCallback) pfCallback ((FIND_PACKAGE_INFO *)bytes.data (), pCustom);
|
||||
}, pErrorCode, pDetailMsg);
|
||||
}
|
||||
void PackageManagerFreeString (LPWSTR lpString) { if (lpString) free (lpString); }
|
||||
496
pkgmgr/pkgmgr.h
496
pkgmgr/pkgmgr.h
@@ -59,18 +59,23 @@ extern "C"
|
||||
#define DEPOLYOPTION_INSTALL_ALL_RESOURCES 0x00000020
|
||||
// 使用默认行为。
|
||||
#define DEPOLYOPTION_NONE 0x00000000
|
||||
// 发现拼写错了,只能将错就错(反正 IDE 不会给宏注释):
|
||||
#define DEPLOYOPTION_FORCE_APP_SHUTDOWN DEPOLYOPTION_FORCE_APP_SHUTDOWN
|
||||
#define DEPLOYOPTION_DEVELOPMENT_MODE DEPOLYOPTION_DEVELOPMENT_MODE
|
||||
#define DEPLOYOPTION_INSTALL_ALL_RESOURCES DEPOLYOPTION_INSTALL_ALL_RESOURCES
|
||||
#define DEPLOYOPTION_NONE DEPOLYOPTION_NONE
|
||||
// 安装一个 Appx/AppxBundle/Msix/MsixBundle 包
|
||||
// 注意:传入的文件路径为 DOS/NT 风格。如:C:\Windows\...
|
||||
// 该函数类似于 PowerShell 的 Add-AppxPackage
|
||||
// dwDeployOption 接受 DEPOLYOPTION_* 常量
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
PKGMGR_API HRESULT AddAppxPackageFromPath (LPCWSTR lpPkgPath, PCREGISTER_PACKAGE_DEFENDENCIES alpDepUrlList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPOLYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT AddAppxPackageFromPath (LPCWSTR lpPkgPath, PCREGISTER_PACKAGE_DEFENDENCIES alpDepUrlList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPLOYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 安装一个 Appx/AppxBundle/Msix/MsixBundle 包
|
||||
// 注意:传入的文件路径为 URI。
|
||||
// 该函数类似于 PowerShell 的 Add-AppxPackage
|
||||
// dwDeployOption 接受 DEPOLYOPTION_* 常量
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
PKGMGR_API HRESULT AddAppxPackageFromURI (LPCWSTR lpFileUri, PCREGISTER_PACKAGE_DEFENDENCIES alpDepFullNameList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPOLYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT AddAppxPackageFromURI (LPCWSTR lpFileUri, PCREGISTER_PACKAGE_DEFENDENCIES alpDepFullNameList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPLOYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
|
||||
typedef struct _FIND_PACKAGE_ID
|
||||
{
|
||||
@@ -122,13 +127,13 @@ extern "C"
|
||||
// 通过回调来获取所有包的信息。回调函数允许传自定义内容。返回的值可以判断是否成功。
|
||||
// 该函数类似于 PowerShell 的 Get-AppxPackage
|
||||
// 注意:回调函数中包的信息无法修改,也不能擅自释放。且随着函数的执行完毕自动释放。这就要求在回调中自行拷贝一份。
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT GetAppxPackages (PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 移除一个已经安装到电脑上的应用。注意:传入的是包完整名。
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT RemoveAppxPackage (LPCWSTR lpPkgFullName, PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 清理指定用户的指定 包 。 用于清除删除用户用户配置文件后为用户安装的包。
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT CleanupAppxPackage (LPCWSTR lpPkgName, LPCWSTR lpUserSID, PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
|
||||
// 注册应用包
|
||||
@@ -167,13 +172,13 @@ extern "C"
|
||||
// 仅当更新包的版本高于已安装包的版本时,才能更新已安装的包。 如果不存在以前版本的包,则操作将失败。
|
||||
// 注意:传入的文件路径为 DOS/NT 风格。如:C:\Windows\...
|
||||
// dwDeployOption 接受 DEPOLYOPTION_* 常量
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT UpdateAppxPackageFromPath (LPCWSTR lpPkgPath, PCREGISTER_PACKAGE_DEFENDENCIES alpDepUrlList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPOLYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 为当前用户汇报已安装的包或其依赖项包。
|
||||
// 仅当更新包的版本高于已安装包的版本时,才能更新已安装的包。 如果不存在以前版本的包,则操作将失败。
|
||||
// 注意:传入的文件路径为 URI。
|
||||
// dwDeployOption 接受 DEPOLYOPTION_* 常量
|
||||
// 输出的错误信息别忘了用 free 释放
|
||||
// 输出的错误信息别忘了用 PackageManagerFreeString 释放
|
||||
PKGMGR_API HRESULT UpdateAppxPackageFromURI (LPCWSTR lpFileUri, PCREGISTER_PACKAGE_DEFENDENCIES alpDepFullNameList _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), DWORD dwDeployOption _DEFAULT_INIT_VALUE_FORFUNC_ (DEPOLYOPTION_NONE), PKGMRR_PROGRESSCALLBACK pfCallback _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 检索有关为任何用户安装的指定 包 的信息。
|
||||
PKGMGR_API HRESULT FindAppxPackage (LPCWSTR lpPackageFullName, PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
@@ -183,6 +188,12 @@ extern "C"
|
||||
PKGMGR_API LPCWSTR GetPackageManagerLastErrorDetailMessage ();
|
||||
// 启动 Metro UI 应用
|
||||
PKGMGR_API HRESULT ActivateAppxApplication (LPCWSTR lpAppUserId, PDWORD pdwProcessId);
|
||||
// 根据提供的包身份名和发布者检索
|
||||
PKGMGR_API HRESULT FindAppxPackagesByIdentity (LPCWSTR lpPkgName, LPCWSTR lpPkgPublisher, PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 根据提供的包系列名检索
|
||||
PKGMGR_API HRESULT FindAppxPackagesByFamilyName (LPCWSTR lpPkgFamilyName, PKGMGR_FINDENUMCALLBACK pfCallback, void *pCustom _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pErrorCode _DEFAULT_INIT_VALUE_FORFUNC_ (NULL), LPWSTR *pDetailMsg _DEFAULT_INIT_VALUE_FORFUNC_ (NULL));
|
||||
// 释放由 pkgmgr.dll 返回的动态字符串。
|
||||
PKGMGR_API void PackageManagerFreeString (LPWSTR lpString);
|
||||
#ifdef _DEFAULT_INIT_VALUE_
|
||||
#undef _DEFAULT_INIT_VALUE_
|
||||
#endif
|
||||
@@ -192,3 +203,470 @@ extern "C"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
void IAsyncProgressCallback (DWORD dwProgress, void *pCustom)
|
||||
{
|
||||
using cbfunc = std::function <void (DWORD)>;
|
||||
if (auto func = reinterpret_cast <cbfunc *> (pCustom)) (*func)(dwProgress);
|
||||
}
|
||||
HRESULT AddAppxPackageFromPath (
|
||||
const std::wstring &pkgpath,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = AddAppxPackageFromPath (pkgpath.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT AddAppxPackageFromURI (
|
||||
const std::wstring &pkguri,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = AddAppxPackageFromURI (pkguri.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
struct find_pkginfo
|
||||
{
|
||||
bool isvalid = false;
|
||||
struct
|
||||
{
|
||||
std::wstring
|
||||
name,
|
||||
publisher,
|
||||
publisher_id,
|
||||
full_name,
|
||||
family_name,
|
||||
resource_id;
|
||||
UINT64 version = 0;
|
||||
// x86: 0
|
||||
// x64: 9
|
||||
// Arm: 5
|
||||
// Neutral: 11
|
||||
// Arm64: 12
|
||||
// Unknown: 65535(-1)
|
||||
WORD architecture = -1;
|
||||
} identity;
|
||||
struct
|
||||
{
|
||||
std::wstring
|
||||
display_name,
|
||||
description,
|
||||
publisher,
|
||||
logo_uri;
|
||||
bool is_framework = false,
|
||||
resource_package = false;
|
||||
} properties;
|
||||
bool is_bundle = false;
|
||||
bool is_development_mode = false;
|
||||
std::wstring install_location;
|
||||
std::vector <std::wstring>
|
||||
users,
|
||||
sids;
|
||||
#define safestring(_pstr_) (_pstr_ ? _pstr_ : L"")
|
||||
static find_pkginfo parse (LPCFIND_PACKAGE_INFO fpi)
|
||||
{
|
||||
if (!fpi) return find_pkginfo ();
|
||||
find_pkginfo fpkg;
|
||||
fpkg.identity.name += safestring (fpi->piIdentity.lpName);
|
||||
fpkg.identity.publisher += safestring (fpi->piIdentity.lpPublisher);
|
||||
fpkg.identity.publisher_id += safestring (fpi->piIdentity.lpPublisherId);
|
||||
fpkg.identity.family_name += safestring (fpi->piIdentity.lpFamilyName);
|
||||
fpkg.identity.full_name += safestring (fpi->piIdentity.lpFullName);
|
||||
fpkg.identity.resource_id += safestring (fpi->piIdentity.lpResourceId);
|
||||
fpkg.identity.version = fpi->piIdentity.qwVersion;
|
||||
fpkg.identity.architecture = fpi->piIdentity.wProcessArchitecture;
|
||||
fpkg.properties.display_name += safestring (fpi->piProperties.lpDisplayName);
|
||||
fpkg.properties.description += safestring (fpi->piProperties.lpDescription);
|
||||
fpkg.properties.publisher += safestring (fpi->piProperties.lpPublisher);
|
||||
fpkg.properties.logo_uri += safestring (fpi->piProperties.lpLogoUri);
|
||||
fpkg.properties.is_framework = fpi->piProperties.bIsFramework;
|
||||
fpkg.properties.resource_package = fpi->piProperties.bIsResourcePackage;
|
||||
fpkg.is_bundle = fpi->piProperties.bIsBundle;
|
||||
fpkg.is_development_mode = fpi->piProperties.bIsDevelopmentMode;
|
||||
fpkg.install_location += safestring (fpi->lpInstallLocation);
|
||||
std::wstring users;
|
||||
users += safestring (fpi->lpUsers);
|
||||
std::wstring sids;
|
||||
sids += safestring (fpi->lpSIDs);
|
||||
std::wstring part = L"";
|
||||
for (size_t i = 0; i < users.length (); i ++)
|
||||
{
|
||||
auto &wch = users [i];
|
||||
if (wch == L';' || wch == L'0')
|
||||
{
|
||||
if (!part.empty ()) fpkg.users.push_back (part);
|
||||
part = L"";
|
||||
continue;
|
||||
}
|
||||
part += wch;
|
||||
}
|
||||
if (!part.empty ()) fpkg.users.push_back (part);
|
||||
part = L"";
|
||||
for (size_t i = 0; i < sids.length (); i ++)
|
||||
{
|
||||
auto &wch = sids [i];
|
||||
if (wch == L';' || wch == L'0')
|
||||
{
|
||||
if (!part.empty ()) fpkg.sids.push_back (part);
|
||||
part = L"";
|
||||
continue;
|
||||
}
|
||||
part += wch;
|
||||
}
|
||||
if (!part.empty ()) fpkg.sids.push_back (part);
|
||||
fpkg.isvalid = true;
|
||||
return fpkg;
|
||||
}
|
||||
#ifdef safestring
|
||||
#undef safestring
|
||||
#endif
|
||||
};
|
||||
void IAsyncFindEnumCallback (LPCFIND_PACKAGE_INFO pNowItem, void *pCustom)
|
||||
{
|
||||
if (pNowItem)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto fpkg = find_pkginfo::parse (pNowItem);
|
||||
if (fpkg.isvalid)
|
||||
{
|
||||
using cbfunc = std::function <void (const find_pkginfo &)>;
|
||||
auto func = reinterpret_cast <cbfunc *> (pCustom);
|
||||
if (func) (*func)(fpkg);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
OutputDebugStringA (e.what ());
|
||||
}
|
||||
}
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
std::function <void (const find_pkginfo &)> callback,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = GetAppxPackages (&IAsyncFindEnumCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
std::vector <find_pkginfo> &out_pkgs,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
return GetAppxPackages ([&] (const find_pkginfo &fpi) {
|
||||
out_pkgs.push_back (fpi);
|
||||
}, errorcode, detailmsg);
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
const std::wstring &package_family_name,
|
||||
std::function <void (const find_pkginfo &)> callback,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = FindAppxPackagesByFamilyName (package_family_name.c_str (), &IAsyncFindEnumCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
const std::wstring &package_family_name,
|
||||
std::vector <find_pkginfo> &out_pkgs,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
return GetAppxPackages (package_family_name , [&] (const find_pkginfo &fpi) {
|
||||
out_pkgs.push_back (fpi);
|
||||
}, errorcode, detailmsg);
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
const std::wstring &package_id_name,
|
||||
const std::wstring &package_id_publisher,
|
||||
std::function <void (const find_pkginfo &)> callback,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = FindAppxPackagesByIdentity (package_id_name.c_str (), package_id_publisher.c_str (), &IAsyncFindEnumCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetAppxPackages (
|
||||
const std::wstring &package_id_name,
|
||||
const std::wstring &package_id_publisher,
|
||||
std::vector <find_pkginfo> &out_pkgs,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
return GetAppxPackages (package_id_name, package_id_publisher, [&] (const find_pkginfo &fpi) {
|
||||
out_pkgs.push_back (fpi);
|
||||
}, errorcode, detailmsg);
|
||||
}
|
||||
HRESULT FindAppxPackage (
|
||||
const std::wstring &package_fullname,
|
||||
std::function <void (const find_pkginfo &)> callback,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = FindAppxPackage (package_fullname.c_str (), &IAsyncFindEnumCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT FindAppxPackage (
|
||||
const std::wstring &package_fullname,
|
||||
find_pkginfo &out_pkginf,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
return FindAppxPackage (package_fullname, [&] (const find_pkginfo &fpkg) {
|
||||
out_pkginf = fpkg;
|
||||
}, errorcode, detailmsg);
|
||||
}
|
||||
HRESULT RemoveAppxPackage (
|
||||
const std::wstring &package_fullname,
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = RemoveAppxPackage (package_fullname.c_str (), &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT CleanupAppxPackage (
|
||||
const std::wstring &package_name,
|
||||
const std::wstring &user_sid,
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = CleanupAppxPackage (package_name.c_str (), user_sid.c_str (), &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT RegisterAppxPackageByPath (
|
||||
const std::wstring &manifest_path,
|
||||
const std::vector <std::wstring> &depurilist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * depurilist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = depurilist.size ();
|
||||
for (size_t i = 0; i < depurilist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)depurilist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = RegisterAppxPackageByPath (manifest_path.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT RegisterAppxPackageByUri (
|
||||
const std::wstring &manifest_uri,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = RegisterAppxPackageByUri (manifest_uri.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT RegisterAppxPackageByFullName (
|
||||
const std::wstring &package_full_name,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = RegisterAppxPackageByFullName (package_full_name.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT StageAppxPackageFromURI (
|
||||
const std::wstring &file_uri,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = StageAppxPackageFromURI (file_uri.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT StageAppxPackageFromPath (
|
||||
const std::wstring &file_path,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = StageAppxPackageFromURI (file_path.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT StageAppxUserData (
|
||||
const std::wstring &package_full_name,
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = StageAppxUserData (package_full_name.c_str (), &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT UpdateAppxPackageFromPath (
|
||||
const std::wstring &file_path,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = UpdateAppxPackageFromPath (file_path.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT UpdateAppxPackageFromURI (
|
||||
const std::wstring &file_uri,
|
||||
const std::vector <std::wstring> &deplist = std::vector <std::wstring> (),
|
||||
DWORD deployoption = DEPOLYOPTION_NONE, // 使用 DEPOLYOPTION_* 前缀
|
||||
std::function <void (DWORD)> callback = nullptr,
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
std::vector <BYTE> bytes (sizeof (REGISTER_PACKAGE_DEFENDENCIES) + sizeof (LPWSTR) * deplist.size ());
|
||||
auto lpdeplist = (PREGISTER_PACKAGE_DEFENDENCIES)bytes.data ();
|
||||
lpdeplist->dwSize = deplist.size ();
|
||||
for (size_t i = 0; i < deplist.size (); i ++) lpdeplist->alpDepUris [i] = (LPWSTR)deplist [i].c_str ();
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = UpdateAppxPackageFromURI (file_uri.c_str (), lpdeplist, deployoption, &IAsyncProgressCallback, &callback, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT SetAppxPackageStatus (
|
||||
const std::wstring &package_full_name,
|
||||
DWORD status, // PACKAGESTATUS_* 前缀常量
|
||||
std::wstring &errorcode = std::wstring (),
|
||||
std::wstring &detailmsg = std::wstring ()
|
||||
) {
|
||||
LPWSTR lperr = nullptr, lpmsg = nullptr;
|
||||
HRESULT hr = SetAppxPackageStatus (package_full_name.c_str (), status, &lperr, &lpmsg);
|
||||
errorcode = lperr ? lperr : L"";
|
||||
detailmsg = lpmsg ? lpmsg : L"";
|
||||
if (lperr) PackageManagerFreeString (lperr);
|
||||
if (lpmsg) PackageManagerFreeString (lpmsg);
|
||||
return hr;
|
||||
}
|
||||
HRESULT ActivateAppxApplication (
|
||||
const std::wstring &app_user_id,
|
||||
PDWORD ret_processid = nullptr
|
||||
) {
|
||||
return ActivateAppxApplication (app_user_id.c_str (), ret_processid);
|
||||
}
|
||||
#endif
|
||||
@@ -15,9 +15,6 @@
|
||||
|
||||
// TODO: 在此处引用程序需要的其他头文件
|
||||
#using <Windows.winmd>
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::Management::Deployment;
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <objbase.h>
|
||||
@@ -30,4 +27,7 @@ using namespace Windows::Management::Deployment;
|
||||
#include <sddl.h>
|
||||
#include <shlobj.h>
|
||||
#include <stdio.h>
|
||||
#include <shobjidl.h>
|
||||
#include <shobjidl.h>
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::Management::Deployment;
|
||||
|
||||
Reference in New Issue
Block a user