예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="castUrl">the URL of the appcast file</param>
        /// <param name="config">the current configuration</param>
        public NetSparkleAppCast(string castUrl, NetSparkleConfiguration config)
        {
            _config = config;
            _castUrl = castUrl;

            _items = new List<NetSparkleAppCastItem>();
        }
예제 #2
0
        /// <summary>
        /// This method updates the profile information which can be sended to the server if enabled
        /// </summary>
        /// <param name="config">the configuration</param>
        public void UpdateSystemProfileInformation(NetSparkleConfiguration config)
        {
            // check if profile data is enabled
            if (!EnableSystemProfiling)
            {
                return;
            }

            // check if we need an update
            if (DateTime.Now - config.LastProfileUpdate < new TimeSpan(7, 0, 0, 0))
            {
                return;
            }

            // touch the profile update time
            config.TouchProfileTime();

            // start the profile thread
            Thread t = new Thread(ProfileDataThreadStart);

            t.Start(config);
        }
예제 #3
0
#pragma warning restore 1591

        /// <summary>
        /// Does a one-off check for updates
        /// </summary>
        /// <param name="useNotificationToast">set false if you want the big dialog to open up, without the user having the chance to ignore the popup toast notification</param>
        private UpdateStatus CheckForUpdates(bool useNotificationToast)
        {
            NetSparkleConfiguration config = GetApplicationConfig();

            // update profile information is needed
            UpdateSystemProfileInformation(config);

            // check if update is required
            NetSparkleAppCastItem[] updates;
            var updateStatus = GetUpdateStatus(config, out updates);

            if (updateStatus == UpdateStatus.UpdateAvailable)
            {
                // show the update window
                ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " +
                                        updates[0].Version);

                UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs
                {
                    NextAction        = NextUpdateAction.ShowStandardUserInterface,
                    ApplicationConfig = config,
                    LatestVersion     = updates[0]
                };

                // if the client wants to intercept, send an event
                if (UpdateDetected != null)
                {
                    UpdateDetected(this, ev);
                }
                //otherwise just go forward with the UI notficiation
                else
                {
                    ShowUpdateNeededUI(updates, useNotificationToast);
                }
            }
            return(updateStatus);
        }
 public NetSparkleDeviceInventory(NetSparkleConfiguration config)
 {
     _config = config;
 }
예제 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="castUrl">the URL of the appcast file</param>
 /// <param name="config">the current configuration</param>
 public NetSparkleAppCast(string castUrl, NetSparkleConfiguration config)
 {
     _config = config;
     _castUrl = castUrl;
 }
