コード例 #1
0
        public static bool Init(string logFileName, bool setCurrentDirectory, string projectDirectory,
                                string userSettingsDirectory, string overrideBinariesDirectory = null)
        {
            if (initialized)
            {
                Log.Fatal("VirtualFileSystem: Init: File system is already initialized.");
                return(false);
            }

            //it can be already started
            StartupTiming.TotalStart();

            StartupTiming.CounterStart("Initialize virtual file system");
            try
            {
                mainThread = Thread.CurrentThread;

                //init directories
                {
                    if (string.IsNullOrEmpty(projectDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project directory must be specified.");
                    }
                    if (!Directory.Exists(projectDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified project directory is not exists.");
                    }
                    projectDirectory    = VirtualPathUtility.NormalizePath(projectDirectory);
                    Directories.project = projectDirectory;
                    if (!Path.IsPathRooted(Directories.project))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project directory path must be rooted.");
                        return(false);
                    }

                    Directories.assets = Path.Combine(Directories.project, "Assets");
                    if (string.IsNullOrEmpty(Directories.assets))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project Assets directory must be specified.");
                    }
                    if (!Directory.Exists(Directories.assets))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified project Assets directory is not exists.");
                    }

                    if (string.IsNullOrEmpty(userSettingsDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: User settings directory must be specified.");
                    }
                    if (!Path.IsPathRooted(userSettingsDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: User settings directory path must be rooted.");
                        return(false);
                    }
                    //if( !Directory.Exists( userSettingsDirectory ) )
                    //	Log.Fatal( "VirtualFileSystem: Init: Specified User settijngs directory is not exists." );
                    userSettingsDirectory    = VirtualPathUtility.NormalizePath(userSettingsDirectory);
                    Directories.userSettings = userSettingsDirectory;

                    if (!string.IsNullOrEmpty(overrideBinariesDirectory) && !Directory.Exists(overrideBinariesDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified binaries directory is not exists.");
                    }
                    if (string.IsNullOrEmpty(overrideBinariesDirectory))
                    {
                        Directories.binaries = PlatformSpecificUtility.Instance.GetExecutableDirectoryPath();
                    }
                    else
                    {
                        Directories.binaries = overrideBinariesDirectory;
                    }
                    Directories.binaries = VirtualPathUtility.NormalizePath(Directories.binaries);
                    if (!Path.IsPathRooted(Directories.binaries))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Executables directory path must be rooted.");
                        return(false);
                    }

                    //// UWP works with relative paths.
                    // should Directories.engineInternal and Directories.platformSpecific be relative for UWP ?
                    //if( SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP )
                    //	Directories.engineInternal = "NeoAxis.Internal";
                    //else
                    Directories.engineInternal = Path.Combine(Directories.binaries, "NeoAxis.Internal");

                    Directories.platformSpecific = Path.Combine(Directories.engineInternal, Path.Combine("Platforms", SystemSettings.CurrentPlatform.ToString()));

                    //!!!!
                    //!!!!ARM
                    if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP)
                    {
                        Directories.platformSpecific = Path.Combine(Directories.platformSpecific, "x64");
                    }
                }

                //!!!!new
                CultureInfo.CurrentCulture = new CultureInfo("en-US");
                try
                {
                    //!!!! deprecated. use CultureInfo.CurrentCulture https://github.com/dotnet/platform-compat/blob/master/docs/DE0008.md
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                }
                catch { }

                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                //bool monoRuntime = Type.GetType( "Mono.Runtime", false ) != null;
                //if( monoRuntime )
                //	AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

                if (setCurrentDirectory)
                {
                    CorrectCurrentDirectory();
                }

                if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Editor)
                {
                    Editor.PackageManager.DeleteFilesAsStartup();
                }

                NativeLibraryManager.PreLoadLibrary("NeoAxisCoreNative");

                InitDefaultSettingsConfig();

                ArchiveManager.Init();
                //if( !ArchiveManager.Init() )
                //{
                //	//ArchiveManager.Shutdown();
                //	return false;
                //}

                initialized = true;

                //InitDeploymentInfoAndUserDirectory();

                string realPath = null;
                if (!string.IsNullOrEmpty(logFileName))
                {
                    realPath = VirtualPathUtility.GetRealPathByVirtual(logFileName);
                }
                Log.Init(Thread.CurrentThread, realPath);

                //!!!!
                //InitFileTypesThatCanBeCached();

                ResourceManager.Init();
                //RegisterAssemblies_IncludingFromDefaultSettingConfig();
                ParseSettingsFromDefaultSettingsConfig();
                //ResourceTypes.Init();

                //!!!!тут?
                VirtualFileWatcher.Init();

                ResourceUpdate.Init();
            }
            finally
            {
                StartupTiming.CounterEnd("Initialize virtual file system");
            }

            return(true);
        }
