资源简介

实现c#开发的winform程序根据程序版本号是否需要更新程序,启动更新程序从服务器下载新版本程序并解压覆盖主程序,运行主程序。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using COMMON;
using Update;

namespace autoUpdate
{

    public partial class Form1 : Form
    {
        [DllImport(“zipfile.dll“)]
        public static extern int MyZip_ExtractFileAll(string zipfile string pathname);
        public Form1()
        {
            InitializeComponent();
            //清除之前下载来的rar文件
            if (File.Exists(Application.StartupPath + “\\Update_autoUpdate.zip“))
            {
                try
                {
                    File.Delete(Application.StartupPath + “\\Update_autoUpdate.zip“);
                }
                catch (Exception)
                {


                }

            }
            if (Directory.Exists(Application.StartupPath + “\\autoupload“))
            {
                try
                {
                    Directory.Delete(Application.StartupPath + “\\autoupload“ true);
                }
                catch (Exception)
                {


                }
            }

            //检查服务端是否有新版本程序
            checkUpdate();
            timer1.Enabled = true;
        }
        SoftUpdate app = new SoftUpdate(Application.ExecutablePath “ExceTransforCsv“);
        public void checkUpdate()
        {

            app.UpdateFinish += new UpdateState(app_UpdateFinish);
            try
            {
                if (app.IsUpdate)
                {
                    app.Update();
                }
                else
                {
                    MessageBox.Show(“未检测到新版本!“);
                    Application.Exit();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void app_UpdateFinish()
        {
            //解压下载后的文件
            string path = app.FinalZipName;
            if (File.Exists(path))
            {
                //后改的 先解压滤波zip植入ini然后再重新压缩
                string dirEcgPath = Application.StartupPath + “\\“ + “autoupload“;
                if (!Directory.Exists(dirEcgPath))
                {
                    Directory.CreateDirectory(dirEcgPath);
                }
                //开始解压压缩包
                MyZip_ExtractFileAll(path dirEcgPath);

                try
                {
                    //复制新文件替换旧文件
                    DirectoryInfo TheFolder = new DirectoryInfo(dirEcgPath);
                    foreach (FileInfo NextFile in TheFolder.GetFiles())
                    {
                        File.Copy(NextFile.FullName Application.StartupPath + “\\program\\“ + NextFile.Name true);
                    }
                    Directory.Delete(dirEcgPath true);
                    File.Delete(path);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4096  2018-12-17 10:20  COMMON\bin\Debug\COMMON.dll

     文件       7680  2018-12-17 10:20  COMMON\bin\Debug\COMMON.pdb

     文件       2306  2018-07-17 16:53  COMMON\COMMON.csproj

     文件        201  2018-07-17 16:45  COMMON\CommonMethod.cs

     文件        456  2018-12-17 10:20  COMMON\obj\Debug\COMMON.csproj.FileListAbsolute.txt

     文件       4096  2018-12-17 10:20  COMMON\obj\Debug\COMMON.dll

     文件       7680  2018-12-17 10:20  COMMON\obj\Debug\COMMON.pdb

     文件       5674  2018-12-26 14:43  COMMON\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1344  2018-07-17 16:44  COMMON\Properties\AssemblyInfo.cs

     文件       4096  2018-12-17 10:20  ExceTransforCsv\bin\Debug\COMMON.dll

     文件       7680  2018-12-17 10:20  ExceTransforCsv\bin\Debug\COMMON.pdb

     文件      17408  2018-12-18 15:25  ExceTransforCsv\bin\Debug\ExceTransforCsv.exe

     文件      40448  2018-12-18 15:25  ExceTransforCsv\bin\Debug\ExceTransforCsv.pdb

     文件      11600  2018-12-26 14:43  ExceTransforCsv\bin\Debug\ExceTransforCsv.vshost.exe

     文件        490  2018-04-12 07:35  ExceTransforCsv\bin\Debug\ExceTransforCsv.vshost.exe.manifest

     文件     200704  2017-04-30 14:19  ExceTransforCsv\bin\Debug\ICSharpCode.SharpZipLib.dll

     文件    1624064  2013-03-06 07:17  ExceTransforCsv\bin\Debug\NPOI.dll

     文件     387072  2013-03-06 07:17  ExceTransforCsv\bin\Debug\NPOI.OOxml.dll

     文件      79872  2013-03-06 07:17  ExceTransforCsv\bin\Debug\NPOI.Openxml4Net.dll

     文件    1316864  2013-03-06 07:17  ExceTransforCsv\bin\Debug\NPOI.OpenxmlFormats.dll

     文件    2145032  2013-03-06 07:13  ExceTransforCsv\bin\Debug\NPOI.xml

     文件       8192  2018-12-17 10:20  ExceTransforCsv\bin\Debug\Update.dll

     文件      19968  2018-12-17 10:20  ExceTransforCsv\bin\Debug\Update.pdb

     文件      10240  2018-07-17 16:53  ExceTransforCsv\bin\Debug\程序运行顺序\autoUpdate.exe

     文件      22016  2018-07-17 16:53  ExceTransforCsv\bin\Debug\程序运行顺序\autoUpdate.pdb

     文件      11600  2018-07-17 16:41  ExceTransforCsv\bin\Debug\程序运行顺序\autoUpdate.vshost.exe

     文件        490  2018-04-12 07:35  ExceTransforCsv\bin\Debug\程序运行顺序\autoUpdate.vshost.exe.manifest

     文件       4096  2018-07-17 16:53  ExceTransforCsv\bin\Debug\程序运行顺序\COMMON.dll

     文件       7680  2018-07-17 16:53  ExceTransforCsv\bin\Debug\程序运行顺序\COMMON.pdb

     文件       4096  2018-07-17 16:53  ExceTransforCsv\bin\Debug\程序运行顺序\program\COMMON.dll

............此处省略116个文件信息

评论

共有 条评论