예제 #6
0
        /// <summary>
        /// This method will be executed as worker thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            // store the did run once feature
            bool goIntoLoop     = true;
            bool checkTSP       = true;
            bool doInitialCheck = _doInitialCheck;
            bool isInitialCheck = true;

            // start our lifecycles
            do
            {
                // set state
                Boolean bUpdateRequired = false;

                // notify
                if (CheckLoopStarted != null)
                {
                    CheckLoopStarted(this);
                }

                // report status
                if (doInitialCheck == false)
                {
                    ReportDiagnosticMessage("Initial check prohibited, going to wait");
                    doInitialCheck = true;
                    goto WaitSection;
                }

                // report status
                ReportDiagnosticMessage("Starting update loop...");

                // read the config
                ReportDiagnosticMessage("Reading config...");
                NetSparkleConfiguration config = GetApplicationConfig();

                // calc CheckTasp
                Boolean checkTSPInternal = checkTSP;

                if (isInitialCheck && checkTSPInternal)
                {
                    checkTSPInternal = !_forceInitialCheck;
                }

                // check if it's ok the recheck to software state
                if (checkTSPInternal)
                {
                    TimeSpan csp = DateTime.Now - config.LastCheckTime;
                    if (csp < _checkFrequency)
                    {
                        ReportDiagnosticMessage(String.Format("Update check performed within the last {0} minutes!", _checkFrequency.TotalMinutes));
                        goto WaitSection;
                    }
                }
                else
                {
                    checkTSP = true;
                }

                // when sparkle will be deactivated wait an other cycle
                if (config.CheckForUpdate == false)
                {
                    ReportDiagnosticMessage("Check for updates disabled");
                    goto WaitSection;
                }

                // update the runonce feature
                goIntoLoop = !config.DidRunOnce;

                // update profile information is needed
                UpdateSystemProfileInformation(config);

                // check if update is required
                NetSparkleAppCastItem[] updates;
                bUpdateRequired = GetUpdateStatus(config, out updates) == UpdateStatus.UpdateAvailable;
                if (!bUpdateRequired)
                {
                    goto WaitSection;
                }

                // show the update window
                ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + updates[0].Version);

                // send notification if needed
                UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs {
                    NextAction = NextUpdateAction.ShowStandardUserInterface, ApplicationConfig = config, LatestVersion = updates[0]
                };
                if (UpdateDetected != null)
                {
                    UpdateDetected(this, ev);
                }

                // check results
                switch (ev.NextAction)
                {
                case NextUpdateAction.PerformUpdateUnattended:
                {
                    ReportDiagnosticMessage("Unattended update whished from consumer");
                    EnableSilentMode = true;
                    _worker.ReportProgress(1, updates);
                    break;
                }

                case NextUpdateAction.ProhibitUpdate:
                {
                    ReportDiagnosticMessage("Update prohibited from consumer");
                    break;
                }

                default:
                {
                    ReportDiagnosticMessage("Showing Standard Update UI");
                    _worker.ReportProgress(1, updates);
                    break;
                }
                }

WaitSection:
                // reset initialcheck
                isInitialCheck = false;

                // notify
                if (CheckLoopFinished != null)
                {
                    CheckLoopFinished(this, bUpdateRequired);
                }

                // report wait statement
                ReportDiagnosticMessage(String.Format("Sleeping for an other {0} minutes, exit event or force update check event", _checkFrequency.TotalMinutes));

                // wait for
                if (!goIntoLoop)
                {
                    break;
                }

                // build the event array
                WaitHandle[] handles = new WaitHandle[1];
                handles[0] = _exitHandle;

                // wait for any
                int i = WaitHandle.WaitAny(handles, _checkFrequency);
                if (WaitHandle.WaitTimeout == i)
                {
                    ReportDiagnosticMessage(String.Format("{0} minutes are over", _checkFrequency.TotalMinutes));
                    continue;
                }

                // check the exit hadnle
                if (i == 0)
                {
                    ReportDiagnosticMessage("Got exit signal");
                    break;
                }

                // check an other check needed
                if (i == 1)
                {
                    ReportDiagnosticMessage("Got force update check signal");
                    checkTSP = false;
                }
            } while (goIntoLoop);

            // reset the islooping handle
            _loopingHandle.Reset();
        }
예제 #7
0
        /// <summary>
        /// This method checks if an update is required. During this process the appcast
        /// will be downloaded and checked against the reference assembly. Ensure that
        /// the calling process has access to the internet and read access to the 
        /// reference assembly. This method is also called from the background loops.
        /// </summary>
        /// <param name="config">the configuration</param>
        /// <param name="updates">list of available updates sorted decreasing</param>
        /// <returns><c>true</c> if an update is required</returns>
        public UpdateStatus GetUpdateStatus(NetSparkleConfiguration config, out NetSparkleAppCastItem[] updates)
        {
            // report
            ReportDiagnosticMessage("Downloading and checking appcast");

            // init the appcast
            NetSparkleAppCast cast = new NetSparkleAppCast(_appCastUrl, config);
            cast.Read();

            // check if any updates are available
            try
            {
                updates = cast.GetUpdates();
            }
            catch (Exception e)
            {
                // show the exception message 
                ReportDiagnosticMessage("Error during app cast download: " + e.Message);

                // just null the version info
                updates = null;
            }

            if (updates == null)
            {
                ReportDiagnosticMessage("No version information in app cast found");
                return UpdateStatus.CouldNotDetermine;
            }

            // set the last check time
            ReportDiagnosticMessage("Touch the last check timestamp");
            config.TouchCheckTime();

            // check if the version will be the same then the installed version
            if (updates.Length == 0)
            {
                ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")");
                return UpdateStatus.UpdateNotAvailable;
            }
            ReportDiagnosticMessage("Latest version on the server is " + updates[0].Version);

            // check if the available update has to be skipped
            if (updates[0].Version.Equals(config.SkipThisVersion))
            {
                ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")");
                return UpdateStatus.UserSkipped;
            }

            // ok we need an update
            return UpdateStatus.UpdateAvailable;
        }
