|
@@ -1,10 +1,7 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.ComponentModel;
|
|
|
-using System.Data;
|
|
|
-using System.Drawing;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
+using ICSharpCode.SharpZipLib.Zip;
|
|
|
+using System;
|
|
|
+using System.IO;
|
|
|
+using System.Net;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace UAS_AutoUpdate
|
|
@@ -15,5 +12,82 @@ namespace UAS_AutoUpdate
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
+
|
|
|
+ private void CheckUpdateWindow_Load(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ //使用WebClient从指定位置下载文件,然后进行解压缩覆盖
|
|
|
+ MessageBox.Show(Application.StartupPath);
|
|
|
+ WebClient wc = new WebClient();
|
|
|
+ wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
|
|
|
+ wc.DownloadFileAsync(new Uri("http://218.17.158.219:8888/Debug.zip"), "Debug.zip");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
|
|
+ {
|
|
|
+ Action act = () =>
|
|
|
+ {
|
|
|
+ _progressbar.Value = e.ProgressPercentage;
|
|
|
+ _processrate.Text = e.ProgressPercentage + "%";
|
|
|
+ };
|
|
|
+ if (IsHandleCreated)
|
|
|
+ this.Invoke(act);
|
|
|
+ if (e.ProgressPercentage == 100)
|
|
|
+ {
|
|
|
+ ZipHelper.UnZip(Application.StartupPath + @"\Debug.zip", @"F:\TEST");
|
|
|
+ }
|
|
|
+ //Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ZipHelper
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 用于解压缩Zip文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="ZipFilePath"></param>
|
|
|
+ /// <param name="UnZipPath"></param>
|
|
|
+ public static void UnZip(string ZipFilePath, string UnZipPath)
|
|
|
+ {
|
|
|
+ if (!File.Exists(ZipFilePath))
|
|
|
+ {
|
|
|
+ throw new FileNotFoundException(string.Format("未能找到文件 '{0}' ", ZipFilePath));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Directory.Exists(UnZipPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(UnZipPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ using (var s = new ZipInputStream(File.OpenRead(ZipFilePath)))
|
|
|
+ {
|
|
|
+ ZipEntry theEntry;
|
|
|
+ while ((theEntry = s.GetNextEntry()) != null)
|
|
|
+ {
|
|
|
+ if (theEntry.IsDirectory)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ string directorName = Path.Combine(UnZipPath, Path.GetDirectoryName(theEntry.Name));
|
|
|
+ string fileName = Path.Combine(directorName, Path.GetFileName(theEntry.Name));
|
|
|
+ if (!Directory.Exists(directorName))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(directorName);
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(fileName))
|
|
|
+ {
|
|
|
+ using (FileStream streamWriter = File.Create(fileName))
|
|
|
+ {
|
|
|
+ int size = 4096;
|
|
|
+ byte[] data = new byte[size];
|
|
|
+ while (size > 0)
|
|
|
+ {
|
|
|
+ streamWriter.Write(data, 0, size);
|
|
|
+ size = s.Read(data, 0, data.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|