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-18 21:13:32 +01:00
using System.Collections.Generic ;
2010-01-08 23:10:02 +01:00
using System.ComponentModel ;
using System.Drawing ;
2010-01-18 21:13:32 +01:00
using System.IO ;
using System.Text.RegularExpressions ;
using System.Windows.Forms ;
2010-03-28 20:29:30 +02:00
using libWiiSharp ;
2010-01-08 23:10:02 +01:00
namespace CustomizeMii
{
partial class CustomizeMii_Main
{
2010-03-28 20:29:30 +02:00
private Forwarder . Simple simpleForwarder = new Forwarder . Simple ( ) ;
private Forwarder . Complex complexForwarder = new Forwarder . Complex ( ) ;
private delegate void messageInvoker ( string message ) ;
private delegate void controlTextInvoker ( Control ctrl , string text ) ;
2010-02-24 22:41:37 +01:00
2010-03-28 20:29:30 +02:00
private bool securityChecks ( )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
if ( cbSecurityChecksOff . Checked ) return true ;
2010-01-18 21:13:32 +01:00
try
{
//Check Channel Title Boxes
if ( ! ( ! string . IsNullOrEmpty ( tbAllLanguages . Text ) | |
( ! string . IsNullOrEmpty ( tbEnglish . Text ) & &
! string . IsNullOrEmpty ( tbJapanese . Text ) & &
! string . IsNullOrEmpty ( tbGerman . Text ) & &
! string . IsNullOrEmpty ( tbFrench . Text ) & &
! string . IsNullOrEmpty ( tbSpanish . Text ) & &
! string . IsNullOrEmpty ( tbItalian . Text ) & &
! string . IsNullOrEmpty ( tbDutch . Text ) ) ) )
{
2010-03-28 20:29:30 +02:00
errorBox ( "You must either enter a general Channel Title or one for each language!" ) ;
2010-01-18 21:13:32 +01:00
return false ;
}
//Check Title ID Length + Chars
if ( tbTitleID . Text . Length ! = 4 )
2010-03-28 20:29:30 +02:00
{ errorBox ( "The Title ID must be 4 characters long!" ) ; return false ; }
2010-01-18 21:13:32 +01:00
Regex allowedchars = new Regex ( "[A-Z0-9]{4}$" ) ;
if ( ! allowedchars . IsMatch ( tbTitleID . Text . ToUpper ( ) ) )
2010-03-28 20:29:30 +02:00
{ errorBox ( "Please enter a valid Title ID!" ) ; return false ; }
2010-01-18 21:13:32 +01:00
2010-03-28 20:29:30 +02:00
//Check Startup IOS Box
2010-02-24 22:41:37 +01:00
int tmp ;
if ( ! int . TryParse ( tbStartupIos . Text , out tmp ) )
2010-03-28 20:29:30 +02:00
{ errorBox ( "Please enter a valid Startup IOS! (0 - 255)" ) ; return false ; }
2010-02-24 22:41:37 +01:00
else if ( tmp < 0 | | tmp > 255 )
2010-03-28 20:29:30 +02:00
{ errorBox ( "Please enter a valid Startup IOS! (0 - 255)" ) ; return false ; }
2010-02-24 22:41:37 +01:00
2010-01-18 21:13:32 +01:00
//Check brlan files
2010-03-28 20:29:30 +02:00
string [ ] validBrlans = new string [ ] { "banner.brlan" , "icon.brlan" , "banner_loop.brlan" , "banner_start.brlan" } ;
2010-01-18 21:13:32 +01:00
foreach ( string thisBrlan in lbxBrlanBanner . Items )
{
2010-03-28 20:29:30 +02:00
if ( ! Array . Exists ( validBrlans , brlanName = > brlanName . ToLower ( ) = = thisBrlan . ToLower ( ) ) )
{ errorBox ( thisBrlan + " is not a valid brlan filename!" ) ; return false ; }
2010-01-18 21:13:32 +01:00
}
foreach ( string thisBrlan in lbxBrlanIcon . Items )
{
2010-03-28 20:29:30 +02:00
if ( ! Array . Exists ( validBrlans , brlanName = > brlanName . ToLower ( ) = = thisBrlan . ToLower ( ) ) )
{ errorBox ( thisBrlan + " is not a valid brlan filename!" ) ; return false ; }
2010-01-18 21:13:32 +01:00
}
//Check TPLs
2010-03-28 20:29:30 +02:00
string [ ] bannerRequiredTpls = new string [ 0 ] ;
string [ ] iconRequiredTpls = new string [ 0 ] ;
List < string > bannerTpls = new List < string > ( ) ;
List < string > iconTpls = new List < string > ( ) ;
2010-01-18 21:13:32 +01:00
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedBanner ) )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
{
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ bannerRequiredTpls = Shared . MergeStringArrays ( bannerRequiredTpls , Brlyt . GetBrlytTpls ( bannerBin . Data [ i ] ) ) ; }
else if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ bannerRequiredTpls = Shared . MergeStringArrays ( bannerRequiredTpls , Brlan . GetBrlanTpls ( bannerBin . Data [ i ] ) ) ; }
else if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{ bannerTpls . Add ( bannerBin . StringTable [ i ] ) ; }
}
2010-01-18 21:13:32 +01:00
}
else
{
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
{
if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ bannerRequiredTpls = Shared . MergeStringArrays ( bannerRequiredTpls , Brlyt . GetBrlytTpls ( newBannerBin . Data [ i ] ) ) ; }
else if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ bannerRequiredTpls = Shared . MergeStringArrays ( bannerRequiredTpls , Brlan . GetBrlanTpls ( newBannerBin . Data [ i ] ) ) ; }
else if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{ bannerTpls . Add ( newBannerBin . StringTable [ i ] ) ; }
}
2010-01-18 21:13:32 +01:00
}
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedIcon ) )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
{
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ iconRequiredTpls = Shared . MergeStringArrays ( iconRequiredTpls , Brlyt . GetBrlytTpls ( iconBin . Data [ i ] ) ) ; }
else if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ iconRequiredTpls = Shared . MergeStringArrays ( iconRequiredTpls , Brlan . GetBrlanTpls ( iconBin . Data [ i ] ) ) ; }
else if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{ iconTpls . Add ( iconBin . StringTable [ i ] ) ; }
}
2010-01-18 21:13:32 +01:00
}
else
{
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
{
if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ iconRequiredTpls = Shared . MergeStringArrays ( iconRequiredTpls , Brlyt . GetBrlytTpls ( newIconBin . Data [ i ] ) ) ; }
else if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ iconRequiredTpls = Shared . MergeStringArrays ( iconRequiredTpls , Brlan . GetBrlanTpls ( newIconBin . Data [ i ] ) ) ; }
else if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{ iconTpls . Add ( newIconBin . StringTable [ i ] ) ; }
}
2010-01-18 21:13:32 +01:00
}
//Check for missing TPLs
2010-03-28 20:29:30 +02:00
List < string > missingTpls = new List < string > ( ) ;
for ( int i = 0 ; i < bannerRequiredTpls . Length ; i + + )
if ( ! Array . Exists ( bannerTpls . ToArray ( ) , thisTpl = > thisTpl . ToLower ( ) = = bannerRequiredTpls [ i ] . ToLower ( ) ) )
missingTpls . Add ( bannerRequiredTpls [ i ] ) ;
if ( missingTpls . Count > 0 )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
errorBox ( "The following Banner TPLs are required by the banner.brlyt, but missing:\n\n" + string . Join ( "\n" , missingTpls . ToArray ( ) ) ) ;
2010-01-18 21:13:32 +01:00
return false ;
}
2010-03-28 20:29:30 +02:00
missingTpls . Clear ( ) ;
for ( int i = 0 ; i < iconRequiredTpls . Length ; i + + )
if ( ! Array . Exists ( iconTpls . ToArray ( ) , thisTpl = > thisTpl . ToLower ( ) = = iconRequiredTpls [ i ] . ToLower ( ) ) )
missingTpls . Add ( iconRequiredTpls [ i ] ) ;
if ( missingTpls . Count > 0 )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
errorBox ( "The following Icon TPLs are required by the icon.brlyt, but missing:\n\n" + string . Join ( "\n" , missingTpls . ToArray ( ) ) ) ;
2010-01-18 21:13:32 +01:00
return false ;
}
//Check Sound length
int soundLength = 0 ;
2010-03-28 20:29:30 +02:00
if ( ! string . IsNullOrEmpty ( replacedSound ) )
2010-01-18 21:13:32 +01:00
{
if ( ! tbSound . Text . ToLower ( ) . EndsWith ( ".bns" ) & & ! tbSound . Text . StartsWith ( "BNS:" ) )
{
2010-03-28 20:29:30 +02:00
Wave w = new Wave ( Headers . IMD5 . RemoveHeader ( newSoundBin ) ) ;
2010-04-20 21:54:36 +02:00
soundLength = w . PlayLength ;
2010-03-28 20:29:30 +02:00
if ( soundLength > soundMaxLength )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
errorBox ( string . Format ( "Your wave sound is longer than {0} seconds and thus not supported.\nIt is recommended to use a sound shorter than {1} seconds, the maximum length is {0} seconds!\nThis limit doesn't affect BNS sounds!" , soundMaxLength , soundWarningLength ) ) ;
2010-01-18 21:13:32 +01:00
return false ;
}
}
}
/ * Errors till here . .
From here only Warnings ! * /
2010-03-28 20:29:30 +02:00
if ( soundLength > soundWarningLength )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
if ( MessageBox . Show ( string . Format ( "Your Sound is longer than {0} seconds.\nIt is recommended to use Sounds that are shorter than {0} seconds!\nDo you still want to continue?" , soundWarningLength ) , "Warning" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) = = DialogResult . No )
2010-01-18 21:13:32 +01:00
return false ;
}
//Check BNS sound length
if ( tbSound . Text . StartsWith ( "BNS:" ) | | tbSound . Text . ToLower ( ) . EndsWith ( ".bns" ) )
{
2010-03-28 20:29:30 +02:00
int bnsLength = BNS . GetBnsLength ( Headers . IMD5 . RemoveHeader ( newSoundBin ) ) ;
if ( bnsLength > bnsWarningLength )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
if ( MessageBox . Show ( string . Format ( "Your BNS Sound is longer than {0} seconds.\nIt is recommended to use Sounds that are shorter than {0} seconds!\nDo you still want to continue?" , bnsWarningLength ) , "Warning" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) = = DialogResult . No )
2010-01-18 21:13:32 +01:00
return false ;
}
}
//Check if brlyt or brlan were changed
2010-03-28 20:29:30 +02:00
if ( brlytChanged & & ! brlanChanged )
2010-01-18 21:13:32 +01:00
{
if ( MessageBox . Show ( "You have changed the brlyt, but didn't change the brlan.\nAre you sure this is correct?" , "brlyt Changed" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = DialogResult . No )
return false ;
}
2010-03-28 20:29:30 +02:00
else if ( brlanChanged & & ! brlytChanged )
2010-01-18 21:13:32 +01:00
{
if ( MessageBox . Show ( "You have changed the brlan, but didn't change the brlyt.\nAre you sure this is correct?" , "brlan Changed" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = DialogResult . No )
return false ;
}
2010-03-28 20:29:30 +02:00
//Check for unused TPLs
List < string > unusedTpls = new List < string > ( ) ;
for ( int i = 0 ; i < bannerTpls . Count ; i + + )
if ( ! Array . Exists ( bannerRequiredTpls , thisTpl = > thisTpl . ToLower ( ) = = bannerTpls [ i ] . ToLower ( ) ) )
unusedTpls . Add ( bannerTpls [ i ] ) ;
if ( unusedTpls . Count > 0 )
2010-01-18 21:13:32 +01:00
{
DialogResult dlgresult = MessageBox . Show (
"The following Banner TPLs are unused by the banner.brlyt:\n\n" +
2010-03-28 20:29:30 +02:00
string . Join ( "\n" , unusedTpls . ToArray ( ) ) +
2010-01-18 21:13:32 +01:00
"\n\nDo you want them to be deleted before the WAD is being created? (Saves space!)" ,
"Delete unused TPLs?" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
if ( dlgresult = = DialogResult . Yes )
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedBanner ) )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
foreach ( string thisTpl in unusedTpls )
bannerBin . RemoveFile ( "/arc/timg/" + thisTpl ) ;
}
else
{
foreach ( string thisTpl in unusedTpls )
newBannerBin . RemoveFile ( "/arc/timg/" + thisTpl ) ;
2010-01-18 21:13:32 +01:00
}
2010-03-28 20:29:30 +02:00
addTpls ( ) ;
2010-01-18 21:13:32 +01:00
}
else if ( dlgresult = = DialogResult . Cancel ) return false ;
}
2010-03-28 20:29:30 +02:00
unusedTpls . Clear ( ) ;
for ( int i = 0 ; i < iconTpls . Count ; i + + )
if ( ! Array . Exists ( iconRequiredTpls , thisTpl = > thisTpl . ToLower ( ) = = iconTpls [ i ] . ToLower ( ) ) )
unusedTpls . Add ( iconTpls [ i ] ) ;
if ( unusedTpls . Count > 0 )
2010-01-18 21:13:32 +01:00
{
DialogResult dlgresult = MessageBox . Show (
"The following Icon TPLs are unused by the icon.brlyt:\n\n" +
2010-03-28 20:29:30 +02:00
string . Join ( "\n" , unusedTpls . ToArray ( ) ) +
2010-01-18 21:13:32 +01:00
"\n\nDo you want them to be deleted before the WAD is being created? (Saves memory!)" ,
"Delete unused TPLs?" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
if ( dlgresult = = DialogResult . Yes )
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedIcon ) )
2010-01-18 21:13:32 +01:00
{
2010-03-28 20:29:30 +02:00
foreach ( string thisTpl in unusedTpls )
iconBin . RemoveFile ( "/arc/timg/" + thisTpl ) ;
2010-01-18 21:13:32 +01:00
}
2010-03-28 20:29:30 +02:00
else
{
foreach ( string thisTpl in unusedTpls )
newIconBin . RemoveFile ( "/arc/timg/" + thisTpl ) ;
}
addTpls ( ) ;
2010-01-18 21:13:32 +01:00
}
else if ( dlgresult = = DialogResult . Cancel ) return false ;
}
currentProgress . progressState = " " ;
currentProgress . progressValue = 100 ;
this . Invoke ( ProgressUpdate ) ;
return true ;
}
catch ( Exception ex )
{
2010-03-28 20:29:30 +02:00
errorBox ( ex . Message ) ;
2010-01-18 21:13:32 +01:00
return false ;
}
}
2010-03-28 20:29:30 +02:00
private void forwarderDialogSimple ( )
2010-01-18 21:13:32 +01:00
{
CustomizeMii_InputBox ib = new CustomizeMii_InputBox ( false ) ;
ib . Size = new Size ( ib . Size . Width , 120 ) ;
ib . lbInfo . Text = "Enter the application folder where the forwarder will point to (3-18 chars)" ;
ib . tbInput . MaxLength = 18 ;
ib . btnExit . Text = "Cancel" ;
ib . cbElf . Visible = true ;
2010-03-28 20:29:30 +02:00
ib . tbInput . Text = simpleForwarder . AppFolder ;
ib . cbElf . Checked = simpleForwarder . ForwardToElf ;
2010-01-18 21:13:32 +01:00
if ( ib . ShowDialog ( ) = = DialogResult . OK )
{
2010-03-28 20:29:30 +02:00
simpleForwarder . ForwardToElf = ib . cbElf . Checked ;
simpleForwarder . AppFolder = ib . Input ;
setControlText ( tbDol , string . Format ( "Simple Forwarder: \"SD:\\apps\\{0}\\boot.{1}\"" ,
simpleForwarder . AppFolder , simpleForwarder . ForwardToElf = = true ? "elf" : "dol" ) ) ;
2010-01-18 21:13:32 +01:00
btnBrowseDol . Text = "Clear" ;
}
}
2010-03-28 20:29:30 +02:00
private void forwarderDialogComplex ( )
2010-01-18 21:13:32 +01:00
{
CustomizeMii_ComplexForwarder cf = new CustomizeMii_ComplexForwarder ( ) ;
2010-02-06 00:09:36 +01:00
TextBox [ ] tbs = new TextBox [ ] { cf . tb1 , cf . tb2 , cf . tb3 , cf . tb4 , cf . tb5 , cf . tb6 , cf . tb7 , cf . tb8 ,
cf . tb9 , cf . tb10 , cf . tb11 , cf . tb12 , cf . tb13 , cf . tb14 , cf . tb15 , cf . tb16 } ;
for ( int i = 0 ; i < tbs . Length ; i + + )
2010-03-28 20:29:30 +02:00
tbs [ i ] . Text = complexForwarder . GetPath ( i ) ;
2010-02-06 00:09:36 +01:00
2010-03-28 20:29:30 +02:00
cf . cbPack1 . Checked = complexForwarder . Packs [ 0 ] ;
cf . cbPack2 . Checked = complexForwarder . Packs [ 1 ] ;
cf . cbPack3 . Checked = complexForwarder . Packs [ 2 ] ;
2010-01-18 21:13:32 +01:00
2010-03-28 20:29:30 +02:00
if ( ! string . IsNullOrEmpty ( complexForwarder . Image43 ) )
2010-01-18 21:13:32 +01:00
{
cf . cbImage43 . Checked = true ;
cf . tbImage43 . Enabled = true ;
cf . btnBrowseImage43 . Enabled = true ;
2010-03-28 20:29:30 +02:00
cf . tbImage43 . Text = complexForwarder . Image43 ;
2010-01-18 21:13:32 +01:00
}
2010-03-28 20:29:30 +02:00
if ( ! string . IsNullOrEmpty ( complexForwarder . Image169 ) )
2010-01-18 21:13:32 +01:00
{
cf . cbImage169 . Checked = true ;
cf . tbImage169 . Enabled = true ;
cf . btnBrowseImage169 . Enabled = true ;
2010-03-28 20:29:30 +02:00
cf . tbImage169 . Text = complexForwarder . Image169 ;
2010-01-18 21:13:32 +01:00
}
if ( cf . ShowDialog ( ) = = DialogResult . OK )
{
2010-02-06 00:09:36 +01:00
for ( int i = 0 ; i < tbs . Length ; i + + )
2010-03-28 20:29:30 +02:00
complexForwarder . SetPath ( i , tbs [ i ] . Text . Replace ( '\\' , '/' ) ) ;
2010-02-06 00:09:36 +01:00
2010-03-28 20:29:30 +02:00
complexForwarder . Packs [ 0 ] = cf . cbPack1 . Checked ;
complexForwarder . Packs [ 1 ] = cf . cbPack2 . Checked ;
complexForwarder . Packs [ 2 ] = cf . cbPack3 . Checked ;
2010-01-18 21:13:32 +01:00
2010-03-28 20:29:30 +02:00
complexForwarder . Image43 = ( cf . cbImage43 . Checked ) ? cf . tbImage43 . Text : string . Empty ;
complexForwarder . Image169 = ( cf . cbImage169 . Checked ) ? cf . tbImage169 . Text : string . Empty ;
2010-01-18 21:13:32 +01:00
2010-03-28 20:29:30 +02:00
setControlText ( tbDol , string . Format ( "Complex Forwarder" ) ) ;
2010-01-18 21:13:32 +01:00
btnBrowseDol . Text = "Clear" ;
}
}
2010-03-28 20:29:30 +02:00
private void enableControls ( )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new MethodInvoker ( enableControls ) ) ;
return ;
}
2010-01-12 18:03:46 +01:00
for ( int i = 0 ; i < tabControl . TabCount ; i + + )
{
if ( tabControl . TabPages [ i ] ! = tabSource )
{
foreach ( Control Ctrl in tabControl . TabPages [ i ] . Controls )
{
if ( Ctrl is Button ) Ctrl . Enabled = true ;
else if ( ( Ctrl is TextBox ) & & ( Ctrl . Tag ! = ( object ) "Disabled" ) ) Ctrl . Enabled = true ;
else if ( Ctrl is CheckBox & & Ctrl . Tag ! = ( object ) "Independent" ) Ctrl . Enabled = true ;
else if ( Ctrl is ComboBox ) Ctrl . Enabled = true ;
2010-01-18 21:13:32 +01:00
//else if (Ctrl is LinkLabel && Ctrl.Tag != (object)"Independent") Ctrl.Enabled = true;
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
llbBannerMultiReplace . Enabled = true ;
llbIconMultiReplace . Enabled = true ;
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
private void disableControls ( )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new MethodInvoker ( disableControls ) ) ;
return ;
}
2010-01-12 18:03:46 +01:00
for ( int i = 0 ; i < tabControl . TabCount ; i + + )
{
if ( tabControl . TabPages [ i ] ! = tabSource )
{
foreach ( Control Ctrl in tabControl . TabPages [ i ] . Controls )
{
if ( Ctrl is Button ) Ctrl . Enabled = false ;
else if ( ( Ctrl is TextBox ) & & ( Ctrl . Tag ! = ( object ) "Disabled" ) ) Ctrl . Enabled = false ;
else if ( Ctrl is CheckBox & & Ctrl . Tag ! = ( object ) "Independent" ) Ctrl . Enabled = false ;
else if ( Ctrl is ComboBox ) Ctrl . Enabled = false ;
2010-01-18 21:13:32 +01:00
//else if (Ctrl is LinkLabel && Ctrl.Tag != (object)"Independent") Ctrl.Enabled = false;
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
llbBannerMultiReplace . Enabled = false ;
llbIconMultiReplace . Enabled = false ;
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
private Image resizeImage ( Image img , int x , int y )
2010-01-12 18:03:46 +01:00
{
Image newimage = new Bitmap ( x , y ) ;
using ( Graphics gfx = Graphics . FromImage ( newimage ) )
{
gfx . DrawImage ( img , 0 , 0 , x , y ) ;
}
return newimage ;
}
2010-03-28 20:29:30 +02:00
private void setControlText ( Control ctrl , string text )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new controlTextInvoker ( setControlText ) , ctrl , text ) ;
return ;
}
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
ctrl . Text = text ;
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
private void addTpls ( )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new MethodInvoker ( addTpls ) ) ;
return ;
}
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
List < string > bannerTpls = new List < string > ( ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{
try
{
TPL tmpTpl = TPL . Load ( bannerBin . Data [ i ] ) ;
2010-04-20 21:54:36 +02:00
string formatString = tmpTpl . GetTextureFormat ( 0 ) . ToString ( ) ;
if ( formatString . StartsWith ( "CI" ) ) formatString + = "+" + tmpTpl . GetPaletteFormat ( 0 ) ;
bannerTpls . Add ( string . Format ( "{0} ({3}, {1} x {2}, {4})" ,
bannerBin . StringTable [ i ] , tmpTpl . GetTextureSize ( 0 ) . Width ,
tmpTpl . GetTextureSize ( 0 ) . Height , formatString ,
getSizeString ( bannerBin . Data [ i ] . Length ) ) ) ;
2010-03-28 20:29:30 +02:00
}
catch { }
}
}
else
{
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{
try
{
TPL tmpTpl = TPL . Load ( newBannerBin . Data [ i ] ) ;
2010-04-20 21:54:36 +02:00
string formatString = tmpTpl . GetTextureFormat ( 0 ) . ToString ( ) ;
if ( formatString . StartsWith ( "CI" ) ) formatString + = "+" + tmpTpl . GetPaletteFormat ( 0 ) ;
bannerTpls . Add ( string . Format ( "{0} ({3}, {1} x {2}, {4})" ,
newBannerBin . StringTable [ i ] , tmpTpl . GetTextureSize ( 0 ) . Width ,
tmpTpl . GetTextureSize ( 0 ) . Height , formatString ,
getSizeString ( newBannerBin . Data [ i ] . Length ) ) ) ;
2010-03-28 20:29:30 +02:00
}
catch { }
}
}
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
_addBannerTpls ( bannerTpls . ToArray ( ) ) ;
2010-02-06 00:09:36 +01:00
2010-03-28 20:29:30 +02:00
List < string > iconTpls = new List < string > ( ) ;
2010-02-06 00:09:36 +01:00
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedIcon ) )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{
try
{
TPL tmpTpl = TPL . Load ( iconBin . Data [ i ] ) ;
iconTpls . Add ( string . Format ( "{0} ({3}, {1} x {2}, {4})" , iconBin . StringTable [ i ] , tmpTpl . GetTextureSize ( 0 ) . Width , tmpTpl . GetTextureSize ( 0 ) . Height , tmpTpl . GetTextureFormat ( 0 ) . ToString ( ) , getSizeString ( iconBin . Data [ i ] . Length ) ) ) ;
}
catch { }
}
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
else
{
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
{
try
{
TPL tmpTpl = TPL . Load ( newIconBin . Data [ i ] ) ;
iconTpls . Add ( string . Format ( "{0} ({3}, {1} x {2}, {4})" , newIconBin . StringTable [ i ] , tmpTpl . GetTextureSize ( 0 ) . Width , tmpTpl . GetTextureSize ( 0 ) . Height , tmpTpl . GetTextureFormat ( 0 ) . ToString ( ) , getSizeString ( newIconBin . Data [ i ] . Length ) ) ) ;
}
catch { }
}
}
_addIconTpls ( iconTpls . ToArray ( ) ) ;
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
private string getSizeString ( int dataLength )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( dataLength > 1022976 )
return string . Format ( "{0}MB" , Math . Round ( dataLength / 1024d / 1024d , 2 ) ) . Replace ( ',' , ',' ) ;
else
return string . Format ( "{0}KB" , Math . Round ( dataLength / 1024d , 2 ) ) . Replace ( ',' , '.' ) ;
2010-01-12 18:03:46 +01:00
}
2010-03-28 20:29:30 +02:00
private void _addBannerTpls ( string [ ] tpls )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
lbxBannerTpls . Items . Clear ( ) ;
2010-01-12 18:03:46 +01:00
if ( tpls . Length > 0 )
{
for ( int i = 0 ; i < tpls . Length ; i + + )
{
2010-03-28 20:29:30 +02:00
if ( bannerTransparents . Contains ( tpls [ i ] . Remove ( tpls [ i ] . IndexOf ( '(' ) - 3 ) ) )
lbxBannerTpls . Items . Add ( tpls [ i ] + " (Transparent)" ) ;
2010-01-12 18:03:46 +01:00
else
2010-03-28 20:29:30 +02:00
lbxBannerTpls . Items . Add ( tpls [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
private void _addIconTpls ( string [ ] tpls )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
lbxIconTpls . Items . Clear ( ) ;
2010-01-12 18:03:46 +01:00
if ( tpls . Length > 0 )
{
for ( int i = 0 ; i < tpls . Length ; i + + )
{
2010-03-28 20:29:30 +02:00
if ( iconTransparents . Contains ( tpls [ i ] . Remove ( tpls [ i ] . IndexOf ( '(' ) - 3 ) ) )
lbxIconTpls . Items . Add ( tpls [ i ] + " (Transparent)" ) ;
2010-01-12 18:03:46 +01:00
else
2010-03-28 20:29:30 +02:00
lbxIconTpls . Items . Add ( tpls [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
private void addBrlyts ( )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new MethodInvoker ( addBrlyts ) ) ;
return ;
}
2010-01-12 18:03:46 +01:00
try
{
2010-03-28 20:29:30 +02:00
List < string > bannerBrlyts = new List < string > ( ) ;
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
bannerBrlyts . Add ( bannerBin . StringTable [ i ] ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
List < string > iconBrlyts = new List < string > ( ) ;
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
iconBrlyts . Add ( iconBin . StringTable [ i ] ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
_addBannerBrlyt ( bannerBrlyts . ToArray ( ) ) ;
_addIconBrlyt ( iconBrlyts . ToArray ( ) ) ;
2010-01-12 18:03:46 +01:00
if ( lbxBrlytBanner . SelectedIndex = = - 1 & & lbxBrlytIcon . SelectedIndex = = - 1 )
{
if ( lbxBrlytBanner . Items . Count > 0 ) lbxBrlytBanner . SelectedIndex = 0 ;
else if ( lbxBrlytIcon . Items . Count > 0 ) lbxBrlytIcon . SelectedIndex = 0 ;
}
}
catch { }
}
2010-03-28 20:29:30 +02:00
private void addBrlans ( )
2010-01-12 18:03:46 +01:00
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new MethodInvoker ( addBrlans ) ) ;
return ;
}
2010-01-12 18:03:46 +01:00
try
{
2010-03-28 20:29:30 +02:00
List < string > bannerBrlans = new List < string > ( ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
bannerBrlans . Add ( bannerBin . StringTable [ i ] ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
List < string > iconBrlans = new List < string > ( ) ;
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
iconBrlans . Add ( iconBin . StringTable [ i ] ) ;
_addBannerBrlan ( bannerBrlans . ToArray ( ) ) ;
_addIconBrlan ( iconBrlans . ToArray ( ) ) ;
2010-01-12 18:03:46 +01:00
if ( lbxBrlanBanner . SelectedIndex = = - 1 & & lbxBrlanIcon . SelectedIndex = = - 1 )
{
if ( lbxBrlanBanner . Items . Count > 0 ) lbxBrlanBanner . SelectedIndex = 0 ;
else if ( lbxBrlanIcon . Items . Count > 0 ) lbxBrlanIcon . SelectedIndex = 0 ;
}
}
catch { }
}
2010-03-28 20:29:30 +02:00
private void _addBannerBrlyt ( string [ ] brlyt )
2010-01-12 18:03:46 +01:00
{
if ( brlyt . Length > 0 )
{
lbxBrlytBanner . Items . Clear ( ) ;
for ( int i = 0 ; i < brlyt . Length ; i + + )
2010-03-28 20:29:30 +02:00
lbxBrlytBanner . Items . Add ( brlyt [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
2010-03-28 20:29:30 +02:00
private void _addIconBrlyt ( string [ ] brlyt )
2010-01-12 18:03:46 +01:00
{
if ( brlyt . Length > 0 )
{
lbxBrlytIcon . Items . Clear ( ) ;
for ( int i = 0 ; i < brlyt . Length ; i + + )
2010-03-28 20:29:30 +02:00
lbxBrlytIcon . Items . Add ( brlyt [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
2010-03-28 20:29:30 +02:00
private void _addBannerBrlan ( string [ ] brlan )
2010-01-12 18:03:46 +01:00
{
if ( brlan . Length > 0 )
{
lbxBrlanBanner . Items . Clear ( ) ;
for ( int i = 0 ; i < brlan . Length ; i + + )
2010-03-28 20:29:30 +02:00
lbxBrlanBanner . Items . Add ( brlan [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
2010-03-28 20:29:30 +02:00
private void _addIconBrlan ( string [ ] brlan )
2010-01-12 18:03:46 +01:00
{
if ( brlan . Length > 0 )
{
lbxBrlanIcon . Items . Clear ( ) ;
for ( int i = 0 ; i < brlan . Length ; i + + )
2010-03-28 20:29:30 +02:00
lbxBrlanIcon . Items . Add ( brlan [ i ] ) ;
2010-01-12 18:03:46 +01:00
}
}
private void errorBox ( string message )
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new messageInvoker ( errorBox ) , message ) ;
return ;
}
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
MessageBox . Show ( message , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
2010-01-12 18:03:46 +01:00
}
private void infoBox ( string message )
{
2010-03-28 20:29:30 +02:00
if ( this . InvokeRequired )
{
this . Invoke ( new messageInvoker ( infoBox ) , message ) ;
return ;
}
2010-01-12 18:03:46 +01:00
MessageBox . Show ( message , "Information" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
2010-03-28 20:29:30 +02:00
private void makeBannerTplsTransparent ( )
2010-01-12 18:03:46 +01:00
{
foreach ( string thisTpl in lbxBannerTpls . Items )
{
if ( thisTpl . EndsWith ( "(Transparent)" ) )
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
{
if ( thisTpl . Remove ( thisTpl . IndexOf ( '(' , 0 ) - 3 ) . ToLower ( ) = = bannerBin . StringTable [ i ] . ToLower ( ) )
{
TPL tmpTpl = TPL . Load ( bannerBin . Data [ i ] ) ;
Size tSize = tmpTpl . GetTextureSize ( 0 ) ;
Image tImg = new Bitmap ( tSize . Width , tSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
2010-04-20 21:54:36 +02:00
tmpTpl . AddTexture ( tImg , TPL_TextureFormat . IA4 ) ;
2010-03-28 20:29:30 +02:00
bannerBin . Data [ i ] = tmpTpl . ToByteArray ( ) ;
}
}
}
else
{
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
{
if ( thisTpl . Remove ( thisTpl . IndexOf ( '(' , 0 ) - 3 ) . ToLower ( ) = = newBannerBin . StringTable [ i ] . ToLower ( ) )
{
TPL tmpTpl = TPL . Load ( newBannerBin . Data [ i ] ) ;
Size tSize = tmpTpl . GetTextureSize ( 0 ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
Image tImg = new Bitmap ( tSize . Width , tSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
2010-04-20 21:54:36 +02:00
tmpTpl . AddTexture ( tImg , TPL_TextureFormat . IA4 ) ;
2010-03-28 20:29:30 +02:00
newBannerBin . Data [ i ] = tmpTpl . ToByteArray ( ) ;
}
}
}
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
private void makeIconTplsTransparent ( )
2010-01-12 18:03:46 +01:00
{
foreach ( string thisTpl in lbxIconTpls . Items )
{
if ( thisTpl . EndsWith ( "(Transparent)" ) )
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedIcon ) )
{
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
{
if ( thisTpl . Remove ( thisTpl . IndexOf ( '(' , 0 ) - 3 ) . ToLower ( ) = = iconBin . StringTable [ i ] . ToLower ( ) )
{
TPL tmpTpl = TPL . Load ( iconBin . Data [ i ] ) ;
Size tSize = tmpTpl . GetTextureSize ( 0 ) ;
2010-01-12 18:03:46 +01:00
2010-03-28 20:29:30 +02:00
Image tImg = new Bitmap ( tSize . Width , tSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
2010-04-20 21:54:36 +02:00
tmpTpl . AddTexture ( tImg , TPL_TextureFormat . IA4 ) ;
2010-03-28 20:29:30 +02:00
iconBin . Data [ i ] = tmpTpl . ToByteArray ( ) ;
}
}
}
else
{
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
{
if ( thisTpl . Remove ( thisTpl . IndexOf ( '(' , 0 ) - 3 ) . ToLower ( ) = = newIconBin . StringTable [ i ] . ToLower ( ) )
{
TPL tmpTpl = TPL . Load ( newIconBin . Data [ i ] ) ;
Size tSize = tmpTpl . GetTextureSize ( 0 ) ;
Image tImg = new Bitmap ( tSize . Width , tSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
2010-04-20 21:54:36 +02:00
tmpTpl . AddTexture ( tImg , TPL_TextureFormat . IA4 ) ;
2010-03-28 20:29:30 +02:00
newIconBin . Data [ i ] = tmpTpl . ToByteArray ( ) ;
}
}
}
2010-01-12 18:03:46 +01:00
}
}
}
2010-03-28 20:29:30 +02:00
private void addTpl ( ListBox lbx )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
addTpl ( lbx , null ) ;
2010-01-08 23:10:02 +01:00
}
2010-03-28 20:29:30 +02:00
private void addTpl ( ListBox lbx , string inputFile )
2010-01-08 23:10:02 +01:00
{
try
{
2010-03-28 20:29:30 +02:00
int switchVal = lbx = = lbxBannerTpls ? cmbFormatBanner . SelectedIndex : cmbFormatIcon . SelectedIndex ;
2010-04-20 21:54:36 +02:00
if ( switchVal > 9 )
2010-03-28 20:29:30 +02:00
throw new Exception ( "This format is not supported, you must choose a different one!" ) ;
2010-01-08 23:10:02 +01:00
if ( string . IsNullOrEmpty ( inputFile ) )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "TPL|*.tpl|PNG|*.png|JPG|*.jpg|GIF|*.gif|BMP|*.bmp|All|*.tpl;*.png;*.jpg;*.gif;*.bmp" ;
ofd . FilterIndex = 6 ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
inputFile = ofd . FileName ;
}
if ( ! string . IsNullOrEmpty ( inputFile ) )
{
2010-03-28 20:29:30 +02:00
string tplName = Path . GetFileNameWithoutExtension ( inputFile ) + ".tpl" ;
2010-01-08 23:10:02 +01:00
2010-03-28 20:29:30 +02:00
if ( lbx = = lbxBannerTpls )
{
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
if ( bannerBin . StringTable [ i ] . ToLower ( ) = = tplName . ToLower ( ) )
{ errorBox ( "This TPL already exists, use the Replace button" ) ; return ; }
}
else
{
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
if ( newBannerBin . StringTable [ i ] . ToLower ( ) = = tplName . ToLower ( ) )
{ errorBox ( "This TPL already exists, use the Replace button" ) ; return ; }
}
}
else
{
if ( string . IsNullOrEmpty ( replacedIcon ) )
{
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
if ( iconBin . StringTable [ i ] . ToLower ( ) = = tplName . ToLower ( ) )
{ errorBox ( "This TPL already exists, use the Replace button" ) ; return ; }
}
else
{
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
if ( newIconBin . StringTable [ i ] . ToLower ( ) = = tplName . ToLower ( ) )
{ errorBox ( "This TPL already exists, use the Replace button" ) ; return ; }
}
}
2010-01-08 23:10:02 +01:00
2010-03-28 20:29:30 +02:00
string [ ] requiredTpls = new string [ 0 ] ;
if ( lbx = = lbxBannerTpls )
{
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
{
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlyt . GetBrlytTpls ( bannerBin . Data [ i ] ) ) ; }
else if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlan . GetBrlanTpls ( bannerBin . Data [ i ] ) ) ; }
}
}
else
{
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
{
if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlyt . GetBrlytTpls ( newBannerBin . Data [ i ] ) ) ; }
else if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlan . GetBrlanTpls ( newBannerBin . Data [ i ] ) ) ; }
}
}
}
else
{
if ( string . IsNullOrEmpty ( replacedIcon ) )
{
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
{
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlyt . GetBrlytTpls ( iconBin . Data [ i ] ) ) ; }
else if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlan . GetBrlanTpls ( iconBin . Data [ i ] ) ) ; }
}
}
else
{
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
{
if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlyt" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlyt . GetBrlytTpls ( newIconBin . Data [ i ] ) ) ; }
else if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".brlan" ) )
{ requiredTpls = Shared . MergeStringArrays ( requiredTpls , Brlan . GetBrlanTpls ( newIconBin . Data [ i ] ) ) ; }
}
}
}
if ( ! Array . Exists ( requiredTpls , thisTpl = > thisTpl . ToLower ( ) = = tplName . ToLower ( ) ) )
{
if ( MessageBox . Show (
string . Format ( "{0} is not required by your {1}.brlyt and thus only wastes memory!\n" +
"Do you still want to add it?" , tplName , lbx = = lbxBannerTpls ? "banner" : "icon" ) ,
"TPL not required" , MessageBoxButtons . YesNo , MessageBoxIcon . Information ) = =
DialogResult . No )
return ;
}
int tplFormat = 6 ;
2010-01-08 23:10:02 +01:00
2010-04-20 21:54:36 +02:00
TPL_PaletteFormat pFormat = TPL_PaletteFormat . RGB5A3 ;
2010-01-08 23:10:02 +01:00
switch ( switchVal )
{
2010-04-20 21:54:36 +02:00
case 6 :
tplFormat = ( int ) TPL_TextureFormat . I4 ;
2010-02-06 00:09:36 +01:00
break ;
2010-04-20 21:54:36 +02:00
case 5 :
tplFormat = ( int ) TPL_TextureFormat . I8 ;
2010-02-06 00:09:36 +01:00
break ;
2010-04-20 21:54:36 +02:00
case 4 :
tplFormat = ( int ) TPL_TextureFormat . IA4 ;
2010-02-06 00:09:36 +01:00
break ;
2010-04-20 21:54:36 +02:00
case 3 :
tplFormat = ( int ) TPL_TextureFormat . IA8 ;
2010-02-06 00:09:36 +01:00
break ;
2010-01-08 23:10:02 +01:00
case 0 :
2010-04-20 21:54:36 +02:00
tplFormat = ( int ) TPL_TextureFormat . RGBA8 ;
2010-01-08 23:10:02 +01:00
break ;
case 1 :
2010-04-20 21:54:36 +02:00
tplFormat = ( int ) TPL_TextureFormat . RGB565 ;
2010-01-08 23:10:02 +01:00
break ;
case 2 :
2010-04-20 21:54:36 +02:00
tplFormat = ( int ) TPL_TextureFormat . RGB5A3 ;
break ;
case 7 :
tplFormat = ( int ) TPL_TextureFormat . CI4 ;
CustomizeMii_PaletteFormatBox pfb = new CustomizeMii_PaletteFormatBox ( ) ;
pfb . ShowDialog ( ) ;
pFormat = pfb . PaletteFormat ;
break ;
case 8 :
tplFormat = ( int ) TPL_TextureFormat . CI8 ;
CustomizeMii_PaletteFormatBox pfb2 = new CustomizeMii_PaletteFormatBox ( ) ;
pfb2 . ShowDialog ( ) ;
pFormat = pfb2 . PaletteFormat ;
break ;
case 9 :
tplFormat = ( int ) TPL_TextureFormat . CI14X2 ;
CustomizeMii_PaletteFormatBox pfb3 = new CustomizeMii_PaletteFormatBox ( ) ;
pfb3 . ShowDialog ( ) ;
pFormat = pfb3 . PaletteFormat ;
2010-01-08 23:10:02 +01:00
break ;
default :
if ( ! inputFile . ToLower ( ) . EndsWith ( ".tpl" ) )
2010-02-06 00:09:36 +01:00
throw new Exception ( "This format is not supported, you must choose a different one!" ) ;
2010-01-08 23:10:02 +01:00
break ;
}
2010-03-28 20:29:30 +02:00
byte [ ] newTpl ;
2010-01-08 23:10:02 +01:00
if ( inputFile . ToLower ( ) . EndsWith ( ".tpl" ) )
2010-03-28 20:29:30 +02:00
newTpl = File . ReadAllBytes ( inputFile ) ;
else
2010-04-20 21:54:36 +02:00
newTpl = TPL . FromImage ( inputFile , ( TPL_TextureFormat ) tplFormat , pFormat ) . ToByteArray ( ) ;
2010-03-28 20:29:30 +02:00
if ( lbx = = lbxBannerTpls )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedBanner ) )
{ bannerBin . AddFile ( "/arc/timg/" + tplName , newTpl ) ; }
else
{ newBannerBin . AddFile ( "/arc/timg/" + tplName , newTpl ) ; }
2010-01-08 23:10:02 +01:00
}
else
{
2010-03-28 20:29:30 +02:00
if ( string . IsNullOrEmpty ( replacedIcon ) )
{ iconBin . AddFile ( "/arc/timg/" + tplName , newTpl ) ; }
else
{ newIconBin . AddFile ( "/arc/timg/" + tplName , newTpl ) ; }
2010-01-08 23:10:02 +01:00
}
2010-03-28 20:29:30 +02:00
addTpls ( ) ;
2010-01-08 23:10:02 +01:00
}
}
catch ( Exception ex ) { throw ex ; }
}
2010-03-28 20:29:30 +02:00
private void loadChannel ( )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
loadChannel ( null ) ;
2010-01-08 23:10:02 +01:00
}
2010-03-28 20:29:30 +02:00
private void loadChannel ( string inputFile )
2010-01-08 23:10:02 +01:00
{
if ( pbProgress . Value = = 100 )
{
if ( string . IsNullOrEmpty ( inputFile ) )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Wii Channels|*.wad" ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
{
BackgroundWorker bwLoadChannel = new BackgroundWorker ( ) ;
bwLoadChannel . DoWork + = new DoWorkEventHandler ( bwLoadChannel_DoWork ) ;
bwLoadChannel . ProgressChanged + = new ProgressChangedEventHandler ( bwLoadChannel_ProgressChanged ) ;
bwLoadChannel . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwLoadChannel_RunWorkerCompleted ) ;
bwLoadChannel . WorkerReportsProgress = true ;
bwLoadChannel . RunWorkerAsync ( ofd . FileName ) ;
}
}
else
{
BackgroundWorker bwLoadChannel = new BackgroundWorker ( ) ;
bwLoadChannel . DoWork + = new DoWorkEventHandler ( bwLoadChannel_DoWork ) ;
bwLoadChannel . ProgressChanged + = new ProgressChangedEventHandler ( bwLoadChannel_ProgressChanged ) ;
bwLoadChannel . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwLoadChannel_RunWorkerCompleted ) ;
bwLoadChannel . WorkerReportsProgress = true ;
bwLoadChannel . RunWorkerAsync ( inputFile ) ;
}
}
}
2010-03-28 20:29:30 +02:00
private void replacePart ( )
2010-01-08 23:10:02 +01:00
{
2010-03-28 20:29:30 +02:00
replacePart ( null ) ;
2010-01-08 23:10:02 +01:00
}
2010-03-28 20:29:30 +02:00
private void replacePart ( string inputFile )
2010-01-08 23:10:02 +01:00
{
if ( ! string . IsNullOrEmpty ( tbSourceWad . Text ) )
{
if ( pbProgress . Value = = 100 )
{
if ( cmbReplace . SelectedIndex = = 2 ) //sound
{
try
{
if ( string . IsNullOrEmpty ( inputFile ) )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Wii Channels|*.wad|00000000.app|00000000.app|sound.bin|sound.bin|All|*.wad;00000000.app;sound.bin" ;
ofd . FilterIndex = 4 ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
{
if ( ofd . FileName ! = tbSourceWad . Text )
{
BackgroundWorker bwSoundReplace = new BackgroundWorker ( ) ;
bwSoundReplace . DoWork + = new DoWorkEventHandler ( bwSoundReplace_DoWork ) ;
bwSoundReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwSoundReplace_ProgressChanged ) ;
bwSoundReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwSoundReplace_RunWorkerCompleted ) ;
bwSoundReplace . WorkerReportsProgress = true ;
bwSoundReplace . RunWorkerAsync ( ofd . FileName ) ;
}
}
}
else
{
if ( inputFile ! = tbSourceWad . Text )
{
BackgroundWorker bwSoundReplace = new BackgroundWorker ( ) ;
bwSoundReplace . DoWork + = new DoWorkEventHandler ( bwSoundReplace_DoWork ) ;
bwSoundReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwSoundReplace_ProgressChanged ) ;
bwSoundReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwSoundReplace_RunWorkerCompleted ) ;
bwSoundReplace . WorkerReportsProgress = true ;
bwSoundReplace . RunWorkerAsync ( inputFile ) ;
}
}
2010-03-28 20:29:30 +02:00
tbSound . Text = string . Empty ;
btnBrowseSound . Text = "Browse..." ;
2010-01-08 23:10:02 +01:00
}
catch ( Exception ex )
{
2010-03-28 20:29:30 +02:00
replacedSound = string . Empty ;
setControlText ( tbReplace , string . Empty ) ;
errorBox ( ex . Message ) ;
2010-01-08 23:10:02 +01:00
}
}
else if ( cmbReplace . SelectedIndex = = 1 ) //icon
{
try
{
if ( string . IsNullOrEmpty ( inputFile ) )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Wii Channels|*.wad|00000000.app|00000000.app|icon.bin|icon.bin|All|*.wad;00000000.app;icon.bin" ;
ofd . FilterIndex = 4 ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
{
if ( ofd . FileName ! = tbSourceWad . Text )
{
BackgroundWorker bwIconReplace = new BackgroundWorker ( ) ;
bwIconReplace . DoWork + = new DoWorkEventHandler ( bwIconReplace_DoWork ) ;
bwIconReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwIconReplace_ProgressChanged ) ;
bwIconReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwIconReplace_RunWorkerCompleted ) ;
bwIconReplace . WorkerReportsProgress = true ;
bwIconReplace . RunWorkerAsync ( ofd . FileName ) ;
}
}
}
else
{
if ( inputFile ! = tbSourceWad . Text )
{
BackgroundWorker bwIconReplace = new BackgroundWorker ( ) ;
bwIconReplace . DoWork + = new DoWorkEventHandler ( bwIconReplace_DoWork ) ;
bwIconReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwIconReplace_ProgressChanged ) ;
bwIconReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwIconReplace_RunWorkerCompleted ) ;
bwIconReplace . WorkerReportsProgress = true ;
bwIconReplace . RunWorkerAsync ( inputFile ) ;
}
}
}
catch ( Exception ex )
{
2010-03-28 20:29:30 +02:00
replacedIcon = string . Empty ;
setControlText ( tbReplace , string . Empty ) ;
errorBox ( ex . Message ) ;
2010-01-08 23:10:02 +01:00
}
}
else //banner
{
try
{
if ( string . IsNullOrEmpty ( inputFile ) )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Wii Channels|*.wad|00000000.app|00000000.app|banner.bin|banner.bin|All|*.wad;00000000.app;banner.bin" ;
ofd . FilterIndex = 4 ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
{
if ( ofd . FileName ! = tbSourceWad . Text )
{
BackgroundWorker bwBannerReplace = new BackgroundWorker ( ) ;
bwBannerReplace . DoWork + = new DoWorkEventHandler ( bwBannerReplace_DoWork ) ;
bwBannerReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwBannerReplace_ProgressChanged ) ;
bwBannerReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwBannerReplace_RunWorkerCompleted ) ;
bwBannerReplace . WorkerReportsProgress = true ;
bwBannerReplace . RunWorkerAsync ( ofd . FileName ) ;
}
}
}
else
{
if ( inputFile ! = tbSourceWad . Text )
{
BackgroundWorker bwBannerReplace = new BackgroundWorker ( ) ;
bwBannerReplace . DoWork + = new DoWorkEventHandler ( bwBannerReplace_DoWork ) ;
bwBannerReplace . ProgressChanged + = new ProgressChangedEventHandler ( bwBannerReplace_ProgressChanged ) ;
bwBannerReplace . RunWorkerCompleted + = new RunWorkerCompletedEventHandler ( bwBannerReplace_RunWorkerCompleted ) ;
bwBannerReplace . WorkerReportsProgress = true ;
bwBannerReplace . RunWorkerAsync ( inputFile ) ;
}
}
}
catch ( Exception ex )
{
2010-03-28 20:29:30 +02:00
replacedBanner = string . Empty ;
setControlText ( tbReplace , string . Empty ) ;
errorBox ( ex . Message ) ;
2010-01-08 23:10:02 +01:00
}
}
}
}
}
2010-02-24 22:41:37 +01:00
2010-03-28 20:29:30 +02:00
private void multiReplace ( bool banner )
2010-02-24 22:41:37 +01:00
{
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
fbd . Description = "Please select the folder where the images are in.\nThe images must have the same filename as the TPLs!" ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
{
string imageDir = fbd . SelectedPath ;
2010-03-28 20:29:30 +02:00
List < string > tpls = new List < string > ( ) ;
2010-02-24 22:41:37 +01:00
List < string > replacedTpls = new List < string > ( ) ;
2010-03-28 20:29:30 +02:00
if ( banner )
{
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
for ( int i = 0 ; i < bannerBin . NumOfNodes ; i + + )
if ( bannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
tpls . Add ( bannerBin . StringTable [ i ] ) ;
}
else
{
for ( int i = 0 ; i < newBannerBin . NumOfNodes ; i + + )
if ( newBannerBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
tpls . Add ( newBannerBin . StringTable [ i ] ) ;
}
}
else
{
if ( string . IsNullOrEmpty ( replacedIcon ) )
{
for ( int i = 0 ; i < iconBin . NumOfNodes ; i + + )
if ( iconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
tpls . Add ( iconBin . StringTable [ i ] ) ;
}
else
{
for ( int i = 0 ; i < newIconBin . NumOfNodes ; i + + )
if ( newIconBin . StringTable [ i ] . ToLower ( ) . EndsWith ( ".tpl" ) )
tpls . Add ( newIconBin . StringTable [ i ] ) ;
}
}
2010-02-24 22:41:37 +01:00
foreach ( string thisTpl in tpls )
{
string image = string . Empty ;
2010-03-28 20:29:30 +02:00
string path = imageDir + Path . DirectorySeparatorChar + Path . GetFileNameWithoutExtension ( thisTpl ) ;
if ( File . Exists ( path + ".png" ) )
image = path + ".png" ;
else if ( File . Exists ( path + ".jpg" ) )
image = path + ".jpg" ;
else if ( File . Exists ( path + ".gif" ) )
image = path + ".gif" ;
else if ( File . Exists ( path + ".bmp" ) )
image = path + ".bmp" ;
2010-02-24 22:41:37 +01:00
else continue ;
try
{
2010-03-28 20:29:30 +02:00
if ( banner )
{
if ( string . IsNullOrEmpty ( replacedBanner ) )
{
TPL tmpTpl = TPL . Load ( bannerBin . Data [ bannerBin . GetNodeIndex ( thisTpl ) ] ) ;
Image img = Image . FromFile ( image ) ;
2010-04-20 21:54:36 +02:00
TPL_TextureFormat tplFormat = tmpTpl . GetTextureFormat ( 0 ) ;
2010-03-28 20:29:30 +02:00
Size tplSize = tmpTpl . GetTextureSize ( 0 ) ;
if ( tplSize . Width ! = img . Width | |
tplSize . Height ! = img . Height )
img = resizeImage ( img , tplSize . Width , tplSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
tmpTpl . AddTexture ( img , tplFormat ) ;
bannerBin . ReplaceFile ( bannerBin . GetNodeIndex ( thisTpl ) , tmpTpl . ToByteArray ( ) ) ;
replacedTpls . Add ( thisTpl ) ;
}
else
{
TPL tmpTpl = TPL . Load ( newBannerBin . Data [ newBannerBin . GetNodeIndex ( thisTpl ) ] ) ;
Image img = Image . FromFile ( image ) ;
2010-04-20 21:54:36 +02:00
TPL_TextureFormat tplFormat = tmpTpl . GetTextureFormat ( 0 ) ;
2010-03-28 20:29:30 +02:00
Size tplSize = tmpTpl . GetTextureSize ( 0 ) ;
if ( tplSize . Width ! = img . Width | |
tplSize . Height ! = img . Height )
img = resizeImage ( img , tplSize . Width , tplSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
tmpTpl . AddTexture ( img , tplFormat ) ;
newBannerBin . ReplaceFile ( newBannerBin . GetNodeIndex ( thisTpl ) , tmpTpl . ToByteArray ( ) ) ;
replacedTpls . Add ( thisTpl ) ;
}
}
else
{
if ( string . IsNullOrEmpty ( replacedIcon ) )
{
TPL tmpTpl = TPL . Load ( iconBin . Data [ iconBin . GetNodeIndex ( thisTpl ) ] ) ;
Image img = Image . FromFile ( image ) ;
2010-04-20 21:54:36 +02:00
TPL_TextureFormat tplFormat = tmpTpl . GetTextureFormat ( 0 ) ;
2010-03-28 20:29:30 +02:00
Size tplSize = tmpTpl . GetTextureSize ( 0 ) ;
2010-02-24 22:41:37 +01:00
2010-03-28 20:29:30 +02:00
if ( tplSize . Width ! = img . Width | |
tplSize . Height ! = img . Height )
img = resizeImage ( img , tplSize . Width , tplSize . Height ) ;
2010-02-24 22:41:37 +01:00
2010-03-28 20:29:30 +02:00
tmpTpl . RemoveTexture ( 0 ) ;
tmpTpl . AddTexture ( img , tplFormat ) ;
2010-02-24 22:41:37 +01:00
2010-03-28 20:29:30 +02:00
iconBin . ReplaceFile ( iconBin . GetNodeIndex ( thisTpl ) , tmpTpl . ToByteArray ( ) ) ;
replacedTpls . Add ( thisTpl ) ;
}
else
{
TPL tmpTpl = TPL . Load ( newIconBin . Data [ newIconBin . GetNodeIndex ( thisTpl ) ] ) ;
Image img = Image . FromFile ( image ) ;
2010-04-20 21:54:36 +02:00
TPL_TextureFormat tplFormat = tmpTpl . GetTextureFormat ( 0 ) ;
2010-03-28 20:29:30 +02:00
Size tplSize = tmpTpl . GetTextureSize ( 0 ) ;
if ( tplSize . Width ! = img . Width | |
tplSize . Height ! = img . Height )
img = resizeImage ( img , tplSize . Width , tplSize . Height ) ;
tmpTpl . RemoveTexture ( 0 ) ;
tmpTpl . AddTexture ( img , tplFormat ) ;
newIconBin . ReplaceFile ( newIconBin . GetNodeIndex ( thisTpl ) , tmpTpl . ToByteArray ( ) ) ;
replacedTpls . Add ( thisTpl ) ;
}
}
2010-02-24 22:41:37 +01:00
}
catch { }
}
if ( replacedTpls . Count > 0 )
{
string replaced = string . Join ( "\n" , replacedTpls . ToArray ( ) ) ;
2010-03-28 20:29:30 +02:00
infoBox ( string . Format ( "The following TPLs were successfully replaced:\n\n{0}" , replaced ) ) ;
2010-02-24 22:41:37 +01:00
}
2010-03-28 20:29:30 +02:00
else errorBox ( "No TPLs were replaced, did you name the images right?" ) ;
2010-02-24 22:41:37 +01:00
}
}
2010-01-08 23:10:02 +01:00
}
}