Esempio n. 1
0
        internal AScriptHandler(OMOD omod, string script, OMODScriptSettings settings, string?extractionFolder)
        {
            ScriptSettings = settings;

            OMOD   = omod;
            Script = script;

            var guid = Guid.NewGuid();

            ExtractionFolder = extractionFolder ?? Path.Combine(Path.GetTempPath(), "OMODFramework", guid.ToString("D"));

            DataFolder    = Path.Combine(ExtractionFolder, "data");
            PluginsFolder = Path.Combine(ExtractionFolder, "plugins");

            if (!settings.DryRun)
            {
                Directory.CreateDirectory(DataFolder);
                Directory.CreateDirectory(PluginsFolder);

                omod.ExtractFilesParallel(DataFolder, 4);
                if (omod.HasEntryFile(OMODEntryFileType.Plugins))
                {
                    omod.ExtractFiles(false, PluginsFolder);
                }
            }

            ScriptReturnData = new ScriptReturnData(DataFolder, PluginsFolder);
            ScriptFunctions  = new ScriptFunctions(ScriptSettings, omod, ScriptReturnData);
        }
Esempio n. 2
0
        /// <summary>
        /// Run the script inside an OMOD.
        /// </summary>
        /// <param name="omod">The OMOD with the script to run.</param>
        /// <param name="settings">The settings to use during Script Execution.</param>
        /// <param name="extractionFolder">The folder to extract the data and plugin files to. Defaults to a path
        /// inside the users temp folder if set to null.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">The omod does not have a script.</exception>
        /// <exception cref="NotImplementedException">The script is of type <see cref="OMODScriptType.Python"/> or
        /// <see cref="OMODScriptType.VisualBasic"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The script has an unknown script type.</exception>
        public static ScriptReturnData RunScript(OMOD omod, OMODScriptSettings settings, string?extractionFolder = null)
        {
            if (!omod.HasEntryFile(OMODEntryFileType.Script))
            {
                throw new ArgumentException("OMOD does not have a script!", nameof(omod));
            }

            var script = omod.GetScript(out var scriptType);

            AScriptHandler handler = scriptType switch
            {
                OMODScriptType.OBMMScript => new OBMMScriptHandler(omod, script, settings, extractionFolder),
                OMODScriptType.CSharp => new CSharpScriptHandler(omod, script, settings, extractionFolder),
#pragma warning disable 618
                OMODScriptType.Python => throw new NotImplementedException(),
                      OMODScriptType.VisualBasic => throw new NotImplementedException(),
#pragma warning restore 618
                            _ => throw new ArgumentOutOfRangeException(nameof(scriptType), scriptType.ToString(),
                                                                       "Unknown script type")
            };

            return(handler.RunScript());
        }
    }