PublishCompleteDialog.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace AutoPatcherAdmin
  4. {
  5. internal sealed class PublishCompleteDialog : Form
  6. {
  7. internal PublishCompleteDialog(
  8. int filesUploaded, int added, int changed, int removed,
  9. long origBytes, long compBytes, bool showCompression,
  10. string timeElapsed)
  11. {
  12. SuspendLayout();
  13. Text = "Publish Complete";
  14. FormBorderStyle = FormBorderStyle.FixedDialog;
  15. MaximizeBox = false;
  16. MinimizeBox = false;
  17. StartPosition = FormStartPosition.CenterParent;
  18. ShowInTaskbar = false;
  19. BackColor = Color.White;
  20. Font = new Font("Segoe UI", 9f);
  21. AutoScaleMode = AutoScaleMode.None;
  22. // Header
  23. var iconBox = new PictureBox
  24. {
  25. Image = SystemIcons.Information.ToBitmap(),
  26. SizeMode = PictureBoxSizeMode.StretchImage,
  27. Size = new Size(28, 28),
  28. Location = new Point(16, 15),
  29. BackColor = Color.Transparent
  30. };
  31. var headerLabel = new Label
  32. {
  33. Text = "Publish Complete",
  34. Font = new Font("Segoe UI", 11f, FontStyle.Bold),
  35. AutoSize = true,
  36. Location = new Point(52, 18),
  37. ForeColor = Color.FromArgb(30, 30, 30),
  38. BackColor = Color.Transparent
  39. };
  40. // Row counts
  41. const int labelW = 148;
  42. const int valueW = 176;
  43. const int rowH = 22;
  44. int rowCount = 3; // Files Uploaded, Added, Changed
  45. if (removed > 0) rowCount++;
  46. rowCount += 1; // spacer
  47. rowCount += showCompression ? 2 : 1; // size section
  48. rowCount += 1; // spacer
  49. rowCount += 1; // Time Taken
  50. var table = new TableLayoutPanel
  51. {
  52. Location = new Point(16, 66),
  53. Size = new Size(labelW + valueW, rowCount * rowH),
  54. ColumnCount = 2,
  55. RowCount = rowCount,
  56. CellBorderStyle = TableLayoutPanelCellBorderStyle.None,
  57. AutoSize = false
  58. };
  59. table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, labelW));
  60. table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, valueW));
  61. for (int i = 0; i < rowCount; i++)
  62. table.RowStyles.Add(new RowStyle(SizeType.Absolute, rowH));
  63. int r = 0;
  64. void AddRow(string label, string value,
  65. bool boldLabel = false, bool boldValue = false,
  66. Color? labelFore = null, Color? valueFore = null)
  67. {
  68. table.Controls.Add(new Label
  69. {
  70. Text = label,
  71. Dock = DockStyle.Fill,
  72. TextAlign = ContentAlignment.MiddleLeft,
  73. Font = boldLabel ? new Font("Segoe UI", 9f, FontStyle.Bold) : Font,
  74. ForeColor = labelFore ?? Color.FromArgb(80, 80, 80),
  75. Margin = new Padding(0)
  76. }, 0, r);
  77. table.Controls.Add(new Label
  78. {
  79. Text = value,
  80. Dock = DockStyle.Fill,
  81. TextAlign = ContentAlignment.MiddleRight,
  82. Font = boldValue ? new Font("Segoe UI", 9f, FontStyle.Bold) : Font,
  83. ForeColor = valueFore ?? Color.FromArgb(30, 30, 30),
  84. Margin = new Padding(0, 0, 2, 0)
  85. }, 1, r);
  86. r++;
  87. }
  88. void AddSpacer()
  89. {
  90. table.Controls.Add(new Label { Dock = DockStyle.Fill, Margin = new Padding(0) }, 0, r);
  91. table.Controls.Add(new Label { Dock = DockStyle.Fill, Margin = new Padding(0) }, 1, r);
  92. r++;
  93. }
  94. // Files section
  95. AddRow("Files Uploaded", $"{filesUploaded:N0}",
  96. boldLabel: true, boldValue: true,
  97. valueFore: Color.FromArgb(0, 128, 0));
  98. AddRow(" Added", $"{added:N0}");
  99. AddRow(" Changed", $"{changed:N0}");
  100. if (removed > 0)
  101. AddRow(" Removed", $"{removed:N0}");
  102. AddSpacer();
  103. // Size section
  104. if (showCompression && origBytes > 0)
  105. {
  106. long saved = origBytes - compBytes;
  107. int pct = (int)((double)saved / origBytes * 100);
  108. AddRow("Original Size", FormatBytes(origBytes));
  109. AddRow("Compressed To", $"{FormatBytes(compBytes)} ({pct}% saved)",
  110. valueFore: Color.FromArgb(0, 128, 0));
  111. }
  112. else
  113. {
  114. AddRow("Upload Size", FormatBytes(origBytes > 0 ? origBytes : compBytes));
  115. }
  116. AddSpacer();
  117. AddRow("Time Taken", timeElapsed, boldLabel: true, boldValue: true);
  118. // Layout sizing
  119. const int padding = 16;
  120. int formWidth = labelW + valueW + padding * 2;
  121. int tableBottom = table.Bottom + padding;
  122. var sep1 = new Panel { BackColor = Color.FromArgb(210, 210, 210), Location = new Point(0, 56), Size = new Size(formWidth, 1) };
  123. var sep2 = new Panel { BackColor = Color.FromArgb(210, 210, 210), Location = new Point(0, tableBottom), Size = new Size(formWidth, 1) };
  124. var okButton = new Button
  125. {
  126. Text = "OK",
  127. DialogResult = DialogResult.OK,
  128. Size = new Size(80, 26),
  129. FlatStyle = FlatStyle.System,
  130. Location = new Point(formWidth - 80 - 12, 9)
  131. };
  132. var footer = new Panel
  133. {
  134. BackColor = Color.FromArgb(245, 245, 245),
  135. Location = new Point(0, tableBottom + 1),
  136. Size = new Size(formWidth, 44)
  137. };
  138. footer.Controls.Add(okButton);
  139. ClientSize = new Size(formWidth, tableBottom + 1 + 44);
  140. AcceptButton = okButton;
  141. Controls.AddRange(new Control[] { iconBox, headerLabel, sep1, table, sep2, footer });
  142. ResumeLayout(true);
  143. }
  144. private static string FormatBytes(long bytes)
  145. {
  146. if (bytes >= 1L << 30) return $"{bytes / (double)(1L << 30):0.##} GB";
  147. if (bytes >= 1L << 20) return $"{bytes / (double)(1L << 20):0.##} MB";
  148. if (bytes >= 1L << 10) return $"{bytes / (double)(1L << 10):0.##} KB";
  149. return $"{bytes} B";
  150. }
  151. }
  152. }