Ejemplo n.º 1
0
        public static bool Stop()
        {
            // MAINT: Ditto the note at the top of Enable().

            try
            {
                m_log?.Log("XPNet CLR: Stop");

                m_plugin.Dispose();
                m_plugin = null;

                m_api.Dispose();
                m_api = null;

                m_configReloadTokenDisposer.Dispose();
                m_configReloadTokenDisposer = null;

                m_configReloadToken = null;
                m_config            = null;

                ApiFunctions = new ApiFunctions();

                return(true);
            }
            catch (Exception exc)
            {
                m_log?.Log(exc);
                return(false);
            }
        }
Ejemplo n.º 2
0
        internal static bool StartInternal(ref StartParams startParams, ref ApiFunctionPointers apiFunctionPointers, string rootDir)
        {
            if (!File.Exists(m_configFilePath))
            {
                m_log.Log($"XPNet CLR: Will not load plugin because config file does not exist: (Path = {m_configFilePath}).");
                return(false);
            }

            m_config = GetConfig(m_configFilePath);
            if (m_config == null)
            {
                m_log.Log($"XPNet CLR: Will not load plugin because config file was unusable: (Path = {m_configFilePath}).");
                return(false);
            }

            m_configReloadToken         = m_config.GetReloadToken();
            m_configReloadTokenDisposer = m_configReloadToken.RegisterChangeCallback(o =>
            {
                m_log.Log($"XPNet CLR: Config file change detected: (Path = {m_configFilePath}).");

                m_log.Log($"XPNet CLR: Will reconfigure logging.");
                m_api.Log = m_log = ReconfigureLogging(forceLogging: false);

                m_log.Log($"XPNet CLR: Will tell plugin that config changed.");
                m_api.RaiseConfigChanged();
            }, state: null);

            // Make a local copy of the given set of API function pointers.
            ApiFunctions = new ApiFunctions(apiFunctionPointers);

            m_api = new XPlaneApi(m_log, m_config);

            m_plugin = LoadPlugin(rootDir);
            if (m_plugin == null)
            {
                m_log.Log("XPNet CLR: Failed to find a plugin to load.  Will tell X-Plane we failed to start.");
                return(false);
            }

            var typeInfo = m_plugin.GetType().GetTypeInfo();
            var xpattr   = typeInfo.GetCustomAttribute <XPlanePluginAttribute>();

            unsafe
            {
                fixed(byte *pc = startParams.Name)
                Interop.CopyCString(pc, 256, xpattr.Name);

                fixed(byte *pc = startParams.Signature)
                Interop.CopyCString(pc, 256, xpattr.Signature);

                fixed(byte *pc = startParams.Description)
                Interop.CopyCString(pc, 256, xpattr.Description);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool Start(ref StartParams startParams, ref ApiFunctionPointers apiFunctionPointers)
        {
            try
            {
                var thisAssemblyPath = typeof(PluginBridge).GetTypeInfo().Assembly.Location;
                var rootDir          = Path.GetDirectoryName(thisAssemblyPath);

                m_configFilePath = Path.Combine(rootDir, "xpnetcfg.json");
                m_logFilePath    = Path.Combine(rootDir, "xpnet.log");

                // We always start out with logging enabled.  We may reconfigure it off once config loads.
                m_log = InitLogging(ref startParams);

                m_log.Log("XPNet CLR: Start");

                if (!File.Exists(m_configFilePath))
                {
                    m_log.Log($"XPNet CLR: Will not load plugin because config file does not exist: (Path = {m_configFilePath}).");
                    return(false);
                }

                m_config = GetConfig(m_configFilePath);
                if (m_config == null)
                {
                    m_log.Log($"XPNet CLR: Will not load plugin because config file was unusable: (Path = {m_configFilePath}).");
                    return(false);
                }

                m_configReloadToken         = m_config.GetReloadToken();
                m_configReloadTokenDisposer = m_configReloadToken.RegisterChangeCallback(o =>
                {
                    m_log.Log($"XPNet CLR: Config file change detected: (Path = {m_configFilePath}).");

                    m_log.Log($"XPNet CLR: Will reconfigure logging.");
                    m_api.Log = m_log = ReconfigureLogging(forceLogging: false);

                    m_log.Log($"XPNet CLR: Will tell plugin that config changed.");
                    m_api.RaiseConfigChanged();
                }, state: null);

                // Make a local copy of the given set of API function pointers.
                ApiFunctions = new ApiFunctions(apiFunctionPointers);

                m_api = new XPlaneApi(m_log, m_config);

                m_plugin = LoadPlugin(rootDir);
                if (m_plugin == null)
                {
                    m_log.Log("XPNet CLR: Failed to find a plugin to load.  Will tell X-Plane we failed to start.");
                    return(false);
                }

                var typeInfo = m_plugin.GetType().GetTypeInfo();
                var xpattr   = typeInfo.GetCustomAttribute <XPlanePluginAttribute>();

                unsafe
                {
                    fixed(byte *pc = startParams.Name)
                    Interop.CopyCString(pc, 256, xpattr.Name);

                    fixed(byte *pc = startParams.Signature)
                    Interop.CopyCString(pc, 256, xpattr.Signature);

                    fixed(byte *pc = startParams.Description)
                    Interop.CopyCString(pc, 256, xpattr.Description);
                }

                return(true);
            }
            catch (Exception exc)
            {
                // File.WriteAllText(@"D:\Games\X-Plane\X-Plane 11 Beta\Resources\plugins\XPNetDev\64\Emergency.txt", "Error: " + exc);
                m_log?.Log(exc);
                return(false);
            }
        }