Author: gedmurphy Date: Mon Jun 25 19:49:49 2007 New Revision: 27275
URL: http://svn.reactos.org/svn/reactos?rev=27275&view=rev Log: object restructuring
Added: trunk/tools/RosTE/GUI/MainConfig.cs Modified: trunk/tools/RosTE/GUI/MainForm.cs trunk/tools/RosTE/GUI/RosTEGUI.csproj trunk/tools/RosTE/GUI/VMConfig.xsd trunk/tools/RosTE/GUI/VMConfig.xsx trunk/tools/RosTE/GUI/VMDataBase.cs trunk/tools/RosTE/GUI/VirtualMachine.cs
Added: trunk/tools/RosTE/GUI/MainConfig.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/MainConfig.cs?rev=2... ============================================================================== --- trunk/tools/RosTE/GUI/MainConfig.cs (added) +++ trunk/tools/RosTE/GUI/MainConfig.cs Mon Jun 25 19:49:49 2007 @@ -1,0 +1,91 @@ +using System.Data; +using System.IO; +using System.Xml; +using System.Windows.Forms; + +namespace RosTEGUI +{ + public class MainConfig + { + private Data data = null; + + private static void PrintRows(DataTable dt) + { + for (int i = 0; i < dt.Rows.Count; i++) + { + string str = "row: " + i + ", VMConfigID: " + dt.Rows[i]["VMConfigID"] + ", Path " + dt.Rows[i]["Path"]; + MessageBox.Show(str); + } + } + + public MainConfig(Data dataIn) + { + data = dataIn; + + // FIXME: unfortunatley, .NET doesn't support binding of + // listview controls, we'll need to implement this manually + // and remove the need for LoadExistingImages / AddVirtMach / DeleteVirtMach + } + + public int GetNumberOfVms() + { + DataTable dt = data.DataSet.Tables["MainConfig"]; + return dt.Rows.Count; + } + + public VirtualMachine GetExistingImage(int index) + { + DataTable dt = data.DataSet.Tables["MainConfig"]; + DataRow dr = dt.Rows[index]; + + VirtualMachine vm = new VirtualMachine(data); + vm.LoadVirtMach((string)dr["Path"]); + return vm; + } + + public int AddVirtMach(string Path) + { + int i; + DataRow dr; + DataTable dt = data.DataSet.Tables["MainConfig"]; + i = dt.Rows.Count + 1; + dr = dt.NewRow(); + dr["VMConfigID"] = i; + dr["Path"] = Path; + dt.Rows.Add(dr); + return i; + } + + public void DeleteVirtMach(int index) + { + DataTable dt = data.DataSet.Tables["MainConfig"]; + dt.Rows.RemoveAt(index); + } + + public void SaveMainConfig() + { + string fileName = "Config.xml"; + 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(); + } + + public bool LoadMainConfig() + { + bool ret = false; + string fileName = "Config.xml"; + + if (File.Exists(fileName)) + { + FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); + XmlTextReader xtr = new XmlTextReader(fs); + data.DataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema); + xtr.Close(); + ret = true; + } + + return ret; + } + } +}
Modified: trunk/tools/RosTE/GUI/MainForm.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/MainForm.cs?rev=272... ============================================================================== --- trunk/tools/RosTE/GUI/MainForm.cs (original) +++ trunk/tools/RosTE/GUI/MainForm.cs Mon Jun 25 19:49:49 2007 @@ -13,7 +13,6 @@ { public partial class MainForm : Form { - //private ArrayList VirtualMachines; private MainConfig mainConf; private ArrayList vmConfigs; private Data mainData; @@ -44,7 +43,15 @@ mainConf = new MainConfig(mainData);
if (mainConf.LoadMainConfig()) - mainConf.LoadExistingImages(VirtMachListView); + { + int num = mainConf.GetNumberOfVms(); + for (int i = 0; i < num; i++) + { + VirtualMachine vm = mainConf.GetExistingImage(i); + ListViewItem lvi = VirtMachListView.Items.Add(vm.ToString(), 0); + lvi.Tag = vm; + } + } }
private void MainMenuHelpAbout_Click(object sender, EventArgs e) @@ -79,34 +86,41 @@ if (wizFrm.Option == 1) { int i = mainConf.AddVirtMach(wizFrm.DefDir); - VirtMachListView.Items.Add(i.ToString(), wizFrm.VMName, 0);
- vmConfigs.Add(new VMConfig(vmData, - wizFrm.VMName, - wizFrm.DefDir, - wizFrm.DiskSizeGB, - wizFrm.ExistImg, - wizFrm.MemSizeMB)); + VirtualMachine VirtMach = new VirtualMachine(vmData); + VirtMach.CreateVMConfig(wizFrm.VMName, + wizFrm.DefDir, + wizFrm.DiskSizeGB, + wizFrm.ExistImg, + wizFrm.MemSizeMB); + vmConfigs.Add(VirtMach); + + ListViewItem lvi = VirtMachListView.Items.Add(VirtMach.ToString(), 0); + lvi.Tag = VirtMach; } else if (wizFrm.Option == 2) {
DirectoryInfo di = Directory.GetParent(wizFrm.ExistImg); int i = mainConf.AddVirtMach(di.FullName); - VirtMachListView.Items.Add(i.ToString(), wizFrm.VMName, 0); + VirtualMachine VirtMach = new VirtualMachine(vmData); + VirtMach.CreateVMConfig(wizFrm.VMName, + wizFrm.ExistImg, + wizFrm.MemSizeMB); + vmConfigs.Add(VirtMach);
- vmConfigs.Add(new VMConfig(vmData, - wizFrm.VMName, - wizFrm.ExistImg, - wizFrm.MemSizeMB)); + ListViewItem lvi = VirtMachListView.Items.Add(VirtMach.ToString(), 0); + lvi.Tag = VirtMach; } else { int i = mainConf.AddVirtMach("Images\" + wizFrm.VMName); - VirtMachListView.Items.Add(i.ToString(), wizFrm.VMName, 0); + VirtualMachine VirtMach = new VirtualMachine(vmData); + VirtMach.CreateVMConfig(wizFrm.VMName); + vmConfigs.Add(VirtMach);
- vmConfigs.Add(new VMConfig(vmData, - wizFrm.VMName)); + ListViewItem lvi = VirtMachListView.Items.Add(VirtMach.ToString(), 0); + lvi.Tag = VirtMach; } } }
Modified: trunk/tools/RosTE/GUI/RosTEGUI.csproj URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/RosTEGUI.csproj?rev... ============================================================================== --- trunk/tools/RosTE/GUI/RosTEGUI.csproj (original) +++ trunk/tools/RosTE/GUI/RosTEGUI.csproj Mon Jun 25 19:49:49 2007 @@ -126,6 +126,9 @@ <Compile Include="DeleteVM.Designer.cs"> <DependentUpon>DeleteVM.cs</DependentUpon> </Compile> + <Compile Include="MainConfig.cs"> + <DependentUpon>MainConfig.xsd</DependentUpon> + </Compile> <Compile Include="MainForm.cs"> <SubType>Form</SubType> </Compile>
Modified: trunk/tools/RosTE/GUI/VMConfig.xsd URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/VMConfig.xsd?rev=27... ============================================================================== --- trunk/tools/RosTE/GUI/VMConfig.xsd (original) +++ trunk/tools/RosTE/GUI/VMConfig.xsd Mon Jun 25 19:49:49 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<xs:schema id="MainDB" targetNamespace="http://tempuri.org/MainDB.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/MainDB.xsd" xmlns:mstns="http://tempuri.org/MainDB.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema%22%3E +<xs:schema id="VMDB" targetNamespace="http://tempuri.org/MainDB.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/MainDB.xsd" xmlns:mstns="http://tempuri.org/MainDB.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema%22%3E <xs:element name="VMConfig"> xs:complexType xs:sequence @@ -29,14 +29,14 @@ xs:complexType xs:sequence <xs:element name="DiskID" type="xs:int" /> - <xs:element name="VMConfigID" type="xs:int" /> + <xs:element name="VirtMachID" type="xs:int" /> <xs:element name="Path" type="xs:string" /> <xs:element name="Size" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:keyref name="VMConfigHardDisks" refer="VMConfigKey"> <xs:selector xpath="." /> - <xs:field xpath="mstns:VMConfigID" /> + <xs:field xpath="mstns:VirtMachID" /> </xs:keyref> <xs:key name="HardDisksKey"> <xs:selector xpath="." /> @@ -47,7 +47,7 @@ xs:complexType xs:sequence <xs:element name="CardID" type="xs:int" /> - <xs:element name="VMConfigID" type="xs:int" /> + <xs:element name="VirtMachID" type="xs:int" /> <xs:element name="Option" type="xs:string" /> <xs:element name="Vlan" type="xs:int" /> <xs:element name="MacAddr" type="xs:string" /> @@ -57,7 +57,7 @@ </xs:complexType> <xs:keyref name="VMConfigNetCards" refer="VMConfigKey"> <xs:selector xpath="." /> - <xs:field xpath="mstns:VMConfigID" /> + <xs:field xpath="mstns:VirtMachID" /> </xs:keyref> <xs:key name="NetCardsKey"> <xs:selector xpath="." />
Modified: trunk/tools/RosTE/GUI/VMConfig.xsx URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/VMConfig.xsx?rev=27... ============================================================================== --- trunk/tools/RosTE/GUI/VMConfig.xsx (original) +++ trunk/tools/RosTE/GUI/VMConfig.xsx Mon Jun 25 19:49:49 2007 @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="utf-8"?> <!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.--> -<XSDDesignerLayout Style="LeftRight" layoutVersion="2" viewPortLeft="0" viewPortTop="-4677" zoom="100"> +<XSDDesignerLayout Style="LeftRight" layoutVersion="2" viewPortLeft="844" viewPortTop="-4677" zoom="100"> <VMConfig_XmlElement left="7091" top="-3148" width="7858" height="11721" selected="0" zOrder="0" index="0" expanded="1" /> - <HardDisks_XmlElement left="872" top="-3201" width="5292" height="2831" selected="0" zOrder="5" index="1" expanded="1" /> - <NetCards_XmlElement left="16033" top="-3176" width="5292" height="5371" selected="0" zOrder="2" index="2" expanded="1" /> - <VMConfigNetCards_XmlKeyref left="14808" top="-4433" width="503" height="503" selected="0" zOrder="10" expanded="0" /> - <VMConfigHardDisks_XmlKeyref left="6080" top="-4540" width="503" height="503" selected="0" zOrder="6" expanded="0" /> + <HardDisks_XmlElement left="872" top="-3201" width="5292" height="2831" selected="0" zOrder="2" index="1" expanded="1" /> + <NetCards_XmlElement left="16033" top="-3176" width="5292" height="5371" selected="0" zOrder="1" index="2" expanded="1" /> + <VMConfigNetCards_XmlKeyref left="14491" top="-4687" width="503" height="503" selected="0" zOrder="7" expanded="0" /> + <VMConfigHardDisks_XmlKeyref left="5763" top="-4794" width="503" height="503" selected="0" zOrder="3" expanded="0" /> </XSDDesignerLayout>
Modified: trunk/tools/RosTE/GUI/VMDataBase.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/VMDataBase.cs?rev=2... ============================================================================== --- trunk/tools/RosTE/GUI/VMDataBase.cs (original) +++ trunk/tools/RosTE/GUI/VMDataBase.cs Mon Jun 25 19:49:49 2007 @@ -54,132 +54,4 @@ return ret; } } - - public class MainConfig - { - private Data data = null; - - private int GetNumberOfVms() - { - DataTable dt = data.DataSet.Tables["MainConfig"]; - return dt.Rows.Count; - } - - private static void PrintRows(DataTable dt) - { - for (int i = 0; i < dt.Rows.Count; i++) - { - string str = "row: " + i + ", VMConfigID: " + dt.Rows[i]["VMConfigID"] + ", Path " + dt.Rows[i]["Path"]; - MessageBox.Show(str); - } - } - - public MainConfig(Data dataIn) - { - data = dataIn; - - // FIXME: unfortunatley, .NET doesn't support binding of - // listview controls, we'll need to implement this manually - // and remove the need for LoadExistingImages / AddVirtMach / DeleteVirtMach - } - - public void LoadExistingImages(ListView lv) - { - DataTable dt = data.DataSet.Tables["MainConfig"]; - - int num = GetNumberOfVms(); - for (int i = 0; i < num; i++) - { - DataRow dr = dt.Rows[i]; - - VirtualMachine vm = new VirtualMachine(data); - vm.LoadVirtMach((string)dr["Path"]); - - ListViewItem lvi = lv.Items.Add((string)dr["Path"], 0); - lvi.Tag = vm; - } - } - - public int AddVirtMach(string Path) - { - int i; - DataRow dr; - DataTable dt = data.DataSet.Tables["MainConfig"]; - i = dt.Rows.Count + 1; - dr = dt.NewRow(); - dr["VMConfigID"] = i; - dr["Path"] = Path; - dt.Rows.Add(dr); - return i; - } - - public void DeleteVirtMach(int index) - { - DataTable dt = data.DataSet.Tables["MainConfig"]; - dt.Rows.RemoveAt(index); - } - - public void SaveMainConfig() - { - string fileName = "Config.xml"; - 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(); - } - - public bool LoadMainConfig() - { - bool ret = false; - string fileName = "Config.xml"; - - if (File.Exists(fileName)) - { - FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); - XmlTextReader xtr = new XmlTextReader(fs); - data.DataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema); - xtr.Close(); - ret = true; - } - - return ret; - } - } - - - public class VMConfig - { - private Data data = null; - - // default - public VMConfig(Data dataIn, string name) : - this(dataIn, name, "Images\" + name, 0.2f, null, 256) - { - } - - // existing - public VMConfig(Data dataIn, string name, string existImg, int memSize) : - this(dataIn, name, null, 0.0f, existImg, memSize) - { - } - - // new - public VMConfig(Data dataIn, - string name, - string dir, - float diskSize, - string existImg, - int memSize) - { - data = dataIn; - - if (existImg != null) - { - DirectoryInfo di = Directory.GetParent(existImg); - dir = di.FullName; - } - - MessageBox.Show(name + " " + dir + " " + diskSize + " " + existImg + " " + memSize); - } - } }
Modified: trunk/tools/RosTE/GUI/VirtualMachine.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosTE/GUI/VirtualMachine.cs?r... ============================================================================== --- trunk/tools/RosTE/GUI/VirtualMachine.cs (original) +++ trunk/tools/RosTE/GUI/VirtualMachine.cs Mon Jun 25 19:49:49 2007 @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; @@ -11,6 +12,8 @@ { public class VirtualMachine { + private Data data; + private DataRow dataRow; private string machine; private StringCollection floppy; private StringCollection hardDisk; @@ -21,6 +24,18 @@ private int processors; private bool localTime; private bool fullScreen; + + public string Name + { + get + { + return (string)dataRow["Name"]; + } + set + { + dataRow["Name"] = value; + } + }
public string Machine { @@ -93,14 +108,51 @@ set { fullScreen = value; } }
+ public override string ToString() + { + return Name; + }
public VirtualMachine(Data dataIn) { - floppy = new StringCollection(); - hardDisk = new StringCollection(); + data = dataIn;
- Floppy.Add("test"); - //MessageBox.Show(Floppy[0]); + DataTable dt = data.DataSet.Tables["VMConfig"]; + dataRow = dt.NewRow(); + } + + // default + public bool CreateVMConfig(string name) + { + return CreateVMConfig(name, "Images\" + name, 0.2f, null, 256); + } + + // existing + public bool CreateVMConfig(string name, string existImg, int memSize) + { + return CreateVMConfig(name, null, 0.0f, existImg, memSize); + } + + // new + public bool CreateVMConfig(string name, + string dir, + float diskSize, + string existImg, + int memSize) + { + bool ret = false; + + if (existImg != null) + { + DirectoryInfo di = Directory.GetParent(existImg); + dir = di.FullName; + } + + Name = name; + + MessageBox.Show(name + " " + dir + " " + diskSize + " " + existImg + " " + memSize); + + return ret; }
public bool LoadVirtMach(string path)