private string GetTarget() { // "<Program Files>\Citrix\XenTools" string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Citrix\\XenTools"); string regPath = (Win32Impl.Is64BitOS()) ? "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenTools" : "HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools"; string targetPath = (string)Registry.GetValue(regPath, "Install_Dir", path); return(String.IsNullOrEmpty(targetPath) ? path : targetPath); }
public Update CheckForUpdates(IWebClientWrapper client) { string url = BrandingControl.getString("BRANDING_updaterURL"); if (String.IsNullOrEmpty(url)) { url = "https://pvupdates.vmd.citrix.com/updates.v2.tsv"; } string identify = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\Software\\Citrix\\XenTools\\AutoUpdate", "Identify", "NO"); if (identify.Equals("YES")) { url += "?id=" + uuid.Value.Substring(4); } if (update_url.Exists) { url = update_url.Value; } url = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "update_url", url); if (String.IsNullOrEmpty(url)) { session.Log("Update URL is Null or Empty"); throw new ArgumentNullException("URL is empty"); } session.Log("Checking URL: " + url + " for updates after: " + version.ToString()); string contents = null; try { string userAgent = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools\\AutoUpdate", "UserAgent", BrandingControl.getString("BRANDING_userAgent")); session.Log("This is my user agent : " + userAgent); client.AddHeader("User-Agent", userAgent); contents = client.DownloadString(url); } catch (Exception e) { session.Log("Download failed " + e.Message); throw; } if (String.IsNullOrEmpty(contents)) { return(null); } string arch = (Win32Impl.Is64BitOS() && (!Win32Impl.IsWOW64())) ? "x64" : "x86"; List <Update> updates = new List <Update>(); foreach (string line in contents.Split(new char[] { '\n' })) { if (String.IsNullOrEmpty(line)) { continue; } try { Update update = new Update(line); session.Log("Update Entry " + update.ToString()); if (update.Arch != arch) { continue; } if (update.Version.CompareTo(version) <= 0) { continue; } updates.Add(update); } catch (Exception e) { session.Log("Exception: " + e.Message); } } updates.Reverse(); if (updates.Count > 0) { return(updates[0]); } session.Log("No updates found"); return(null); }
private Update CheckForUpdates() { string url = Branding.GetString("BRANDING_updaterURL"); if (String.IsNullOrEmpty(url)) { url = "https://pvupdates.vmd.citrix.com/updates.tsv"; } if (update_url.Exists) { url = update_url.Value; } url = (string)GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "update_url", url); if (String.IsNullOrEmpty(url)) { session.Log("Update URL is Null or Empty"); throw new ArgumentNullException("URL is empty"); } session.Log("Checking URL: " + url + " for updates after: " + version.ToString()); WebClient client = new WebClient(); string contents = client.DownloadString(url); string arch = (Win32Impl.Is64BitOS() && (!Win32Impl.IsWOW64())) ? "x64" : "x86"; List <Update> updates = new List <Update>(); foreach (string line in contents.Split(new char[] { '\n' })) { if (String.IsNullOrEmpty(line)) { continue; } try { Update update = new Update(line); if (update.Arch != arch) { continue; } if (update.Version.CompareTo(version) <= 0) { continue; } updates.Add(update); session.Log("Update Entry :" + update.ToString()); } catch (Exception e) { session.Log("Exception: " + e.Message); } } updates.Reverse(); if (updates.Count > 0) { return(updates[0]); } session.Log("No updates found"); return(null); }
List<string> getExtentNames(Win32Impl.Extents extents) { List<string> extentnames = new List<string>(); WmiBase.Singleton.DebugMsg("There are " + extents.Count.ToString() + " extents"); foreach (Win32Impl.Extent extent in extents) { try { WmiBase.Singleton.DebugMsg("Find disk name for extent " + extent.DiskNumber.ToString()); string disk = findDiskName(extent.DiskNumber); extentnames.Add(disk); } catch { }// unable to find a matching disk } return extentnames; }
public StoredVolume Change(Win32Impl.Volume vol) { WmiBase.Singleton.DebugMsg("changing stored volume id " + Id.ToString()); WmiBase.Singleton.DebugMsg("name : "+ name.ToString()); WmiBase.Singleton.DebugMsg("size : " + size.ToString()); try { name.value = vol.Name; size.value = vol.SizeBytes.ToString(); if ((ulong)Math.Abs((long)(vol.FreeBytes - freebytes)) > (vol.SizeBytes / 100)) { freebytes = vol.FreeBytes; free.value = freebytes.ToString(); } volumeName.value = vol.VolumeName; filesystem.value = vol.FSName; } catch { throw; } try { List<XenStoreItemCached>.Enumerator storecursor = mountPoints.GetEnumerator(); List<string>.Enumerator newcursor = vol.pathnames.GetEnumerator(); int i = 0; while (true) { if (!storecursor.MoveNext()) { while (newcursor.MoveNext()) { XenStoreItemCached mp = wmisession.GetXenStoreItemCached(path + "/mount_points/" + i.ToString()); mp.value = newcursor.Current; mountPoints.Add(mp); i++; } break; } else if (!newcursor.MoveNext()) { do { storecursor.Current.Remove(); } while (storecursor.MoveNext()); break; } else { storecursor.Current.value = newcursor.Current; i++; } } } catch { throw; } try { List<XenStoreItemCached>.Enumerator storecursor = extents.GetEnumerator(); List<string>.Enumerator newcursor = getExtentNames(vol.extents).GetEnumerator(); int i = 0; while (true) { if (!storecursor.MoveNext()) { while (newcursor.MoveNext()) { XenStoreItemCached ext = wmisession.GetXenStoreItemCached(path + "/extents/" + i.ToString()); ext.value = newcursor.Current; mountPoints.Add(ext); i++; } break; } else if (!newcursor.MoveNext()) { do { storecursor.Current.Remove(); } while (storecursor.MoveNext()); break; } else { storecursor.Current.value = newcursor.Current; i++; } } } catch { throw; } return this; }
public StoredVolume(Win32Impl.Volume vol, WmiSession wmisession, long nextid) { try { Id = nextid; this.wmisession = wmisession; WmiBase.Singleton.DebugMsg("Stored volume: new " + vol.Name); path = getVolumePath(); WmiBase.Singleton.DebugMsg("creating " + path + "/name"); name = wmisession.GetXenStoreItemCached(path + "/name"); WmiBase.Singleton.DebugMsg(" : " + name.ToString()); size = wmisession.GetXenStoreItemCached(path + "/size"); free = wmisession.GetXenStoreItemCached(path + "/free"); volumeName = wmisession.GetXenStoreItemCached(path + "/volume_name"); filesystem = wmisession.GetXenStoreItemCached(path + "/filesystem"); } catch { throw; } try { name.value = vol.Name; size.value = vol.SizeBytes.ToString(); freebytes = vol.FreeBytes; free.value = freebytes.ToString(); volumeName.value = vol.VolumeName; filesystem.value = vol.FSName; } catch { throw; } try { mountPoints = new List<XenStoreItemCached>(); int i = 0; foreach (string mountpoint in vol.pathnames) { XenStoreItemCached mp = wmisession.GetXenStoreItemCached(path + "/mount_points/" + i.ToString()); mp.value = mountpoint; mountPoints.Add(mp); i++; } } catch { throw; } try { int i = 0; extents = new List<XenStoreItemCached>(); WmiBase.Singleton.DebugMsg("About to iterrate through extent names"); foreach (string disk in getExtentNames(vol.extents)) { XenStoreItemCached ext = wmisession.GetXenStoreItemCached(path + "/extents/" + i.ToString()); ext.value = disk; extents.Add(ext); } } catch { throw; } }
public bool update(Win32Impl.Volumes volumes) { int changecount = WmiBase.Singleton.GetChangeCount(); Dictionary<string, StoredVolume> newVolumes = new Dictionary<string, StoredVolume>(); foreach (Win32Impl.Volume volume in volumes) { if (storedVolumes.ContainsKey(volume.Name)) { newVolumes[volume.Name] = storedVolumes[volume.Name].Change(volume); storedVolumes.Remove(volume.Name); } else { newVolumes[volume.Name] = new StoredVolume(volume, wmisession, nextid); nextid++; } } foreach (StoredVolume svol in storedVolumes.Values) { svol.Remove(); } storedVolumes = newVolumes; int newchangecount = WmiBase.Singleton.GetChangeCount() ; if( newchangecount!= changecount) { // This indicates that we may well have changed siomething in xenstore return true; } // This indicates nothing in xenstore has changed return false; }