Exemplo n.º 1
0
        private void deleteFromDiskToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VHDFile vhdFile = clbVhdFiles.SelectedItem as VHDFile;

            if (vhdFile != null)
            {
                // Make user to confirm twice before deleting.
                if (MessageBox.Show("你确实从磁盘上要删除VHD文件 " + vhdFile.Path + " 吗?",
                                    "确认删除",
                                    MessageBoxButtons.YesNo)
                    == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                if (MessageBox.Show("你真的要删除该VHD文件吗?该虚拟磁盘内容讲永久丢失!",
                                    "再次确认",
                                    MessageBoxButtons.YesNo)
                    == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                if (vhdFile.DeleteFromDisk())
                {
                    clbVhdFiles.Items.Remove(vhdFile);
                    lblStatus.Text = vhdFile.Path + "删除成功!";
                }
                else
                {
                    lblStatus.Text = vhdFile.Path + "删除失败!";
                }
            }
        }
Exemplo n.º 2
0
        private void mnuVhdFiles_Opened(object sender, EventArgs e)
        {
            VHDFile vhdFile = clbVhdFiles.SelectedItem as VHDFile;

            if (vhdFile != null)
            {
                readOnlyToolStripMenuItem.Checked = vhdFile.ReadOnly;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an object for the vhd file and add it to the list box.
        /// </summary>
        /// <param name="fileName">...</param>
        /// <param name="readOnly">...</param>
        /// <param name="selected">...</param>
        private void AddVHDFile(string fileName, bool readOnly, bool selected)
        {
            VHDFile vhdFile = new VHDFile(fileName, readOnly);

            if (!clbVhdFiles.Items.Contains(vhdFile))
            {
                clbVhdFiles.Items.Add(vhdFile);
                clbVhdFiles.SetItemChecked(clbVhdFiles.Items.IndexOf(vhdFile), selected);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Equals only when the property 'Path' of the two VHDFile objects equal.
        /// </summary>
        /// <param name="obj">another object</param>
        /// <returns>equals or not</returns>
        public override bool Equals(object obj)
        {
            VHDFile vhdFile = obj as VHDFile;

            if (vhdFile == null)
            {
                return(false);
            }
            return(vhdFile.Path.Equals(Path));
        }
Exemplo n.º 5
0
        private void readOnlyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            readOnlyToolStripMenuItem.Checked = !readOnlyToolStripMenuItem.Checked;
            VHDFile vhdFile = clbVhdFiles.SelectedItem as VHDFile;

            if (vhdFile != null)
            {
                vhdFile.ReadOnly = readOnlyToolStripMenuItem.Checked;
                clbVhdFiles.Refresh();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Unmount vhd file and update status label.
 /// </summary>
 /// <param name="vhdFile">...</param>
 private void UnmountVHDFile(VHDFile vhdFile)
 {
     if (vhdFile == null)
     {
         return;
     }
     if (vhdFile.Unmount())
     {
         lblStatus.Text = vhdFile.Path + "已卸载!";
     }
     else
     {
         lblStatus.Text = vhdFile.Path + "卸载失败!";
     }
 }
Exemplo n.º 7
0
        private void CreateVDiskToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateVDiskForm dlg = new CreateVDiskForm();

            dlg.ShowDialog();

            VHDFile vhdFile = dlg.VhdFile;

            if (dlg.VhdCreated)
            {
                AddVHDFile(dlg.VhdFile.Path, false, true);
                lblStatus.Text = vhdFile.Path + "已创建!";
            }
            else if (vhdFile == null)
            {
                lblStatus.Text = "未创建虚拟磁盘!";
            }
            else
            {
                lblStatus.Text = vhdFile.Path + "创建失败!";
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Mount vhd file and update status label.
 /// </summary>
 /// <param name="vhdFile">...</param>
 private void MountVHDFile(VHDFile vhdFile)
 {
     if (vhdFile == null)
     {
         return;
     }
     if (vhdFile.Mount())
     {
         lblStatus.Text = vhdFile.Path + "已挂载";
         if (vhdFile.ReadOnly)
         {
             lblStatus.Text += "[只读模式]!";
         }
         else
         {
             lblStatus.Text += "!";
         }
     }
     else
     {
         lblStatus.Text = vhdFile.Path + "挂载失败!";
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Return a record string to be written to the list file.
        /// </summary>
        /// <param name="vhdFile">...</param>
        /// <returns>record string</returns>
        private string RecordStringOfVHDFile(VHDFile vhdFile)
        {
            if (vhdFile == null)
            {
                return("");
            }
            string result;

            if (clbVhdFiles.GetItemChecked(clbVhdFiles.Items.IndexOf(vhdFile)))
            {
                result = "*";
            }
            else
            {
                result = "";
            }
            result += vhdFile.Path;
            if (vhdFile.ReadOnly)
            {
                result += "*";
            }
            return(result);
        }
Exemplo n.º 10
0
        private void unmountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VHDFile vhdFile = clbVhdFiles.SelectedItem as VHDFile;

            UnmountVHDFile(vhdFile);
        }