mirror of
https://github.com/reactos/RosTE.git
synced 2024-11-26 21:00:31 +00:00
continue rewriting stuff...
svn path=/trunk/tools/RosTE/; revision=661
This commit is contained in:
parent
aecdd8c171
commit
25261e84b9
@ -21,7 +21,6 @@ namespace RosTEGUI
|
||||
|
||||
public class MainConfig
|
||||
{
|
||||
private VMConfig vmConfig = null;
|
||||
private DataSet dataSet = null;
|
||||
|
||||
private string qemuPath;
|
||||
@ -134,14 +133,14 @@ namespace RosTEGUI
|
||||
{
|
||||
if (dataSet != null && virtMachs != null)
|
||||
{
|
||||
int id = virtMachs.Count + 1;
|
||||
int id = virtMachs.Count;
|
||||
virtMachs.Add(new VirtMach(id, pathIn));
|
||||
}
|
||||
|
||||
return virtMachs.Count;
|
||||
}
|
||||
|
||||
public void DeleteVirtMach(int index)
|
||||
public bool DeleteVirtMach(int index)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
@ -153,6 +152,8 @@ namespace RosTEGUI
|
||||
bRet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
public int GetNumberOfVms()
|
||||
@ -311,6 +312,7 @@ namespace RosTEGUI
|
||||
#region private methods
|
||||
private bool LoadMainSchema()
|
||||
{
|
||||
XmlTextReader xtr = null;
|
||||
string filename = "MainConfig.xsd";
|
||||
bool ret = false;
|
||||
|
||||
@ -320,57 +322,14 @@ namespace RosTEGUI
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||
XmlTextReader xtr = new XmlTextReader(fs);
|
||||
xtr = new XmlTextReader(fs);
|
||||
dataSet.ReadXmlSchema(xtr);
|
||||
xtr.Close();
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading main config schema", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class VMConfig
|
||||
{
|
||||
private DataSet data = null;
|
||||
|
||||
public DataSet DataSet
|
||||
{
|
||||
get { return data; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the schema for the virtual machine configuration file
|
||||
/// </summary>
|
||||
/// <returns>True on success, false on failure</returns>
|
||||
public bool LoadVirtMachData()
|
||||
{
|
||||
XmlTextReader xtr = null;
|
||||
string filename = "VMConfig.xsd";
|
||||
bool ret = false;
|
||||
|
||||
data = new DataSet();
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||
xtr = new XmlTextReader(fs);
|
||||
data.ReadXmlSchema(xtr);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading VM config schema", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xtr != null)
|
||||
@ -380,5 +339,6 @@ namespace RosTEGUI
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ namespace RosTEGUI
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private MainConfig mainConf;
|
||||
private VMConfig mainData;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@ -44,6 +43,8 @@ namespace RosTEGUI
|
||||
VirtualMachine vm = new VirtualMachine();
|
||||
if (vm.LoadVMConfig(image))
|
||||
{
|
||||
vm.LoadVmSettings();
|
||||
|
||||
ListViewItem lvi = VirtMachListView.Items.Add(vm.ToString(), 0);
|
||||
lvi.SubItems.Add(vm.MemSize.ToString() + " MB");
|
||||
lvi.Tag = vm;
|
||||
|
@ -5,13 +5,35 @@ using System.Data;
|
||||
using System.Xml;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RosTEGUI
|
||||
{
|
||||
public struct VirtMachInfo
|
||||
{
|
||||
public int virtMachID;
|
||||
public string name;
|
||||
public string machType;
|
||||
public string defDir;
|
||||
public int memSize;
|
||||
public bool setClockToHost;
|
||||
public bool cdRomEnable;
|
||||
public bool cdRomUsePhys;
|
||||
public string cdRomPhysDrv;
|
||||
public bool cdRomUseIso;
|
||||
public string cdRomIsoImg;
|
||||
public bool floppyEnable;
|
||||
public bool floppyUsePhys;
|
||||
public string floppyPhysDrv;
|
||||
public bool floppyUseImg;
|
||||
public string floppyIsoImg;
|
||||
}
|
||||
|
||||
|
||||
public class VMHardDrive
|
||||
{
|
||||
private VMConfig vmConfig;
|
||||
private DataRow hdDataRow;
|
||||
private DataSet dataSet;
|
||||
|
||||
#region properties
|
||||
|
||||
@ -47,12 +69,6 @@ namespace RosTEGUI
|
||||
get { return (bool)hdDataRow["BootImg"]; }
|
||||
set { hdDataRow["BootImg"] = value; }
|
||||
}
|
||||
|
||||
public VMHardDrive(VMConfig vmConfigIn)
|
||||
{
|
||||
vmConfig = vmConfigIn;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
@ -70,7 +86,7 @@ namespace RosTEGUI
|
||||
|
||||
try
|
||||
{
|
||||
DataTable hddt = vmConfig.DataSet.Tables["HardDisks"];
|
||||
DataTable hddt = dataSet.Tables["HardDisks"];
|
||||
hdDataRow = hddt.NewRow();
|
||||
hdDataRow["DiskID"] = hddt.Rows.Count;
|
||||
hdDataRow["Name"] = nameIn;
|
||||
@ -93,7 +109,7 @@ namespace RosTEGUI
|
||||
|
||||
public void DeleteHardDrive(int diskID)
|
||||
{
|
||||
DataTable dt = vmConfig.DataSet.Tables["HardDisks"];
|
||||
DataTable dt = dataSet.Tables["HardDisks"];
|
||||
//DataRow dr = dt.Rows.Find(diskID); <-- can't seem to apply a primary key??
|
||||
// workaround for the above
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
@ -109,17 +125,23 @@ namespace RosTEGUI
|
||||
|
||||
public void LoadHardDrive(int index)
|
||||
{
|
||||
DataTable hddt = vmConfig.DataSet.Tables["HardDisks"];
|
||||
DataTable hddt = dataSet.Tables["HardDisks"];
|
||||
hdDataRow = hddt.Rows[index];
|
||||
}
|
||||
}
|
||||
|
||||
public class VirtualMachine
|
||||
{
|
||||
private VMConfig vmConfig;
|
||||
private DataRow vmDataRow;
|
||||
private List<VirtMachInfo> virtMachInfo = null;
|
||||
private ArrayList hardDrives;
|
||||
private ArrayList netCards;
|
||||
private DataSet dataSet = null;
|
||||
|
||||
public DataSet DataSet
|
||||
{
|
||||
get { return dataSet; }
|
||||
}
|
||||
|
||||
#region Virtual machine properties
|
||||
|
||||
@ -318,7 +340,7 @@ namespace RosTEGUI
|
||||
|
||||
try
|
||||
{
|
||||
DataTable vmdt = vmConfig.DataSet.Tables["VMConfig"];
|
||||
DataTable vmdt = dataSet.Tables["VMConfig"];
|
||||
vmDataRow = vmdt.NewRow();
|
||||
vmDataRow["VirtMachID"] = vmdt.Rows.Count + 1;
|
||||
vmDataRow["Name"] = name;
|
||||
@ -338,11 +360,11 @@ namespace RosTEGUI
|
||||
vmDataRow["FloppyIsoImg"] = string.Empty;
|
||||
vmdt.Rows.Add(vmDataRow);
|
||||
|
||||
VMHardDrive vmhd = new VMHardDrive(vmConfig);
|
||||
VMHardDrive vmhd = new VMHardDrive();
|
||||
vmhd.CreateHardDrive("Main Drive", "hda", dir, 768, true);
|
||||
hardDrives.Add(vmhd);
|
||||
|
||||
DataTable netdt = vmConfig.DataSet.Tables["NetCards"];
|
||||
DataTable netdt = dataSet.Tables["NetCards"];
|
||||
netDataRow = netdt.NewRow();
|
||||
netDataRow["CardID"] = netdt.Rows.Count + 1;
|
||||
netDataRow["VirtMachID"] = vmDataRow["VirtMachID"];
|
||||
@ -365,74 +387,18 @@ namespace RosTEGUI
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
vmConfig.DataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema);
|
||||
xtr.Close();
|
||||
|
||||
DataTable vmdt = vmConfig.DataSet.Tables["VMConfig"];
|
||||
vmDataRow = vmdt.Rows[0];
|
||||
|
||||
DataTable hddt = vmConfig.DataSet.Tables["HardDisks"];
|
||||
for (int i = 0; i < hddt.Rows.Count; i++)
|
||||
{
|
||||
VMHardDrive vmhd = new VMHardDrive(vmConfig);
|
||||
vmhd.LoadHardDrive(i);
|
||||
hardDrives.Add(vmhd);
|
||||
}
|
||||
|
||||
DataTable netdt = vmConfig.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);
|
||||
vmConfig.DataSet.WriteXml(xtw, System.Data.XmlWriteMode.WriteSchema);
|
||||
xtw.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show("error loading VM Config.xml: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
public VirtualMachine()
|
||||
{
|
||||
{/*
|
||||
vmConfig = new VMConfig();
|
||||
if (!vmConfig.LoadVirtMachData())
|
||||
MessageBox.Show("Failed to load VM Schema");
|
||||
|
||||
hardDrives = new ArrayList(3);
|
||||
netCards = new ArrayList();
|
||||
netCards = new ArrayList();*/
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -490,7 +456,7 @@ namespace RosTEGUI
|
||||
int sizeIn,
|
||||
bool bootImgIn)
|
||||
{
|
||||
VMHardDrive vmhd = new VMHardDrive(vmConfig);
|
||||
VMHardDrive vmhd = new VMHardDrive();
|
||||
if (vmhd.CreateHardDrive(nameIn, driveIn, pathIn, sizeIn, bootImgIn))
|
||||
{
|
||||
hardDrives.Add(vmhd);
|
||||
@ -510,5 +476,185 @@ namespace RosTEGUI
|
||||
{
|
||||
return hardDrives;
|
||||
}
|
||||
|
||||
|
||||
public bool LoadVmSettings()
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if (dataSet != null)
|
||||
{
|
||||
if (virtMachInfo == null)
|
||||
{
|
||||
virtMachInfo = new List<VirtMachInfo>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (DataRow vmRow in dataSet.Tables["VMConfig"].Rows)
|
||||
{
|
||||
VirtMachInfo vmi = new VirtMachInfo();
|
||||
vmi.virtMachID = (int)vmRow["VirtMachID"];
|
||||
vmi.name = (string)vmRow["Name"];
|
||||
vmi.machType = (string)vmRow["MachType"];
|
||||
vmi.defDir = (string)vmRow["DefDir"];
|
||||
vmi.memSize = (int)vmRow["MemSize"];
|
||||
vmi.setClockToHost = (bool)vmRow["SetClockToHost"];
|
||||
vmi.cdRomEnable = (bool)vmRow["CdRomEnable"];
|
||||
vmi.cdRomUsePhys = (bool)vmRow["CdRomUsePhys"];
|
||||
vmi.cdRomPhysDrv = (string)vmRow["CdRomPhysDrv"];
|
||||
vmi.cdRomUseIso = (bool)vmRow["CdRomUseIso"];
|
||||
vmi.cdRomIsoImg = (string)vmRow["CdRomIsoImg"];
|
||||
vmi.floppyEnable = (bool)vmRow["FloppyEnable"];
|
||||
vmi.floppyUsePhys = (bool)vmRow["FloppyUsePhys"];
|
||||
vmi.floppyPhysDrv = (string)vmRow["FloppyPhysDrv"];
|
||||
vmi.floppyUseImg = (bool)vmRow["FloppyUseImg"];
|
||||
vmi.floppyIsoImg = (string)vmRow["FloppyIsoImg"];
|
||||
|
||||
virtMachInfo.Add(vmi);
|
||||
}
|
||||
|
||||
bRet = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading VM config", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
public void SaveVmSettings()
|
||||
{
|
||||
if (dataSet != null)
|
||||
{
|
||||
dataSet.Tables["VirtMach"].Rows.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (VirtMachInfo vmi in virtMachInfo)
|
||||
{
|
||||
DataRow vmRow = dataSet.Tables["VirtMach"].NewRow();
|
||||
|
||||
vmRow["VirtMachID"] = vmi.virtMachID;
|
||||
vmRow["Name"] = vmi.name;
|
||||
vmRow["MachType"] = vmi.machType;
|
||||
vmRow["DefDir"] = vmi.defDir;
|
||||
vmRow["MemSize"] = vmi.memSize;
|
||||
vmRow["SetClockToHost"] = vmi.setClockToHost;
|
||||
vmRow["CdRomEnable"] = vmi.cdRomEnable;
|
||||
vmRow["CdRomUsePhys"] = vmi.cdRomUsePhys;
|
||||
vmRow["CdRomPhysDrv"] = vmi.cdRomPhysDrv;
|
||||
vmRow["CdRomUseIso"] = vmi.cdRomUseIso;
|
||||
vmRow["CdRomIsoImg"] = vmi.cdRomIsoImg;
|
||||
vmRow["FloppyEnable"] = vmi.floppyEnable;
|
||||
vmRow["FloppyUsePhys"] = vmi.floppyUsePhys;
|
||||
vmRow["FloppyPhysDrv"] = vmi.floppyPhysDrv;
|
||||
vmRow["FloppyUseImg"] = vmi.floppyUseImg;
|
||||
vmRow["FloppyIsoImg"] = vmi.floppyIsoImg;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading VM config", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool LoadVMConfig(string path)
|
||||
{
|
||||
XmlTextReader xtr = null;
|
||||
string fileName = path + "\\Config.xml";
|
||||
bool ret = false;
|
||||
|
||||
if (LoadVirtMachSchema())
|
||||
{
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
||||
xtr = new XmlTextReader(fs);
|
||||
dataSet.ReadXml(xtr, System.Data.XmlReadMode.ReadSchema);
|
||||
xtr.Close();
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading VM config", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xtr != null)
|
||||
xtr.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void SaveVMConfig()
|
||||
{
|
||||
XmlTextWriter xtw = null;
|
||||
string fileName = DefDir + "\\Config.xml";
|
||||
|
||||
if (!Directory.Exists(DefDir))
|
||||
Directory.CreateDirectory(DefDir);
|
||||
|
||||
if (dataSet == null)
|
||||
{
|
||||
if (!LoadVirtMachSchema())
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
|
||||
xtw = new XmlTextWriter(fs, System.Text.Encoding.Unicode);
|
||||
dataSet.WriteXml(xtw, System.Data.XmlWriteMode.WriteSchema);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error saving VM config", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xtw != null)
|
||||
xtw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private bool LoadVirtMachSchema()
|
||||
{
|
||||
XmlTextReader xtr = null;
|
||||
string filename = "VMConfig.xsd";
|
||||
bool ret = false;
|
||||
|
||||
dataSet = new DataSet();
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||
xtr = new XmlTextReader(fs);
|
||||
dataSet.ReadXmlSchema(xtr);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage("error loading VM config schema", ex.Message, ex.StackTrace, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xtr != null)
|
||||
xtr.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user