| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Drawing;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using System.Windows.Forms;
|
|---|
| 8 | using System.Net;
|
|---|
| 9 | using System.Diagnostics;
|
|---|
| 10 | using Baza_Reklam.Classes;
|
|---|
| 11 |
|
|---|
| 12 | namespace Baza_Reklam
|
|---|
| 13 | {
|
|---|
| 14 | public partial class FormBadVer : Form
|
|---|
| 15 | {
|
|---|
| 16 | private WebClient webClient;
|
|---|
| 17 | private bool isBusy = false;
|
|---|
| 18 | const string strUrl = "http://www.infocity.pl/baza_reklam/files/Updater.exe";
|
|---|
| 19 |
|
|---|
| 20 | public FormBadVer()
|
|---|
| 21 | {
|
|---|
| 22 | InitializeComponent();
|
|---|
| 23 |
|
|---|
| 24 | webClient = new WebClient();
|
|---|
| 25 | webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | private void button1_Click(object sender, EventArgs e)
|
|---|
| 29 | {
|
|---|
| 30 | string updater = Environment.CurrentDirectory + "\\Updater.exe";
|
|---|
| 31 |
|
|---|
| 32 | if (System.IO.File.Exists(updater))
|
|---|
| 33 | {
|
|---|
| 34 | StartUpdater();
|
|---|
| 35 | }
|
|---|
| 36 | else
|
|---|
| 37 | {
|
|---|
| 38 | isBusy = true;
|
|---|
| 39 | webClient.DownloadFileAsync(new Uri(strUrl), Environment.CurrentDirectory + "\\Updater.exe");
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
|---|
| 44 | {
|
|---|
| 45 | isBusy = false;
|
|---|
| 46 |
|
|---|
| 47 | if (e.Error == null)
|
|---|
| 48 | {
|
|---|
| 49 | StartUpdater();
|
|---|
| 50 | }
|
|---|
| 51 | else
|
|---|
| 52 | {
|
|---|
| 53 | MessageBox.Show("B³¹d aktualizacji oprogramowania: " + e.Error.Message, "Aktualizacja oprogramowania", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|---|
| 54 | Close();
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | private void StartUpdater()
|
|---|
| 59 | {
|
|---|
| 60 | string updater = Environment.CurrentDirectory + "\\Updater.exe";
|
|---|
| 61 |
|
|---|
| 62 | Close();
|
|---|
| 63 | ProcessStartInfo startInfo = new ProcessStartInfo();
|
|---|
| 64 | startInfo.Arguments = "1";
|
|---|
| 65 | startInfo.FileName = updater;
|
|---|
| 66 | Process.Start(startInfo);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | private void Extract(string zipFileName, string destinationPath)
|
|---|
| 70 | {
|
|---|
| 71 | Shell32.ShellClass sc = new Shell32.ShellClass();
|
|---|
| 72 | Shell32.Folder SrcFlder = sc.NameSpace(zipFileName);
|
|---|
| 73 | Shell32.Folder DestFlder = sc.NameSpace(destinationPath);
|
|---|
| 74 | Shell32.FolderItems items = SrcFlder.Items();
|
|---|
| 75 | DestFlder.CopyHere(items, 20);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | }
|
|---|
| 80 | } |
|---|