mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-10 11:12:47 +08:00
add try catch
This commit is contained in:
parent
bf8f3ca3a5
commit
42c3768d94
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using ManagedCommon;
|
||||||
using Microsoft.CmdPal.Ext.Apps.Utils;
|
using Microsoft.CmdPal.Ext.Apps.Utils;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Windows.Win32;
|
using Windows.Win32;
|
||||||
@ -37,8 +38,11 @@ public static class AppxPackageHelper
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAppxManifestApplication* manifestApp;
|
IAppxManifestApplication* manifestApp = null;
|
||||||
manifestApps->GetCurrent(&manifestApp);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
manifestApps->GetCurrent(&manifestApp).ThrowOnFailure();
|
||||||
|
|
||||||
var hr = manifestApp->GetStringValue("AppListEntry", out var appListEntryPtr);
|
var hr = manifestApp->GetStringValue("AppListEntry", out var appListEntryPtr);
|
||||||
var appListEntry = ComFreeHelper.GetStringAndFree(hr, appListEntryPtr);
|
var appListEntry = ComFreeHelper.GetStringAndFree(hr, appListEntryPtr);
|
||||||
@ -51,6 +55,16 @@ public static class AppxPackageHelper
|
|||||||
{
|
{
|
||||||
manifestApp->Release();
|
manifestApp->Release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (manifestApp != null)
|
||||||
|
{
|
||||||
|
manifestApp->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.LogError($"Failed to get current application from manifest: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
manifestApps->MoveNext(out var hasNext);
|
manifestApps->MoveNext(out var hasNext);
|
||||||
if (hasNext == false)
|
if (hasNext == false)
|
||||||
|
Loading…
Reference in New Issue
Block a user