Esempio n. 1
0
        private void patchConverterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog.Title    = "Select the patch you wish to convert";
            openFileDialog.Filter   = "MUO patch (*.muo)|*.muo|UOP patch (*.uop)|*.uop|Verdata patch (verdata.mul)|verdata.mul";
            openFileDialog.FileName = string.Empty;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                UpdateStatus("Loading " = openFileDialog.FileName + "...");
                PatchReader reader = new PatchReader(File.Open(openFileDialog.FileName, FileMode.Open), PatchReader.ExtensionToPatchFileType(Path.GetExtension(openFileDialog.FileName)));

                UpdateStatus("Reading patches, please wait... ");
                List <Patch> patches = reader.ReadPatches();


                UpdateStatus("Loaded " + patches.Count.ToString() + " patches into memory...");
                saveFileDialog.Title    = "Select where you wish to save the patches to";
                saveFileDialog.Filter   = "MUO patch (*.muo)|*.muo|UOP patch (*.uop)|*.uop|Verdata patch (verdata.mul)|verdata.mul";
                saveFileDialog.FileName = string.Empty;

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    PatchFileType type = PatchReader.ExtensionToPatchFileType(Path.GetExtension(saveFileDialog.FileName));

                    UpdateStatus("Saving patches, please wait... ");

                    PatchWriter writer = new PatchWriter(File.Open(saveFileDialog.FileName, FileMode.OpenOrCreate), type);

                    switch (type)
                    {
                    case PatchFileType.MUO:
                        PatchWriter.CreateMUO(saveFileDialog.FileName, patches); break;

                    case PatchFileType.UOP:
                        PatchWriter.CreateUOP(saveFileDialog.FileName, patches); break;

                    case PatchFileType.Verdata:
                        break;
                    }

                    UpdateStatus("Patch conversion complete");
                    MessageBox.Show("Patch conversion complete", "Success");
                }
                else
                {
                    MessageBox.Show("Patch conversion process aborted", "Aborted");
                }

                if (reader != null)
                {
                    reader.Close();
                }

                patches = null;
            }
        }
Esempio n. 2
0
        public async Task PatchSingleItem(IArchiveFileEntry file, CancellationToken cancellationToken)
        {
            OnProgress(new ProgressUpdateEventArgs(file, 0, 0));
            if (await PatchWriter.Exists(file).ConfigureAwait(false))
            {
                return;
            }
            int              counter    = 0;
            Stream           fileData   = null;
            List <Exception> exceptions = new List <Exception>();

            do
            {
                try
                {
                    fileData = await PatchSource.DownloadHashAsync((int)Index.RootIndex.BuildNumber, file.Hash,
                                                                   cancellationToken);
                }
                catch (Exception ex)
                {
                    counter++;
                    exceptions.Add(ex);
                }
            } while (fileData == null && counter < FileRetryCount);

            if (fileData == null)
            {
                throw new AggregateException(exceptions);
            }

            counter = 0;
            do
            {
                try
                {
                    await PatchWriter.AppendAsync(fileData, file).ConfigureAwait(false);

                    break;
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                    counter++;
                }
            } while (counter < FileRetryCount);

            if (counter >= FileRetryCount)
            {
                throw new AggregateException(exceptions);
            }
        }