2020-03-01 15:52:59 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Data ;
using System.Windows.Documents ;
using System.Windows.Input ;
using System.Windows.Media ;
using System.Windows.Media.Imaging ;
using System.Windows.Navigation ;
using System.Windows.Shapes ;
2020-03-13 22:35:20 +00:00
2020-03-08 22:25:34 +00:00
using UWUVCI_AIO_WPF.Classes ;
2020-03-13 22:35:20 +00:00
using GameBaseClassLibrary ;
2020-04-06 17:50:12 +00:00
using System.Windows.Forms ;
using System.IO ;
2020-04-17 16:02:45 +00:00
using UWUVCI_AIO_WPF.UI.Windows ;
2020-04-20 09:31:26 +00:00
using Microsoft.WindowsAPICodePack.Dialogs ;
2020-03-01 15:52:59 +00:00
2020-03-02 17:44:01 +00:00
namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Bases
2020-03-01 15:52:59 +00:00
{
/// <summary>
2020-03-02 17:44:01 +00:00
/// Interaktionslogik für CustomBaseFrame.xaml
2020-03-01 15:52:59 +00:00
/// </summary>
2020-03-02 17:44:01 +00:00
public partial class CustomBaseFrame : Page
2020-03-01 15:52:59 +00:00
{
2020-03-13 22:35:20 +00:00
GameConsoles console ;
2020-03-08 22:25:34 +00:00
GameBases bases ;
bool existing ;
MainViewModel mvm ;
2020-03-13 22:35:20 +00:00
public CustomBaseFrame ( GameBases Base , GameConsoles console , bool existing )
2020-03-01 15:52:59 +00:00
{
InitializeComponent ( ) ;
2020-04-06 17:50:12 +00:00
tbCode . Text = "Code Folder not found" ;
tbCode . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbContent . Text = "Content Folder not found" ;
tbContent . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbMeta . Text = "Meta Folder not found" ;
tbMeta . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
2020-03-08 22:25:34 +00:00
mvm = ( MainViewModel ) FindResource ( "mvm" ) ;
bases = Base ;
2020-04-20 00:35:31 +00:00
mvm . isCkeySet ( ) ;
2020-03-08 22:25:34 +00:00
this . existing = existing ;
this . console = console ;
2020-04-06 17:50:12 +00:00
mvm . SetCBASE ( this ) ;
2020-04-19 17:36:03 +00:00
if ( mvm . Ckeys )
{
CK . Visibility = Visibility . Hidden ;
2020-04-20 00:35:31 +00:00
path . IsEnabled = true ;
2020-04-19 17:36:03 +00:00
}
2020-03-08 22:25:34 +00:00
}
2020-04-06 19:30:31 +00:00
2020-04-06 15:51:15 +00:00
2020-03-08 22:25:34 +00:00
private void Button_Click ( object sender , RoutedEventArgs e )
{
2020-04-06 17:50:12 +00:00
tbCode . Text = "Code Folder not found" ;
tbCode . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbContent . Text = "Content Folder not found" ;
tbContent . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbMeta . Text = "Meta Folder not found" ;
tbMeta . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
mvm . BaseDownloaded = false ;
2020-04-06 19:30:31 +00:00
mvm . CBasePath = null ;
2020-04-18 03:31:36 +00:00
//warning if using custom bases program may crash
2020-04-30 15:01:41 +00:00
Custom_Message cm = new Custom_Message ( "Information" , "If using Custom Bases there will be a chance that the program crashes if adding a wrong base (example: a normal wiiu game instead of a nds vc game).\nA custom base is containing either the code/content/meta folders or Installable files (*.h3, *.app, ...)\nIf you add a wrong base, we will not assist you fixing it, other than telling you to use another base.\nIf you agree to this please hit continue" ) ;
try {
cm . Owner = mvm . mw ;
}
catch ( Exception )
{
}
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
if ( mvm . choosefolder )
{
mvm . choosefolder = false ; //get folder
2020-04-20 09:31:26 +00:00
using ( var dialog = new CommonOpenFileDialog ( ) )
2020-04-06 17:50:12 +00:00
{
2020-04-20 09:31:26 +00:00
dialog . IsFolderPicker = true ;
CommonFileDialogResult result = dialog . ShowDialog ( ) ;
if ( result = = CommonFileDialogResult . Ok )
2020-04-06 17:50:12 +00:00
{
try
{
2020-04-20 09:31:26 +00:00
if ( mvm . DirectoryIsEmpty ( dialog . FileName ) )
2020-04-06 17:50:12 +00:00
{
2020-05-06 21:53:52 +00:00
Custom_Message cm1 = new Custom_Message ( "Issue" , "The Folder is Empty. Please choose another Folder." ) ;
try
{
cm . Owner = mvm . mw ;
}
2020-06-11 08:12:03 +00:00
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm1 . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-06 17:50:12 +00:00
}
else
{
2020-04-20 09:31:26 +00:00
if ( Directory . GetDirectories ( dialog . FileName ) . Length > 3 )
2020-04-06 17:50:12 +00:00
{
2020-05-06 21:53:52 +00:00
Custom_Message cm1 = new Custom_Message ( "Issue" , "This Folder has too many subfolders. Please choose another folder" ) ;
try
{
cm . Owner = mvm . mw ;
}
2020-06-11 08:12:03 +00:00
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm1 . ShowDialog ( ) ;
2020-04-06 17:50:12 +00:00
}
else
{
2020-04-20 09:31:26 +00:00
if ( Directory . GetDirectories ( dialog . FileName ) . Length > 0 )
2020-04-06 17:50:12 +00:00
{
//Code Content Meta
2020-04-20 09:31:26 +00:00
if ( Directory . Exists ( System . IO . Path . Combine ( dialog . FileName , "content" ) ) & & Directory . Exists ( System . IO . Path . Combine ( dialog . FileName , "code" ) ) & & Directory . Exists ( System . IO . Path . Combine ( dialog . FileName , "meta" ) ) )
2020-04-06 17:50:12 +00:00
{
//create new Game Config
mvm . GameConfiguration . Console = console ;
2020-04-20 09:31:26 +00:00
mvm . GameConfiguration . CBasePath = dialog . FileName ;
2020-04-06 17:50:12 +00:00
GameBases gb = new GameBases ( ) ;
gb . Name = "Custom" ;
gb . Region = Regions . EU ;
gb . Path = mvm . GameConfiguration . CBasePath ;
2020-04-20 00:35:31 +00:00
bar . Text = gb . Path ;
2020-04-06 17:50:12 +00:00
mvm . GameConfiguration . BaseRom = gb ;
tbCode . Text = "Code Folder exists" ;
tbCode . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
tbContent . Text = "Content Folder exists" ;
tbContent . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
tbMeta . Text = "Meta Folder exists" ;
tbMeta . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
mvm . BaseDownloaded = true ;
}
else
{
2020-05-06 21:53:52 +00:00
Custom_Message cm1 = new Custom_Message ( "Issue" , "This folder is not in the \"loadiine\" format" ) ;
try
{
cm . Owner = mvm . mw ;
}
2020-06-11 08:12:03 +00:00
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm1 . ShowDialog ( ) ;
2020-04-06 17:50:12 +00:00
}
}
else
{
//WUP
2020-04-20 09:31:26 +00:00
if ( Directory . GetFiles ( dialog . FileName , "*.app" ) . Length > 0 & & Directory . GetFiles ( dialog . FileName , "*.h3" ) . Length > 0 & & File . Exists ( System . IO . Path . Combine ( dialog . FileName , "title.tmd" ) ) & & File . Exists ( System . IO . Path . Combine ( dialog . FileName , "title.tik" ) ) )
2020-04-06 17:50:12 +00:00
{
if ( mvm . CBaseConvertInfo ( ) )
{
//Convert to LOADIINE => save under bases/custom or custom_x path => create new config
2020-04-20 09:31:26 +00:00
string path = Injection . ExtractBase ( dialog . FileName , console ) ;
2020-04-06 17:50:12 +00:00
mvm . GameConfiguration = new GameConfig ( ) ;
mvm . GameConfiguration . Console = console ;
mvm . GameConfiguration . CBasePath = path ;
GameBases gb = new GameBases ( ) ;
gb . Name = "Custom" ;
gb . Region = Regions . EU ;
gb . Path = mvm . GameConfiguration . CBasePath ;
2020-04-06 19:30:31 +00:00
mvm . CBasePath = mvm . GameConfiguration . CBasePath ;
2020-04-06 17:50:12 +00:00
mvm . GameConfiguration . BaseRom = gb ;
tbCode . Text = "Code Folder exists" ;
tbCode . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
tbContent . Text = "Content Folder exists" ;
tbContent . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
tbMeta . Text = "Meta Folder exists" ;
tbMeta . Foreground = new SolidColorBrush ( Color . FromRgb ( 50 , 205 , 50 ) ) ;
mvm . BaseDownloaded = true ;
}
}
else
{
2020-05-06 21:53:52 +00:00
Custom_Message cm1 = new Custom_Message ( "Issue" , "This Folder does not contain needed NUS files" ) ;
try
{
cm . Owner = mvm . mw ;
}
2020-06-11 08:12:03 +00:00
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm1 . ShowDialog ( ) ;
2020-04-06 17:50:12 +00:00
}
}
}
}
}
catch ( Exception )
{
}
}
}
}
}
public void Reset ( )
{
tbCode . Text = "Code Folder not found" ;
tbCode . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbContent . Text = "Content Folder not found" ;
tbContent . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
tbMeta . Text = "Meta Folder not found" ;
tbMeta . Foreground = new SolidColorBrush ( Color . FromRgb ( 205 , 50 , 50 ) ) ;
mvm = ( MainViewModel ) FindResource ( "mvm" ) ;
2020-03-01 15:52:59 +00:00
}
2020-04-19 17:36:03 +00:00
private void CK_Click ( object sender , RoutedEventArgs e )
{
mvm . EnterKey ( true ) ;
if ( mvm . Ckeys )
{
CK . Visibility = Visibility . Hidden ;
path . IsEnabled = true ;
}
}
2020-03-01 15:52:59 +00:00
}
}