示例#1
0
        protected override void BeginTask(object state)
        {
            PatchingTask task      = (PatchingTask)state;
            Exception    exception = null;

            try
            {
                if (!CancelRequested)
                {
                    task.OnProgressStarted(this, new ProgressStartedEventArgs(task));
                }

                Patcher patcher = _kernel.Get <Patcher>();

                patcher.Patches      = task.Patches;
                patcher.ServerFolder = task.ServerDirectory;

                patcher.ProgressChanged +=
                    new EventHandler <PatcherProgressChangeEventArgs>(delegate(object sender, PatcherProgressChangeEventArgs e)
                {
                    if (!CancelRequested)
                    {
                        task.OnProgressUpdate(this, new ProgressUpdateEventArgs(task, e.PercentComplete, 100));
                    }
                });


                patcher.WritePatches();
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                if (!CancelRequested)
                {
                    task.OnProgressCompleted(this, new ProgressCompletedEventArgs(exception, CancelRequested, task, 100, 100));
                }
            }

            base.BeginTask(state);
        }
示例#2
0
 private void UpdatePatchingStatus(PatchingTask task, ListViewItem item, int current, int total, int completed, string status)
 {
     item.SubItems[0].Text = task.PatchType;
     item.SubItems[1].Text = "100";
     item.SubItems[2].Text = string.Format("{0}", current);
     item.SubItems[3].Text = string.Format("{0:00}%", completed);
     item.SubItems[4].Text = status;
 }
示例#3
0
        private void InitializePatchingProcess()
        {
            Invoke((MethodInvoker)delegate()
            {
                lblStatus.Text = "Status: Gathering patching information...";
            });

            DirectoryInfo directory = new DirectoryInfo(_serverDirectory);
            List<FileInfo> files = new List<FileInfo>();

            FileInfo[] muoFiles = directory.GetFiles("*.muo");
            FileInfo[] uopFiles = directory.GetFiles("*.uop");
            FileInfo[] mulFiles = directory.GetFiles("verdata.mul");

            List<FileInfo> patchFiles = new List<FileInfo>();

            patchFiles.AddRange(muoFiles);
            patchFiles.AddRange(uopFiles);
            patchFiles.AddRange(mulFiles);

            List<Patch> patches = new List<Patch>();

            for (int i = 0; i < patchFiles.Count; i++)
            {
                PatchReader reader = new PatchReader(
                    File.OpenRead(patchFiles[i].FullName), PatchReader.ExtensionToPatchFileType(patchFiles[i].FullName));

                patches.AddRange(reader.ReadPatches());
                reader.Close();
            }

            for (int i = 0; i < muoFiles.Length; i++)
                muoFiles[i].Delete();
            for (int i = 0; i < uopFiles.Length; i++)
                uopFiles[i].Delete();
            for (int i = 0; i < mulFiles.Length; i++)
                mulFiles[i].Delete();

            if (patches.Count <= 0)
            {
                Complete();
                return;
            }

            Dictionary<int, List<Patch>> typedPatchTable = new Dictionary<int, List<Patch>>();

            for (int i = 0; i < patches.Count; i++)
            {
                if (!typedPatchTable.ContainsKey(patches[i].FileId))
                    typedPatchTable.Add(patches[i].FileId, new List<Patch>());

                typedPatchTable[patches[i].FileId].Add(patches[i]);
            }

            Invoke((MethodInvoker)delegate()
            {
                lvDownloads.Items.Clear();

                columnHeader1.Text = "Mul File";
                columnHeader2.Text = "Total";
                columnHeader3.Text = "Completed";
                columnHeader4.Text = "Progress";
                columnHeader7.Text = "Status";
            });

            List<int> keys = new List<int>(typedPatchTable.Keys);

            _patchCount = keys.Count;

            for (int i = 0; i < keys.Count; i++)
            {
                int key = keys[i];
                patches = typedPatchTable[keys[i]];

                if(patches.Count > 0)
                {
                    FileId id = (FileId)i;

                    PatchingTask task = new PatchingTask(patches.ToArray(), _serverDirectory, id.ToString().Replace('_', '.'));

                    task.ProgressUpdate += new EventHandler<ProgressUpdateEventArgs>(OnPatchingProgressUpdate);
                    task.ProgressCompleted += new EventHandler<ProgressCompletedEventArgs>(OnPatchingProgressCompleted);

                    ListViewItem item = new ListViewItem(new string[5]);

                    Invoke((MethodInvoker)delegate()
                    {
                        lvDownloads.Items.Add(item);
                        UpdatePatchingStatus(task, item, 0, 100, 0, "Patching Queued");
                    });

                    _patchTable.Add(task, item);
                    _patchManager.Queue(task);

                }
            }

            _patchManager.Begin();
        }