/**
 * Copies all files from install folder
 */
function installFiles( $folder )
{
	if ( JFolder::exists( $folder.'/all' ) ) {
		if ( !copy_from_folder( $folder.'/all', 1 ) ) {
			return 0;
		}
	}
	if ( JFolder::exists( $folder.'/15' ) ) {
		if ( !copy_from_folder( $folder.'/15', 1 ) ) {
			return 0;
		}
	}
	if ( JFolder::exists( $folder.'/15_optional' ) ) {
		if ( !copy_from_folder( $folder.'/15_optional', 0 ) ) {
			return 0;
		}
	}
	if ( JFolder::exists( $folder.'/language' ) ) {
		installLanguages( $folder.'/language' );
	}
	return 1;
}
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );

define( 'JV15', ( version_compare( JVERSION, '1.6.0', 'l' ) ) );

$jv = JV15 ? '15' : '16';
$comp_folder = dirname( __FILE__ );

require_once $comp_folder.'/installer/helper_'.$jv.'.php';

$mainframe =& JFactory::getApplication();
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );

// Install the Installer languages
installLanguages( $comp_folder.'/installer/language', 1, 0 );

// Load language for messaging
$lang =& JFactory::getLanguage();
if ( $lang->getTag() != 'en-GB' ) {
	// Loads English language file as fallback (for undefined stuff in other language file)
	$lang->load( 'com_nonumber-installer-uninstallme', JPATH_ADMINISTRATOR, 'en-GB' );
}
$lang->load( 'com_nonumber-installer-uninstallme', JPATH_ADMINISTRATOR, null, 1 );

$install_file = $comp_folder.'/extensions.php';
if ( !JFile::exists( $install_file ) || !is_readable( $install_file ) ) {
	$mainframe->enqueueMessage( JText::sprintf( 'NNI_CANNOT_READ_THE_REQUIRED_INSTALLATION_FILE', $install_file ), 'error' );
	uninstallInstaller();
} else if ( !JFolder::exists( $comp_folder.'/extensions/'.$jv ) ) {
	$mainframe->enqueueMessage( JText::sprintf( 'NNI_NOT_COMPATIBLE', round( JVERSION, 1 ) ), 'error' );