Skip to content

Commit c779ed9

Browse files
committed
3.1 build 20171014
**experimental** fix compilation error in VMGuide.CUI refined descriptions for VMware hardware options fix bugs in unattend mode
1 parent e4a60b5 commit c779ed9

File tree

10 files changed

+140
-146
lines changed

10 files changed

+140
-146
lines changed

VMGuide.CUI/Program.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,24 @@ static Errors Set(string command)
233233
case "acpi":
234234
if (bool.TryParse(value, out bool ACPI_Val))
235235
{
236-
CurrentVM.ACPI = ACPI_Val;
236+
//Virtual PC暂不支持ACPI设置
237+
if (CurrentVM is VirtualMachineWithACPI)
238+
((VirtualMachineWithACPI)CurrentVM).ACPI = ACPI_Val;
239+
237240
ret = Errors.Complete;
238241
}
239242
break;
240243

241244
case "firmware":
242-
if (CurrentVM is VMwareVM && Array.IndexOf (VMware.Firmwares, value) != -1)
245+
if (CurrentVM is VMwareVM && VMware.Firmwares.ContainsKey(value))
243246
{
244247
((VMwareVM)CurrentVM).Firmware = value;
245248
ret = Errors.Complete;
246249
}
247250
break;
248251

249252
case "sound":
250-
if (CurrentVM is VMwareVM && Array.IndexOf(VMware.SoundCards, value) != -1)
253+
if (CurrentVM is VMwareVM && VMware.SoundCards.ContainsKey(value))
251254
{
252255
((VMwareVM)CurrentVM).SoundCard = value;
253256
ret = Errors.Complete;
@@ -262,7 +265,7 @@ static Errors Set(string command)
262265
var nic = new List<string>();
263266
foreach (string s in split)
264267
{
265-
if (s == "none" || Array.IndexOf(VMware.NICs, s) == -1) continue;
268+
if (s == "none" || !VMware.NICs.ContainsKey(s)) continue;
266269
nic.Add(s);
267270
}
268271
((VMwareVM)CurrentVM).NICs = nic;

VMGuide.Core/base.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
namespace VMGuide
66
{
7+
//虚拟机基类
78
public class VirtualMachine
89
{
910
private string path;
1011
public string Path { get { return path; } }
1112
public string Name { get; set; }
1213

14+
public VirtualMachine(string FilePath = null)
15+
{
16+
path = FilePath;
17+
if (FilePath != null) Name = System.IO.Path.GetFileNameWithoutExtension(FilePath);
18+
}
19+
20+
//输出设置值
1321
public virtual void ShowSettings()
1422
{
1523
if (Path == null) return;
@@ -22,22 +30,33 @@ public virtual void ShowSettings()
2230

2331
Console.WriteLine($"Date Lock\t{DateLock}");
2432
Console.WriteLine($"BIOS Date\t{BIOSDate.ToShortDateString()}");
25-
if (!(this is VirtualPC_VM)) Console.WriteLine($"ACPI Enabled\t{ACPI}");
2633
}
27-
28-
public virtual Boolean ACPI { get; set; }
29-
34+
3035
public virtual Boolean DateLock { get; set; }
3136

3237
public virtual DateTime BIOSDate { get; set; }
3338

39+
//返回当前虚拟机是否已锁定
3440
public virtual Boolean IsLocked { get { return false; } }
3541

36-
public VirtualMachine(string FilePath = null)
42+
}
43+
44+
//支持修改ACPI的虚拟机基类
45+
public class VirtualMachineWithACPI : VirtualMachine
46+
{
47+
public VirtualMachineWithACPI(string FilePath) : base(FilePath) { }
48+
49+
//输出设置值
50+
public override void ShowSettings()
3751
{
38-
path = FilePath;
39-
if (FilePath != null) Name = System.IO.Path.GetFileNameWithoutExtension(FilePath);
52+
if (Path == null) return;
53+
54+
base.ShowSettings();
55+
56+
Console.WriteLine($"ACPI Enabled\t{ACPI}");
4057
}
58+
59+
public virtual Boolean ACPI { get; set; }
4160
}
4261

4362
public class Core
@@ -51,6 +70,7 @@ public static string GetCoreVersion()
5170
return ($"VMGuide Core {FileVersion.FileMajorPart}.{FileVersion.FileMinorPart} ({FileVersion.Comments})");
5271
}
5372

73+
//搜索虚拟机
5474
public static List<VirtualMachine> SearchVM()
5575
{
5676
var VMList = new List<VirtualMachine>();

VMGuide.Core/vbox.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace VMGuide
88
{
9-
public class VBoxVM : VirtualMachine
9+
public class VBoxVM : VirtualMachineWithACPI
1010
{
1111
VBoxXML XML;
1212

@@ -43,11 +43,9 @@ public override DateTime BIOSDate
4343

4444
string value; DateTime ret = DateTime.Now;
4545
value = XML.ReadAttribute(@"VirtualBox/Machine/Hardware/BIOS/TimeOffset", "value");
46-
46+
4747
if (double.TryParse(value, out double TimeOffest))
48-
{
4948
ret = ret.AddMilliseconds(TimeOffest);
50-
}
5149

5250
return ret;
5351
}
@@ -97,6 +95,7 @@ public override bool IsLocked
9795
}
9896
}
9997

98+
//读写VirtualBox相关XML配置文件的类
10099
public class VBoxXML
101100
{
102101
private string path;
@@ -114,7 +113,8 @@ public VBoxXML (string FilePath)
114113
NamespaceMgr.AddNamespace("v", "http://www.virtualbox.org/");
115114
}
116115

117-
public string XPathConvert(string XPath) //add prefix
116+
//不带namespace的路转换为带namespace修饰的路径
117+
public string XPathConvert(string XPath)
118118
{
119119
if (XPath.Substring(0, 2) == "v:") return XPath;
120120

@@ -149,9 +149,7 @@ public List<string> ReadAttributes(string XPath, string name)
149149
NodeList = XML.SelectNodes(XPath, NamespaceMgr);
150150

151151
foreach (XmlNode node in NodeList)
152-
{
153152
list.Add(node.Attributes[name].Value);
154-
}
155153
}
156154
catch { }
157155

@@ -178,18 +176,20 @@ public void WriteAttribute(string XPath, string Attribute, string Value) //no pr
178176

179177
XML.Save(Path);
180178
}
179+
180+
//根据一个路径,一路创建一棵树
181181
private void CreateTree (string XPath)
182182
{
183183
char[] s = { '/' };
184184
var Elements = XPathConvert(XPath).Split(s);
185185

186-
XmlNode Parent = XML;
186+
XmlNode Parent = XML; //从XML的根开始操作
187187
foreach (string Element in Elements)
188188
{
189189
var Node = Parent.SelectSingleNode(Element, NamespaceMgr);
190190
if (Node == null)
191191
{
192-
var name = Element.Replace("v:", ""); //Name only, remove prefix
192+
var name = Element.Replace("v:", ""); //CreateNode方法需要的是没有前缀修饰的名字
193193
var Child = XML.CreateNode(XmlNodeType.Element, name, "http://www.virtualbox.org/");
194194
Parent.AppendChild(Child);
195195
Parent = Parent.SelectSingleNode(Element, NamespaceMgr);

VMGuide.Core/virtualpc.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public override bool DateLock
3232
}
3333

3434
var str = XML.ReadValue(XPath);
35-
//var value = false;
3635

3736
if (bool.TryParse(str, out bool value) == false) value = true;
3837
value = !value; //value is "time sync enabled", but we need "date lock enabled"
@@ -122,6 +121,7 @@ public override DateTime BIOSDate
122121
}
123122
}
124123

