コード例 #1
0
        private void CalculatePartitions()
        {
            FillLabels();
            if (vhd.vhdReadException != null)
            {
                return;
            }

            // this.Width = Width - Margin.Right - Margin.Left;
            // this.Width = StartingWidth;
            if (Parent != null)
            {
                // this.Width = Parent.Width - Parent.Margin.Right - Parent.Margin.Left;
            }

            //this.Anchor = Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top)
            //            | System.Windows.Forms.AnchorStyles.Left)
            //            | System.Windows.Forms.AnchorStyles.Right)));
            // adl.Dock = System.Windows.Forms.DockStyle.Fill;

            double minPercent; // We want each prp to be a minimum of 95 pixels wide.  That's slightly over 0.15
            int    availableWidth = (Width - Padding.Left - Padding.Right);

            minPercent = 80 / (double)availableWidth;
            if (minPercent > 1D / diskUsageModel.PartitionCount)
            {
                minPercent = 1D / diskUsageModel.PartitionCount;
            }
            // minPercent = 0;

            PartitionUsageModel pm;

            long LBADiskLength = (long)(diskModel.footer.CurrentSize / 512);

            int partitionCount = diskUsageModel.PartitionCount;

            List <int>    sizes        = new List <int>();
            List <double> sizePercents = new List <double>();
            int           sizeLeft     = (int)LBADiskLength;

            sizeBorrowed = 0;
            int newSize;

            for (int i = 0; i < partitionCount; i++)
            {
                int    size    = (int)diskUsageModel.GetPartitionUsageModel(i).LBALength;
                double percent = (double)size / LBADiskLength;
                if (percent < minPercent)
                {
                    percent       = minPercent;
                    newSize       = (int)(LBADiskLength * percent);
                    sizeBorrowed += (newSize - size);
                    size          = newSize;
                }
                sizePercents.Add(percent);
                sizes.Add(size);
            }

            double totalPercent = sizePercents.Sum();

            while (totalPercent > 1D)
            {
                for (int i = 0; i < sizePercents.Count; i++)
                {
                    if ((sizePercents[i]) > minPercent)
                    {
                        sizePercents[i] -= 0.01;
                    }
                }
                totalPercent = sizePercents.Sum();
            }
            // e.g. we're using 115% of space (1.15), need to normalise down to 100%, but can't shorten below minPercent.



            double PercentPointer = 0.0;

            //List<Control> toDelete = new List<Control>();
            //foreach (Control c in this.Controls)
            //{
            //    if (c is PartitionRoundedPanel)
            //    {
            //        toDelete.Add(c);
            //    }
            //}
            //foreach (Control c in toDelete)
            //{
            //    //  Controls.Remove(c);
            //}


            for (int i = 0; i < partitionCount; i++)
            {
                PartitionRoundedPanel prp;
                if (Controls.Count < (5 + partitionCount))
                {
                    // TODO: SOrt out this mess of upside down MVC and duplicate values and improper or non-use of models and controllers
                    // NOTE: PartitionController will call GetCluster which may result in VhdReadException
                    prp = new PartitionRoundedPanel(i, partitionCount, new PartitionController(vhd, i));
                    // prp.controller = new PartitionController(vhd, i);
                }
                else
                {
                    prp = (Controls[i + 5] as PartitionRoundedPanel);
                }

                prp.SuspendLayout();

                pm = diskUsageModel.GetPartitionUsageModel(i);
                // double partitionPercent = (double)pm.LBALength / LBADiskLength;
                // double partitionPercent = (double)sizes[i] / LBADiskLength;
                double partitionPercent = sizePercents[i];
                prp.PartitionStartPercent = (double)pm.LBAStart / LBADiskLength;
                if (prp.PartitionStartPercent < PercentPointer)
                {
                    prp.PartitionStartPercent = PercentPointer;
                }
                PercentPointer = prp.PartitionStartPercent;
                prp.PartitionRealLengthPercent = (double)pm.LBALength / LBADiskLength;
                prp.PartitionLengthPercent     = partitionPercent;
                PercentPointer += prp.PartitionLengthPercent;

                prp.partitionModel      = pm; // This is *so* wrong
                prp.UsedSpacePercentage = prp.PartitionRealLengthPercent;
                // prp.Size = new Size((adl.clientWidth / partitionCount) - 20, prp.Size.Height);
                // int w = (ClientSize.Width - adl.Padding.Left) / partitionCount;
                // prp.Location = new Point(100 + (i * w), 5);
                prp.Number     = i;
                prp.ChildCount = partitionCount;
                // prp.RectangleFillColor = Color.WhiteSmoke;
                // prp.Size = new Size(w - 10, 80);
                // Size is calculated in prp.  Location should be too.  But hey.
                // partitionModels.Add(pm);
                prp.Name = "PartitionRoundedPanel " + i;
                if (this.Controls.IndexOf(prp) < 0)
                {
                    this.Controls.Add(prp);
                }
                else
                {
                }
                prp.ResumeLayout(true);
                // prp.Invalidate(true);
            }
            FillLabels();
            FreeSpaceStartPercent = PercentPointer;
        }
