// transfer data from a drive to a vessel public static bool Transfer(Drive drive, Vessel dst, bool samples) { double dataAmount = drive.FilesSize(); int sampleSlots = drive.SamplesSize(); if (dataAmount < double.Epsilon && (sampleSlots == 0 || !samples)) { return(true); } // get drives var allDst = GetDrives(dst); bool allMoved = true; foreach (var b in allDst) { if (drive.Move(b, samples)) { allMoved = true; break; } } return(allMoved); }
public void Update() { UpdateCapacity(); if (Lib.IsFlight()) { // show DATA UI button, with size info Events["ToggleUI"].guiName = Lib.StatusToggle("Data", drive.Empty() ? "empty" : drive.Size()); Events["ToggleUI"].active = true; // show TakeData eva action button, if there is something to take Events["TakeData"].active = !drive.Empty(); // show StoreData eva action button, if active vessel is an eva kerbal and there is something to store from it Vessel v = FlightGlobals.ActiveVessel; Events["StoreData"].active = v != null && v.isEVA && !EVA.IsDead(v) && drive.FilesSize() > double.Epsilon; // hide TransferLocation button Events["TransferData"].active = true; } }
/// <summary> /// If short_strings parameter is true then the strings used for display of the data will be shorter when inflight. /// </summary> public static void Fileman(this Panel p, Vessel v, bool short_strings = false) { // avoid corner-case when this is called in a lambda after scene changes v = FlightGlobals.FindVessel(v.id); // if vessel doesn't exist anymore, leave the panel empty if (v == null) { return; } // get info from the cache VesselData vd = v.KerbalismData(); // if not a valid vessel, leave the panel empty if (!vd.IsSimulated) { return; } // set metadata p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(40)), " ", Lib.Color(Local.FILEMANAGER_title, Lib.Kolor.LightGrey))); //"FILE MANAGER" p.Width(Styles.ScaleWidthFloat(465.0f)); p.paneltype = Panel.PanelType.data; // time-out simulation if (!Lib.IsControlUnit(v) && p.Timeout(vd)) { return; } List <ObjectPair <uint, Drive> > drives = new List <ObjectPair <uint, Drive> >(); int filesCount = 0; double usedDataCapacity = 0; double totalDataCapacity = 0; int samplesCount = 0; int usedSlots = 0; int totalSlots = 0; double totalMass = 0; bool unlimitedData = false; bool unlimitedSamples = false; foreach (PartData partData in vd.PartDatas) { Drive drive = partData.Drive; if (drive == null) { continue; } drives.Add(new ObjectPair <uint, Drive>(partData.FlightId, drive)); if (!drive.is_private) { usedDataCapacity += drive.FilesSize(); totalDataCapacity += drive.dataCapacity; unlimitedData |= drive.dataCapacity < 0; unlimitedSamples |= drive.sampleCapacity < 0; usedSlots += drive.SamplesSize(); totalSlots += drive.sampleCapacity; } filesCount += drive.files.Count; samplesCount += drive.samples.Count; foreach (var sample in drive.samples.Values) { totalMass += sample.mass; } } if (filesCount > 0 || totalDataCapacity > 0) { var title = Local.FILEMANAGER_DataCapacity + " " + Lib.HumanReadableDataSize(usedDataCapacity); //"DATA " if (!unlimitedData) { title += Local.FILEMANAGER_DataAvailable.Format(Lib.HumanReadablePerc((totalDataCapacity - usedDataCapacity) / totalDataCapacity)); //Lib.BuildString(" (", Lib.HumanReadablePerc((totalDataCapacity - usedDataCapacity) / totalDataCapacity), " available)"); } p.AddSection(title); foreach (var drive in drives) { foreach (File file in drive.Value.files.Values) { Render_file(p, drive.Key, file, drive.Value, short_strings && Lib.IsFlight(), v); } } if (filesCount == 0) { p.AddContent("<i>" + Local.FILEMANAGER_nofiles + "</i>", string.Empty); //no files } } if (samplesCount > 0 || totalSlots > 0) { var title = Local.FILEMANAGER_SAMPLESMass.Format(Lib.HumanReadableMass(totalMass)) + " " + Lib.HumanReadableSampleSize(usedSlots); //"SAMPLES " + if (totalSlots > 0 && !unlimitedSamples) { title += ", " + Lib.HumanReadableSampleSize(totalSlots) + " " + Local.FILEMANAGER_SAMPLESAvailable; //available } p.AddSection(title); foreach (var drive in drives) { foreach (Sample sample in drive.Value.samples.Values) { Render_sample(p, drive.Key, sample, drive.Value, short_strings && Lib.IsFlight()); } } if (samplesCount == 0) { p.AddContent("<i>" + Local.FILEMANAGER_nosamples + "</i>", string.Empty); //no samples } } }