mirror of
https://github.com/reactos/RosTE.git
synced 2025-02-17 01:49:41 +00:00
object restructuring
svn path=/trunk/tools/RosTE/; revision=250
This commit is contained in:
parent
b72e145c4b
commit
d032917b3a
91
GUI/MainConfig.cs
Normal file
91
GUI/MainConfig.cs
Normal file
@ -0,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;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ namespace RosTEGUI
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
//private ArrayList VirtualMachines;
|
||||
private MainConfig mainConf;
|
||||
private ArrayList vmConfigs;
|
||||
private Data mainData;
|
||||
@ -44,7 +43,15 @@ namespace RosTEGUI
|
||||
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 @@ namespace RosTEGUI
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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">
|
||||
<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">
|
||||
<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="." />
|
||||
|
@ -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>
|
@ -54,132 +54,4 @@ namespace RosTEGUI
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
@ -11,6 +12,8 @@ namespace RosTEGUI
|
||||
{
|
||||
public class VirtualMachine
|
||||
{
|
||||
private Data data;
|
||||
private DataRow dataRow;
|
||||
private string machine;
|
||||
private StringCollection floppy;
|
||||
private StringCollection hardDisk;
|
||||
@ -22,6 +25,18 @@ namespace RosTEGUI
|
||||
private bool localTime;
|
||||
private bool fullScreen;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)dataRow["Name"];
|
||||
}
|
||||
set
|
||||
{
|
||||
dataRow["Name"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Machine
|
||||
{
|
||||
get { return machine; }
|
||||
@ -93,14 +108,51 @@ namespace RosTEGUI
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user