예제 #1
0
        /// <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
            Vessel_info vi = Cache.VesselInfo(v);

            // if not a valid vessel, leave the panel empty
            if (!vi.is_valid)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(40)), " <color=#cccccc>FILE MANAGER</color>"));
            p.Width(Styles.ScaleWidthFloat(465.0f));
            p.paneltype = Panel.PanelType.data;

            // time-out simulation
            if (!Lib.IsControlUnit(v) && p.Timeout(vi))
            {
                return;
            }

            var drives = Drive.GetDriveParts(v);

            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 (var idDrivePair in drives)
            {
                var drive = idDrivePair.Value;

                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 = "DATA " + Lib.HumanReadableDataSize(usedDataCapacity);
                if (!unlimitedData)
                {
                    title += Lib.BuildString(" (", Lib.HumanReadablePerc((totalDataCapacity - usedDataCapacity) / totalDataCapacity), " available)");
                }
                p.AddSection(title);

                foreach (var idDrivePair in drives)
                {
                    uint partId = idDrivePair.Key;
                    var  drive  = idDrivePair.Value;
                    foreach (var pair in drive.files)
                    {
                        string filename = pair.Key;
                        File   file     = pair.Value;
                        Render_file(p, partId, filename, file, drive, short_strings && Lib.IsFlight(), v);
                    }
                }

                if (filesCount == 0)
                {
                    p.AddContent("<i>no files</i>", string.Empty);
                }
            }

            if (samplesCount > 0 || totalSlots > 0)
            {
                var title = "SAMPLES " + Lib.HumanReadableMass(totalMass) + " " + Lib.HumanReadableSampleSize(usedSlots);
                if (totalSlots > 0 && !unlimitedSamples)
                {
                    title += ", " + Lib.HumanReadableSampleSize(totalSlots) + " available";
                }
                p.AddSection(title);

                foreach (var idDrivePair in drives)
                {
                    uint partId = idDrivePair.Key;
                    var  drive  = idDrivePair.Value;
                    foreach (var pair in drive.samples)
                    {
                        string samplename = pair.Key;
                        Sample sample     = pair.Value;
                        Render_sample(p, partId, samplename, sample, drive, short_strings && Lib.IsFlight());
                    }
                }

                if (samplesCount == 0)
                {
                    p.AddContent("<i>no samples</i>", string.Empty);
                }
            }
        }