Open() public method

public Open ( VolumePath path, bool ksmDefault = false ) : VolumeItem
path VolumePath
ksmDefault bool
return VolumeItem
Ejemplo n.º 1
0
        private IEnumerable<VolumePath> BootDirectoryFiles()
        {
            var result = new List<VolumePath>();

            var archive = new Archive(SafeHouse.ArchiveFolder);

            var path = VolumePath.FromString(BootDirectoryName);

            var bootDirectory = archive.Open(path) as VolumeDirectory;

            if (bootDirectory == null)
            {
                return result;
            }

            var files = bootDirectory.List();

            foreach (KeyValuePair<string, VolumeItem> pair in files)
            {
                if (pair.Value is VolumeFile && (pair.Value.Extension.Equals(Volume.KERBOSCRIPT_EXTENSION)
                    || pair.Value.Extension.Equals(Volume.KOS_MACHINELANGUAGE_EXTENSION)))
                {
                    result.Add(pair.Value.Path);
                }
            }

            return result;
        }
Ejemplo n.º 2
0
        private void InitUI()
        {
            //Populate selector for boot scripts
            BaseField field = Fields["bootFile"];
            var options = (UI_ChooseOption)field.uiControlEditor;

            var bootFiles = new List<VolumePath>();

            bootFiles.AddRange(BootDirectoryFiles());

            //no need to show the control if there are no available boot files
            options.controlEnabled = bootFiles.Count >= 1;
            field.guiActiveEditor = bootFiles.Count >= 1;
            var availableOptions = bootFiles.Select(e => e.ToString()).ToList();
            var availableDisplays = bootFiles.Select(e => e.Name).ToList();

            availableOptions.Insert(0, "None");
            availableDisplays.Insert(0, "None");

            var bootFilePath = BootFilePath; // store the selected path temporarily
            if (bootFilePath != null && !bootFiles.Contains(bootFilePath))
            {
                // if the path is not null ("None", null, or empty) and if it isn't in list of files
                var archive = new Archive(SafeHouse.ArchiveFolder);
                var file = archive.Open(bootFilePath) as VolumeFile;  // try to open the file as saved
                if (file == null)
                {
                    // check the same file name, but in the boot directory.
                    var path = VolumePath.FromString(BootDirectoryName).Combine(bootFilePath.Name);
                    file = archive.Open(path) as VolumeFile; // try to open the new path
                    if (file == null)
                    {
                        // try the file name without "boot" prefix
                        var name = bootFilePath.Name;
                        if (name.StartsWith("boot", StringComparison.OrdinalIgnoreCase) && name.Length > 4)
                        {
                            // strip the boot prefix and try that file name
                            name = name.Substring(4);
                            path = VolumePath.FromString(BootDirectoryName).Combine(name);
                            file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                            if (file == null)
                            {
                                // try the file name without "boot_" prefix
                                if (name.StartsWith("_", StringComparison.OrdinalIgnoreCase) && name.Length > 1)
                                {
                                    // only need to strip "_" here
                                    name = name.Substring(1);
                                    path = VolumePath.FromString(BootDirectoryName).Combine(name);
                                    file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                                }
                            }
                        }
                    }
                }

                // now, if we have a file object, use its values.
                if (file != null)
                {
                    // store the boot file information
                    bootFile = file.Path.ToString();
                    if (!bootFiles.Contains(file.Path))
                    {
                        availableOptions.Insert(1, bootFile);
                        availableDisplays.Insert(1, "*" + file.Path.Name); // "*" is indication the file is not normally available
                    }
                }
            }
            SafeHouse.Logger.SuperVerbose("bootFile: " + bootFile);

            options.options = availableOptions.ToArray();
            options.display = availableDisplays.ToArray();

            //populate diskSpaceUI selector
            diskSpaceUI = diskSpace.ToString();
            field = Fields["diskSpaceUI"];
            options = (UI_ChooseOption)field.uiControlEditor;
            var sizeOptions = new string[3];
            sizeOptions[0] = baseDiskSpace.ToString();
            sizeOptions[1] = (baseDiskSpace * 2).ToString();
            sizeOptions[2] = (baseDiskSpace * 4).ToString();
            options.options = sizeOptions;
        }
Ejemplo n.º 3
0
        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();
        }