FormMain.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ReleaseHelper.Services;
  2. using ReleaseHelper.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ReleaseHelper
  13. {
  14. public partial class FormMain : Form
  15. {
  16. public FormMain()
  17. {
  18. InitializeComponent();
  19. textBoxLocalFile.Text = Const.TOBE_UPLOAD_LOCAL_FILE;
  20. textBoxOssPath.Text = Const.OSS_PATH;
  21. Task.Run(async () =>
  22. {
  23. var info = await Services.Release.GetLatestVersionInfo(Variables.Const.HTTP_UPDATE_FILE);
  24. BeginInvoke(new Action(() =>
  25. {
  26. textBoxNowVersion.Text = textBoxLatestVersion.Text = info.Version.ToString();
  27. }));
  28. });
  29. }
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. if (string.IsNullOrEmpty(textBoxNowVersion.Text) || string.IsNullOrEmpty(textBoxUsername.Text) || string.IsNullOrEmpty(textBoxPassword.Text))
  33. {
  34. MessageBox.Show("信息不全");
  35. }
  36. else
  37. {
  38. try
  39. {
  40. Task.Run(async () =>
  41. {
  42. string res = await Release.ReleaseApplication(
  43. textBoxUsername.Text,
  44. textBoxPassword.Text,
  45. Convert.ToDouble(textBoxNowVersion.Text.Trim()),
  46. Const.TOBE_UPLOAD_LOCAL_FILE,
  47. Const.OSS_PATH,
  48. setProgressBar
  49. );
  50. if (string.IsNullOrEmpty(res))
  51. {
  52. res = "更新成功!";
  53. }
  54. MessageBox.Show(res);
  55. });
  56. }
  57. catch
  58. {
  59. }
  60. }
  61. }
  62. private void setProgressBar(int max, int now)
  63. {
  64. Utils.ControlExts.FormInvoke(this, () => {
  65. toolStripProgressBarRelease.Maximum = max;
  66. toolStripProgressBarRelease.Minimum = 0;
  67. toolStripProgressBarRelease.Value = now;
  68. Console.WriteLine(now.ToString(), "/", max.ToString());
  69. });
  70. }
  71. }
  72. }