private void ThreadWorker()
        {
            String errorMessage = null;

            // download changelog
            try
            {
                WebRequest request = WebRequest.Create(Config.UpdateUrl + changeLogFileName);

                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        // workaround for not being able to create a FlowDocument in a background thread
                        FlowDocument fd = (FlowDocument)XamlReader.Load(stream);
                        MemoryStream ms = new MemoryStream();
                        XamlWriter.Save(fd, ms);
                        ms.Position = 0;
                        SetChangeLogDocument(ms);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                errorMessage = ex.Message;
            }
            finally
            {
                UpdateComplete(errorMessage);
            }
        }
Beispiel #2
0
        private void CheckForUpdateThreadWorker()
        {
            try
            {
                WebRequest request = WebRequest.Create(Config.UpdateUrl + versionFileName);

                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Version));
                        version = (Version)serializer.Deserialize(stream);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                errorMessage = ex.Message;
                updateCheckInterface.UpdateCheckComplete();
                return;
            }

            // see if found version number is greater than current version
            Int32 deltaMajor = version.Major - Config.ProgramVersionMajor;
            Int32 deltaMinor = version.Minor - Config.ProgramVersionMinor;
            Int32 deltaUpdate = version.Update - Config.ProgramVersionUpdate;

            if (deltaMajor > 0 || (deltaMajor == 0 && deltaMinor > 0) || (deltaMajor == 0 && deltaMinor == 0 && deltaUpdate > 0))
            {
                available = true;
            }

            updateCheckInterface.UpdateCheckComplete();
        }
Beispiel #3
0
        /// <summary>
        /// Reads the program configuration from the configuration file, if it exists. Otherwise, default values and information from the registry are used.
        /// </summary>
        /// <returns>True if the config file exists, False if it doesn't.</returns>
        public static Boolean Read()
        {
            ProgramDataPath    = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + ProgramName;
            ProgramExeFullPath = Common.SanitisePath(Environment.GetCommandLineArgs()[0]);
#if DEBUG
            // Use the working directory when debugging. This is due to the Express edition of VS2008's limited debugging options.
            // The working directory should be set to the bin sub-directory (e.g. trunk\bin).
            ProgramPath = Environment.CurrentDirectory;
#else
            ProgramPath = Path.GetDirectoryName(ProgramExeFullPath);
#endif

            Settings = null;
            Boolean result         = true;
            String  configFullPath = ProgramDataPath + "\\" + fileName;

            if (File.Exists(configFullPath))
            {
                // deserialize
                try
                {
                    using (StreamReader stream = new StreamReader(configFullPath))
                    {
                        Serializer serializer = new Serializer(typeof(ProgramSettings));
                        Settings = (ProgramSettings)serializer.Deserialize(stream);
                    }
                }
                catch (Exception ex)
                {
                    // Assume the file has been corrupted by the user or some other external influence. Log the exception as a warning, delete the file and use default config values.
                    Common.LogException(ex, true);
                    File.Delete(configFullPath);
                    Settings = null;
                }
            }

            if (Settings == null)
            {
                Settings = new ProgramSettings();
                result   = false;
                ReadFromRegistry();
            }

            return(result);
        }
Beispiel #4
0
 private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
 {
     Common.LogException(e.Exception);
     Common.Message(null, "Unhandled exception.", e.Exception, MessageWindow.Flags.Error);
 }