/// <summary> /// Loads mod's scripting features. /// Returns true if successful. /// </summary> public static bool LoadEngine(bool verbose = false) { if (PythonEnvironment.LoadPythonAssembly()) { try { PythonEnvironment.InitializeEngine(); CreateScriptingEnvironment(); _component = Mod.Controller.AddComponent <ScriptComponent>(); if (verbose) { ModConsole.AddMessage(LogType.Log, $"[LenchScripterMod]: {Python.Execute("sys.version")}"); } Mod.LoadedScripter = true; } catch (Exception e) { if (verbose) { ModConsole.AddMessage(LogType.Log, "[LenchScripterMod]: Error while initializing python engine:", e.ToString()); } Mod.LoadedScripter = false; } } else { Mod.LoadedScripter = false; } return(Mod.LoadedScripter); }
private static void InstallIronPython() { if (PythonEnvironment.LoadPythonAssembly()) { download_button_text = "Complete"; return; } downloading_in_progress = true; download_button_text = "0.0 %"; if (!Directory.Exists(Application.dataPath + "/Mods/Resources/LenchScripter/lib/")) { Directory.CreateDirectory(Application.dataPath + "/Mods/Resources/LenchScripter/lib/"); } try { for (int file_index = 0; file_index < files_required; file_index++) { using (var client = new WebClient()) { var i = file_index; // delete existing file if (File.Exists(Application.dataPath + file_paths[i])) { File.Delete(Application.dataPath + file_paths[i]); } // progress handler client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { received_size[i] = e.BytesReceived; float progress = (Convert.ToSingle(received_size.Sum()) / Convert.ToSingle(total_size.Sum()) * 100f); download_button_text = progress.ToString("0.0") + " %"; }; // completion handler client.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) => { if (e.Error != null) { // set error messages spaar.ModLoader.ModConsole.AddMessage(LogType.Log, "[ACM]: Error downloading file:" + file_paths[i].Split('/').Last()); spaar.ModLoader.ModConsole.AddMessage(LogType.Error, "\t" + e.Error.Message); downloading_in_progress = false; download_button_text = "Error"; // delete failed file if (File.Exists(Application.dataPath + file_paths[i])) { File.Delete(Application.dataPath + file_paths[i]); } } else { spaar.ModLoader.ModConsole.AddMessage(LogType.Log, "[ACM]: File downloaded: " + file_paths[i].Split('/').Last()); files_downloaded++; if (files_downloaded == files_required) { // finish download and load assemblies download_button_text = "Complete"; PythonEnvironment.LoadPythonAssembly(); } } }; // start download client.DownloadFileAsync( file_uris[i], Application.dataPath + file_paths[i]); } } } catch (Exception e) { Debug.Log("[ACM]: Error while downloading:"); Debug.LogException(e); downloading_in_progress = false; download_button_text = "Error"; } }
private static void InstallIronPython() { downloading_in_progress = true; download_button_text = "0.0 %"; info_text = "<b>Please wait</b>\n"; if (!Directory.Exists(Application.dataPath + "/Mods/Resources/LenchScripter/lib/")) { Directory.CreateDirectory(Application.dataPath + "/Mods/Resources/LenchScripter/lib/"); } try { for (int file_index = 0; file_index < files_required; file_index++) { using (var client = new WebClient()) { var i = file_index; // delete existing file if (File.Exists(Application.dataPath + file_paths[i])) { File.Delete(Application.dataPath + file_paths[i]); } // progress handler client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { received_size[i] = e.BytesReceived; float progress = (Convert.ToSingle(received_size.Sum()) / Convert.ToSingle(total_size.Sum()) * 100f); download_button_text = progress.ToString("0.0") + " %"; }; // completion handler client.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) => { if (e.Error != null) { // set error messages ModConsole.AddMessage(LogType.Log, "[LenchScripterMod]: Error downloading file:" + file_paths[i].Split('/').Last()); ModConsole.AddMessage(LogType.Error, "\t" + e.Error.Message); info_text = file_paths[i].Split('/').Last() + " <color=red>✘</color>" + "\n\n<b><color=red>Download failed</color></b>\n" + e.Error.Message; downloading_in_progress = false; download_button_text = "Retry"; // delete failed file if (File.Exists(Application.dataPath + file_paths[i])) { File.Delete(Application.dataPath + file_paths[i]); } } else { ModConsole.AddMessage(LogType.Log, "[LenchScripterMod]: File downloaded: " + file_paths[i].Split('/').Last()); info_text += "\n" + file_paths[i].Split('/').Last() + " <color=green>✓</color>"; files_downloaded++; if (files_downloaded == files_required) { // finish download and load assemblies if (PythonEnvironment.LoadPythonAssembly()) { download_button_text = "Complete"; ScripterMod.LoadScripter(); Instance.Visible = false; Destroy(Instance); } else { download_button_text = "Retry"; info_text = "<b><color=red>Download failed</color></b>\nFailed to initialize Python engine."; } downloading_in_progress = false; } } }; // start download client.DownloadFileAsync( file_uris[i], Application.dataPath + file_paths[i]); } } } catch (Exception e) { Debug.Log("[LenchScripterMod]: Error while downloading:"); Debug.LogException(e); downloading_in_progress = false; download_button_text = "Retry"; info_text = "<b><color=red>Download failed</color></b>\n" + e.Message; } }