[ros-diffs] [gedmurphy] 27307: - implement a harddisk class allowing the usage of multiple disk images - populate the settings dialog with this data

gedmurphy at svn.reactos.org gedmurphy at svn.reactos.org
Thu Jun 28 14:49:13 CEST 2007


Author: gedmurphy
Date: Thu Jun 28 16:49:12 2007
New Revision: 27307

URL: http://svn.reactos.org/svn/reactos?rev=27307&view=rev
Log:
- implement a harddisk class allowing the usage of multiple disk images
- populate the settings dialog with this data

Modified:
    trunk/tools/RosTE/GUI/SettingsForm.cs
    trunk/tools/RosTE/GUI/VirtualMachine.cs

Modified: trunk/tools/RosTE/GUI/SettingsForm.cs
URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/SettingsForm.cs?rev=27307&r1=27306&r2=27307&view=diff
==============================================================================
--- trunk/tools/RosTE/GUI/SettingsForm.cs (original)
+++ trunk/tools/RosTE/GUI/SettingsForm.cs Thu Jun 28 16:49:12 2007
@@ -85,6 +85,17 @@
             }
         }
 
+        private void LoadHardDiskPage()
+        {
+            ArrayList hardDrives = VirtMach.GetHardDisks();
+            foreach (VMHardDrive vmhd in hardDrives)
+            {
+                harddiskLstBox.Items.Add(vmhd);
+            }
+
+            harddiskLstBox.SelectedIndex = 0;
+        }
+
         private void LoadFloppyPage()
         {
             DriveInfo[] drives = DriveInfo.GetDrives();
@@ -117,6 +128,7 @@
             if (!LoadMemoryPage())
                 MessageBox.Show("An error occured whilst loading memory page data");
             LoadCdRomPage();
+            LoadHardDiskPage();
             LoadFloppyPage();
         }
 
@@ -289,5 +301,16 @@
                 generalSetClockHost.Checked = VirtMach.SetClockToHost;
             }
         }
+
+        private void harddiskLstBox_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            ListBox lb = (ListBox)sender;
+            VMHardDrive vmhd = (VMHardDrive)lb.SelectedItem;
+
+            harddiskDriveName.Text = vmhd.Drive;
+            harddiskFileNameTxtBox.Text = vmhd.Path;
+            harddiskSizeLbl.Text = vmhd.Size.ToString();
+            harddiskBootImageChk.Checked = vmhd.BootImg;
+        }
     }
 }

Modified: trunk/tools/RosTE/GUI/VirtualMachine.cs
URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/VirtualMachine.cs?rev=27307&r1=27306&r2=27307&view=diff
==============================================================================
--- trunk/tools/RosTE/GUI/VirtualMachine.cs (original)
+++ trunk/tools/RosTE/GUI/VirtualMachine.cs Thu Jun 28 16:49:12 2007
@@ -8,14 +8,94 @@
 
 namespace RosTEGUI
 {
+    public class VMHardDrive
+    {
+        private Data data;
+        private DataRow hdDataRow;
+
+        public string Name
+        {
+            get { return (string)hdDataRow["Name"]; }
+            set { hdDataRow["Name"] = value; }
+        }
+
+        public string Drive
+        {
+            get { return (string)hdDataRow["Drive"]; }
+        }
+
+        public string Path
+        {
+            get { return (string)hdDataRow["Path"]; }
+            set { hdDataRow["Path"] = value; }
+        }
+
+        public int Size
+        {
+            get { return (int)hdDataRow["Size"]; }
+        }
+
+        public bool BootImg
+        {
+            get { return (bool)hdDataRow["BootImg"]; }
+            set { hdDataRow["BootImg"] = value; }
+        }
+
+        public VMHardDrive(Data dataIn)
+        {
+            data = dataIn;
+        }
+
+        public override string ToString()
+        {
+            return Name;
+        }
+
+        public bool CreateHardDrive(string nameIn,
+                                    string driveIn,
+                                    string pathIn,
+                                    int sizeIn,
+                                    bool bootImgIn)
+        {
+            bool ret = false;
+
+            try
+            {
+                DataTable hddt = data.DataSet.Tables["HardDisks"];
+                hdDataRow = hddt.NewRow();
+                hdDataRow["DiskID"] = hddt.Rows.Count + 1;
+                hdDataRow["Name"] = nameIn;
+                hdDataRow["Drive"] = driveIn;
+                hdDataRow["Path"] = pathIn;
+                hdDataRow["Size"] = sizeIn;
+                hdDataRow["BootImg"] = bootImgIn;
+                hddt.Rows.Add(hdDataRow);
+
+                ret = true;
+            }
+            catch (Exception e)
+            {
+                string message = "Failed to populate hard disk database";
+                ErrorForm err = new ErrorForm(message, e.Message, e.StackTrace);
+                err.ShowDialog();
+            }
+
+            return ret;
+        }
+
+        public void LoadHardDrive(int index)
+        {
+            DataTable hddt = data.DataSet.Tables["HardDisks"];
+            hdDataRow = hddt.Rows[index];
+        }
+    }
+
     public class VirtualMachine
     {
         private Data data;
         private DataRow vmDataRow;
-        private DataRow hdDataRow;
-        private DataRow netDataRow;
         private ArrayList hardDrives;
-
+        private ArrayList netCards;
 
         #region Virtual machine properties
 
@@ -206,6 +286,8 @@
         }
 
         #endregion
+
+        #region database functions
 
         private bool PopulateVMDatabase(string name,
                                         string dir,
@@ -213,6 +295,7 @@
                                         string existImg,
                                         int memSize)
         {
+            DataRow netDataRow;
             bool ret = false;
 
             try
@@ -237,25 +320,25 @@
                 vmDataRow["FloppyIsoImg"] = string.Empty;
                 vmdt.Rows.Add(vmDataRow);
 
-                DataTable hddt = data.DataSet.Tables["HardDisks"];
-                hdDataRow = hddt.NewRow();
-                hdDataRow["DiskID"] = hddt.Rows.Count + 1;
-                hdDataRow["VirtMachID"] = vmDataRow["VirtMachID"];
-                hdDataRow["Name"] = "hda";
-                hdDataRow["Path"] = string.Empty;
-                hdDataRow["Size"] = 0;
-                hddt.Rows.Add(hdDataRow);
+                VMHardDrive vmhd = new VMHardDrive(data);
+                vmhd.CreateHardDrive("Main Drive", "hda", dir, 768, true);
+                hardDrives.Add(vmhd);
+
+                // tester
+                vmhd.CreateHardDrive("Secondary Drive","hdb", dir, 512, false);
+                hardDrives.Add(vmhd);
 
                 DataTable netdt = data.DataSet.Tables["NetCards"];
                 netDataRow = netdt.NewRow();
                 netDataRow["CardID"] = netdt.Rows.Count + 1;
                 netDataRow["VirtMachID"] = vmDataRow["VirtMachID"];
-                netDataRow["Option"] = "hda";
+                netDataRow["Option"] = "user";
                 netDataRow["Vlan"] = 0;
                 netDataRow["MacAddr"] = string.Empty;
                 netDataRow["Model"] = string.Empty;
                 netDataRow["Hostname"] = string.Empty;
                 netdt.Rows.Add(netDataRow);
+                netCards.Add(netDataRow);
 
                 ret = true;
             }
@@ -269,16 +352,79 @@
             return ret;
         }
 
