<!--
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.LumiaUnlockRootTargetSelectionView"
             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:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter" />
    </UserControl.Resources>
    <StackPanel VerticalAlignment="Center">
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0,0,0,25">
            <StackPanel>
                <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" Margin="20,0,20,0" VerticalScrollBarVisibility="Auto" >
                    <FlowDocument FontFamily="Segoe UI" FontSize="12" Loaded="Document_Loaded" TextAlignment="Left">
                        <FlowDocument.Resources>
                            <!-- This style is used to set the margins for all paragraphs in the FlowDocument to 0. -->
                            <Style TargetType="{x:Type Paragraph}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                            <Style TargetType="{x:Type Section}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </FlowDocument.Resources>
                        <local:Paragraph>
                            <Run Text="Enable Root Access directly on phone" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="Before you can enable Root Access directly on the phone, you need to have Mass Storage mode " />
                            <Hyperlink NavigateUri="UnlockBoot">unlocked</Hyperlink>
                            <Run Text=" first. Make sure you don't have any Windows Phone disks or partitions mounted before you continue to Mass Storage Mode. Not all OS versions are supported. The OS version will verified after the phone is switched to Mass Storage mode." />
                            <LineBreak />
                            <LineBreak />
                            <local:CollapsibleRun Text="You have to connect your phone before you can continue." IsVisible="{Binding IsPhoneDisconnected, Mode=OneWay}"/>
                            <local:CollapsibleRun Text="When you continue, the phone will be switched to Mass Storage mode and then Root Access will be enabled." IsVisible="{Binding IsPhoneInOtherMode, Mode=OneWay}"/>
                            <local:CollapsibleRun Text="The phone is in Mass Storage mode. You can continue to enable Root Access." IsVisible="{Binding IsPhoneInMassStorage, Mode=OneWay}"/>
                        </local:Paragraph>
                    </FlowDocument>
                </local:FlowDocumentScrollViewerNoMouseWheel>
                <StackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,10,40,25">
                    <Button Command="{Binding Path=UnlockPhoneCommand, Mode=OneWay}" Content="Unlock phone" Width="120" Height="Auto" Padding="0,5" />
                </StackPanel>
            </StackPanel>
        </Border>
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center">
            <StackPanel>
                <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" Margin="20,0,20,0" VerticalScrollBarVisibility="Auto" >
                    <FlowDocument FontFamily="Segoe UI" FontSize="12" Loaded="Document_Loaded" TextAlignment="Left">
                        <FlowDocument.Resources>
                            <!-- This style is used to set the margins for all paragraphs in the FlowDocument to 0. -->
                            <Style TargetType="{x:Type Paragraph}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                            <Style TargetType="{x:Type Section}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </FlowDocument.Resources>
                        <local:Paragraph>
                            <Run Text="Enable Root Access on ROM images" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="In some cases you may want to unlock a ROM image, instead of enabling Root Access directly on the phone. For example, if you were not able to unlock Mass Storage mode on the phone, or when you want to prepare a ROM image for later use."/>
                            <LineBreak />
                            <LineBreak />
                            <Run Text="If you can't use Mass Storage on the phone, you need to "/>
                            <Hyperlink NavigateUri="Dump">dump</Hyperlink>
                            <Run Text=" the EFIESP and MainOS partitions from an FFU file. Then you need to mount the partitions with a tool like " />
                            <Hyperlink NavigateUri="http://www.osforensics.com/tools/mount-disk-images.html">OSFMount</Hyperlink>
                            <Run Text=" and use the selection fields below to browse to the mounted partitions. After the images are unlocked you need to unmount them and then " />
                            <Hyperlink NavigateUri="Flash">flash</Hyperlink>
                            <Run Text=" the unlocked images to the phone. Unlocking the EFIESP partition is something you typically need to do only once. Note that the EFIESP partition contains model-specific data for your phone! So you need to make sure that you dump EFIESP partition from an FFU file that is meant specifically for your phone." />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="WARNING: " Foreground="Red" FontWeight="Bold"/>
                            <Run Text="Due to the complexity of SecureBoot Hack v2, unlocking mounted ROM images is only possible for Lumia's with bootloader Spec A. For Lumia's with bootloader Spec B you can create Custom ROM's with Root Access using the &quot;Build and capture&quot; technique, as described on the " />
                            <Hyperlink NavigateUri="GettingStarted">Getting started</Hyperlink>
                            <Run Text=" page." />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="Select the mount-points of the partitions you wish to unlock:" />
                            <LineBreak />
                            <LineBreak />
                            <local:FolderPicker Caption="EFIESP: " SelectionText="Select the drive where the EFIESP partition is mounted..." Path="{Binding EFIESPMountPoint, Mode=TwoWay}" AllowNull="True" HorizontalAlignment="Stretch" PathChanged="FolderPicker_PathChanged"/>
                            <LineBreak />
                            <LineBreak />
                            <local:FolderPicker Caption="MainOS: " SelectionText="Select the drive where the MainOS partition is mounted..." Path="{Binding MainOSMountPoint, Mode=TwoWay}" AllowNull="True" HorizontalAlignment="Stretch" PathChanged="FolderPicker_PathChanged"/>
                        </local:Paragraph>
                    </FlowDocument>
                </local:FlowDocumentScrollViewerNoMouseWheel>
                <StackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,10,40,25">
                    <Button Command="{Binding Path=UnlockImageCommand, Mode=OneWay}" Content="Unlock images" Width="120" Height="Auto" Padding="0,5" />
                </StackPanel>
            </StackPanel>
        </Border>
    </StackPanel>
</UserControl>
