kOS.Module.kOSProcessor.InitUI C# (CSharp) Method

InitUI() private method

private InitUI ( ) : void
return void
        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;
        }