Пример #1
0
        private void FinishUpdate()
        {
            if (!_updating)
            {
                return;
            }

            int i = 0;

            // Key: original file name
            // Value: temp destination of downloaded file
            foreach (var kvp in _downloadDestinations)
            {
                // If the file we want to move to the current directory already exists, rename it to a tmp name
                if (File.Exists(kvp.Key))
                {
                    File.Move(kvp.Key, $"temp{i}.mbtemp");
                    i++;
                }

                string directoryPath = Path.GetDirectoryName(kvp.Key);
                if (!string.IsNullOrEmpty(directoryPath))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(kvp.Key));
                }

                File.Move(kvp.Value, kvp.Key);
            }

            UpdateFinished?.Invoke();
        }
Пример #2
0
 private void NotifyCommandFinished()
 {
     if (UpdateFinished != null)
     {
         UpdateFinished.Invoke(this, new EventArgs());
     }
 }
Пример #3
0
        private void UpdateInThreadPerforming(IModuleDiscovery afterUpdateModulesToBeLoaded)
        {
            try
            {
                // FIXME: this sleep is totally wrong
                Thread.Sleep(100);

                _modulesOperations.UnloadModules();

                // use packager for the each of the downloaded packages
                foreach (ModulePackage modulePackage in _modulesPackages)
                {
                    var targetDirectory = _moduleFinder.FindDirectoryForPackage(_targetDirectory,
                                                                                modulePackage);

                    _modulePackager.PerformUpdates(targetDirectory, modulePackage);
                }
                _modulesOperations.LoadModules(afterUpdateModulesToBeLoaded);
            }
            catch (Exception)
            {
                // catch exceptions, TODO: add logging for this
                Status = UpdaterStatus.Invalid;
                // make signal about finishing the update
                UpdateFinished.Set();
                return;
            }
            // set result of the updates
            Status = UpdaterStatus.Idle;

            // make signal about finishing the update.
            UpdateFinished.Set();
        }
        /// <summary>
        /// Raised when file is modifiled.
        /// </summary>
        private void OnFileChanged()
        {
            // notify listeners
            UpdateStarted?.Invoke();

            // load file
            IDataContainer changed = (IDataContainer)XmlHelper.DeserializeFromFile(_container.FilePath, _container.GetType());

            // update properties
            if (changed != null)
            {
                if (CanAddItems)
                {
                    _container.Merge(changed);
                }

                if (CanRemoveItems)
                {
                    _container.InplaceIntersect(changed);
                }

                _container.Refresh(changed);
            }

            // notify listeners
            UpdateFinished?.Invoke();
        }
Пример #5
0
        /// <summary>
        ///     Starts update process
        /// </summary>
        /// <remarks>
        /// <para>
        /// Using provided <see cref="IModulesOperations"/> it unloads all modules,
        /// than it places update files into modules directory, and loads modules back.
        /// </para>
        /// <para>
        ///     This implementation creates the new thread to be used to unload modules. It is obligatory because of the
        /// <see cref="AppDomain.Unload"/> method, which can not be invoked by thread which used to be on unloading domain.
        /// </para>
        /// <para>
        ///     Upon success or failure sets the flag <see cref="Status"/> with corresponding value.
        /// </para>
        /// </remarks>
        public void PerformUpdates(IModuleDiscovery afterUpdateModulesToBeLoaded)
        {
            Status = UpdaterStatus.Performing;

            // manage resources faster than GC would do
            if (UpdateFinished != null)
            {
                UpdateFinished.Close();
            }
            UpdateFinished = new AutoResetEvent(false);

            ThreadPool.QueueUserWorkItem(
                delegate { UpdateInThreadPerforming(afterUpdateModulesToBeLoaded); });
        }
Пример #6
0
        private void CheckFilesFinished(object sender, RunWorkerCompletedEventArgs e)
        {
            if (corruptFiles.Count > 0)
            {
                ReportDownloadStatus();

                fileUpdateWorker                     = new BackgroundWorker();
                fileUpdateWorker.DoWork             += UpdateFiles;
                fileUpdateWorker.RunWorkerCompleted += UpdateFilesFinished;
                fileUpdateWorker.RunWorkerAsync();
            }
            else
            {
                StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.Finished"));
                UpdateFinished?.Invoke(this, EventArgs.Empty);
            }
        }
Пример #7
0
        private void UpdateFilesFinished(object sender, RunWorkerCompletedEventArgs e)
        {
            if (File.Exists("content.xml"))
            {
                File.Delete("content.xml");
            }
            if (File.Exists("content.version"))
            {
                File.Delete("content.version");
            }
            if (File.Exists("content.changes"))
            {
                File.Delete("content.changes");
            }

            StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.Finished"));
            UpdateFinished?.Invoke(this, EventArgs.Empty);
        }
Пример #8
0
 private void OnUpdateFinished()
 {
     UpdateFinished?.Invoke();
 }
Пример #9
0
 protected virtual void OnUpdateFinished()
 {
     UpdateFinished?.Invoke(this, EventArgs.Empty);
 }