51
51
public VMItem (XmlAttributeCollection MachineAttrs)
53
53
string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
55
uuid = MachineAttrs["uuid"].Value.Replace("{", "").Replace("}", "");
55
uuid = MachineAttrs["uuid"].Value.Replace ("{", "").Replace("}", "");
56
56
//find machine specific xml file
57
57
string MachineSource = MachineAttrs["src"].Value;
58
if (!File.Exists (MachineSource)) {
59
MachineSource = string.Format("{0}/.VirtualBox/{1}", home, MachineSource);
58
if (!File.Exists (MachineSource))
59
MachineSource = Path.Combine (Path.Combine (home, ".VirtualBox"), MachineSource);
61
60
//find the OS type of the machine
62
XmlDocument MachineDoc = new XmlDocument();
63
MachineDoc.Load(MachineSource);
61
XmlDocument MachineDoc = new XmlDocument ();
62
MachineDoc.Load (MachineSource);
64
63
XmlNodeList MachineInfo = MachineDoc.GetElementsByTagName("Machine");
65
64
name = MachineInfo[0].Attributes["name"].Value;
68
ico_file = string.Format("os_{0}.png@{1}", MachineInfo[0].Attributes["OSType"].Value, GetType().Assembly.FullName);
67
string icon = IconMap.LookUp (MachineInfo[0].Attributes["OSType"].Value);
68
ico_file = string.Format("os_{0}.png@{1}", icon, GetType ().Assembly.FullName);
70
catch //can't find icon, assign default VBox Icon
70
catch //something went bad trying to assign an icon
72
Log.Warn("Could not determine machine type for VM: {0}", name);
73
ico_file = string.Format("VirtualBox_64px.png@{0}", GetType().Assembly.FullName);
72
Log<VMItem>.Warn ("Could not determine machine type for VM: {0}", name);
73
ico_file = string.Format ("VirtualBox_64px.png@{0}", GetType().Assembly.FullName);
75
75
this.state = CurrentState;
76
Log.Info("VM: {0} indexed [State: {1} Uuid: {2}]", name, state, uuid);
76
Log<VMItem>.Info ("VM: {0} indexed [State: {1} Uuid: {2}]", name, state, uuid);
79
79
public VMState CurrentState
83
VMState cur_state = default(VMState);
83
VMState cur_state = default (VMState);
84
84
//determine the state of thte VM
85
85
ProcessStartInfo ps = new ProcessStartInfo ("VBoxManage", "showvminfo " + uuid);
86
86
ps.UseShellExecute = false;
91
91
string output = p.StandardOutput.ReadToEnd ();
92
int s = output.IndexOf("State:");
93
int e = output.IndexOf("\n", s);
92
int s = output.IndexOf ("State:");
93
int e = output.IndexOf ("\n", s);
94
94
string outputState = output.Substring(s, e-s);
95
95
//States: saved, running, paused, powered off
96
if (outputState.Contains("saved"))
96
if (outputState.Contains ("saved"))
97
97
cur_state = VMState.saved;
98
else if (outputState.Contains("running"))
98
else if (outputState.Contains ("running"))
99
99
cur_state = VMState.on;
100
else if (outputState.Contains("paused"))
100
else if (outputState.Contains ("paused"))
101
101
cur_state = VMState.paused;
102
else if (outputState.Contains("powered off"))
102
else if (outputState.Contains ("powered off"))
103
103
cur_state = VMState.off;
104
if (output.Contains("Snapshots:"))
104
if (output.Contains ("Snapshots:"))
105
105
has_saved_states = true;
107
107
return cur_state;