コード例 #2
0
        public static RegisteredAssemblyItem RegisterAssembly(Assembly assembly, string registerTypeNamesWithIncludedAssemblyName)
        {
            lock ( registeredAssemblies )
            {
                RegisteredAssemblyItem item2 = GetRegisteredAssembly(assembly);
                if (item2 != null)
                {
                    return(item2);
                }

                if (disableAssemblyRegistration == null)
                {
                    ParseDisableAssemblyNamespaceRegistration();
                }

                RegisteredAssemblyItem item = new RegisteredAssemblyItem();
                item.assembly = assembly;
                item.registerTypeNamesWithIncludedAssemblyName = registerTypeNamesWithIncludedAssemblyName;
                registeredAssemblies.Add(assembly, item);

                string name = assembly.GetName().Name;
                if (name.EndsWith(".STUB"))
                {
                    name = name.Replace(".STUB", "");
                }

                bool enabled = !disableAssemblyRegistration.Contains(name);
                Log.InvisibleInfo("Register assembly: {0}{1}", (enabled ? "" : "[DISABLED] "), assembly.FullName);
                //Log.InvisibleInfo( "AssemblyUtils: RegisterAssembly: {0} {1}", ( enabled ? "" : "[DISABLED]" ), assembly.FullName );
                //Log.InvisibleInfo( "AssemblyUtils: RegisterAssembly: [{0}] {1}", ( enabled ? "ENABLED" : "DISABLED" ), assembly.FullName );

                if (enabled)
                {
                    StartupTiming.CounterStart("Register assembly \'" + name + "\'");
                    try
                    {
                        var types = assembly.GetExportedTypes();

                        //optimization
                        var isBaseNetAssembly = assembly == typeof(string).Assembly || assembly == typeof(Uri).Assembly;

                        MetadataManager.RegisterTypesOfAssembly(assembly, types);

                        if (!isBaseNetAssembly)
                        {
                            //Android: 8 seconds.
                            MetadataManager.RegisterAutoConvertItemsForAssembly(assembly, types);

                            MetadataManager.RegisterExtensions(assembly, types);

                            //invoke AssemblyRegistration classes
                            foreach (Type type in types)
                            {
                                if (!type.IsAbstract && typeof(AssemblyRegistration).IsAssignableFrom(type))
                                {
                                    ConstructorInfo constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                      null, new Type[0] {
                                    }, null);
                                    AssemblyRegistration ins = (AssemblyRegistration)constructor.Invoke(new object[0]);

                                    item.registrationObjects.Add(ins);

                                    ins.OnRegister();
                                }
                            }
                        }

                        if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Editor)
                        {
                            EditorUtility.RegisterEditorExtensions(assembly);
                            ResourcesWindowItems.RegisterAssembly(assembly);
                        }

                        RegisterAssemblyEvent?.Invoke(assembly);
                    }
                    catch (Exception e)
                    {
                        Log.Error("Unable to register assembly \'" + name + "\'. " + e.Message);
                    }
                    finally
                    {
                        StartupTiming.CounterEnd("Register assembly \'" + name + "\'");
                    }
                }

                return(item);
            }
        }