Skip to content

Commit

Permalink
3.1 build 20171014
Browse files Browse the repository at this point in the history
**experimental**

fix compilation error in VMGuide.CUI
refined descriptions for VMware hardware options
fix bugs in unattend mode
  • Loading branch information
driver1998 committed Oct 14, 2017
1 parent e4a60b5 commit c779ed9
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 146 deletions.
11 changes: 7 additions & 4 deletions VMGuide.CUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,24 @@ static Errors Set(string command)
case "acpi":
if (bool.TryParse(value, out bool ACPI_Val))
{
CurrentVM.ACPI = ACPI_Val;
//Virtual PC暂不支持ACPI设置
if (CurrentVM is VirtualMachineWithACPI)
((VirtualMachineWithACPI)CurrentVM).ACPI = ACPI_Val;

ret = Errors.Complete;
}
break;

case "firmware":
if (CurrentVM is VMwareVM && Array.IndexOf (VMware.Firmwares, value) != -1)
if (CurrentVM is VMwareVM && VMware.Firmwares.ContainsKey(value))
{
((VMwareVM)CurrentVM).Firmware = value;
ret = Errors.Complete;
}
break;

case "sound":
if (CurrentVM is VMwareVM && Array.IndexOf(VMware.SoundCards, value) != -1)
if (CurrentVM is VMwareVM && VMware.SoundCards.ContainsKey(value))
{
((VMwareVM)CurrentVM).SoundCard = value;
ret = Errors.Complete;
Expand All @@ -262,7 +265,7 @@ static Errors Set(string command)
var nic = new List<string>();
foreach (string s in split)
{
if (s == "none" || Array.IndexOf(VMware.NICs, s) == -1) continue;
if (s == "none" || !VMware.NICs.ContainsKey(s)) continue;
nic.Add(s);
}
((VMwareVM)CurrentVM).NICs = nic;
Expand Down
34 changes: 27 additions & 7 deletions VMGuide.Core/base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

namespace VMGuide
{
//虚拟机基类
public class VirtualMachine
{
private string path;
public string Path { get { return path; } }
public string Name { get; set; }

public VirtualMachine(string FilePath = null)
{
path = FilePath;
if (FilePath != null) Name = System.IO.Path.GetFileNameWithoutExtension(FilePath);
}

//输出设置值
public virtual void ShowSettings()
{
if (Path == null) return;
Expand All @@ -22,22 +30,33 @@ public virtual void ShowSettings()

Console.WriteLine($"Date Lock\t{DateLock}");
Console.WriteLine($"BIOS Date\t{BIOSDate.ToShortDateString()}");
if (!(this is VirtualPC_VM)) Console.WriteLine($"ACPI Enabled\t{ACPI}");
}

public virtual Boolean ACPI { get; set; }


public virtual Boolean DateLock { get; set; }

public virtual DateTime BIOSDate { get; set; }

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

public VirtualMachine(string FilePath = null)
}

//支持修改ACPI的虚拟机基类
public class VirtualMachineWithACPI : VirtualMachine
{
public VirtualMachineWithACPI(string FilePath) : base(FilePath) { }

//输出设置值
public override void ShowSettings()
{
path = FilePath;
if (FilePath != null) Name = System.IO.Path.GetFileNameWithoutExtension(FilePath);
if (Path == null) return;

base.ShowSettings();

Console.WriteLine($"ACPI Enabled\t{ACPI}");
}

public virtual Boolean ACPI { get; set; }
}

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

//搜索虚拟机
public static List<VirtualMachine> SearchVM()
{
var VMList = new List<VirtualMachine>();
Expand Down
18 changes: 9 additions & 9 deletions VMGuide.Core/vbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace VMGuide
{
public class VBoxVM : VirtualMachine
public class VBoxVM : VirtualMachineWithACPI
{
VBoxXML XML;

Expand Down Expand Up @@ -43,11 +43,9 @@ public override DateTime BIOSDate

string value; DateTime ret = DateTime.Now;
value = XML.ReadAttribute(@"VirtualBox/Machine/Hardware/BIOS/TimeOffset", "value");

if (double.TryParse(value, out double TimeOffest))
{
ret = ret.AddMilliseconds(TimeOffest);
}

return ret;
}
Expand Down Expand Up @@ -97,6 +95,7 @@ public override bool IsLocked
}
}

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

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

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

foreach (XmlNode node in NodeList)
{
list.Add(node.Attributes[name].Value);
}
}
catch { }

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

XML.Save(Path);
}

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

XmlNode Parent = XML;
XmlNode Parent = XML; //从XML的根开始操作
foreach (string Element in Elements)
{
var Node = Parent.SelectSingleNode(Element, NamespaceMgr);
if (Node == null)
{
var name = Element.Replace("v:", ""); //Name only, remove prefix
var name = Element.Replace("v:", ""); //CreateNode方法需要的是没有前缀修饰的名字
var Child = XML.CreateNode(XmlNodeType.Element, name, "http://www.virtualbox.org/");
Parent.AppendChild(Child);
Parent = Parent.SelectSingleNode(Element, NamespaceMgr);
Expand Down
6 changes: 4 additions & 2 deletions VMGuide.Core/virtualpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public override bool DateLock
}

var str = XML.ReadValue(XPath);
//var value = false;

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

//判断是否为Windows Virtual PC
public bool IsVersion7
{
get
Expand All @@ -132,6 +132,7 @@ public bool IsVersion7
}
}

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

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

XmlNode Parent = XML;
XmlNode Parent = XML; //从根开始操作

