Du kannst nicht mehr als 25 Themen auswählen
Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
|
- using System;
- using System.Collections.Generic;
- using System.Threading;
-
- namespace NScript.Install
- {
- public class Installer
- {
- private List<IInstallable> _toInstall;
-
- private bool _isRunning = false;
-
- private bool _isCompleted = false;
-
- public bool Completed => _isCompleted;
-
- private string _currentItemName = null;
-
- public string CurrentlyInstalling => _currentItemName;
-
- private Thread _worker = null;
-
- public Installer()
- {
- _toInstall = new List<IInstallable>();
- }
-
- public Installer(IEnumerable<IInstallable> toInstall)
- {
- _toInstall = new List<IInstallable>(toInstall);
- }
-
- public void AddInstallable(IInstallable i)
- {
- if (_isRunning) throw new Exception("Cannot add IInstallable when already installing");
- _toInstall.Add(i);
- }
-
- public void InstallEverything()
- {
- if (_worker != null) _worker.Join();
- _worker = new Thread(InstallWorker);
- _worker.Start();
- }
-
- public void WaitForCompletion()
- {
- if (_worker != null) _worker.Join();
- _worker = null;
- }
-
- private void InstallWorker()
- {
- _isRunning = true;
- foreach (var i in _toInstall)
- {
- _currentItemName = i.Name;
- if (!i.IsInstalled())
- {
- try
- {
- i.Install();
- }
- catch (Exception e)
- {
- GamecraftModdingAPI.Utility.Logging.LogWarning(
- $"Failed to install {_currentItemName}: {e.Message}");
- }
- }
- }
- _isRunning = false;
- _isCompleted = true;
- _currentItemName = null;
- }
- }
- }
|