/// <summary>Runs when the search for updates has completed for an auto update.</summary> /// <param name="sender">The object that called the event.</param> /// <param name="e">The <c>SearchCompletedEventArgs</c> instance containing the event data.</param> static void SearchCompleted(object sender, SearchCompletedEventArgs e) { IsInstalling = false; Applications = e.Applications as Collection <Sui>; if (Applications == null) { return; } if (Applications.Count > 0) { if (Applications[0].AppInfo.SuiUrl == @"http://apps.sevenupdate.com/SevenUpdate.sui" || Applications[0].AppInfo.SuiUrl == @"http://apps.sevenupdate.com/SevenUpdate-dev.sui") { Sui sevenUpdate = Applications[0]; Applications.Clear(); Applications.Add(sevenUpdate); e.OptionalCount = 0; e.ImportantCount = 1; } Utilities.Serialize(Applications, Path.Combine(AllUserStore, "updates.sui")); Utilities.StartProcess( @"cacls.exe", "\"" + Path.Combine(AllUserStore, "updates.sui") + "\" /c /e /g Users:F"); if (Settings.AutoOption == AutoUpdateOption.Notify) { Application.Current.Dispatcher.BeginInvoke(UpdateNotifyIcon, NotifyType.SearchComplete); } else { Application.Current.Dispatcher.BeginInvoke(UpdateNotifyIcon, NotifyType.DownloadStarted); Download.DownloadUpdates(Applications, "SevenUpdate", Path.Combine(AllUserStore, "downloads")); // Task.Factory.StartNew(() => Download.DownloadUpdates(Applications, "SevenUpdate", // Path.Combine(AllUserStore, "downloads"))); IsInstalling = true; } } else { ShutdownApp(); } }
/// <summary>Adds an update to the update history.</summary> /// <param name="appInfo">The application information.</param> /// <param name="updateInfo">The update information.</param> /// <param name="failed"><c>True</c> if the update failed, otherwise <c>False</c>.</param> static void AddHistory(Sui appInfo, Update updateInfo, bool failed = false) { var hist = new Suh(updateInfo.Name, appInfo.AppInfo.Publisher, updateInfo.Description) { HelpUrl = appInfo.AppInfo.HelpUrl, AppUrl = appInfo.AppInfo.AppUrl, Status = failed == false ? UpdateStatus.Successful : UpdateStatus.Failed, InfoUrl = updateInfo.InfoUrl, InstallDate = DateTime.Now.ToShortDateString(), ReleaseDate = updateInfo.ReleaseDate, Importance = updateInfo.Importance, }; if (UpdateInstalled != null) { UpdateInstalled(null, new UpdateInstalledEventArgs(hist)); } }
/// <summary>Checks for updates.</summary> /// <param name="app">A collection of applications to check for updates.</param> /// <returns>Returns <c>True</c> if found updates, otherwise <c>False</c>.</returns> static bool CheckForUpdates(ref Sui app) { app.AppInfo.Directory = Utilities.IsRegistryKey(app.AppInfo.Directory) ? Utilities.GetRegistryValue( app.AppInfo.Directory, app.AppInfo.ValueName, app.AppInfo.Platform) : Utilities.ConvertPath(app.AppInfo.Directory, true, app.AppInfo.Platform); if (!Directory.Exists(app.AppInfo.Directory)) { return false; } for (int y = 0; y < app.Updates.Count; y++) { Update updates = app.Updates[y]; ulong size = IterateUpdate( ref updates, app.AppInfo.Directory, app.AppInfo.ValueName, app.AppInfo.Platform); app.Updates[y] = updates; bool remove = true; // Checks to see if the update only contains execute and delete actions if (app.Updates[y].Files.Count > 0) { // ReSharper disable ForCanBeConvertedToForeach for (int z = 0; z < app.Updates[y].Files.Count; z++) { app.Updates[y].Files[z].Destination = Utilities.ExpandInstallLocation( app.Updates[y].Files[z].Destination, app.AppInfo.Directory, app.AppInfo.Platform, app.AppInfo.ValueName); app.Updates[y].Files[z].Source = Utilities.ExpandDownloadUrl( app.Updates[y].Files[z].Source, app.Updates[y].DownloadUrl, app.AppInfo.Platform); if (app.Updates[y].Files[z].Action != FileAction.ExecuteThenDelete) { remove = false; } } // ReSharper restore ForCanBeConvertedToForeach } // If the update does not have any files or if the update only contains execute and delete, then let's // remove the update. if (app.Updates[y].Files.Count == 0 || remove) { app.Updates.Remove(app.Updates[y]); if (app.Updates.Count == 0) { break; } y--; continue; } app.Updates[y].Size = size; switch (app.Updates[y].Importance) { case Importance.Important: importantCount++; break; case Importance.Recommended: recommendedCount++; break; case Importance.Optional: case Importance.Locale: optionalCount++; break; } } if (app.Updates.Count > 0) { // Found updates, return return true; } app = null; // No updates, let's return return false; }
/// <summary>Updates the UI the search for updates has completed.</summary> /// <param name="e">The SearchComplete data.</param> void SearchCompleted(SearchCompletedEventArgs e) { if (Core.Instance.UpdateAction == UpdateAction.ErrorOccurred) { return; } Core.Applications = e.Applications as Collection <Sui>; if (Core.Applications == null) { Core.Instance.UpdateAction = UpdateAction.NoUpdates; return; } if (Core.Applications.Count > 0) { if (Core.Settings.IncludeRecommended) { e.ImportantCount += e.RecommendedCount; } else { e.OptionalCount += e.RecommendedCount; } string suiUrl = null; if (App.IsDev) { suiUrl = Core.SevenUpdateUrl + @"-dev.sui"; } if (App.IsBeta) { suiUrl = Core.SevenUpdateUrl + @"-beta.sui"; } if (!App.IsDev && !App.IsBeta) { suiUrl = Core.SevenUpdateUrl + @".sui"; } if (Core.Applications[0].AppInfo.SuiUrl == suiUrl) { Sui sevenUpdate = Core.Applications[0]; Core.Applications.Clear(); Core.Applications.Add(sevenUpdate); e.OptionalCount = 0; e.ImportantCount = 1; } try { Utilities.Serialize(Core.Applications, Path.Combine(App.AllUserStore, "updates.sui")); Utilities.StartProcess( @"cacls.exe", "\"" + Path.Combine(App.AllUserStore, "updates.sui") + "\" /c /e /g Users:F"); Utilities.StartProcess( @"cacls.exe", "\"" + Path.Combine(App.AllUserStore, "updates.sui") + "\" /c /e /r " + Environment.UserName); } catch (Exception ex) { if (!(ex is UnauthorizedAccessException || ex is IOException)) { Utilities.ReportError(ex, ErrorType.GeneralError); throw; } } if (e.ImportantCount > 0 || e.OptionalCount > 0) { string uiString; Core.Instance.UpdateAction = UpdateAction.UpdatesFound; if (e.ImportantCount > 0 && e.OptionalCount > 0) { this.line.Y1 = 50; } if (e.ImportantCount > 0) { uiString = e.ImportantCount == 1 ? Properties.Resources.ImportantUpdateAvailable : Properties.Resources.ImportantUpdatesAvailable; this.tbViewImportantUpdates.Text = string.Format( CultureInfo.CurrentCulture, uiString, e.ImportantCount); this.tbViewImportantUpdates.Visibility = Visibility.Visible; } else { this.tbViewImportantUpdates.Visibility = Visibility.Collapsed; } if (e.OptionalCount > 0) { if (e.ImportantCount == 0) { this.tbHeading.Text = Properties.Resources.NoImportantUpdates; } uiString = e.OptionalCount == 1 ? Properties.Resources.OptionalUpdateAvailable : Properties.Resources.OptionalUpdatesAvailable; this.tbViewOptionalUpdates.Text = string.Format( CultureInfo.CurrentCulture, uiString, e.OptionalCount); this.tbViewOptionalUpdates.Visibility = Visibility.Visible; } else { this.tbViewOptionalUpdates.Visibility = Visibility.Collapsed; } } } else { Core.Instance.UpdateAction = UpdateAction.NoUpdates; } }