internal PlatformManager()
{
// First look in current Executing assembly for a PlatformManager
if ( instance == null )
{
DynamicLoader platformMgr = new DynamicLoader();
IList<ObjectCreator> platforms = platformMgr.Find( typeof( IPlatformManager ) );
if ( platforms.Count != 0 )
{
instance = platformMgr.Find( typeof( IPlatformManager ) )[ 0 ].CreateInstance<IPlatformManager>();
}
}
#if !( XBOX || XBOX360 )
// Then look in loaded assemblies
if ( instance == null )
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for ( int index = 0; index < assemblies.Length && instance == null; index++ )
{
//TODO: NRSC Added: Deal with Dynamic Assemblies not having a Location
//if (assemblies[index].IsDynamic)
// continue;
try {
DynamicLoader platformMgr = new DynamicLoader( assemblies[ index ].Location );
IList<ObjectCreator> platforms = platformMgr.Find( typeof( IPlatformManager ) );
if ( platforms.Count != 0 )
{
instance = platformMgr.Find( typeof( IPlatformManager ) )[ 0 ].CreateInstance<IPlatformManager>();
}
} catch (Exception)
{
System.Diagnostics.Debug.WriteLine( String.Format( "Failed to load assembly: {0}.", assemblies[index].FullName ) );
}
}
}
#endif
// Then look in external assemblies
if ( instance == null )
{
// find and load a platform manager assembly
string[] files = Directory.GetFiles( ".", "Axiom.Platforms.*.dll" );
string file = "";
// make sure there is 1 platform manager available
if ( files.Length == 0 )
{
throw new PluginException( "A PlatformManager was not found in the execution path, and is required." );
}
else
{
bool isWindows = IsWindowsOS;
string platform = IsWindowsOS ? "Win32" : "OpenTK";
if ( files.Length == 1 )
{
file = files[ 0 ];
}
else
{
for ( int i = 0; i < files.Length; i++ )
{
if ( ( files[ i ].IndexOf( platform ) != -1 ) == true )
{
file = files[ i ];
}
}
}
System.Diagnostics.Debug.WriteLine( String.Format( "Selected the PlatformManager contained in {0}.", file ) );
}
string path = Path.Combine( System.IO.Directory.GetCurrentDirectory(), file );
DynamicLoader platformMgr = new DynamicLoader( path );
IList<ObjectCreator> platforms = platformMgr.Find( typeof( IPlatformManager ) );
if ( platforms.Count != 0 )
{
instance = platformMgr.Find( typeof( IPlatformManager ) )[ 0 ].CreateInstance<IPlatformManager>();
}
}
// All else fails, yell loudly
if ( instance == null )
throw new PluginException( "The available Platform assembly did not contain any subclasses of PlatformManager, which is required." );
}