Update Lib hinzugefügt
This commit is contained in:
187
UpdateLib/UI/frmUpdater.Designer.cs
generated
Normal file
187
UpdateLib/UI/frmUpdater.Designer.cs
generated
Normal file
@@ -0,0 +1,187 @@
|
||||
namespace UpdateLib.UI
|
||||
{
|
||||
partial class frmUpdater
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.btnInstall = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.pbInstall = new System.Windows.Forms.ProgressBar();
|
||||
this.pbDownload = new System.Windows.Forms.ProgressBar();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.lblStatus = new System.Windows.Forms.Label();
|
||||
this.lvItems = new System.Windows.Forms.ListView();
|
||||
this.clmName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.clmStatus = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.clmDesc = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.panel1.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.panel1.Controls.Add(this.btnInstall);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 319);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(472, 49);
|
||||
this.panel1.TabIndex = 0;
|
||||
//
|
||||
// btnInstall
|
||||
//
|
||||
this.btnInstall.Location = new System.Drawing.Point(385, 13);
|
||||
this.btnInstall.Name = "btnInstall";
|
||||
this.btnInstall.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnInstall.TabIndex = 0;
|
||||
this.btnInstall.Text = "Install";
|
||||
this.btnInstall.UseVisualStyleBackColor = true;
|
||||
this.btnInstall.Click += new System.EventHandler(this.btnInstall_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.pbInstall);
|
||||
this.groupBox1.Controls.Add(this.pbDownload);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 235);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(448, 78);
|
||||
this.groupBox1.TabIndex = 1;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Details";
|
||||
//
|
||||
// pbInstall
|
||||
//
|
||||
this.pbInstall.Location = new System.Drawing.Point(120, 45);
|
||||
this.pbInstall.Name = "pbInstall";
|
||||
this.pbInstall.Size = new System.Drawing.Size(322, 23);
|
||||
this.pbInstall.TabIndex = 3;
|
||||
//
|
||||
// pbDownload
|
||||
//
|
||||
this.pbDownload.Location = new System.Drawing.Point(120, 16);
|
||||
this.pbDownload.Name = "pbDownload";
|
||||
this.pbDownload.Size = new System.Drawing.Size(322, 23);
|
||||
this.pbDownload.TabIndex = 2;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(15, 51);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(84, 13);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "Install Progress: ";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(15, 21);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(105, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Download Progress: ";
|
||||
//
|
||||
// lblStatus
|
||||
//
|
||||
this.lblStatus.AutoSize = true;
|
||||
this.lblStatus.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lblStatus.Location = new System.Drawing.Point(12, 9);
|
||||
this.lblStatus.Name = "lblStatus";
|
||||
this.lblStatus.Size = new System.Drawing.Size(148, 25);
|
||||
this.lblStatus.TabIndex = 2;
|
||||
this.lblStatus.Text = "Status: Waiting...";
|
||||
//
|
||||
// lvItems
|
||||
//
|
||||
this.lvItems.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.clmName,
|
||||
this.clmStatus,
|
||||
this.clmDesc});
|
||||
this.lvItems.Location = new System.Drawing.Point(12, 41);
|
||||
this.lvItems.Name = "lvItems";
|
||||
this.lvItems.Size = new System.Drawing.Size(448, 188);
|
||||
this.lvItems.TabIndex = 3;
|
||||
this.lvItems.UseCompatibleStateImageBehavior = false;
|
||||
this.lvItems.View = System.Windows.Forms.View.Details;
|
||||
//
|
||||
// clmName
|
||||
//
|
||||
this.clmName.Text = "Name";
|
||||
this.clmName.Width = 104;
|
||||
//
|
||||
// clmStatus
|
||||
//
|
||||
this.clmStatus.Text = "Status";
|
||||
this.clmStatus.Width = 99;
|
||||
//
|
||||
// clmDesc
|
||||
//
|
||||
this.clmDesc.Text = "Description";
|
||||
this.clmDesc.Width = 228;
|
||||
//
|
||||
// frmUpdater
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.ClientSize = new System.Drawing.Size(472, 368);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.lvItems);
|
||||
this.Controls.Add(this.lblStatus);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "frmUpdater";
|
||||
this.Text = "Programm updater";
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button btnInstall;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.ProgressBar pbInstall;
|
||||
private System.Windows.Forms.ProgressBar pbDownload;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label lblStatus;
|
||||
private System.Windows.Forms.ListView lvItems;
|
||||
private System.Windows.Forms.ColumnHeader clmName;
|
||||
private System.Windows.Forms.ColumnHeader clmStatus;
|
||||
private System.Windows.Forms.ColumnHeader clmDesc;
|
||||
}
|
||||
}
|
||||
107
UpdateLib/UI/frmUpdater.cs
Normal file
107
UpdateLib/UI/frmUpdater.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using UpdateLib.Data;
|
||||
|
||||
namespace UpdateLib.UI
|
||||
{
|
||||
public partial class frmUpdater : Form
|
||||
{
|
||||
int index = 0;
|
||||
private UpdateSaveFile localInfoFile;
|
||||
private String baseUrl;
|
||||
|
||||
public frmUpdater(UpdateSaveFile file, String baseUrl)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
localInfoFile = file;
|
||||
pbInstall.Maximum = (file.UpdateFileCollection.Count) * 100;
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
foreach (UpdateFileInfo fileInfo in file.UpdateFileCollection)
|
||||
{
|
||||
ListViewItem lvItem = new ListViewItem(new String[] { fileInfo.Name, "Waiting...", fileInfo.Description });
|
||||
lvItems.Items.Add(lvItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnInstall_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (btnInstall.Text.Equals("Finish"))
|
||||
{
|
||||
MessageBox.Show("Update erfolgreich. Programm wird beendet");
|
||||
Application.Exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
btnInstall.Enabled = false;
|
||||
DownloadFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void DownloadFile()
|
||||
{
|
||||
WebClient downloadClient = new WebClient();
|
||||
|
||||
downloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadClient_DownloadProgressChanged);
|
||||
downloadClient.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadClient_DownloadFileCompleted);
|
||||
|
||||
ListViewItem currItem = lvItems.Items[index];
|
||||
String name = currItem.SubItems[0].Text;
|
||||
|
||||
SetStatus(String.Format("Downloading {0} ...", name));
|
||||
currItem.SubItems[1].Text = "Downloading...";
|
||||
|
||||
String local = String.Format(@".\{0}", name);
|
||||
String online = String.Format("{0}{1}", baseUrl, name);
|
||||
|
||||
if (File.Exists(local))
|
||||
{
|
||||
if (File.Exists(local + ".old"))
|
||||
File.Delete(local + ".old");
|
||||
File.Move(local, local + ".old");
|
||||
}
|
||||
downloadClient.DownloadFileAsync(new Uri(online), local);
|
||||
}
|
||||
|
||||
private void SetStatus(string p)
|
||||
{
|
||||
lblStatus.Text = String.Format("Status: {0}", p);
|
||||
}
|
||||
|
||||
private void downloadClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
ListViewItem currItem = lvItems.Items[index];
|
||||
currItem.SubItems[1].Text = "Downloaded";
|
||||
|
||||
pbInstall.Increment(100);
|
||||
pbDownload.Value = 0;
|
||||
index++;
|
||||
|
||||
if (lvItems.Items.Count - 1 >= index)
|
||||
DownloadFile();
|
||||
else
|
||||
{
|
||||
SetStatus("Finished!");
|
||||
btnInstall.Text = "Finish";
|
||||
btnInstall.Enabled = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
pbDownload.Value = e.ProgressPercentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user