コード例 #2
0
        public void MakeView()
        {
            drp = new DiskRoundedPanel();
            // adl.Margin = new Padding(20);
            drp.BackColor          = BackColor;
            drp.RectangleFillColor = SystemColors.ControlLight;
            drp.Padding            = new System.Windows.Forms.Padding(drp.Width + 10, 5, 5, 5);

            // drp.diskModel = diskModel;
            drp.diskUsageModel = model;
            drp.vhd            = vhd;

            drp.bitArrayBar1.FalseColor = drp.RectangleFillColor;
            drp.bitArrayBar1.TrueColor  = Color.FromArgb(0xff, 128, 128, 128);
            drp.bitArrayBar1.bitArray   = vhd.batUsage;

            drp.bitArrayBar1.MouseLeave += new System.EventHandler(this.VhdPartitionView_MouseLeave);
            drp.bitArrayBar1.MouseMove  += new System.Windows.Forms.MouseEventHandler(this.VhdPartitionView_MouseMove);

            using (Bitmap b = new Bitmap(Properties.Resources.MagnifyingGlass_96_64_centered))
            {
                Cursor c = new Cursor(b.GetHicon());
                drp.bitArrayBar1.Cursor = c;
            }


            foreach (Control c in drp.Controls)
            {
                if (c.Location.X > drp.Width)
                {
                    c.Location = new Point(c.Location.X - drp.Width, c.Location.Y + 5);
                }
            }
            drp.Width = 640;

            // We may or may not get this every time, b/c you never know when it's changed.

            if (mountedVolumes == null)
            {
                mountedVolumes = VDS.LaurentEtiemble.example();
            }
            if (mountedVolumes.Count > 0)
            {
                string physicalDisk;
                if (mountedVolumes.TryGetValue(vhd.Filename, out physicalDisk))
                {
                    SetAttached(physicalDisk);
                }
            }


#if false
            PartitionUsageModel pm;

            long LBADiskLength  = (long)(footer.CurrentSize / 512);
            int  partitionCount = model.PartitionCount;

            List <int> sizes   = new List <int>();
            int        sizeSum = (int)LBADiskLength;

            for (int i = 0; i < partitionCount; i++)
            {
                int    size    = (int)model.GetPartitionUsageModel(i).LBALength;
                double percent = (double)size / LBADiskLength;
                if (percent < 0.1)
                {
                    size = (int)LBADiskLength / 10;
                }
                sizes.Add(size);
                sizeSum = sizes.Sum();
            }
            double PercentPointer = 0.0;
            for (int i = 0; i < partitionCount; i++)
            {
                PartitionRoundedPanel prp = new PartitionRoundedPanel();

                pm = model.GetPartitionUsageModel(i);
                // double partitionPercent = (double)pm.LBALength / LBADiskLength;
                double partitionPercent = (double)sizes[i] / LBADiskLength;
                prp.PartitionStartPercent = (double)pm.LBAStart / LBADiskLength;
                if (prp.PartitionStartPercent < PercentPointer)
                {
                    prp.PartitionStartPercent = PercentPointer;
                }
                PercentPointer             = prp.PartitionStartPercent;
                prp.PartitionLengthPercent = (double)pm.LBALength / LBADiskLength;
                if (prp.PartitionLengthPercent < 0.15)
                {
                    prp.PartitionLengthPercent = 0.15;
                }
                PercentPointer         += prp.PartitionLengthPercent;
                prp.partitionModel      = pm; // This is *so* wrong
                prp.UsedSpacePercentage = partitionPercent;
                // prp.Size = new Size((adl.clientWidth / partitionCount) - 20, prp.Size.Height);
                // int w = (ClientSize.Width - adl.Padding.Left) / partitionCount;
                // prp.Location = new Point(100 + (i * w), 5);
                prp.Number     = i;
                prp.ChildCount = partitionCount;
                // prp.Size = new Size(w - 10, 80);
                // Size is calculated in prp.  Location should be too.  But hey.
                // partitionModels.Add(pm);
                adl.Controls.Add(prp);
            }
#endif
            // adl.CalculatePartitions();

            drp.MouseClick += new System.Windows.Forms.MouseEventHandler(this.VhdPartitionView_MouseClick);
            foreach (Control c in drp.Controls)
            {
                if (!(c is TransparentControl) || (c is DiskRoundedPanel))
                {
                    c.MouseClick += new System.Windows.Forms.MouseEventHandler(this.VhdPartitionView_MouseClick);
                }
            }
            Controls.Add(drp);
        }