Ejemplo n.º 1
0
 public VMwareVM(string FilePath) : base(FilePath)
 {
     if (FilePath == null)
     {
         return;
     }
     VMX  = new VMXFile(FilePath);
     Name = VMX.ReadValue("displayName");
 }
Ejemplo n.º 2
0
        public static void SearchVM(ref List <VirtualMachine> VMList)
        {
            /*
             * type=0 VMware Workstation
             * type=1 VMware Player
             */

            int type = 0;

            for (type = 0; type < 2; type++)
            {
                string  ConfigDir, ConfigFile, name;
                VMXFile config; List <string> values;
                ConfigDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VMware");

                if (type == 0)
                {
                    ConfigFile = Path.Combine(ConfigDir, "inventory.vmls");
                    name       = "index\\d+.id";
                }
                else
                {
                    ConfigFile = Path.Combine(ConfigDir, "preferences.ini");
                    name       = "pref.mruVM\\d+.filename";
                }

                if (File.Exists(ConfigFile) == false)
                {
                    continue;
                }
                config = new VMXFile(ConfigFile);
                values = config.ReadValues(name);


                foreach (string path in values)
                {
                    bool AlreadyExist = false;
                    foreach (VirtualMachine vm in VMList)
                    {
                        if (vm.Path == path)
                        {
                            AlreadyExist = true; break;
                        }
                    }
                    if (AlreadyExist || !File.Exists(path))
                    {
                        continue;
                    }
                    var VMX = new VMwareVM(path);
                    VMList.Add(VMX);
                }
            }
        }