From 63add3c308571c1018fd1f8801100ead98e989b4 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 18 Aug 2017 21:50:54 +0100 Subject: WinGui: Make the app UWP aware. When in a UWP container, the update options will now be disabled. --- .../HandBrakeWPF/Converters/OptionTabConverter.cs | 38 ++++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 ++ win/CS/HandBrakeWPF/Services/UpdateService.cs | 7 ++++ win/CS/HandBrakeWPF/Utilities/UwpDetect.cs | 40 ++++++++++++++++++++++ win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 2 ++ win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 8 +++++ win/CS/HandBrakeWPF/Views/MainView.xaml | 4 +-- win/CS/HandBrakeWPF/Views/OptionsView.xaml | 3 +- 8 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/OptionTabConverter.cs create mode 100644 win/CS/HandBrakeWPF/Utilities/UwpDetect.cs (limited to 'win') diff --git a/win/CS/HandBrakeWPF/Converters/OptionTabConverter.cs b/win/CS/HandBrakeWPF/Converters/OptionTabConverter.cs new file mode 100644 index 000000000..9ad7111ec --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/OptionTabConverter.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Controls display of tab pages +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters +{ + using System; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrakeWPF.Model; + using HandBrakeWPF.Utilities; + + public class OptionTabConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + OptionsTab[] tabs = value as OptionsTab[]; + if (tabs != null && UwpDetect.IsUWP()) + { + return tabs.Where(s => s != OptionsTab.Updates).ToArray(); + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 42c3882a6..8ac0f2b20 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -159,6 +159,7 @@ + @@ -270,6 +271,7 @@ + diff --git a/win/CS/HandBrakeWPF/Services/UpdateService.cs b/win/CS/HandBrakeWPF/Services/UpdateService.cs index 3b3d09125..0702b1909 100644 --- a/win/CS/HandBrakeWPF/Services/UpdateService.cs +++ b/win/CS/HandBrakeWPF/Services/UpdateService.cs @@ -20,6 +20,8 @@ namespace HandBrakeWPF.Services using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Model; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Utilities; + using AppcastReader = HandBrakeWPF.Utilities.AppcastReader; /// @@ -61,6 +63,11 @@ namespace HandBrakeWPF.Services /// public void PerformStartupUpdateCheck(Action callback) { + if (UwpDetect.IsUWP()) + { + return; // Disable Update checker if we are in a UWP container. + } + // Make sure it's running on the calling thread if (this.userSettingService.GetUserSetting(UserSettingConstants.UpdateStatus)) { diff --git a/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs b/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs new file mode 100644 index 000000000..068165924 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs @@ -0,0 +1,40 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Helper class to detect if we are running in a UWP container. +// https://msdn.microsoft.com/en-us/library/windows/desktop/hh446599(v=vs.85).aspx +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System; + using System.Runtime.InteropServices; + + public class UwpDetect + { + [DllImport("kernel32.dll")] + static extern int GetCurrentPackageFullName(ref int length, IntPtr fullName); + + public static bool IsUWP() + { + if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor <= 1) + { + return false; + } + + int length = 0; + IntPtr name = IntPtr.Zero; + GetCurrentPackageFullName(ref length, name); // Only available in 6.2 or later. + + if (length > 0) + { + return true; + } + + return false; + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 1502d4baa..33e9acf25 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1254,6 +1254,8 @@ namespace HandBrakeWPF.ViewModels /// public bool IsQueueShowingInLine { get; set; } = false; + public bool IsUWP { get; } = UwpDetect.IsUWP(); + #endregion #region Commands diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 5d936be0c..5f3241a12 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -162,6 +162,14 @@ namespace HandBrakeWPF.ViewModels #region Properties + public bool IsUWP + { + get + { + return UwpDetect.IsUWP(); + } + } + #region General /// diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 641026e29..6577b2fd1 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -117,8 +117,8 @@ - - + + diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 4be816551..65f2d7800 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -37,6 +37,7 @@ + @@ -72,7 +73,7 @@ - -- cgit v1.2.3