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 ;
2023-05-01 17:52:34 +00:00
using ChovySign_GUI.Settings ;
2023-04-23 08:15:11 +00:00
using GameBuilder.Psp ;
using LibChovy ;
using LibChovy.Config ;
using System ;
2023-04-26 00:08:47 +00:00
using System.Media ;
2023-05-01 17:52:34 +00:00
using System.Runtime.CompilerServices ;
2023-04-26 00:08:47 +00:00
using System.Threading.Tasks ;
2023-04-23 08:15:11 +00:00
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 ( ) ;
}
2023-04-26 00:08:47 +00:00
2023-04-23 08:15:11 +00:00
private async void onProcessFinished ( object? sender , EventArgs e )
{
keySelector . IsEnabled = true ;
isoSelector . IsEnabled = true ;
2023-06-09 09:06:44 +00:00
SettingsTab . Settings . 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" ) ;
2023-04-26 00:08:47 +00:00
_ = App . PlayFinishSound ( ) ;
2023-04-23 08:15:11 +00:00
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 ;
isoSelector . IsEnabled = false ;
2023-05-01 17:52:34 +00:00
SettingsTab . Settings . IsEnabled = false ;
2023-04-23 08:15:11 +00:00
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-05-01 17:52:34 +00:00
// read settings from settings tab.
if ( SettingsTab . Settings . DevkitMode ) pspParameters . Account = new Account ( 0 ) ;
SettingsReader . BackupsFolder = SettingsTab . Settings . CmaDirectory ;
2023-04-24 11:53:22 +00:00
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
}
}
}