-        public override string ToString()
-        {
-            return Name;
-        }
+        public bool LoadVMConfig(string path)
+        {
+            bool ret = false;
+            string fileName = path + "\\Config.xml";
+
+            if (File.Exists(fileName))
+            {
+                try
+                {
+                    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
+                    XmlTextReader xtr = new XmlTextReader(fs);
+                    data.DataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema);
+                    xtr.Close();
+
+                    DataTable vmdt = data.DataSet.Tables["VMConfig"];
+                    vmDataRow = vmdt.Rows[0];
+
+                    DataTable hddt = data.DataSet.Tables["HardDisks"];
+                    foreach (DataRow dr in hddt.Rows)
+                    {
+                        VMHardDrive vmhd = new VMHardDrive(data);
+                        vmhd.LoadHardDrive((int)dr["DiskID"] - 1);
+                        hardDrives.Add(vmhd);
+                    }
+
+                    DataTable netdt = data.DataSet.Tables["NetCards"];
+                    foreach (DataRow dr in netdt.Rows)
+                        netCards.Add(dr);
+
+                    ret = true;
+                }
+                catch (Exception e)
+                {
+                    MessageBox.Show("error loading the VM Config.xml: " + e.Message);
+                }
+            }
+
+            return ret;
+        }
+
+        public void SaveVMConfig()
+        {
+            try
+            {
+                string fileName = DefDir + "\\Config.xml";
+                Directory.CreateDirectory(DefDir);
+                FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
+                XmlTextWriter xtw = new XmlTextWriter(fs, System.Text.Encoding.Unicode);
+                data.DataSet.WriteXml(xtw, System.Data.XmlWriteMode.WriteSchema);
+                xtw.Close();
+            }
+            catch (Exception e)
+            {
+                MessageBox.Show("error loading VM Config.xml: " + e.Message);
+            }
+        }
+
+
+        #endregion
 
         public VirtualMachine()
         {
             data = new Data();
             if (!data.LoadVirtMachData())
                 MessageBox.Show("Failed to load VM Schema");
+
+            hardDrives = new ArrayList(3);
+            netCards = new ArrayList();
+        }
+
+        public override string ToString()
+        {
+            return Name;
         }
 
         // default
@@ -321,52 +467,16 @@
                                       memSize);
         }
 
-        public bool LoadVMConfig(string path)
-        {
-            bool ret = false;
-            string fileName = path + "\\Config.xml";
-
-            if (File.Exists(fileName))
-            {
-                try
-                {
-                    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
-                    XmlTextReader xtr = new XmlTextReader(fs);
-                    data.DataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema);
-                    xtr.Close();
-
-                    DataTable vmdt = data.DataSet.Tables["VMConfig"];
-                    vmDataRow = vmdt.Rows[0];
-
-                    DataTable hddt = data.DataSet.Tables["HardDisks"];
-                    hdDataRow = hddt.Rows[0];
-
-                    ret = true;
-                }
-                catch (Exception e)
-                {
-                    MessageBox.Show("error loading the VM Config.xml: " + e.Message);
-                }
-            }
-
-            return ret;
-        }
-
-        public void SaveVMConfig()
-        {
-            try
-            {
-                string fileName = DefDir + "\\Config.xml";
-                Directory.CreateDirectory(DefDir);
-                FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
-                XmlTextWriter xtw = new XmlTextWriter(fs, System.Text.Encoding.Unicode);
-                data.DataSet.WriteXml(xtw, System.Data.XmlWriteMode.WriteSchema);
-                xtw.Close();
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("error loading VM Config.xml: " + e.Message);
-            }
+        public string GetHardDiskName(int i)
+        {
+            DataRow dr = (DataRow)hardDrives[i];
+
+            return (string)dr["Name"];
+        }
+
+        public ArrayList GetHardDisks()
+        {
+            return hardDrives;
         }
     }
 }




More information about the Ros-diffs mailing list