|
|
|
|
|
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.Diagnostics;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using SevenZip;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AutoUpdate
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class autoUpdate : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = string.Empty;
|
|
|
|
|
|
string filePath = string.Empty;
|
|
|
|
|
|
private static readonly string fileNm = ConfigurationManager.AppSettings["FileNm"];
|
|
|
|
|
|
//bool isDownload
|
|
|
|
|
|
public autoUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void autoUpdate_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
autoUpdateVersion.AutoUpdate WS = new autoUpdateVersion.AutoUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
filePath = Application.StartupPath + "\\update\\";
|
|
|
|
|
|
if (!Directory.Exists(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
url = WS.ZipFile();
|
|
|
|
|
|
WebClient wClient = new WebClient();
|
|
|
|
|
|
wClient.DownloadFileCompleted += new AsyncCompletedEventHandler(wClient_DownloadFileCompleted);
|
|
|
|
|
|
Uri ul = new Uri(url);
|
|
|
|
|
|
wClient.DownloadFileAsync(ul, filePath + "update.zip");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void wClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
autoUpdateVersion.AutoUpdate WS = new autoUpdateVersion.AutoUpdate();
|
|
|
|
|
|
WS.deleteFile(url);
|
|
|
|
|
|
SevenZipExtractor Extractor = new SevenZipExtractor(filePath + "update.zip");
|
|
|
|
|
|
Extractor.ExtractionFinished+=new EventHandler<EventArgs>(Extractor_ExtractionFinished);
|
|
|
|
|
|
|
|
|
|
|
|
Extractor.ExtractFiles(filePath + "tmp", Extractor.ArchiveFileNames.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Extractor_ExtractionFinished(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
DirectoryInfo di = new DirectoryInfo(filePath + "tmp");
|
|
|
|
|
|
DirectoryInfo diroot = new DirectoryInfo((Application.StartupPath));
|
|
|
|
|
|
DirectoryInfo[] dis = di.GetDirectories();
|
|
|
|
|
|
//string[] dis = Directory.GetDirectories(filePath + "tmp");
|
|
|
|
|
|
foreach (DirectoryInfo d in dis)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(Application.StartupPath + "\\" + d.Name))
|
|
|
|
|
|
Directory.CreateDirectory(Application.StartupPath + "\\" + d.Name);
|
|
|
|
|
|
FileInfo[] fis = d.GetFiles();
|
|
|
|
|
|
foreach (FileInfo fi in fis)
|
|
|
|
|
|
fi.CopyTo(Application.StartupPath + "\\" + d.Name+"\\"+fi.Name, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
FileInfo[] files = di.GetFiles();
|
|
|
|
|
|
foreach (FileInfo file in files)
|
|
|
|
|
|
{
|
|
|
|
|
|
file.CopyTo(Application.StartupPath + "\\" + file.Name, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
File.Delete(filePath + "update.zip");
|
|
|
|
|
|
Directory.Delete(filePath + "tmp", true);
|
|
|
|
|
|
Process.Start(Application.StartupPath + "\\"+ fileNm);
|
|
|
|
|
|
Process.GetCurrentProcess().Kill();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|