2010-01-12 18:03:46 +01:00
/ * This file is part of CustomizeMii
* Copyright ( C ) 2009 Leathl
*
* CustomizeMii is free software : you can redistribute it and / or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* CustomizeMii is distributed in the hope that it will be
* useful , but WITHOUT ANY WARRANTY ; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
using System ;
2010-01-08 23:10:02 +01:00
using System.ComponentModel ;
using System.IO ;
using System.Windows.Forms ;
using System.Collections.Generic ;
2010-03-28 20:29:30 +02:00
using libWiiSharp ;
2010-01-08 23:10:02 +01:00
namespace CustomizeMii
{
partial class CustomizeMii_Main
{
private void CustomizeMii_Main_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) & & pbProgress . Value = = 100 )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data . Length = = 1 & & data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) )
e . Effect = DragDropEffects . Copy ;
}
}
private void CustomizeMii_Main_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data . Length = = 1 & & data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) )
{
2010-03-28 20:29:30 +02:00
loadChannel ( data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
}
}
private void tbReplace_DragEnter ( object sender , DragEventArgs e )
{
if ( ! string . IsNullOrEmpty ( tbSourceWad . Text ) )
{
if ( pbProgress . Value = = 100 & & e . Data . GetDataPresent ( DataFormats . FileDrop ) )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data . Length = = 1 )
{
if ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( "00000000.app" ) )
e . Effect = DragDropEffects . Copy ;
else if ( ( cmbReplace . SelectedIndex = = 2 & & data [ 0 ] . ToLower ( ) . EndsWith ( "sound.bin" ) ) | |
( cmbReplace . SelectedIndex = = 1 & & data [ 0 ] . ToLower ( ) . EndsWith ( "icon.bin" ) ) | |
( cmbReplace . SelectedIndex = = 0 & & data [ 0 ] . ToLower ( ) . EndsWith ( "banner.bin" ) ) )
e . Effect = DragDropEffects . Copy ;
}
}
}
}
private void tbReplace_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data . Length = = 1 & & ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( "00000000.app" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( "sound.bin" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( "icon.bin" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( "banner.bin" ) ) )
{
2010-03-28 20:29:30 +02:00
replacePart ( data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
}
}
private void tbDol_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) & & pbProgress . Value = = 100 )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data . Length = = 1 & & ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) | | data [ 0 ] . ToLower ( ) . EndsWith ( ".dol" ) ) )
e . Effect = DragDropEffects . Copy ;
}
}
private void tbDol_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wad" ) )
{
try
{
2010-03-28 20:29:30 +02:00
WAD tmpWad = WAD . Load ( data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
2010-03-28 20:29:30 +02:00
if ( tmpWad . NumOfContents = = 3 )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
int appIndex = 0 ;
if ( tmpWad . BootIndex = = 1 ) appIndex = 2 ;
else if ( tmpWad . BootIndex = = 2 ) appIndex = 1 ;
2010-01-08 23:10:02 +01:00
2010-03-28 20:29:30 +02:00
if ( appIndex > 0 )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
newDol = tmpWad . Contents [ appIndex ] ;
setControlText ( tbDol , data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
btnBrowseDol . Text = "Clear" ;
}
2010-03-28 20:29:30 +02:00
else errorBox ( "The DOL file couldn't be found!" ) ;
2010-01-08 23:10:02 +01:00
}
2010-03-28 20:29:30 +02:00
else errorBox ( "The DOL file couldn't be found!" ) ;
2010-01-08 23:10:02 +01:00
}
catch ( Exception ex )
{
2010-03-28 20:29:30 +02:00
setControlText ( tbDol , string . Empty ) ;
btnBrowseDol . Text = "Browse..." ;
errorBox ( ex . Message ) ;
2010-01-08 23:10:02 +01:00
}
}
else if ( data [ 0 ] . ToLower ( ) . EndsWith ( ".dol" ) )
{
2010-03-28 20:29:30 +02:00
newDol = File . ReadAllBytes ( data [ 0 ] ) ;
setControlText ( tbDol , data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
btnBrowseDol . Text = "Clear" ;
}
}
private void tbSound_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) & & pbProgress . Value = = 100 )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
2010-03-28 20:29:30 +02:00
if ( File . Exists ( Application . StartupPath + Path . DirectorySeparatorChar + "lame.exe" ) )
2010-01-08 23:10:02 +01:00
{
if ( data . Length = = 1 & & ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wav" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".bns" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".mp3" ) ) )
e . Effect = DragDropEffects . Copy ;
}
else
{
if ( data . Length = = 1 & & ( data [ 0 ] . ToLower ( ) . EndsWith ( ".wav" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".bns" ) ) )
e . Effect = DragDropEffects . Copy ;
}
}
}
private void tbSound_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( data [ 0 ] . ToLower ( ) . EndsWith ( ".mp3" ) )
{
2010-03-28 20:29:30 +02:00
convertMp3ToWave ( data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
}
else
{
2010-03-28 20:29:30 +02:00
replacedSound = data [ 0 ] ;
setControlText ( tbSound , data [ 0 ] ) ;
2010-01-08 23:10:02 +01:00
btnBrowseSound . Text = "Clear" ;
2010-03-28 20:29:30 +02:00
newSoundBin = Headers . IMD5 . AddHeader ( File . ReadAllBytes ( data [ 0 ] ) ) ;
if ( cmbReplace . SelectedIndex = = 2 ) setControlText ( tbReplace , string . Empty ) ;
2010-01-08 23:10:02 +01:00
}
}
private void lbxBannerTpls_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) & & pbProgress . Value = = 100 )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
bool correct = true ;
for ( int i = 0 ; i < data . Length ; i + + )
if ( ! ( data [ 0 ] . ToLower ( ) . EndsWith ( ".tpl" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".png" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".jpg" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".gif" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".bmp" ) ) )
correct = false ;
if ( correct ) e . Effect = DragDropEffects . Copy ;
}
}
private void lbxBannerTpls_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
List < string > errors = new List < string > ( ) ;
foreach ( string thisFile in data )
{
try
{
2010-03-28 20:29:30 +02:00
addTpl ( lbxBannerTpls , thisFile ) ;
2010-01-08 23:10:02 +01:00
}
catch { errors . Add ( thisFile ) ; }
}
if ( errors . Count > 0 )
{
2010-03-28 20:29:30 +02:00
errorBox ( string . Format ( "These files were not added, because either they already exist or an error occured during conversion:\n\n{0}" , string . Join ( "\n" , ( errors . ToArray ( ) ) ) ) ) ;
2010-01-08 23:10:02 +01:00
}
}
private void lbxIconTpls_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) & & pbProgress . Value = = 100 )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
bool correct = true ;
for ( int i = 0 ; i < data . Length ; i + + )
if ( ! ( data [ 0 ] . ToLower ( ) . EndsWith ( ".tpl" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".png" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".jpg" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".gif" ) | |
data [ 0 ] . ToLower ( ) . EndsWith ( ".bmp" ) ) )
correct = false ;
if ( correct ) e . Effect = DragDropEffects . Copy ;
}
}
private void lbxIconTpls_DragDrop ( object sender , DragEventArgs e )
{
string [ ] data = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
List < string > errors = new List < string > ( ) ;
foreach ( string thisFile in data )
{
try
{
2010-03-28 20:29:30 +02:00
addTpl ( lbxIconTpls , thisFile ) ;
2010-01-08 23:10:02 +01:00
}
catch { errors . Add ( thisFile ) ; }
}
if ( errors . Count > 0 )
{
2010-03-28 20:29:30 +02:00
errorBox ( string . Format ( "These files were not added, because either they already exist or an error occured during conversion:\n\n{0}" , string . Join ( "\n" , ( errors . ToArray ( ) ) ) ) ) ;
2010-01-08 23:10:02 +01:00
}
}
}
}