예제 #1
0
        /// <summary>
        /// Initializes the updatewindow
        /// </summary>
        /// <param name="patchTask">The update task</param>
        /// <param name="patcher"></param>
        /// <param name="progress"></param>
        /// <param name="targetVersionString">The version to update to</param>
        /// <param name="cancellationTokenSource">Cancellationsource for the updatetask</param>
        /// <param name="isInstall">Is this the first install</param>
        public ApplyUpdateWindow(Task patchTask, RxPatcher patcher, Progress <DirectoryPatcherProgressReport> progress, string targetVersionString, CancellationTokenSource cancellationTokenSource, UpdateWindowType type)
        {
            TargetVersionString      = targetVersionString;
            _cancellationTokenSource = cancellationTokenSource;
            string[] statusTitle = new string[] { "updated", "update" };

            Dictionary <UpdateWindowType, string[]> statusTitleDict = new Dictionary <UpdateWindowType, string[]>()
            {
                { UpdateWindowType.Install, new string[] { "installed", "installation" } },
                { UpdateWindowType.Update, new string[] { "updated", "update" } },
                { UpdateWindowType.Verify, new string[] { "verified", "verification" } },
                { UpdateWindowType.Reset, new string[] { "modified", "modification" } }
            };

            statusTitleDict.TryGetValue(type, out statusTitle);

            this.StatusMessage = string.Format("Please wait while Renegade X is being {0}.", statusTitle[0]);

            if (patcher.UpdateServer == null)
            {
                this.ServerMessage = "pending";
            }
            else
            {
                this.ServerMessage = patcher.UpdateServer.Name;
            }

            InitializeComponent();
            this.Title = string.Format("Renegade X {0} ", statusTitle[1]);

            DirectoryPatcherProgressReport lastReport = new DirectoryPatcherProgressReport();

            progress.ProgressChanged += (o, report) => lastReport = report;

            // Here we start the actual patching process, the whole thing from verification to applying.
            Task backgroundTask = Task.Factory.StartNew(async() =>
            {
                while (await Task.WhenAny(patchTask, Task.Delay(500)) != patchTask)
                {
                    if (_cancellationTokenSource.IsCancellationRequested)
                    {
                        throw new OperationCanceledException();
                    }
                    ProgressReport = lastReport;
                }
                ProgressReport = lastReport;

                try
                {
                    await patchTask; // Collect exceptions.
                    this.StatusMessage = string.Format("Renegade X was successfully {0} to version {1}.", statusTitle[0], TargetVersionString);
                    RxLogger.Logger.Instance.Write($"Renegade X was successfully {statusTitle[0]} to version {TargetVersionString}.");
                }
                catch (Exception exception)
                {
                    StatusMessage = string.Format("Renegade X could not be {0}. The following exception occurred:\n\n{1}", statusTitle[0], exception.Message);
                    RxLogger.Logger.Instance.Write($"Renegade X could not be {statusTitle[0]}. The following exception occurred:\n\n{exception.Message}\r\n{exception.StackTrace}");
                }
                HasFinished = true;
            }, _cancellationTokenSource.Token);
        }
        /// <summary>
        /// Initializes the updatewindow
        /// </summary>
        /// <param name="patchTask">The update task</param>
        /// <param name="progress"></param>
        /// <param name="targetVersionString">The version to update to</param>
        /// <param name="cancellationTokenSource">Cancellationsource for the updatetask</param>
        /// <param name="isInstall">Is this the first install</param>


        public ApplyUpdateWindow(Task patchTask, RXPatcher patcher, Progress <DirectoryPatcherProgressReport> progress, string targetVersionString, CancellationTokenSource cancellationTokenSource, UpdateWindowType type)
        {
            TargetVersionString     = targetVersionString;
            CancellationTokenSource = cancellationTokenSource;
            string[] StatusTitle = new string[] { "updated", "update" };

            Dictionary <UpdateWindowType, string[]> StatusTitleDict = new Dictionary <UpdateWindowType, string[]>()
            {
                { UpdateWindowType.Install, new string[] { "installed", "installation" } },
                { UpdateWindowType.Update, new string[] { "updated", "update" } },
                { UpdateWindowType.Verify, new string[] { "verified", "verification" } },
                { UpdateWindowType.Reset, new string[] { "modified", "modification" } }
            };

            StatusTitleDict.TryGetValue(type, out StatusTitle);

            this.StatusMessage = string.Format("Please wait while Renegade X is being {0}.", StatusTitle[0]);

            if (patcher.BaseURL == null || patcher.BaseURL == "")
            {
                this.ServerMessage = "pending";
            }
            else
            {
                this.ServerMessage = patcher.BaseURL;
            }

            InitializeComponent();
            this.Title = string.Format("Renegade X {0} ", StatusTitle[1]);

            DirectoryPatcherProgressReport lastReport = new DirectoryPatcherProgressReport();

            progress.ProgressChanged += (o, report) => lastReport = report;

            Task backgroundTask = Task.Factory.StartNew(async() =>
            {
                while (await Task.WhenAny(patchTask, Task.Delay(500)) != patchTask)
                {
                    // URL could theoretically change at any point
                    if (this.ServerMessage != patcher.BaseURL)
                    {
                        if (patcher.BaseURL == null)
                        {
                            this.ServerMessage = "pending";
                        }
                        else
                        {
                            this.ServerMessage = patcher.BaseURL;
                        }
                    }

                    ProgressReport = lastReport;
                }
                ProgressReport = lastReport;

                try
                {
                    await patchTask; // Collect exceptions.
                    this.StatusMessage = string.Format("Renegade X was successfully {0} to version {1}.", StatusTitle[0], TargetVersionString);
                }
                catch (Exception exception)
                {
                    StatusMessage = string.Format("Renegade X could not be {0}. The following exception occurred:\n\n{1}", StatusTitle[0], exception.Message);
                }
                HasFinished = true;
            });
        }