wyDay.Controls.AutoUpdaterInfo.Save C# (CSharp) Method

Save() public method

public Save ( ) : void
return void
        public void Save()
        {
            #if !CLIENT
            // Disable filesystem redirection on x64 (mostly for Windows Services)
            if (Is32BitProcessOn64BitProcessor())
                EnableWow64FSRedirection(false);

            try
            {
            #endif
                int retriedTimes = 0;

                while (true)
                {
                    try
                    {
                        // save for each filename
                        Save(filenames[0]);

                        if (filenames[1] != null)
                            Save(filenames[1]);
                    }
                    catch (IOException IOEx)
                    {
                        int HResult = Marshal.GetHRForException(IOEx);

                        // if sharing violation
                        if ((HResult & 0xFFFF) == 32)
                        {
                            // sleep for 1/2 second
                            Thread.Sleep(500);

                            // if we're skipping UI and we've already waited 20 seconds for a file to be released
                            // then throw the exception, rollback updates, etc
                            if (retriedTimes == 20)
                                throw;

                            // otherwise, retry file copy
                            ++retriedTimes;
                            continue;
                        }

                        throw;
                    }

                    break;
                }
            #if !CLIENT
            }
            finally
            {
                // Re-enable filesystem redirection on x64
                if (Is32BitProcessOn64BitProcessor())
                    EnableWow64FSRedirection(true);
            }
            #endif
        }

Same methods

AutoUpdaterInfo::Save ( string filename ) : void

Usage Example

Example #1
0
        /// <summary>
        /// The function that must be called when your app has loaded.
        /// </summary>
        public void AppLoaded()
        {
            if (AutoUpdaterInfo == null)
            {
                throw new FailedToInitializeException();
            }

            // if we want to kill ourself, then don't bother checking for updates
            if (ClosingForInstall)
            {
                return;
            }

            // get the current update step from the info file
            m_UpdateStepOn = AutoUpdaterInfo.UpdateStepOn;

            if (UpdateStepOn != UpdateStepOn.Nothing)
            {
                version       = AutoUpdaterInfo.UpdateVersion;
                changes       = AutoUpdaterInfo.ChangesInLatestVersion;
                changesAreRTF = AutoUpdaterInfo.ChangesIsRTF;

                switch (UpdateStepOn)
                {
                case UpdateStepOn.UpdateAvailable:
                    if (internalUpdateType == UpdateType.CheckAndDownload || internalUpdateType == UpdateType.Automatic)
                    {
                        DownloadUpdate(); // begin downloading the update
                    }
                    else
                    {
                        UpdateReady();
                    }

                    break;

                case UpdateStepOn.UpdateReadyToInstall:
                    UpdateReadyToInstall();
                    break;

                case UpdateStepOn.UpdateDownloaded:

                    if (internalUpdateType == UpdateType.Automatic)
                    {
                        ExtractUpdate(); // begin extraction
                    }
                    else
                    {
                        UpdateReadyToExtract();
                    }

                    break;
                }
            }
            else // UpdateStepOn == UpdateStepOn.Nothing
            {
                switch (AutoUpdaterInfo.AutoUpdaterStatus)
                {
                case AutoUpdaterStatus.UpdateSucceeded:

                    // set the version & changes
                    version       = AutoUpdaterInfo.UpdateVersion;
                    changes       = AutoUpdaterInfo.ChangesInLatestVersion;
                    changesAreRTF = AutoUpdaterInfo.ChangesIsRTF;

                    if (UpdateSuccessful != null)
                    {
                        UpdateSuccessful(this, new SuccessArgs {
                            Version = version
                        });
                    }

                    break;

                case AutoUpdaterStatus.UpdateFailed:

                    if (UpdateFailed != null)
                    {
                        UpdateFailed(this, new FailArgs {
                            ErrorTitle = AutoUpdaterInfo.ErrorTitle, ErrorMessage = AutoUpdaterInfo.ErrorMessage
                        });
                    }

                    break;
                }

                // clear the changes and resave
                AutoUpdaterInfo.ClearSuccessError();
                AutoUpdaterInfo.Save();
            }
        }