<!--
Copyright (c) 2018, Rene Lergner - wpinternals.net - @Heathcliff74xda

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->

<UserControl x:Class="WPinternals.BootRestoreResourcesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPinternals"
             mc:Ignorable="d" 
             d:DesignWidth="700">
    <UserControl.Resources>
        <local:HexConverter x:Key="HexConverter" />
        <local:BooleanConverter x:Key="VisibilityConverter" OnTrue="Visible" OnFalse="Collapsed" OnNull="Collapsed"/>
        <local:BooleanConverter x:Key="InverseVisibilityConverter" OnTrue="Collapsed" OnFalse="Visible" OnNull="Collapsed" />
    </UserControl.Resources>
    <StackPanel VerticalAlignment="Center">
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Padding="25" Margin="0,0,0,0">
            <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" Margin="20,0" VerticalScrollBarVisibility="Auto" >
                <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                    <local:Paragraph>
                        <Run Text="General info" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                        <LineBreak />
                        <LineBreak />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Text="Operating mode" />
                            <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding CurrentMode}" FontWeight="Bold" Foreground="#FF3753A6" TextWrapping="Wrap" />
                            <TextBlock Grid.Row="1" Grid.Column="0" Text="Root Key Hash" />
                            <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=RootKeyHash, Converter={StaticResource HexConverter}, Mode=OneWay}" TextWrapping="Wrap" />
                        </Grid>
                    </local:Paragraph>
                </FlowDocument>
            </local:FlowDocumentScrollViewerNoMouseWheel>
        </Border>
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Padding="25" Margin="0,20,0,0" >
            <StackPanel Margin="20,0,20,0">
                <StackPanel Visibility="{Binding Path=TargetHasNewFlashProtocol, Converter={StaticResource InverseVisibilityConverter}}">
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" >
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <Run Text="Resources for boot restore" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                                <LineBreak />
                                <LineBreak />
                                <Run Text="You can use this function to restore the boot partitions to their original state or to repair corrupted boot partitions. If your phone currently has Root Access, then first disable Root Access before you restore the bootloader! If your bootloader is currently unlocked, the bootloader will be restored to its original state and the phone will boot normally. If you are trying to repair a corrupted bootloader, afterwards the phone will probably remain in Flash-mode. From there on, you can only flash a stock ROM. This will erase all you apps, data and settings."/>
                                <LineBreak />
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FilePicker SelectionText="Select your FFU-image..." Path="{Binding FFUPath, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" Visibility="{Binding Path=IsBootLoaderUnlocked, Converter={StaticResource InverseVisibilityConverter}}">
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <LineBreak />
                                <Run Text="You should also select a folder where you have Lumia Emergency Flash Loaders. This tool will try to select the Loader that is suitable for your phone."/>
                                <LineBreak />
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FolderPicker SelectionText="Select the folder with Lumia Emergency Flash Loaders..." Path="{Binding LoadersPath, Mode=TwoWay}" HorizontalAlignment="Stretch" Visibility="{Binding Path=IsBootLoaderUnlocked, Converter={StaticResource InverseVisibilityConverter}}"/>
                </StackPanel>
                <StackPanel Visibility="{Binding Path=TargetHasNewFlashProtocol, Converter={StaticResource VisibilityConverter}}">
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" >
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <Run Text="Restore SecureBoot" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                                <LineBreak />
                                <LineBreak />
                                <Run Text="You can use this function to restore SecureBoot to its original state. During the process of restoring SecureBoot, the phone will be switched to Mass Storage mode. After that the phone must be rebooted. You will be notified. You will need to reboot the phone manually at that stage, because it cannot be done programmatically. After you reboot the phone, the relock procedure will continue automatically."/>
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" Visibility="{Binding Path=IsProfileFfuValid, Converter={StaticResource InverseVisibilityConverter}}">
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <LineBreak />
                                <Run Text="WARNING: " FontWeight="Bold" Foreground="Red" />
                                <Run Text="No valid profile-FFU could be found. Go to the "/>
                                <Hyperlink NavigateUri="Download">download</Hyperlink>
                                <Run Text=" page in this tool and download a new FFU-file for your phone, or add an existing FFU-file to the repository."/>
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,25,0,0">
                    <Button Command="{Binding Path=OkCommand, Mode=OneWay}" Content="Continue" Width="100" Height="Auto" Padding="0,5"/>
                    <Button Command="{Binding Path=CancelCommand, Mode=OneWay}" Content="Abort" Width="100" Height="Auto" Padding="0,5" Margin="20,0,0,0" />
                </StackPanel>
            </StackPanel>
        </Border>
    </StackPanel>
</UserControl>
