diff options
author | sr55 <[email protected]> | 2017-08-18 21:50:54 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2017-08-18 21:50:54 +0100 |
commit | 63add3c308571c1018fd1f8801100ead98e989b4 (patch) | |
tree | 65830fd0bbe9d5504038dcf176a579029abf0a2f /win | |
parent | a5d09db0caec7c880e9b280d72a2fafeb122815b (diff) |
WinGui: Make the app UWP aware. When in a UWP container, the update options will now be disabled.
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/Converters/OptionTabConverter.cs | 38 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/UpdateService.cs | 7 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/UwpDetect.cs | 40 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 8 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/MainView.xaml | 4 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 3 |
8 files changed, 101 insertions, 3 deletions
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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="OptionTabConverter.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Controls display of tab pages +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +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 @@ <Compile Include="Converters\Filters\SharpenPresetConverter.cs" />
<Compile Include="Converters\Options\FileSizeConverter.cs" />
<Compile Include="Converters\Options\LogLevelConverter.cs" />
+ <Compile Include="Converters\OptionTabConverter.cs" />
<Compile Include="Converters\PresetsMenuConverter.cs" />
<Compile Include="Converters\Queue\PictureSettingsDescConveter.cs" />
<Compile Include="Converters\Subtitles\SubtitleBurnInBehaviourConverter.cs" />
@@ -270,6 +271,7 @@ <Compile Include="Utilities\Portable.cs" />
<Compile Include="Utilities\DirectoryUtilities.cs" />
<Compile Include="Utilities\SystemInfo.cs" />
+ <Compile Include="Utilities\UwpDetect.cs" />
<Compile Include="Utilities\Win32.cs" />
<Compile Include="Utilities\Win7.cs" />
<Compile Include="ViewModels\Interfaces\IManagePresetViewModel.cs" />
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;
/// <summary>
@@ -61,6 +63,11 @@ namespace HandBrakeWPF.Services /// </param>
public void PerformStartupUpdateCheck(Action<UpdateCheckInformation> 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<bool>(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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="UwpDetect.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// 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 +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +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 /// </summary>
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
/// <summary>
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 @@ <Image Width="16" Height="16" Source="Images/information.png" />
</MenuItem.Icon>
</MenuItem>
- <Separator />
- <MenuItem Header="_Check for Updates" cal:Message.Attach="[Event Click] = [Action CheckForUpdates]" />
+ <Separator Visibility="{Binding IsUWP, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
+ <MenuItem Header="_Check for Updates" cal:Message.Attach="[Event Click] = [Action CheckForUpdates]" Visibility="{Binding IsUWP, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
<Separator />
<MenuItem Header="_About..." cal:Message.Attach="[Event Click] = [Action OpenAboutApplication]" />
</MenuItem>
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 @@ <Converters:EnumComboConverter x:Key="enumComboConverter" />
<Options:LogLevelConverter x:Key="LogLevelConverter" />
<Options:FileSizeConverter x:Key="fileSizeConverter" />
+ <Converters:OptionTabConverter x:Key="optionTabConverter" />
<Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
@@ -72,7 +73,7 @@ <Border BorderBrush="DarkGray" Grid.Column="0" Grid.Row="1" BorderThickness="0,0,1,0">
<StackPanel Orientation="Vertical" Margin="11,5,-1,0">
- <ListBox ItemsSource="{Binding Source={StaticResource OptionTabsList}}" SelectedItem="{Binding SelectedTab}"
+ <ListBox ItemsSource="{Binding Source={StaticResource OptionTabsList}, Converter={StaticResource optionTabConverter}}" SelectedItem="{Binding SelectedTab}"
BorderThickness="0" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
|