foreach (string Element in Elements)
{
Expand Down
38 changes: 6 additions & 32 deletions VMGuide.Core/vmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace VMGuide
{
//读写VMX配置文件的类
//VMX本身是key=value形式的键值对
public class VMXFile
{
private string file;
Expand Down Expand Up @@ -57,7 +59,7 @@ public void WriteValue(string key, string value)

}

public class VMwareVM : VirtualMachine //设置会直接储存
public class VMwareVM : VirtualMachineWithACPI //设置会直接储存
{
VMXFile VMX;

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

Console.WriteLine("Firmware\t{0}", Firmware.ToUpper());
Console.WriteLine("Sound Card\t{0}", SoundCard);
Console.WriteLine("Sound Card\t{0}\t{1}", SoundCard, VMware.ValueToDescripton(SoundCard));
Console.WriteLine();

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

for (int i = 0; i < NIC.Count; i++)
{
Console.WriteLine("\t[{0}]\t{1}", i, NIC[i]);
Console.WriteLine("\t[{0}]\t{1}\t{2}", i, NIC[i], VMware.ValueToDescripton(NIC[i]));
}
}

Expand Down Expand Up @@ -250,6 +252,7 @@ public override bool DateLock
}
}

//vmware的BIOSDate保存为unix时间戳
public override DateTime BIOSDate
{
get
Expand Down Expand Up @@ -353,36 +356,7 @@ public static string ValueToDescripton(string value)
if (NICs.ContainsKey(value)) return NICs[value];
return "";
}
/*
public static string DescriptionToValue(string des)
{
int index = -1, i;
string ret = des;

for (i = 0; i < 3; i++)
{
switch (i)
{
case 0:
index = Array.IndexOf(fw_des, des.ToLower());
if (index != -1) ret = Firmwares[index];
break;
case 1:
index = Array.IndexOf(snd_des, des.ToLower());
if (index != -1) ret = SoundCards[index];
break;
case 2:
index = Array.IndexOf(nic_des, des.ToLower());
if (index != -1) ret = NICs[index];
break;
}
if (index != -1) break;
}
return ret;
}
*/
public static void SearchVM(ref List<VirtualMachine> VMList)
{
/*
Expand Down
49 changes: 16 additions & 33 deletions VMGuide.GUI/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,9 @@

<Grid Margin="0,0,0,0" Background="#184689" Grid.Row="1" >
<Image x:Name="image" HorizontalAlignment="Left" Width="60" Margin="15,5,0,15" Source="Resources\logo.png"/>
<Label x:Name="label" VerticalAlignment="Top" Height="40" Margin="85,5,10,0"
Foreground="White" FontFamily="Microsoft Yahei Light" VerticalContentAlignment="Center"
Padding="0" IsEnabled="{Binding ElementName=page_home,Path=IsUnattendMode.Value}">
<Label.Style >
<Style TargetType="Label" >
<Style.Triggers >
<Trigger Property="IsEnabled" Value="true">
<Setter Property="FontSize" Value="30"/>
<Setter Property="Content" Value="Importing Settings"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="FontSize" Value="35"/>
<Setter Property="Content" Value="Welcome"/>
</Trigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<Label x:Name="label" VerticalAlignment="Top" Height="40" Margin="85,5,10,0" FontSize="35" Content="Welcome"
Foreground="White" FontFamily="Microsoft Yahei Light" VerticalContentAlignment="Center" Padding="0"/>

<Label x:Name="label1" Margin="85,45,10,15" Foreground="White"
Content="To Continue, please select a virtual machine."
FontFamily="Microsoft Yahei Light" FontSize="14"
Expand All @@ -122,13 +107,11 @@

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

</Grid>


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

Expand Down Expand Up @@ -162,22 +145,22 @@
</StackPanel>
</ScrollViewer>

<StackPanel Grid.Row="3" Margin="0,0,0,0" Background="#f2f2f2" Orientation="Horizontal" >
<ToggleButton x:Name="settingsToggle" Width="68" Height="48"
HorizontalAlignment="Right" VerticalAlignment="Top" Content="&#xE713;"
FontSize="18" Style="{StaticResource ToolBarToggleStyle }"
IsHitTestVisible="{Binding ElementName=settingsPopup, Path=IsOpen ,Converter={StaticResource BooleanReverseConverter}}"/>

<Button Width="68" Margin="0,0,68,0"
HorizontalAlignment="Right" Content="&#xE109;"
FontSize="18" Style="{StaticResource ToolBarButtonStyle }" Click="Button_Click"/>
</StackPanel>
<Grid Grid.Row="3" Margin="0,0,0,0" Background="#f2f2f2">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">

<Button HorizontalAlignment="Right" Content="&#xE109;" FontSize="18"
Style="{StaticResource ToolBarButtonStyle }" Click="Button_Click"/>
<ToggleButton x:Name="settingsToggle" Content="&#xE713;" Style="{StaticResource ToolBarToggleStyle }" FontSize="18"
IsHitTestVisible="{Binding ElementName=settingsPopup, Path=IsOpen ,Converter={StaticResource BooleanReverseConverter}}"/>

</StackPanel>
</Grid>

<Popup x:Name="settingsPopup" StaysOpen="False"
IsOpen="{Binding ElementName=settingsToggle ,Path=IsChecked}"
Placement="Top" PlacementTarget="{Binding ElementName=settingsToggle}">

<ListBox Width="{Binding ElementName=settingsToggle,Path=Width}">
<ListBox Width="{Binding ElementName=settingsToggle,Path=Width}" ItemContainerStyle="{StaticResource MenuListBoxItem}">
<ListBoxItem Content="Refresh" MouseUp="RefreshMenuClicked"/>
<ListBoxItem Content="About" MouseUp="AboutMenuClicked"/>
</ListBox>
Expand Down
Loading

0 comments on commit c779ed9

Please sign in to comment.