using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Diagnostics;

namespace UpDate
{
    public partial class Form1 : Form
    {
        private WebClient update = new WebClient();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string URL = @"https://files.cnblogs.com/mossan/Zhongwen.rar";
            int n = URL.LastIndexOf('/');
            string fileName = URL.Substring(n + 1, URL.Length - n - 1);

            if (!(Directory.Exists(Application.StartupPath + "\\update")))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\update");
            }

            try { update.DownloadFile(URL, Application.StartupPath + "\\update\\" + fileName); }
            catch (WebException ex) { MessageBox.Show(ex.Message, "Error"); }

            try
            {
                Process UnWinrar = new Process();
                UnWinrar.StartInfo.FileName = "WinRAR.exe";
                UnWinrar.StartInfo.Arguments = "e -o+ \"" + Application.StartupPath + "\\update\\" + fileName + "\"" + " \"" + Application.StartupPath + "\\update" + "\"";
                UnWinrar.Start();
                MessageBox.Show("解压缩完成!");
                File.Copy(Application.StartupPath + "\\update\\" + "Zhongwen.exe", Application.StartupPath + "\\Zhongwen.exe", true);

                Process ProZhongwen = new Process();
                ProZhongwen.StartInfo.FileName = Application.StartupPath + "\\Zhongwen.exe";
                ProZhongwen.Start();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            this.Close();
        }
    }
}

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-10-13
  • 2022-02-02
  • 2022-12-23
  • 2021-12-08
  • 2021-11-29
猜你喜欢
  • 2021-11-17
  • 2021-06-15
  • 2022-12-23
  • 2021-08-27
  • 2021-05-14
  • 2022-12-23
  • 2022-02-21
相关资源
相似解决方案