Пример #1
0
        /// <summary>
        /// Try to deserialize from the backup file.
        /// </summary>
        /// <param name="backupFile">The backup file.</param>
        /// <param name="recover">if set to <c>true</c> do a settings recover attempt.</param>
        /// <returns>
        ///     <c>Null</c> if we have been unable to load anything from files, the generated settings otherwise
        /// </returns>
        private static SerializableSettings TryDeserializeFromBackupFile(string backupFile, bool recover = true)
        {
            // Backup file doesn't exist
            if (!File.Exists(backupFile))
            {
                return(null);
            }

            EveMonClient.Trace("begin");

            // Check backup settings file length
            FileInfo backupInfo = new FileInfo(backupFile);

            if (backupInfo.Length == 0)
            {
                return(null);
            }

            string settingsFile = EveMonClient.SettingsFileNameFullPath;

            const string Caption = "Corrupt Settings";

            if (recover)
            {
                // Prompts the user to use the backup
                string fileDate =
                    $"{backupInfo.LastWriteTime.ToLocalTime().ToShortDateString()} " +
                    $"at {backupInfo.LastWriteTime.ToLocalTime().ToShortTimeString()}";
                DialogResult dialogResult = MessageBox.Show(
                    $"The settings file is missing or corrupt. There is a backup available from {fileDate}.{Environment.NewLine}" +
                    @"Do you want to use the backup file?", Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (dialogResult == DialogResult.No)
                {
                    MessageBox.Show($"A new settings file will be created.{Environment.NewLine}"
                                    + @"You may wish then to restore a saved copy of the file.", Caption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // Save a copy of the corrupt file just in case
                    FileHelper.CopyOrWarnTheUser(backupFile, settingsFile + ".corrupt");

                    return(null);
                }
            }

            // Get the revision number of the assembly which generated this file
            // Try to load from a file (when no revision found then it's a pre 1.3.0 version file)
            SerializableSettings settings = Util.GetRevisionNumber(backupFile) == 0
                ? (SerializableSettings)UIHelper.ShowNoSupportMessage()
                : Util.DeserializeXmlFromFile <SerializableSettings>(backupFile,
                                                                     SettingsTransform);

            // If the settings loaded OK, copy to the main settings file, then copy back to stamp date
            if (settings != null)
            {
                CheckSettingsVersion(settings);
                FileHelper.CopyOrWarnTheUser(backupFile, settingsFile);
                FileHelper.CopyOrWarnTheUser(settingsFile, backupFile);

                EveMonClient.Trace("done");
                return(settings);
            }

            if (recover)
            {
                // Backup failed too, notify the user we have a problem
                MessageBox.Show($"Loading from backup failed.\nA new settings file will be created.{Environment.NewLine}"
                                + @"You may wish then to restore a saved copy of the file.",
                                Caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                // Save a copy of the corrupt file just in case
                FileHelper.CopyOrWarnTheUser(backupFile, settingsFile + ".corrupt");
            }
            else
            {
                // Restoring from file failed
                MessageBox.Show($"Restoring settings from {backupFile} failed, the file is corrupted.",
                                Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(null);
        }
Пример #2
0
 /// <summary>
 /// Schedules a check a specified time period in the future.
 /// </summary>
 /// <param name="time">Time period in the future to start check.</param>
 private static void ScheduleCheck(TimeSpan time)
 {
     s_checkScheduled = true;
     Dispatcher.Schedule(time, () => BeginCheckAsync().ConfigureAwait(false));
     EveMonClient.Trace("in " + time);
 }
Пример #3
0
        /// <summary>
        /// Scans the update feed.
        /// </summary>
        /// <param name="result">The result.</param>
        private static void ScanUpdateFeed(SerializablePatch result)
        {
            Version             currentVersion = Version.Parse(EveMonClient.FileVersionInfo.FileVersion);
            SerializableRelease newestRelease  = result.Releases?
                                                 .FirstOrDefault(release => Version.Parse(release.Version).Major == currentVersion.Major);

            Version newestVersion = newestRelease != null?Version.Parse(newestRelease.Version) : currentVersion;

            Version mostRecentDeniedVersion = !String.IsNullOrEmpty(Settings.Updates.MostRecentDeniedUpgrade)
                ? new Version(Settings.Updates.MostRecentDeniedUpgrade)
                : new Version();

            // Is the program out of date and user has not previously denied this version?
            if (currentVersion < newestVersion & mostRecentDeniedVersion < newestVersion)
            {
                // Quit if newest release is null
                // (Shouldn't happen but it's nice to be prepared)
                if (newestRelease == null)
                {
                    return;
                }

                // Reset the most recent denied version
                Settings.Updates.MostRecentDeniedUpgrade = String.Empty;

                Uri    forumUrl       = new Uri(newestRelease.TopicAddress);
                Uri    installerUrl   = new Uri(newestRelease.PatchAddress);
                string updateMessage  = newestRelease.Message;
                string installArgs    = newestRelease.InstallerArgs;
                string md5Sum         = newestRelease.MD5Sum;
                string additionalArgs = newestRelease.AdditionalArgs;
                bool   canAutoInstall = !String.IsNullOrEmpty(installerUrl.AbsoluteUri) && !String.IsNullOrEmpty(installArgs);

                if (!String.IsNullOrEmpty(additionalArgs) && additionalArgs.Contains("%EVEMON_EXECUTABLE_PATH%"))
                {
                    string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                    installArgs = $"{installArgs} {additionalArgs}";
                    installArgs = installArgs.Replace("%EVEMON_EXECUTABLE_PATH%", appPath);
                }

                // Requests a notification to subscribers and quit
                EveMonClient.OnUpdateAvailable(forumUrl, installerUrl, updateMessage, currentVersion,
                                               newestVersion, md5Sum, canAutoInstall, installArgs);

                return;
            }

            // New data files released?
            if (result.FilesHaveChanged)
            {
                // Requests a notification to subscribers
                EveMonClient.OnDataUpdateAvailable(result.ChangedDatafiles);
                return;
            }

            //Notify about a new major version
            Version             newestMajorVersion = result.Releases?.Max(release => Version.Parse(release.Version)) ?? new Version();
            SerializableRelease newestMajorRelease = result.Releases?
                                                     .FirstOrDefault(release => Version.Parse(release.Version) == newestMajorVersion);

            if (newestMajorRelease == null)
            {
                return;
            }

            newestVersion = Version.Parse(newestMajorRelease.Version);
            Version mostRecentDeniedMajorUpgrade = !String.IsNullOrEmpty(Settings.Updates.MostRecentDeniedMajorUpgrade)
                ? new Version(Settings.Updates.MostRecentDeniedMajorUpgrade)
                : new Version();

            // Is there is a new major version and the user has not previously denied it?
            if (currentVersion >= newestVersion | mostRecentDeniedMajorUpgrade >= newestVersion)
            {
                return;
            }

            // Reset the most recent denied version
            Settings.Updates.MostRecentDeniedMajorUpgrade = String.Empty;

            EveMonClient.OnUpdateAvailable(null, null, null, currentVersion,
                                           newestVersion, null, false, null);
        }