Example #1
0
        private void Load()
        {
            _appController = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, null);

            _appController.InitializeLifetimeService();

            _guiController =
                (IGuiController)
                _appController.CreateInstanceAndUnwrap(
                    Properties.Settings.Default.AssemblyName,
                    Properties.Settings.Default.TypeName);

            _guiController.Update += OnUpdate;
            _guiController.Closed += OnShutDown;
        }
        /// <summary>
        /// Creates the local loader class
        /// </summary>
        /// <param name="pluginDirectory">The plugin directory</param>
        public LocalLoader(string pluginDirectory)
        {
            var setup = new AppDomainSetup
            {
                ApplicationName = "Plugins",
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                PrivateBinPath = "plugins",
                CachePath = Path.Combine(pluginDirectory, "cache" + Path.DirectorySeparatorChar),
                ShadowCopyFiles = "true",
                ShadowCopyDirectories = pluginDirectory
            };

            appDomain = AppDomain.CreateDomain("Plugins", null, setup);

            // Used for a Cross AppDomain Singleton
            //appDomain.SetData("PersistentMemoryInstance", PersistentMemory.Instance);
            appDomain.AssemblyResolve += AppDomainAssemblyResolve;

            appDomain.UnhandledException += AppDomainUnhandledException;
            appDomain.InitializeLifetimeService();

            remoteLoader = (RemoteLoader)appDomain.CreateInstanceAndUnwrap("Huffelpuff", "Huffelpuff.Plugins.RemoteLoader");
        }
Example #3
0
        public static ScriptDomain Load(string path)
        {
            int num;

            List <string> list;
            List <string> list2;

            path = Path.GetFullPath(path);
            AppDomainSetup info = new AppDomainSetup {
                ApplicationBase       = path,
                ShadowCopyFiles       = "true",
                ShadowCopyDirectories = path
            };

            StrongName[]     fullTrustAssemblies = new StrongName[0];
            System.AppDomain domain = System.AppDomain.CreateDomain("ScriptDomain_" + (path.GetHashCode() * Environment.TickCount).ToString("X"), null, info, new PermissionSet(PermissionState.Unrestricted), fullTrustAssemblies);
            domain.InitializeLifetimeService();
            ScriptDomain domain2 = null;

            try
            {
                domain2 = (ScriptDomain)domain.CreateInstanceFromAndUnwrap(typeof(ScriptDomain).Assembly.Location, typeof(ScriptDomain).FullName);
            }
            catch (Exception exception1)
            {
                string[] strArray2 = new string[] { "Failed to create script domain '", domain.FriendlyName, "':", Environment.NewLine, exception1.ToString() };
                GTA.Log("[ERROR]", strArray2);
                System.AppDomain.Unload(domain);
                return(null);
            }
            string[] message = new string[] { "Loading scripts from '", path, "' into script domain '", domain.FriendlyName, "' ..." };
            GTA.Log("[INFO]", message);
            if (!Directory.Exists(path))
            {
                string[] strArray7 = new string[] { "Failed to reload scripts because the directory is missing." };
                GTA.Log("[ERROR]", strArray7);
                return(domain2);
            }
            else
            {
                list2 = new List <string>();
                list  = new List <string>();
                try
                {
                    list2.AddRange(Directory.GetFiles(path, "*.vb", SearchOption.AllDirectories));
                    list2.AddRange(Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories));
                    list.AddRange(Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories));
                }
                catch (Exception exception5)
                {
                    string[] strArray6 = new string[] { "Failed to reload scripts:", Environment.NewLine, exception5.ToString() };
                    GTA.Log("[ERROR]", strArray6);
                    System.AppDomain.Unload(domain);
                    return(null);
                }
                num = 0;
            }
            while (true)
            {
                if (num >= list.Count)
                {
                    List <string> .Enumerator enumerator2 = list2.GetEnumerator();
                    if (enumerator2.MoveNext())
                    {
                        do
                        {
                            string current = enumerator2.Current;
                            domain2.LoadScript(current);
                        }while (enumerator2.MoveNext());
                    }
                    List <string> .Enumerator enumerator = list.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        do
                        {
                            string current = enumerator.Current;
                            domain2.LoadAssembly(current);
                        }while (enumerator.MoveNext());
                    }
                    break;
                }
                try
                {
                    string assemblyFile = list[num];
                    if (AssemblyName.GetAssemblyName(assemblyFile).Name == "ScriptHookVDotNet")
                    {
                        string[] strArray5 = new string[] { "Removing assembly file '", Path.GetFileName(assemblyFile), "'." };
                        GTA.Log("[WARNING]", strArray5);
                        num += -1;
                        list.RemoveAt(num);
                        try
                        {
                            File.Delete(assemblyFile);
                        }
                        catch (Exception exception6)
                        {
                            string[] strArray4 = new string[] { "Failed to delete assembly file:", Environment.NewLine, exception6.ToString() };
                            GTA.Log("[ERROR]", strArray4);
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                }
                catch (Exception exception7)
                {
                    string[] strArray3 = new string[] { "Failed to load assembly ", list[num], Environment.NewLine, exception7.ToString() };
                    GTA.Log("[ERROR]", strArray3);
                }
                num++;
            }
            return(domain2);
        }
Example #4
0
        private void StartInDomain()
        {
            GallatinEventLog.WriteEntry( "Starting Gallatin Proxy", EventLogEntryType.Information );

            AppDomainSetup appDomainSetup = new AppDomainSetup();
            appDomainSetup.ApplicationName = "GallatinProxyAppDomain";
            appDomainSetup.ShadowCopyFiles = "true";

            _domain = AppDomain.CreateDomain( "GallatinDomain", AppDomain.CurrentDomain.Evidence, appDomainSetup );
            _domain.UnhandledException += HandleDomainUnhandledException;
            _domain.InitializeLifetimeService();
            _service = (IProxyService) _domain.CreateInstanceAndUnwrap( "Gallatin.Core", "Gallatin.Core.Service.CrossDomainProxyService" );
            _service.Start();

            MarshalByRefObject marshalByRefObject = _service as MarshalByRefObject;
            if ( marshalByRefObject == null )
            {
                throw new InvalidCastException( "Unable to cast service as a MarshalByRefObject" );
            }

            _sponsor = new ClientSponsor();
            _sponsor.Register( marshalByRefObject );
        }