private void WindowShouldClose(object sender, CancelEventArgs e) { if (status == WindowStatus.Downloading) { CancelDownloadClicked(null, null); if (Delegate != null) { Delegate.UpdateWindowClosed(this); } } else if (status == WindowStatus.UncancellableAction) { e.Cancel = true; MessageBox.Show(SULocalizedStrings.StringForKey("Update Cannot Be Cancelled")); } else if (status == WindowStatus.WaitingForInitialAction) { if (Delegate != null) { Delegate.UpdateAlertMadeChoice(this, SUUpdateAlertChoice.SURemindMeLaterChoice, false); } } else if (status == WindowStatus.WaitingForInstall) { } if (!e.Cancel && status != WindowStatus.UpdateAborted) { if (Delegate != null) { Delegate.UpdateWindowClosed(this); } } }
public void ObserveValueForKeyPathOfObject(string keyPath, object obj, Dictionary <string, object> change, object context) { if (keyPath.Equals("Host") || keyPath.Equals("Item")) { // Set up the UI! if (Host != null && Item != null) { ReleaseNotes.Source = Item.ReleaseNotesURL; ReleaseNotes.LoadCompleted += ReleaseNotesDidLoad; UpdateHeaderLabel.Text = String.Format(SULocalizedStrings.StringForKey("Update Available Header"), Host.Name); if (Item.DisplayVersionString.Equals(Host.DisplayVersion)) { // Display more info if the version strings are the same; useful for betas. UpdateHeaderDescription.Text = String.Format(SULocalizedStrings.StringForKey("Update Available Extra Detail"), Host.Name, Item.DisplayVersionString, Host.DisplayVersion, Item.VersionString, Host.Version); } else { UpdateHeaderDescription.Text = String.Format(SULocalizedStrings.StringForKey("Update Available Detail"), Host.Name, Item.DisplayVersionString, Host.DisplayVersion); } IconView.Source = Host.LargeIcon; } } }
public SUUpdatePermissionPromptViewController(SUHost host) : base(new SUUpdatePermissionPromptView()) { Host = host; UpdateHeaderDescription.Text = String.Format(SULocalizedStrings.StringForKey("Update Automatically Prompt Header"), Host.Name, SULocalizedStrings.StringForKey("Help")); IconView.Source = host.LargeIcon; ExtendedInfoContainer.Expanded += ExpandWindow; ExtendedInfoContainer.Collapsed += CollapseWindow; ExtendedInfoContainer.IsExpanded = false; oldHeight = 150; string systemInfo = ""; try { foreach (Dictionary <string, string> item in SUSystemProfiler.SystemProfileForHost(host)) { systemInfo = String.Concat(systemInfo, item.ValueForKey(SUConstants.SUProfileItemDisplayKeyKey), ": ", item.ValueForKey(SUConstants.SUProfileItemDisplayValueKey), Environment.NewLine); } InfoBox.Text = systemInfo; } catch (Exception e) { if (e is System.Runtime.InteropServices.COMException || e is System.Management.ManagementException) { InfoBox.Text = SULocalizedStrings.StringForKey("Profile Generation Error"); } else { throw e; } } }
protected override void ExtractUpdate() { if (alert != null) { alert.SwitchToIndeterminateAction(SULocalizedStrings.StringForKey("Extracting...")); } base.ExtractUpdate(); }
protected override void VerifySignature() { if (alert != null) { alert.SwitchToIndeterminateAction(SULocalizedStrings.StringForKey("Verifying...")); } base.VerifySignature(); }
public void UpdateDownloadProgressWithEvent(DownloadProgressChangedEventArgs e) { downloadingViewController.ProgressBar.Value = e.ProgressPercentage; downloadingViewController.ProgressLabel.Text = String.Format(SULocalizedStrings.StringForKey("Downloading Status"), HumanReadableFileSize(e.BytesReceived), HumanReadableFileSize(e.TotalBytesToReceive)); Window.TaskbarItemInfo.ProgressValue = ((double)e.ProgressPercentage) / 100.0; }
protected override void DidNotFindUpdate() { if (Updater.Delegate != null) { Updater.Delegate.UpdaterDidNotFindUpdate(Updater); } MessageBox.Show(SULocalizedStrings.StringForKey(SUConstants.SUNoUpdateError), SULocalizedStrings.StringForKey("Up To Date"), MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); AbortUpdate(); }
private void CancelDownloadClicked(object sender, EventArgs e) { if (Delegate != null) { Delegate.CancelDownload(this); mainViewController.ActionViewController = buttons; Window.TaskbarItemInfo.ProgressValue = 0; status = WindowStatus.WaitingForInitialAction; Window.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; downloadingViewController.ProgressBar.Value = 0; downloadingViewController.ProgressLabel.Text = SULocalizedStrings.StringForKey("Downloading update..."); } }
protected override void AbortUpdateWithError(Exception error) { string message = SULocalizedStrings.StringForKey("Generic Error Message"); string specificMessage = SULocalizedStrings.StringForKey(error.Message); if (!Helpers.StringIsNullOrWhiteSpace(specificMessage)) { message = specificMessage; } MessageBox.Show(message, SULocalizedStrings.StringForKey("Update Failed"), MessageBoxButton.OK, MessageBoxImage.Error); base.AbortUpdateWithError(error); }
private string HumanReadableFileSize(double value) { try { double dblAns = 0; if (value <= 0) { //this method should never attempt to divide by 0 //this is just an extra precaution return("0" + SULocalizedStrings.StringForKey("Byte Unit")); } else if (value >= (Math.Pow(1024, 4))) { //TB dblAns = (((value / 1024) / 1024) / 1024) / 1024; return(String.Format("{0:###,###,##0.##}", dblAns) + SULocalizedStrings.StringForKey("Terabyte Unit")); } else if (value >= (Math.Pow(1024, 3))) { //GB dblAns = ((value / 1024) / 1024) / 1024; return(String.Format("{0:###,###,##0.##}", dblAns) + SULocalizedStrings.StringForKey("Gigabyte Unit")); } else if (value >= (Math.Pow(1024, 2))) { //MB dblAns = (value / 1024) / 1024; return(String.Format("{0:###,###,##0.0}", dblAns) + SULocalizedStrings.StringForKey("Megabyte Unit")); } else if (value >= 1024) { //KB dblAns = value / 1024; return(String.Format("{0:###,###,##0}", dblAns) + SULocalizedStrings.StringForKey("Kilobyte Unit")); } else { //Bytes return(String.Format("{0:###,###,##0}", dblAns) + SULocalizedStrings.StringForKey("Byte Unit")); } } catch {} return(SULocalizedStrings.StringForKey("unknown")); }
public static List <Dictionary <string, string> > SystemProfileForHost(SUHost host) { List <Dictionary <string, string> > profile = new List <Dictionary <string, string> >(); // App name profile.Add(DictionaryForProfileItem("appName", SULocalizedStrings.StringForKey("Application Name"), host.Name, host.Name)); // App version profile.Add(DictionaryForProfileItem("appVersion", SULocalizedStrings.StringForKey("Application Version"), host.Version, host.Version)); // System version string version = Environment.OSVersion.ToString(); profile.Add(DictionaryForProfileItem("osVersion", SULocalizedStrings.StringForKey("OS Version"), version, version)); // .NET version string frameworkVersion = Environment.Version.ToString(); profile.Add(DictionaryForProfileItem("dotNetVersion", SULocalizedStrings.StringForKey(".NET Version"), frameworkVersion, frameworkVersion)); // 64-bit? if (Helpers.Is64BitOperatingSystem) { profile.Add(DictionaryForProfileItem("cpu64bit", SULocalizedStrings.StringForKey("CPU is 64-Bit?"), "1", SULocalizedStrings.StringForKey("Yes"))); } else { profile.Add(DictionaryForProfileItem("cpu64bit", SULocalizedStrings.StringForKey("CPU is 64-Bit?"), "0", SULocalizedStrings.StringForKey("No"))); } // CPU Count profile.Add(DictionaryForProfileItem("ncpu", SULocalizedStrings.StringForKey("Number of CPUs"), Environment.ProcessorCount.ToString(), Environment.ProcessorCount.ToString())); // CPU Speed // Use methods other than System.Management when possible, because WMI is both horrendously slow, and // quite prone to deciding to break or completely screw up by itself, it seems. string cpuSpeed; using (var cpuRegistryKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0", false)) cpuSpeed = cpuRegistryKey.GetValue("~MHz").ToString(); if (Helpers.StringIsNullOrWhiteSpace(cpuSpeed)) { using (var mObj = new System.Management.ManagementObject("Win32_Processor.DeviceID='CPU0'")) cpuSpeed = mObj["CurrentClockSpeed"].ToString(); } profile.Add(DictionaryForProfileItem("cpuFreqMHz", SULocalizedStrings.StringForKey("CPU Speed (GHz)"), cpuSpeed.ToString(), (Double.Parse(cpuSpeed) / 1000.0).ToString())); // CPU Type // A problem with this is that Mac OS X and Windows have different values for this; on Windows this is // the processor architecture, and on OS X it is the CPU type. // Windows: http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx // OS X: http://www.opensource.apple.com/source/xnu/xnu-1228.12.14/osfmk/mach/machine.h var sysInfo = new NativeMethods.SYSTEM_INFO(); NativeMethods.GetSystemInfoAbstracted(ref sysInfo); int archSparkle = -1; string archDisplay = "Unknown"; switch (sysInfo.wProcessorArchitecture) { case 0: archSparkle = 7; archDisplay = "x86"; break; case 1: archSparkle = 8; archDisplay = "MIPS"; break; case 2: archSparkle = 16; archDisplay = "Alpha"; break; case 3: archSparkle = 3; archDisplay = "PowerPC"; break; case 9: archSparkle = 7; archDisplay = "x86_64"; break; } profile.Add(DictionaryForProfileItem("cputype", SULocalizedStrings.StringForKey("CPU Type"), archSparkle.ToString(), archDisplay)); // CPU Subtype // Until someone wants to write something that will work this out, let's just send the equivalent to // the OS X _ALL. Actually, that's probably accurate, since .NET was designed to be portable. profile.Add(DictionaryForProfileItem("cpusubtype", SULocalizedStrings.StringForKey("CPU Subtype"), "0", "0")); // RAM ulong installedMemory = 0; var memStatus = new NativeMethods.MEMORYSTATUSEX(); if (NativeMethods.GlobalMemoryStatusEx(memStatus)) { installedMemory = memStatus.ullTotalPhys / 1024 / 1024; } profile.Add(DictionaryForProfileItem("ramMB", SULocalizedStrings.StringForKey("Memory (MB)"), installedMemory.ToString(), installedMemory.ToString())); // User preferred language profile.Add(DictionaryForProfileItem("lang", SULocalizedStrings.StringForKey("Preferred Language"), CultureInfo.CurrentCulture.TwoLetterISOLanguageName, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); return(profile); }
public void ResetView() { ProgressLabel.Text = SULocalizedStrings.StringForKey("Downloading update..."); ProgressBar.IsIndeterminate = false; ProgressBar.Value = 0; }