|
||
|
|
#1 (permalink) |
|
Lurker
Join Date: May 2008
Posts: 3
|
Ive been looking around google after seeing how RunUO Compiles its scripts at runtime, and altho ive found ways to compile say a single file, Ive not been able to find anyway to do something along the lines of how RunUO handel's it,
Has Anyone seen a guide or have any suggestions on how I would add similar functionality to my own applications? Im not after someone to hold my hand and write a Step by Step guide, (unless some one does happen to have one :P) But more a general howto/suggestions on how to acheive this. Note: on another note im now off to go find the RunUO.exe source.. |
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
|
Yeah I was gonna say, just look through the RunUO source and just walk through how it does it.
The site is: Revision 295: /devel
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#3 (permalink) |
|
Forum Expert
Join Date: Jan 2008
Posts: 286
|
I would look at ScriptCompiler.cs at the CompileCSSScripts method
Code:
public static bool CompileCSScripts( bool debug, bool cache, out Assembly assembly )
{
Console.Write( "Scripts: Compiling C# scripts..." );
string[] files = GetScripts( "*.cs" );
if( files.Length == 0 )
{
Console.WriteLine( "no files found." );
assembly = null;
return true;
}
if( File.Exists( "Scripts/Output/Scripts.CS.dll" ) )
{
if( cache && File.Exists( "Scripts/Output/Scripts.CS.hash" ) )
{
try
{
byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.CS.dll", files, debug );
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.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.CS.dll" );
if( !m_AdditionalReferences.Contains( assembly.Location ) )
{
m_AdditionalReferences.Add( assembly.Location );
}
Console.WriteLine( "done (cached)" );
return true;
}
}
}
}
}
catch
{
}
}
}
DeleteFiles( "Scripts.CS*.dll" );
#if Framework_3_5
using ( CSharpCodeProvider provider = new CSharpCodeProvider( new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } } ) )
#else
using ( CSharpCodeProvider provider = new CSharpCodeProvider() )
#endif
{
string path = GetUnusedPath( "Scripts.CS" );
CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), path, debug );
string defines = GetDefines();
if( defines != null )
parms.CompilerOptions = defines;
if( Core.HaltOnWarning )
parms.WarningLevel = 4;
#if !MONO
CompilerResults results = provider.CompileAssemblyFromFile( parms, files );
#else
parms.CompilerOptions = String.Format( "{0} /nowarn:169,219,414 /recurse:Scripts/*.cs", parms.CompilerOptions );
CompilerResults results = provider.CompileAssemblyFromFile( parms, "" );
#endif
m_AdditionalReferences.Add( path );
Display( results );
#if !MONO
if( results.Errors.Count > 0 )
{
assembly = null;
return false;
}
#else
if( results.Errors.Count > 0 ) {
foreach( CompilerError err in results.Errors ) {
if ( !err.IsWarning ) {
assembly = null;
return false;
}
}
}
#endif
if( cache && Path.GetFileName( path ) == "Scripts.CS.dll" )
{
try
{
byte[] hashCode = GetHashCode( path, files, debug );
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.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;
}
}
![]()
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|