예제 #8
0
        /// <summary>
        /// This method updates the profile information which can be sended to the server if enabled    
        /// </summary>
        /// <param name="config">the configuration</param>
        public void UpdateSystemProfileInformation(NetSparkleConfiguration config)
        {
            // check if profile data is enabled
            if (!EnableSystemProfiling)
                return;

            // check if we need an update
            if (DateTime.Now - config.LastProfileUpdate < new TimeSpan(7, 0, 0, 0))
                return;

            // touch the profile update time
            config.TouchProfileTime();

            // start the profile thread
            Thread t = new Thread(ProfileDataThreadStart);
            t.Start(config);
        }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="castUrl">the URL of the appcast file</param>
 /// <param name="config">the current configuration</param>
 public NetSparkleAppCast(string castUrl, NetSparkleConfiguration config)
 {
     _config  = config;
     _castUrl = castUrl;
 }
 public NetSparkleDeviceInventory(NetSparkleConfiguration config)
 {
     _config = config;
 }
예제 #11
0
        /// <summary>
        /// This method checks if an update is required. During this process the appcast
        /// will be downloaded and checked against the reference assembly. Ensure that
        /// the calling process has read access to the reference assembly.
        /// This method is also called from the background loops.
        /// </summary>
        /// <param name="config">the configuration</param>
        /// <returns>SparkleUpdate with information on whether there is an update available or not.</returns>
        public async Task<SparkleUpdateInfo> GetUpdateStatus(NetSparkleConfiguration config)
        {
            NetSparkleAppCastItem[] updates = null;
            // report
            ReportDiagnosticMessage("Downloading and checking appcast");

            // init the appcast
            NetSparkleAppCast cast = new NetSparkleAppCast(_appCastUrl, this, config);
            // check if any updates are available
            try
            {
                var task = Task.Factory.StartNew(() =>
                {
                    if (cast.Read())
                        updates = cast.GetUpdates();
                });
                await task;
            }
            catch (Exception e)
            {
                ReportDiagnosticMessage("Couldn't read/parse the app cast: " + e.Message);
                updates = null;
            }


            if (updates == null)
            {
                ReportDiagnosticMessage("No version information in app cast found");
                return new SparkleUpdateInfo(UpdateStatus.CouldNotDetermine);
            }

            // set the last check time
            ReportDiagnosticMessage("Touch the last check timestamp");
            config.TouchCheckTime();

            // check if the version will be the same then the installed version
            if (updates.Length == 0)
            {
                ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")");
                return new SparkleUpdateInfo(UpdateStatus.UpdateNotAvailable);
            }
            ReportDiagnosticMessage("Latest version on the server is " + updates[0].Version);

            // check if the available update has to be skipped
            if (updates[0].Version.Equals(config.SkipThisVersion))
            {
                ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")");
                return new SparkleUpdateInfo(UpdateStatus.UserSkipped);
            }

            // ok we need an update
            return new SparkleUpdateInfo(UpdateStatus.UpdateAvailable, updates);
        }