public static bool CompileVBScripts( bool debug, bool cache, out Assembly assembly )
{
Console.Write( "Scripts: Compiling VB.NET scripts..." );
string[] files = GetScripts( "*.vb" );
if( files.Length == 0 )
{
Console.WriteLine( "no files found." );
assembly = null;
return true;
}
if( File.Exists( "Scripts/Output/Scripts.VB.dll" ) )
{
if( cache && File.Exists( "Scripts/Output/Scripts.VB.hash" ) )
{
byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.VB.dll", files, debug );
try
{
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.VB.hash", FileMode.Open, FileAccess.Read, FileShare.Read ) )
{
using( BinaryReader bin = new BinaryReader( fs ) )
{
byte[] bytes = bin.ReadBytes( hashCode.Length );
if( bytes.Length == hashCode.Length )
{
bool valid = true;
for( int i = 0; i < bytes.Length; ++i )
{
if( bytes[i] != hashCode[i] )
{
valid = false;
break;
}
}
if( valid )
{
assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.VB.dll" );
if( !m_AdditionalReferences.Contains( assembly.Location ) )
{
m_AdditionalReferences.Add( assembly.Location );
}
Console.WriteLine( "done (cached)" );
return true;
}
}
}
}
}
catch
{
}
}
}
DeleteFiles( "Scripts.VB*.dll" );
using ( VBCodeProvider provider = new VBCodeProvider() )
{
string path = GetUnusedPath( "Scripts.VB" );
CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), path, debug );
string options = GetCompilerOptions( debug );
if( options != null )
parms.CompilerOptions = options;
if( Core.HaltOnWarning )
parms.WarningLevel = 4;
CompilerResults results = provider.CompileAssemblyFromFile( parms, files );
m_AdditionalReferences.Add( path );
Display( results );
if( results.Errors.Count > 0 )
{
assembly = null;
return false;
}
if( cache && Path.GetFileName( path ) == "Scripts.VB.dll" )
{
try
{
byte[] hashCode = GetHashCode( path, files, debug );
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.VB.hash", FileMode.Create, FileAccess.Write, FileShare.None ) )
{
using( BinaryWriter bin = new BinaryWriter( fs ) )
{
bin.Write( hashCode, 0, hashCode.Length );
}
}
}
catch
{
}
}
assembly = results.CompiledAssembly;
return true;
}
}