示例#1
0
        /// <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));
            }
        }
示例#2
0
        /// <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;
        }