Exemplo n.º 1
0
        public override void SetScriptExtensionsConfiguration(IPluginMaster pluginMaster)
        {
            if (Root == null)
            {
                return;
            }

            try
            {
                var extensionsConfig = Root[MagicStringEnumerator.JSONCustomExtensions].Values <JToken>().ToArray();

                foreach (var ext in extensionsConfig)
                {
                    try
                    {
                        pluginMaster.AddScriptExtension((ext as JProperty).Name, ext.ToObject <string>());
                    }
                    catch (ArgumentException ex)
                    {
                        Log.Instance?.Error(ex.Message);
                    }
                }
            }
            catch (NullReferenceException)
            {
                Log.Instance?.Warn("custom_extensions is not found in the configuration file.");
            }
        }
Exemplo n.º 2
0
        public override void SetInterpreterNameConfiguration(IPluginMaster pluginMaster)
        {
            if (Root == null)
            {
                return;
            }

            var interpreterConfig = Root[MagicStringEnumerator.JSONIntepreter];

            foreach (var fileType in pluginMaster.AcceptedFilesTypes[PluginFileInfos.FileType.Script])
            {
                var key = fileType;
                var val = "";

                try
                {
                    // an intepreter can change depending the os
                    val = interpreterConfig[OSAttribute.GetOSFamillyName()]
                          ?.Value <string>(pluginMaster.ExtensionsNames[fileType]);
                }
                catch (NullReferenceException)
                {
                    // if we cant find one we need to search in the environment variables
                    var extensionName = pluginMaster.ExtensionsNames[fileType].ToUpper();

                    if (OSAttribute.IsWindows)
                    {
                        foreach (EnvironmentVariableTarget enumValue in Enum.GetValues(
                                     typeof(EnvironmentVariableTarget)))
                        {
                            val = Environment.GetEnvironmentVariable(extensionName, enumValue);

                            if (val != null)
                            {
                                Log.Instance?.Info($"Environment variable found: {extensionName} : {val}");
                                break;
                            }
                        }
                    }
                    else if (OSAttribute.IsLinux)
                    {
                        using var dllimport = new DllImportLaunchCmdUnix();

                        val = dllimport.UseLaunchCommand($"printenv | grep {extensionName} | cut -d '=' -f 2").Trim();

                        if (!string.IsNullOrEmpty(val))
                        {
                            Log.Instance?.Info($"Environment variable found: {extensionName} : {val}");
                        }
                    }
                }

                // if it can't be found, the default one is choose
                if (string.IsNullOrEmpty(val))
                {
                    val = pluginMaster.ExtensionsNames[fileType];
                }

                if (!File.Exists(val))
                {
                    return;
                }

                if (!pluginMaster.ExtensionsNames.ContainsKey(key))
                {
                    pluginMaster.AddScriptExtension(key, val);
                }
                else
                {
                    pluginMaster.ExtensionsNames[key] = val;
                }
            }
        }