<!--
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.FlashRomView"
             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,20">
            <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="Flash Custom ROM" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="A Custom ROM typically contains an unlocked EFIESP partition and an uninitialized MainOS partition and Data partition. If you have a phone with a Bootloader Spec B, you can flash the Custom ROM straight to the phone. If you have a phone with Bootloader Spec A, your bootloader needs to be "/>
                            <Hyperlink NavigateUri="UnlockBoot">unlocked</Hyperlink>
                            <Run Text=" before you can flash a Custom ROM or restore a backup. You don't need to have an Engineering bootloader to use this flash-method. A Custom ROM can be created based on a "/>
                            <Hyperlink NavigateUri="Backup">backup</Hyperlink>
                            <Run Text=" of a live phone, or you can "/>
                            <Hyperlink NavigateUri="Dump">dump</Hyperlink>
                            <Run Text=" these partitions from an original FFU file, which can then be customized. After a Custom ROM is flashed, all apps, data and settings are be removed from the phone! " />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="NOTE: " FontWeight="Bold"/>
                            <Run Text=" Flashing a Custom ROM usually takes a lot of time, especially on phones with Bootloader Spec B! Be sure that the battery of your phone is properly charged before you start flashing a Custom ROM."/>
                            <LineBreak />
                            <LineBreak />
                            <local:FilePicker Caption="Custom ROM or backup image: " SelectionText="Select the source-file to flash to the phone..." Path="{Binding ArchivePath, Mode=TwoWay}" AllowNull="True" HorizontalAlignment="Stretch" PathChanged="FilePicker_PathChanged"/>
                            <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 Flash mode and then the Custom ROM will be flashed." IsVisible="{Binding IsPhoneInOtherMode, Mode=OneWay}"/>
                            <local:CollapsibleRun Text="The phone is in Flash mode. You can continue to flash the Custom ROM." IsVisible="{Binding IsPhoneInFlashMode, 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=FlashArchiveCommand, Mode=OneWay}" Content="Flash custom ROM" Width="120" Height="Auto" Padding="0,5" />
                </StackPanel>
            </StackPanel>
        </Border>
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0,0,0,20">
            <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="Flash original FFU" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="When you flash an original FFU, the phone will be restored to its original configuration. All unlocks, apps and data will be removed from the phone!"/>
                            <LineBreak />
                            <LineBreak />
                            <local:FilePicker Caption="FFU: " SelectionText="Select the FFU-file to flash to the phone..." Path="{Binding FFUPath, Mode=TwoWay}" AllowNull="True" HorizontalAlignment="Stretch" PathChanged="FilePicker_PathChanged"/>
                            <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 Flash mode and then the FFU image will be flashed." IsVisible="{Binding IsPhoneInOtherMode, Mode=OneWay}"/>
                            <local:CollapsibleRun Text="The phone is in Flash mode. You can continue to flash the FFU image." IsVisible="{Binding IsPhoneInFlashMode, 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=FlashFFUCommand, Mode=OneWay}" Content="Flash FFU image" Width="120" Height="Auto" Padding="0,5" />
                </StackPanel>
            </StackPanel>
        </Border>
        <Border BorderThickness="1" BorderBrush="#FFD4D4D4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0,0,0,0">
            <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="Flash separate partitions" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                            <LineBreak />
                            <LineBreak />
                            <Run Text="To flash separate partitions, your bootloader needs to be "/>
                            <Hyperlink NavigateUri="UnlockBoot">unlocked</Hyperlink>
                            <Run Text=". You can flash an " />
                            <Hyperlink NavigateUri="UnlockRoot">unlocked</Hyperlink>
                            <Run Text=" EFIESP partition, which you typically need to do only once. Make sure you flash an EFIESP partition for exact model of the phone because this partition contains model-specific information. After that you can flash an " />
                            <Hyperlink NavigateUri="UnlockRoot">unlocked</Hyperlink>
                            <Run Text=" MainOS partition or custom ROM as often as you want. Remember that the MainOS partition and Data partition are tied together, so you need to flash both partitions together. When these partitions are flashed, all apps, data and settings are removed from the phone!" />
                            <LineBreak />
                            <LineBreak />
                            <local:FilePicker Caption="EFIESP: " SelectionText="Select the source-file to flash to the EFIESP partition..." Path="{Binding EFIESPPath, Mode=TwoWay}" AllowNull="True" DefaultFileName="EFIESP.bin" HorizontalAlignment="Stretch" PathChanged="FilePicker_PathChanged"/>
                            <LineBreak />
                            <LineBreak />
                            <local:FilePicker Caption="MainOS: " SelectionText="Select the source-file to flash to the MainOS partition..." Path="{Binding MainOSPath, Mode=TwoWay}" AllowNull="True" DefaultFileName="MainOS.bin" HorizontalAlignment="Stretch" PathChanged="FilePicker_PathChanged"/>
                            <LineBreak />
                            <LineBreak />
                            <local:FilePicker Caption="Data: " SelectionText="Select the source-file to flash to the Data partition..." Path="{Binding DataPath, Mode=TwoWay}" AllowNull="True" DefaultFileName="Data.bin" HorizontalAlignment="Stretch" PathChanged="FilePicker_PathChanged"/>
                            <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 Flash mode and then the selected partitions will be flashed." IsVisible="{Binding IsPhoneInOtherMode, Mode=OneWay}"/>
                            <local:CollapsibleRun Text="The phone is in Flash mode. You can continue to flash selected partitions." IsVisible="{Binding IsPhoneInFlashMode, 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=FlashPartitionsCommand, Mode=OneWay}" Content="Flash partitions" Width="120" Height="Auto" Padding="0,5" />
                </StackPanel>
            </StackPanel>
        </Border>
    </StackPanel>
</UserControl>
