| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Update
- {
- public partial class Form1 : Form
- {
- private readonly static string mainAppPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "..");
- private readonly static string mainAppFile = Path.Combine(mainAppPath, "dajiaoyan.exe");
- public Form1()
- {
- InitializeComponent();
- Task.Factory.StartNew(async () =>
- {
- await Task.Delay(2000);
- await Services.Update.UpdateApplication(
- "http://static.yuansiwei.com/app/dajiaoyan/ocr/dajiaoyan.zip",
- mainAppPath,
- UpdateProgress,
- AfterUpdate);
- });
- }
- public void UpdateProgress(string step, int nowP, int maxP)
- {
- Task.Factory.StartNew(() =>
- {
- BeginInvoke(new Action(() =>
- {
- stepProgressLabel.Text = step;
- stepProgressBar.Minimum = 0;
- stepProgressBar.Maximum = maxP;
- stepProgressBar.Value = nowP;
- }));
- });
- }
- public void AfterUpdate(bool ok, string info)
- {
- BeginInvoke(new Action(() =>
- {
- if (ok)
- {
- MessageBox.Show(info, "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
- try
- {
- Task.Delay(2000);
- Process.Start(mainAppFile);
- }
- catch
- {
- }
- }
- else
- {
- MessageBox.Show(info, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- Close();
- }));
- }
- }
- }
|