Пример #1
0
        private bool PrepareUpdate()
        {
            bool _result = true;

            m_Files.Clear();
            m_Events.Clear();

            try
            {
                XmlNodeList _filesToDownload = m_docVersionInfo.SelectNodes("//CurrentVersion/Files/File");
                foreach (XmlNode _node in _filesToDownload)
                {
                    string _filename = GenericHelpers.GetValueFromXmlNode(_node.SelectSingleNode("Name"));
                    if (string.IsNullOrEmpty(_filename))
                    {
                        continue;
                    }
                    string _remoteFilename = GenericHelpers.GetValueFromXmlNode(_node.SelectSingleNode("RemoteName"));
                    _remoteFilename = string.IsNullOrEmpty(_remoteFilename) ? _filename : _remoteFilename;
                    string _fileUrl       = string.Format("{0}/{1}", RemoteDomain.Repository, _remoteFilename);
                    string _localTempFile = Path.Combine(Path.GetTempPath(), _filename);
                    string _isZipped      = GenericHelpers.GetAttributeFromXmlNode(_node, "Zipped");

                    ManualResetEvent _event = new ManualResetEvent(false);

                    FileItem _fileItem = new FileItem();
                    _fileItem.FilePath       = _localTempFile;
                    _fileItem.Source         = new Uri(_fileUrl, UriKind.RelativeOrAbsolute);
                    _fileItem.RemoteFileName = _remoteFilename;
                    _fileItem.Event          = _event;
                    _fileItem.IsZipped       = string.IsNullOrEmpty(_isZipped) ? false : Boolean.Parse(_isZipped);

                    m_Events.Add(_event);
                    m_Files.Add(_fileItem);
                }
            }
            catch
            {
                _result = false;
            }
            return(_result);
        }
Пример #2
0
        static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
        {
            if (args.Name.Contains("NLog"))
            {
                return(GenericHelpers.GetEmbeddedAssembly("ThumbGen.Core.Assemblies.NLog.dll"));
            }

            if (args.Name.Contains("Ionic"))
            {
                return(GenericHelpers.GetEmbeddedAssembly("ThumbGen.Core.Assemblies.Ionic.Zip.Reduced.dll"));
            }

            if (args.Name.Contains("Avalon"))
            {
                return(GenericHelpers.GetEmbeddedAssembly("ThumbGen.Core.Assemblies.AvalonDock.dll"));
            }

            if (args.Name.Contains("Fluent"))
            {
                return(GenericHelpers.GetEmbeddedAssembly("ThumbGen.Core.Assemblies.Fluent.dll"));
            }

            return(null);
        }
Пример #3
0
        private void client_DownloadVersionInfoFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            try
            {
                SetProcessed();

                if (e.Error == null && !e.Cancelled && File.Exists(m_VersionInfoFile))
                {
                    try
                    {
                        m_docVersionInfo.Load(m_VersionInfoFile);
                    }
                    catch
                    {
                        //MessageBox.Show("Cannot check updates. Please retry later", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        CheckUpdates();
                        return;
                    }
                    finally
                    {
                        CleanupFilesAndSetProcessed();
                    }

                    Version _lastVersion    = new Version(m_docVersionInfo.SelectSingleNode("//CurrentVersion/VersionNumber").FirstChild.InnerText);
                    Version _currentVersion = new Version(VersionNumber.LongVersion);

                    string _releaseNotes = GenericHelpers.GetValueFromXmlNode(m_docVersionInfo.SelectSingleNode("//CurrentVersion/ReleaseNotes"));
                    _releaseNotes = string.IsNullOrEmpty(_releaseNotes) ? string.Empty : string.Format("Comment: {0}\n\n", _releaseNotes);

                    if (_lastVersion.CompareTo(_currentVersion) > 0)
                    {
                        MessageBoxResult _res = MessageBox.Show(string.Format("There is a new version available for download!\n\nNew version: {0} (you have {1})\n\n{2}Do you want to upgrade now?", _lastVersion, _currentVersion, _releaseNotes),
                                                                "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        switch (_res)
                        {
                        case MessageBoxResult.Yes:
                            SetProcessing();
                            if (PrepareUpdate())
                            {
                                ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), m_Files);

                                if (m_Events.Count > 0)
                                {
                                    bool _b = false;
                                    while (!_b)
                                    {
                                        _b = true;
                                        foreach (WaitHandle _handle in m_Events)
                                        {
                                            bool _cb = _handle.WaitOne(50);
                                            if (!_cb)
                                            {
                                                _b = false;
                                            }
                                        }
                                        //_b = WaitHandle.WaitAll(m_Events.ToArray(), 50);
                                        GenericHelpers.DoEvents();
                                        Thread.Sleep(0);
                                    }

                                    string _currentBasePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

                                    bool _doRestart = true;
                                    foreach (FileItem _file in m_Files)
                                    {
                                        if (File.Exists(_file.FilePath))
                                        {
                                            string _fn        = Path.GetFileName(_file.FilePath);
                                            string _fnbak     = Path.ChangeExtension(_fn, ".bak");
                                            string _fncurrent = Path.Combine(_currentBasePath, _fn);
                                            try
                                            {
                                                DeleteFile(_fnbak);
                                                if (File.Exists(_fncurrent))
                                                {
                                                    File.Move(_fncurrent, Path.Combine(_currentBasePath, _fnbak));
                                                }
                                                if (_file.IsZipped)
                                                {
                                                    using (ZipFile _zip = new ZipFile(_file.FilePath))
                                                    {
                                                        _zip.ExtractAll(Path.GetDirectoryName(_fncurrent), ExtractExistingFileAction.OverwriteSilently);
                                                    }
                                                }
                                                else
                                                {
                                                    File.Copy(_file.FilePath, _fncurrent);
                                                }
                                            }
                                            catch
                                            {
                                                _doRestart = false;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            _doRestart = false;
                                            break;
                                        }
                                    }

                                    if (!_doRestart)
                                    {
                                        CleanupFilesAndSetProcessed();
                                        MessageBox.Show("Error during updating current version. Please retry later.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                                        return;
                                    }

                                    CleanupFilesAndSetProcessed();

                                    MessageBox.Show("Upgrade successful! Please restart the application.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                                    //System.Windows.Forms.Application.Restart();
                                    Application.Current.Shutdown();
                                }
                                else
                                {
                                    CleanupFilesAndSetProcessed();
                                }
                            }
                            else
                            {
                                CleanupFilesAndSetProcessed();
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        if (!IsAutoUpdateCall)
                        {
                            MessageBox.Show("You have the latest version!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
                else
                {
                    CheckUpdates();
                }
            }
            catch (Exception ex)
            {
                Loggy.Logger.Error(ex.Message);
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }