public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory) { try { string content = null; if (configNode.TryGetValue("ascii", ref content)) // ASCII files just get decoded from the ConfigNode safe representation { return(new FileContent(PersistenceUtilities.DecodeLine(content))); } if (configNode.TryGetValue("binary", ref content)) // binary files get decoded from Base64 and gzip { return(new FileContent(PersistenceUtilities.DecodeBase64ToBinary(content))); } if (configNode.TryGetValue("line", ref content)) // fall back to legacy logic { return(Decode(content)); } } catch (Exception ex) { SafeHouse.Logger.LogError(string.Format("Exception caught loading file information: {0}\n\nStack Trace:\n{1}", ex.Message, ex.StackTrace)); } SafeHouse.Logger.LogError(string.Format("Error loading file information from ConfigNode at path {0} on hard disk {1}", directory.Path, harddisk.Name)); return(new FileContent("")); // if there was an error, just return a blank file. }
public static ConfigNode ToConfigNode(this Harddisk harddisk, string nodeName) { var node = harddisk.RootHarddiskDirectory.ToConfigNode(nodeName); node.AddValue("capacity", harddisk.Capacity); node.AddValue("volumeName", harddisk.Name); return(node); }
public static HarddiskFile ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk) { var filename = configNode.GetValue(FILENAME_VALUE_STRING); FileContent fileContent = Decode(configNode.GetValue("line")); harddisk.Save(filename, fileContent); return(new HarddiskFile(harddisk, filename)); }
public static ConfigNode ToConfigNode(this Harddisk harddisk, string nodeName) { var node = new ConfigNode(nodeName); node.AddValue("capacity", harddisk.Capacity); node.AddValue("volumeName", harddisk.Name); foreach (ProgramFile file in harddisk.FileList.Values) { node.AddNode(file.ToConfigNode("file")); } return(node); }
public static Harddisk ToHardDisk(this ConfigNode configNode) { var capacity = 10000; if (configNode.HasValue("capacity")) { capacity = int.Parse(configNode.GetValue("capacity")); } var toReturn = new Harddisk(capacity); if (configNode.HasValue("volumeName")) { toReturn.Name = configNode.GetValue("volumeName"); } toReturn.RootHarddiskDirectory = configNode.ToHarddiskDirectory(toReturn, VolumePath.EMPTY); return(toReturn); }
public static Harddisk ToHardDisk(this ConfigNode configNode) { var capacity = 10000; if (configNode.HasValue("capacity")) { capacity = int.Parse(configNode.GetValue("capacity")); } var toReturn = new Harddisk(capacity); if (configNode.HasValue("volumeName")) { toReturn.Name = configNode.GetValue("volumeName"); } foreach (ConfigNode fileNode in configNode.GetNodes("file")) { toReturn.Save(fileNode.ToHarddiskFile(toReturn)); } return(toReturn); }
public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory) { return(Decode(configNode.GetValue("line"))); }
private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path) { HarddiskDirectory directory = new HarddiskDirectory(harddisk, path); foreach (ConfigNode fileNode in configNode.GetNodes("file")) { directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory)); } foreach (ConfigNode dirNode in configNode.GetNodes("directory")) { string dirName = dirNode.GetValue(DirnameValueString); directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path))); } return(directory); }
public override void OnLoad(ConfigNode node) { // KSP Seems to want to make an instance of my partModule during initial load if (vessel == null) return; if (node.HasNode("harddisk")) { var newDisk = new Harddisk(node.GetNode("harddisk")); HardDisk = newDisk; } InitObjects(); if (shared != null && shared.Cpu != null) { shared.Cpu.OnLoad(node); } base.OnLoad(node); }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.Cpu = new Execution.CPU(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null && archive.CheckRange(vessel)) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) {Filename = "boot"}; HardDisk.Add(boot); } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } shared.Cpu.Boot(); }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(shared); shared.Cpu = new Execution.CPU(shared); // initialize the file system shared.VolumeMgr.Add(shared.Factory.CreateArchive()); if (HardDisk == null) HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); shared.VolumeMgr.Add(HardDisk); if (!Config.GetInstance().StartOnArchive) shared.VolumeMgr.SwitchTo(HardDisk); }