public void InitObjects()
{
shared = new SharedObjects();
shared.Vessel = vessel;
shared.Processor = this;
shared.KSPPart = part;
shared.UpdateHandler = new UpdateHandler();
shared.BindingMgr = new BindingManager(shared);
shared.Interpreter = new Screen.ConnectivityInterpreter(shared);
shared.Screen = shared.Interpreter;
shared.ScriptHandler = new KSScript();
shared.Logger = new KSPLogger(shared);
shared.VolumeMgr = new ConnectivityVolumeManager(shared);
shared.ProcessorMgr = new ProcessorManager();
shared.FunctionManager = new FunctionManager(shared);
shared.TransferManager = new TransferManager(shared);
shared.Cpu = new CPU(shared);
shared.AddonManager = new AddOns.AddonManager(shared);
// Make the window that is going to correspond to this kOS part:
var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow));
DontDestroyOnLoad(gObj);
shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow));
shared.Window.AttachTo(shared);
shared.SoundMaker = shared.Window.GetSoundMaker();
// initialize archive
Archive = new Archive(SafeHouse.ArchiveFolder);
shared.VolumeMgr.Add(Archive);
Messages = new MessageQueue();
// initialize harddisk
if (HardDisk == null)
{
HardDisk = new Harddisk(diskSpace);
if (!string.IsNullOrEmpty(Tag))
{
HardDisk.Name = Tag;
}
var path = BootFilePath;
// populate it with the boot file, but only if using a new disk and in PRELAUNCH situation:
if (vessel.situation == Vessel.Situations.PRELAUNCH && path != null && !SafeHouse.Config.StartOnArchive)
{
var bootVolumeFile = Archive.Open(BootFilePath) as VolumeFile;
if (bootVolumeFile != null)
{
if (HardDisk.SaveFile(BootFilePath, bootVolumeFile.ReadAll()) == null)
{
// Throwing an exception during InitObjects will break the initialization and won't show
// the error to the user. So we just log the error instead. At some point in the future
// it would be nice to queue up these init errors and display them to the user somewhere.
SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space.");
}
}
}
}
shared.VolumeMgr.Add(HardDisk);
// process setting
if (!SafeHouse.Config.StartOnArchive)
{
shared.VolumeMgr.SwitchTo(HardDisk);
}
// initialize processor mode if different than READY
if (ProcessorMode != ProcessorModes.READY)
{
ProcessorModeChanged();
}
InitProcessorTracking();
}