2023-04-20 08:15:36 +00:00
using Avalonia.Controls ;
2023-04-23 08:15:11 +00:00
using Avalonia.Interactivity ;
using ChovySign_GUI.Popup.Global ;
using GameBuilder.Psp ;
using LibChovy ;
using LibChovy.Config ;
using System ;
using Vita.ContentManager ;
using static ChovySign_GUI . Popup . Global . MessageBox ;
2023-04-20 08:15:36 +00:00
namespace ChovySign_GUI.Psp
{
public partial class PspTab : UserControl
{
2023-04-23 08:15:11 +00:00
private void check ( )
{
this . progressStatus . IsEnabled = ( this . keySelector . IsValid & & this . isoSelector . HasUmd ) ;
}
2023-04-20 08:15:36 +00:00
public PspTab ( )
{
InitializeComponent ( ) ;
2023-04-21 06:21:21 +00:00
2023-04-23 08:15:11 +00:00
keySelector . ValidStateChanged + = onValidStateChange ;
isoSelector . UmdChanged + = onUmdChanged ;
progressStatus . BeforeStart + = onProcessStarting ;
progressStatus . Finished + = onProcessFinished ;
check ( ) ;
}
private async void onProcessFinished ( object? sender , EventArgs e )
{
keySelector . IsEnabled = true ;
isoSelector . IsEnabled = true ;
2023-04-24 11:53:22 +00:00
devkitAccount . IsEnabled = true ;
2023-04-23 08:15:11 +00:00
Window ? currentWindow = this . VisualRoot as Window ;
if ( currentWindow is not Window ) throw new Exception ( "could not find current window" ) ;
await MessageBox . Show ( currentWindow , "Finished creating PSP Game!\nCan now go restore it to your PSVita using Content Manager." , "Done!" , MessageBoxButtons . Ok ) ;
}
private void onProcessStarting ( object? sender , EventArgs e )
{
keySelector . IsEnabled = false ;
2023-04-24 11:53:22 +00:00
devkitAccount . IsEnabled = false ;
2023-04-23 08:15:11 +00:00
isoSelector . IsEnabled = false ;
if ( keySelector . Rif is null ) return ;
if ( keySelector . VersionKey is null ) return ;
NpDrmRif rifInfo = new NpDrmRif ( keySelector . Rif ) ;
NpDrmInfo drmInfo = new NpDrmInfo ( keySelector . VersionKey , rifInfo . ContentId , keySelector . KeyIndex ) ;
PspParameters pspParameters = new PspParameters ( drmInfo , rifInfo ) ;
UmdInfo ? umd = isoSelector . Umd ;
if ( umd is null ) return ;
pspParameters . Umd = umd ;
pspParameters . Compress = isoSelector . Compress ;
2023-04-24 11:53:22 +00:00
if ( devkitAccount . IsDevkitMode )
pspParameters . Account = new Account ( 0 ) ;
2023-04-23 08:15:11 +00:00
progressStatus . Parameters = pspParameters ;
}
private void onUmdChanged ( object? sender , EventArgs e )
{
check ( ) ;
}
private void onValidStateChange ( object? sender , EventArgs e )
{
check ( ) ;
2023-04-20 08:15:36 +00:00
}
}
}