124+
//判断是否为Windows Virtual PC
125125
public bool IsVersion7
126126
{
127127
get
@@ -132,6 +132,7 @@ public bool IsVersion7
132132
}
133133
}
134134

135+
//读写VirtualPC相关XML配置文件的类
135136
public class VirtualPC_XML
136137
{
137138
private string path;
@@ -180,12 +181,13 @@ public void WriteValue(string XPath, string type, string value)
180181
XML.Save(Path);
181182
}
182183

184+
//根据一个路径,一路创建一棵树
183185
private void CreateTree(string XPath)
184186
{
185187
char[] s = { '/' };
186188
var Elements = (XPath).Split(s);
187189

188-
XmlNode Parent = XML;
190+
XmlNode Parent = XML; //从根开始操作
189191

190192
foreach (string Element in Elements)
191193
{

VMGuide.Core/vmware.cs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace VMGuide
88
{
9+
//读写VMX配置文件的类
10+
//VMX本身是key=value形式的键值对
911
public class VMXFile
1012
{
1113
private string file;
@@ -57,7 +59,7 @@ public void WriteValue(string key, string value)
5759

5860
}
5961

60-
public class VMwareVM : VirtualMachine //设置会直接储存
62+
public class VMwareVM : VirtualMachineWithACPI //设置会直接储存
6163
{
6264
VMXFile VMX;
6365

@@ -75,15 +77,15 @@ public override void ShowSettings()
7577
base.ShowSettings();
7678

7779
Console.WriteLine("Firmware\t{0}", Firmware.ToUpper());
78-
Console.WriteLine("Sound Card\t{0}", SoundCard);
80+
Console.WriteLine("Sound Card\t{0}\t{1}", SoundCard, VMware.ValueToDescripton(SoundCard));
7981
Console.WriteLine();
8082

8183
List<string> NIC = NICs;
8284
if (NIC.Count >0) Console.Write("NICs");
8385

8486
for (int i = 0; i < NIC.Count; i++)
8587
{
86-
Console.WriteLine("\t[{0}]\t{1}", i, NIC[i]);
88+
Console.WriteLine("\t[{0}]\t{1}\t{2}", i, NIC[i], VMware.ValueToDescripton(NIC[i]));
8789
}
8890
}
8991

@@ -250,6 +252,7 @@ public override bool DateLock
250252
}
251253
}
252254

255+
//vmware的BIOSDate保存为unix时间戳
253256
public override DateTime BIOSDate
254257
{
255258
get
@@ -353,36 +356,7 @@ public static string ValueToDescripton(string value)
353356
if (NICs.ContainsKey(value)) return NICs[value];
354357
return "";
355358
}
356-
/*
357-
public static string DescriptionToValue(string des)
358-
{
359-
int index = -1, i;
360-
string ret = des;
361359

362-
for (i = 0; i < 3; i++)
363-
{
364-
switch (i)
365-
{
366-
case 0:
367-
index = Array.IndexOf(fw_des, des.ToLower());
368-
if (index != -1) ret = Firmwares[index];
369-
break;
370-
case 1:
371-
index = Array.IndexOf(snd_des, des.ToLower());
372-
if (index != -1) ret = SoundCards[index];
373-
break;
374-
case 2:
375-
index = Array.IndexOf(nic_des, des.ToLower());
376-
if (index != -1) ret = NICs[index];
377-
break;
378-
}
379-
380-
if (index != -1) break;
381-
}
382-
383-
return ret;
384-
}
385-
*/
386360
public static void SearchVM(ref List<VirtualMachine> VMList)
387361
{
388362
/*

VMGuide.GUI/HomePage.xaml

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,9 @@
9696

9797
<Grid Margin="0,0,0,0" Background="#184689" Grid.Row="1" >
9898
<Image x:Name="image" HorizontalAlignment="Left" Width="60" Margin="15,5,0,15" Source="Resources\logo.png"/>
99-
<Label x:Name="label" VerticalAlignment="Top" Height="40" Margin="85,5,10,0"
100-
Foreground="White" FontFamily="Microsoft Yahei Light" VerticalContentAlignment="Center"
101-
Padding="0" IsEnabled="{Binding ElementName=page_home,Path=IsUnattendMode.Value}">
102-
<Label.Style >
103-
<Style TargetType="Label" >
104-
<Style.Triggers >
105-
<Trigger Property="IsEnabled" Value="true">
106-
<Setter Property="FontSize" Value="30"/>
107-
<Setter Property="Content" Value="Importing Settings"/>
108-
</Trigger>
109-
<Trigger Property="IsEnabled" Value="false">
110-
<Setter Property="FontSize" Value="35"/>
111-
<Setter Property="Content" Value="Welcome"/>
112-
</Trigger>
113-
</Style.Triggers>
114-
</Style>
115-
</Label.Style>
116-
</Label>
99+
<Label x:Name="label" VerticalAlignment="Top" Height="40" Margin="85,5,10,0" FontSize="35" Content="Welcome"
100+
Foreground="White" FontFamily="Microsoft Yahei Light" VerticalContentAlignment="Center" Padding="0"/>
101+
117102
<Label x:Name="label1" Margin="85,45,10,15" Foreground="White"
118103
Content="To Continue, please select a virtual machine."
119104
FontFamily="Microsoft Yahei Light" FontSize="14"
@@ -122,13 +107,11 @@
122107

123108
<ScrollViewer Margin="50,30,50,30" Grid.Row="2" VerticalScrollBarVisibility="Auto">
124109
<StackPanel Margin="0">
125-
<Grid Margin="5" Visibility="{Binding ElementName=page_home,Path=IsUnattendMode.Value,Converter={StaticResource BooleanToCollapseConverter } }">
110+
<Grid x:Name="grid_unattendMode" Margin="5" Visibility="{Binding ElementName=page_home,Path=IsUnattendMode.Value,Converter={StaticResource BooleanToCollapseConverter}}">
126111
<Label x:Name ="ImportPrompt" Content="Importing setting: BIOSDate 20160101" HorizontalAlignment="Left" FontSize="12"/>
127112
<Button x:Name="ImportCancel" Style="{StaticResource TextButtonStyle}" Content="Cancel" HorizontalAlignment="Right" HorizontalContentAlignment="Center" Click="ImportCancel_Click"/>
128-
129113
</Grid>
130114

131-
132115
<Grid x:Name="grid_vpc" Height="Auto" Style="{StaticResource GridList }"
133116
Visibility="{Binding ElementName=listbox_vpc,Path=HasItems,Converter={StaticResource BooleanToCollapseConverter} }">
134117

@@ -162,22 +145,22 @@
162145
</StackPanel>
163146
</ScrollViewer>
164147

165-
<StackPanel Grid.Row="3" Margin="0,0,0,0" Background="#f2f2f2" Orientation="Horizontal" >
166-
<ToggleButton x:Name="settingsToggle" Width="68" Height="48"
167-
HorizontalAlignment="Right" VerticalAlignment="Top" Content="&#xE713;"
168-
FontSize="18" Style="{StaticResource ToolBarToggleStyle }"
169-
IsHitTestVisible="{Binding ElementName=settingsPopup, Path=IsOpen ,Converter={StaticResource BooleanReverseConverter}}"/>
170-
171-
<Button Width="68" Margin="0,0,68,0"
172-
HorizontalAlignment="Right" Content="&#xE109;"
173-
FontSize="18" Style="{StaticResource ToolBarButtonStyle }" Click="Button_Click"/>
174-
</StackPanel>
175-
148+
<Grid Grid.Row="3" Margin="0,0,0,0" Background="#f2f2f2">
149+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
150+
151+
<Button HorizontalAlignment="Right" Content="&#xE109;" FontSize="18"
152+
Style="{StaticResource ToolBarButtonStyle }" Click="Button_Click"/>
153+
<ToggleButton x:Name="settingsToggle" Content="&#xE713;" Style="{StaticResource ToolBarToggleStyle }" FontSize="18"
154+
IsHitTestVisible="{Binding ElementName=settingsPopup, Path=IsOpen ,Converter={StaticResource BooleanReverseConverter}}"/>
155+
156+
</StackPanel>
157+
</Grid>
158+
176159
<Popup x:Name="settingsPopup" StaysOpen="False"
177160
IsOpen="{Binding ElementName=settingsToggle ,Path=IsChecked}"
178161
Placement="Top" PlacementTarget="{Binding ElementName=settingsToggle}">
179162

180-
<ListBox Width="{Binding ElementName=settingsToggle,Path=Width}">
163+
<ListBox Width="{Binding ElementName=settingsToggle,Path=Width}" ItemContainerStyle="{StaticResource MenuListBoxItem}">
181164
<ListBoxItem Content="Refresh" MouseUp="RefreshMenuClicked"/>
182165
<ListBoxItem Content="About" MouseUp="AboutMenuClicked"/>
183166
</ListBox>

0 commit comments

Comments
 (0)