3
// GNOME Do is the legal property of its developers.
4
// Please refer to the COPYRIGHT file distributed with this
5
// source distribution.
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Diagnostics;
22
using System.Collections.Generic;
25
using System.Threading;
41
public class VMItem : IItem
46
bool has_saved_states = false;
49
public VMItem (string xmlLineEntry) {
50
uuid = xmlLineEntry.Substring(xmlLineEntry.IndexOf("uuid=\"{")+7,36);
51
//find machine specific xml file
52
int StartMachinePath = xmlLineEntry.IndexOf("src=\"")+5;
53
int EndMachinePath = xmlLineEntry.LastIndexOf(".xml\" ");
54
string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
55
string MachineSource = ("~/.VirtualBox/"+xmlLineEntry.Substring(StartMachinePath,(EndMachinePath+4) - StartMachinePath)).Replace ("~", home);
56
//parse machine specific xml file
59
StreamReader re = File.OpenText(MachineSource);
61
while ((input = re.ReadLine()) != null)
63
if ((input.Length > 20) && (input.Substring(0,11) == " <Machine "))
65
int start = input.IndexOf("OSType=\"")+8;
66
int end = input.IndexOf("\" lastState");
67
ico_file = "os_" + input.Substring(start,end-start) + ".png";
72
catch //can't find icon, assign default VBox Icon
74
ico_file = "VirtualBox_64px.png@"+GetType().Assembly.FullName;
76
ico_file += "@"+GetType().Assembly.FullName;
77
string[] split = xmlLineEntry.Substring(StartMachinePath,EndMachinePath -StartMachinePath).Split('/');
79
//determine the state of thte VM
80
ProcessStartInfo ps = new ProcessStartInfo ("VBoxManage", "showvminfo " + uuid);
81
ps.UseShellExecute = false;
82
ps.RedirectStandardOutput = true;
83
using (Process p = Process.Start (ps)) {
85
string output = p.StandardOutput.ReadToEnd ();
86
int s = output.IndexOf("State:");
87
int e = output.IndexOf("\n", s);
88
string outputState = output.Substring(s, e-s);
89
//States: saved, running, paused, powered off
90
if (outputState.Contains("saved"))
91
state = VMState.saved;
92
else if (outputState.Contains("running"))
94
else if (outputState.Contains("paused"))
95
state = VMState.paused;
96
else if (outputState.Contains("powered off"))
98
if (output.Contains("Snapshots:"))
99
has_saved_states = true;
103
public string Name { get { return name; } }
104
public string Uuid { get { return uuid; } }
105
public bool HasSavedStates { get { return has_saved_states; } }
106
public VMState Status
108
get { return state; }
109
set { state = value; }
111
public string Description { get { return "Virtual Machine: " + name; } }
112
public string Icon { get { return ico_file; } }
b'\\ No newline at end of file'