Beispiel #1
0
        private void Start()
        {
            ScripterMod.LoadScripter();

            if (!PythonEnvironment.Loaded)
            {
                DependencyInstaller.Instance.Visible = true;
            }

            if (ModUpdaterEnabled)
            {
                CheckForModUpdate();
            }
        }
Beispiel #2
0
        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;
            }
        }