<!--
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.FlashResourcesView"
             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="SecureBoot Unlock V1" FontSize="18" FontWeight="Bold" Foreground="#FF3753A6" />
                                <LineBreak />
                                <LineBreak />
                                <Run Text="When you unlock the bootloader, Windows Phone Internals will also need an original FFU file for this phone, to extract some data from it. If you don't have an FFU-image for your phone yet, you can "/>
                                <Hyperlink NavigateUri="Download">
                                    <Run Text="download"/>
                                </Hyperlink>
                                <Run Text=" it."/>
                                <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}}"/>
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" >
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <LineBreak />
                                <Run Text="You can optionally select an image that contains the SBL3 partition of an engineering phone. This is for the purpose of unlocking Mass Storage Mode. This mode is not implemented in the retail versions of the SBL3 partition. You can select an " />
                                <Hyperlink NavigateUri="https://www.google.com/search?safe=off&amp;q=%22Lumia%22+%22Engineering+ROM%22&amp;oq=%22Lumia%22+%22Engineering+ROM%22">FFU-image</Hyperlink>
                                <Run Text=" or raw-image. This tool will try to extract the partition. SBL3 also contains hardware-profiles. So it is not possible to exchange SBL3 partitions from different CPU's or OEM's! Verify that the SBL3 you select was originally meant for a phone from the same OEM and it has the same CPU as your target device! Flashing a wrong SBL3 will harm your phone!" />
                                <LineBreak />
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FilePicker SelectionText="Optionally select an FFU-image or raw image with an Engineering SBL3 partition..." AllowNull="True" Path="{Binding SBL3Path, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                </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 Foreground="#FF3753A6" FontWeight="Bold" FontSize="18" Text="SecureBoot Unlock V2"/>
                                <LineBreak/>
                                <LineBreak/>
                                <Run Text="To unlock this phone you need Windows Phone Internals SecureBoot Unlock V2. To flash this to the phone Windows Phone Internals needs to have a &quot;Flashing Profile&quot;. If you unlock or flash this phone for the first time, Windows Phone Internals will try to find the flashing profile. During this phase your phone will start to reboot a couple of times. This may look weird, but it is expected behavior. When a flashing profile is found, it is saved. After that Windows Phone Internals will flash an unlocked bootloader." />
                                <LineBreak/>
                                <LineBreak/>
                                <Run Text="Warning: " Foreground="Red" FontWeight="Bold"/>
                                <Run Text="While looking for a Flashing Profile, the phone will be rebooted through different modes. The phone will also enter Emergency Download Mode. Windows Phone Internals will use the Emergency Programmer to run faster through the process. If you haven't downloaded the Emergency Programmer for target phone yet, you can still do so by going to the " />
                                <Hyperlink NavigateUri="Download">
                                    <Run Text="download-section"/>
                                </Hyperlink>
                                <Run Text=". Emergency Programmers are available for most Lumia-models. If you don't have an Emergency Programmer for the phone and you still choose to continue, the phone may pause for up to 30 seconds between reboots. Some phone models may not even reboot at all without an Emergency Programmer. In this case you need to manually reboot the phone, when it hangs after an attempt to find the Flashing Profile. Reboot the phone by pressing and holding the power-button until the phone vibrates."/>
                                <LineBreak/>
                                <LineBreak/>
                                <Run Text="Warning: " Foreground="Red" FontWeight="Bold"/>
                                <Run Text="Some Windows 10 based phones need additional modifications to be able to boot properly after the bootloader is unlocked. The patches will be applied automatically if the OS on the phone is on a supported version. In case the phone doesn't boot properly, you can still enter Mass Storage Mode if you want. To boot properly again, restore the bootloader. You can update to a supported OS version and try again after that." />
                                <LineBreak/>
                                <LineBreak/>
                                <Run Text="Warning: " Foreground="Red" FontWeight="Bold"/>
                                <Run Text="The unlock sequence for Lumia's with bootloader spec B depends on a certain &quot;Boot order&quot;. Right after a Full Flash or right after you relocked a phone, this boot order is different. When you flash an FFU, you can interrupt the boot immediately, before it has completed its first boot. If you would then try to unlock the bootloader, this will fail halfway. This problem will be detected and the changes will be rolled back. A simple reboot will solve the problem; the boot order is restored. After that you can start the unlock sequence again." />
                                <LineBreak />
                                <LineBreak />
                                <Run Text="When you perform a &quot;Custom Flash&quot; Windows Phone Internals will also need an original FFU file for this phone, to extract some profiling information from it. If you don't have an FFU-image for your phone yet, you can "/>
                                <Hyperlink NavigateUri="Download">
                                    <Run Text="download"/>
                                </Hyperlink>
                                <Run Text=" it."/>
                                <LineBreak/>
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FilePicker SelectionText="Select your FFU-image for profiling..." Path="{Binding ProfileFFUPath, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                    <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" >
                        <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1">
                            <local:Paragraph TextAlignment="Left">
                                <LineBreak />
                                <Run Text="You will also need an emergency programmer for your phone."/>
                                <LineBreak />
                            </local:Paragraph>
                        </FlowDocument>
                    </local:FlowDocumentScrollViewerNoMouseWheel>
                    <local:FilePicker SelectionText="Select the EDE-file for your phone..." Path="{Binding EDEPath, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                    <StackPanel Visibility="{Binding Path=IsSupportedFfuNeeded, 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">
                                    <LineBreak />
                                    <Run Text="The FFU-image you selected for profiling does not have a supported OS-version. Windows Phone Internals needs to extract files from a supported OS-version. You need to select such donor-FFU. If necessary, you can select an FFU-image for a different model." />
                                    <LineBreak />
                                </local:Paragraph>
                            </FlowDocument>
                        </local:FlowDocumentScrollViewerNoMouseWheel>
                        <local:FilePicker SelectionText="Select an FFU-image with supported OS-version..." AllowNull="False" Path="{Binding SupportedFFUPath, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                        <local:FlowDocumentScrollViewerNoMouseWheel Grid.Column="1" VerticalScrollBarVisibility="Auto" Visibility="{Binding Path=IsSupportedFfuValid, Converter={StaticResource InverseVisibilityConverter}}">
                            <FlowDocument Loaded="Document_Loaded" FontFamily="Segoe UI" FontSize="12" PagePadding="1" FontWeight="Bold" Foreground="Red">
                                <local:Paragraph TextAlignment="Left">
                                    <LineBreak />
                                    <Run Text="The OS version of the selected FFU is not supported. Select a donor-FFU with a supported OS version." />
                                </local:Paragraph>
                            </FlowDocument>
                        </local:FlowDocumentScrollViewerNoMouseWheel>
                    </StackPanel>
                </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="Unlock" 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>
