Esempio n. 1
0
        private void ResizeVolume()
        {
            long additionalNumberOfSectors = m_additionalNumberOfBytes / m_volume.BytesPerSector;

            btnBack.Enabled = false;
            btnNext.Enabled = false;

            m_processing           = true;
            m_resizeTimer          = new System.Windows.Forms.Timer();
            m_resizeTimer.Interval = 1000;
            m_resizeTimer.Tick    += new EventHandler(ResizeTimer_Tick);
            m_resizeTimer.Start();

            Thread thread = new Thread(delegate()
            {
                // Because of performance implications, we must fill the container
                // before writing the updated TrueCrypt header to the end of the container.
                // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2011/09/22/10215053.aspx
                long oldSize  = m_disk.Size;
                m_bytesToFill = additionalNumberOfSectors * m_disk.BytesPerSector;
                try
                {
                    m_disk.Extend(m_bytesToFill);
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    this.Invoke((MethodInvoker) delegate()
                    {
                        btnBack.Enabled = true;
                        btnNext.Enabled = true;
                    });
                    return;
                }
                if (chkFillWithRandomData.Checked)
                {
                    TrueCryptResize.FillAllocatedSpaceWithData(m_disk, oldSize, ref m_bytesFilled);
                }
                MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(m_disk);
                if (mbr != null && mbr.IsGPTBasedDisk)
                {
                    GuidPartitionTable.RebaseDisk(m_disk, mbr);
                }
                m_resizeStatus = TrueCryptResize.ExtendVolumeAndFileSystem(m_disk, m_password, additionalNumberOfSectors);
                // reinitialize the partition / volume
                m_partition  = VolumeSelectionHelper.GetLastPartition(m_disk);
                m_volume     = new TrueCryptVolume(m_partition, m_password);
                m_processing = false;
            });

            thread.Start();

            if (chkFillWithRandomData.Checked)
            {
                progressBarFillWithRandomData.Visible = true;
            }
        }