Beispiel #1
0
        private void patcher_PatchingStateChanged(object sender, PatchingEventArgs e)
        {
            switch (e.State)
            {
            case PatchingState.PatchStart:
                AppendStateText("开始更新" + e.Part.FileName + "\r\n");
                break;

            case PatchingState.VerifyOldChecksumBegin:
                AppendStateText("  检查旧文件checksum...");
                break;

            case PatchingState.VerifyOldChecksumEnd:
                AppendStateText("  结束\r\n");
                break;

            case PatchingState.VerifyNewChecksumBegin:
                AppendStateText("  检查新文件checksum...");
                break;

            case PatchingState.VerifyNewChecksumEnd:
                AppendStateText("  结束\r\n");
                break;

            case PatchingState.TempFileCreated:
                AppendStateText("  创建临时文件...\r\n");
                progressBarX1.Maximum = e.Part.NewFileLength;
                break;

            case PatchingState.TempFileBuildProcessChanged:
                progressBarX1.Value = (int)e.CurrentFileLength;
                progressBarX1.Text  = string.Format("{0:N0}/{1:N0}", e.CurrentFileLength, e.Part.NewFileLength);
                break;

            case PatchingState.TempFileClosed:
                AppendStateText("  关闭临时文件...\r\n");
                progressBarX1.Value   = 0;
                progressBarX1.Maximum = 0;
                progressBarX1.Text    = string.Empty;

                if (!string.IsNullOrEmpty(this.compareFolder) &&
                    e.Part.Type == 1 &&
                    Path.GetExtension(e.Part.FileName).Equals(".wz", StringComparison.OrdinalIgnoreCase) &&
                    !Path.GetFileName(e.Part.FileName).Equals("list.wz", StringComparison.OrdinalIgnoreCase))
                {
                    Wz_Structure wznew = new Wz_Structure();
                    Wz_Structure wzold = new Wz_Structure();
                    try
                    {
                        AppendStateText("  (comparer)正在对比文件...\r\n");
                        EasyComparer comparer = new EasyComparer();
                        comparer.OutputPng               = chkOutputPng.Checked;
                        comparer.OutputAddedImg          = chkOutputAddedImg.Checked;
                        comparer.OutputRemovedImg        = chkOutputRemovedImg.Checked;
                        comparer.Comparer.PngComparison  = (WzPngComparison)cmbComparePng.SelectedItem;
                        comparer.Comparer.ResolvePngLink = chkResolvePngLink.Checked;
                        wznew.Load(e.Part.TempFilePath, false);
                        wzold.Load(e.Part.OldFilePath, false);
                        comparer.EasyCompareWzFiles(wznew.wz_files[0], wzold.wz_files[0], this.compareFolder);
                    }
                    catch (Exception ex)
                    {
                        txtPatchState.AppendText(ex.ToString());
                    }
                    finally
                    {
                        wznew.Clear();
                        wzold.Clear();
                        GC.Collect();
                    }
                }

                if (this.deadPatch && e.Part.Type == 1 && sender is WzPatcher patcher)
                {
                    if (patcher.IsKMST1125Format.Value)
                    {
                        // TODO: we should build the file dependency tree to make sure all old files could be overridden safely.
                        AppendStateText("  (deadpatch)延迟应用文件...\r\n");
                    }
                    else
                    {
                        patcher.SafeMove(e.Part.TempFilePath, e.Part.OldFilePath);
                        AppendStateText("  (deadpatch)正在应用文件...\r\n");
                    }
                }
                break;

            case PatchingState.PrepareVerifyOldChecksumBegin:
                AppendStateText($"预检查旧文件checksum: {e.Part.FileName}");
                break;

            case PatchingState.PrepareVerifyOldChecksumEnd:
                AppendStateText(" 结束\r\n");
                break;

            case PatchingState.ApplyFile:
                AppendStateText($"应用文件: {e.Part.FileName}\r\n");
                break;
            }
        }
Beispiel #2
0
        private void patcher_PatchingStateChanged(object sender, PatchingEventArgs e)
        {
            switch (e.State)
            {
            case PatchingState.PatchStart:
                AppendStateText("Starting Update: " + e.Part.FileName + "\r\n");
                break;

            case PatchingState.VerifyOldChecksumBegin:
                AppendStateText("  Checking old file checksum...");
                break;

            case PatchingState.VerifyOldChecksumEnd:
                AppendStateText("  Complete\r\n");
                break;

            case PatchingState.VerifyNewChecksumBegin:
                AppendStateText("  Checking new file checksum...");
                break;

            case PatchingState.VerifyNewChecksumEnd:
                AppendStateText("  Complete\r\n");
                break;

            case PatchingState.TempFileCreated:
                AppendStateText("  Creating temporary files...\r\n");
                progressBarX1.Maximum = e.Part.NewFileLength;
                break;

            case PatchingState.TempFileBuildProcessChanged:
                progressBarX1.Value = (int)e.CurrentFileLength;
                progressBarX1.Text  = string.Format("{0:N0}/{1:N0}", e.CurrentFileLength, e.Part.NewFileLength);
                break;

            case PatchingState.TempFileClosed:
                AppendStateText("  Closing temporary files...\r\n");
                progressBarX1.Value   = 0;
                progressBarX1.Maximum = 0;
                progressBarX1.Text    = string.Empty;

                if (!string.IsNullOrEmpty(this.compareFolder) &&
                    e.Part.Type == 1 &&
                    Path.GetExtension(e.Part.FileName).Equals(".wz", StringComparison.OrdinalIgnoreCase) &&
                    !Path.GetFileName(e.Part.FileName).Equals("list.wz", StringComparison.OrdinalIgnoreCase))
                {
                    Wz_Structure wznew = new Wz_Structure();
                    Wz_Structure wzold = new Wz_Structure();
                    try
                    {
                        AppendStateText("  (comparer)Comparing files...\r\n");
                        EasyComparer comparer = new EasyComparer();
                        comparer.OutputPng               = chkOutputPng.Checked;
                        comparer.OutputAddedImg          = chkOutputAddedImg.Checked;
                        comparer.OutputRemovedImg        = chkOutputRemovedImg.Checked;
                        comparer.Comparer.PngComparison  = (WzPngComparison)cmbComparePng.SelectedItem;
                        comparer.Comparer.ResolvePngLink = chkResolvePngLink.Checked;
                        wznew.Load(e.Part.TempFilePath, false);
                        wzold.Load(e.Part.OldFilePath, false);
                        comparer.EasyCompareWzFiles(wznew.wz_files[0], wzold.wz_files[0], this.compareFolder);
                    }
                    catch (Exception ex)
                    {
                        txtPatchState.AppendText(ex.ToString());
                    }
                    finally
                    {
                        wznew.Clear();
                        wzold.Clear();
                        GC.Collect();
                    }
                }

                if (this.deadPatch && e.Part.Type == 1)
                {
                    ((WzPatcher)sender).SafeMove(e.Part.TempFilePath, e.Part.OldFilePath);
                    AppendStateText("  (deadpatch)Applying files...\r\n");
                }
                break;
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     wz_Structure.Clear();
 }