This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ComImport] | |
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")] | |
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
public interface IInitializeWithWindow | |
{ | |
void Initialize(IntPtr hwnd); | |
} | |
public void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
var initWindow = (IInitializeWithWindow)(object)context; | |
initWindow.Initialize(handle); | |
} |
このための修正としては、usingにWinRTを加えた上でAsでIInitializeWithWindowキャストする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using WinRT; | |
public void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
var initWindow = context.As<IInitializeWithWindow>(); | |
initWindow.Initialize(handle); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using WinRT.Interop; | |
public void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
InitializeWithWindow.Initialize(context, handle); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.NetworkInformation; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Interop; | |
using Windows.Services.Store; | |
using WinRT.Interop; | |
internal static class StoreHelper | |
{ | |
/// <summary> | |
/// Checks if updated packages are available. | |
/// </summary> | |
/// <returns>True if available</returns> | |
/// <remarks> | |
/// If the packages are installed locally or published but as Package flights, this method | |
/// will not work correctly. | |
/// </remarks> | |
public static async Task<bool> CheckUpdateAsync() | |
{ | |
if (!NetworkInterface.GetIsNetworkAvailable()) | |
return false; | |
var context = StoreContext.GetDefault(); | |
try | |
{ | |
var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); | |
return (updates.Count > 0); | |
} | |
catch | |
{ | |
return false; | |
} | |
} | |
/// <summary> | |
/// Proceeds to download and install updated packages. | |
/// </summary> | |
/// <param name="window">Owner window</param> | |
/// <returns>True if successfully finished downloading and installing</returns> | |
public static async Task<bool> ProceedUpdateAsync(Window window) | |
{ | |
if (window is null) | |
throw new ArgumentNullException(nameof(window)); | |
if (!NetworkInterface.GetIsNetworkAvailable()) | |
return false; | |
var context = StoreContext.GetDefault(); | |
try | |
{ | |
var updates = await context.GetAppAndOptionalStorePackageUpdatesAsync(); | |
if (updates.Count == 0) | |
return false; | |
SetOwnerWindow(context, window); | |
var result = await context.RequestDownloadAndInstallStorePackageUpdatesAsync(updates); | |
return (result.OverallState == StorePackageUpdateState.Completed); | |
} | |
catch | |
{ | |
return false; | |
} | |
} | |
private static void SetOwnerWindow(StoreContext context, Window window) | |
{ | |
var handle = new WindowInteropHelper(window).Handle; | |
InitializeWithWindow.Initialize(context, handle); | |
} | |
} |
0 コメント :
コメントを投稿