Example #1
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();
        }