From b7048beede4ee0ce3d02648f3fc7b4eb01fb1daa Mon Sep 17 00:00:00 2001 From: Husky Date: Thu, 25 Mar 2021 19:01:54 +0100 Subject: [PATCH] =?UTF-8?q?Update=20Lib=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SanSystem/SanSystem.csproj | 4 + SanSystem/frmMain.Designer.cs | 62 ++++----- SanSystem/frmMain.cs | 1 + SanSystem/frmMain.resx | 3 + SanVerwaltung.sln | 6 + UpdateLib/Data/UpdateFileInfo.cs | 21 +++ UpdateLib/Data/UpdateSaveFile.cs | 34 +++++ UpdateLib/Properties/AssemblyInfo.cs | 36 ++++++ UpdateLib/UI/frmUpdater.Designer.cs | 187 +++++++++++++++++++++++++++ UpdateLib/UI/frmUpdater.cs | 107 +++++++++++++++ UpdateLib/UpdateLib.csproj | 60 +++++++++ UpdateLib/Updater.cs | 105 +++++++++++++++ 12 files changed, 597 insertions(+), 29 deletions(-) create mode 100644 UpdateLib/Data/UpdateFileInfo.cs create mode 100644 UpdateLib/Data/UpdateSaveFile.cs create mode 100644 UpdateLib/Properties/AssemblyInfo.cs create mode 100644 UpdateLib/UI/frmUpdater.Designer.cs create mode 100644 UpdateLib/UI/frmUpdater.cs create mode 100644 UpdateLib/UpdateLib.csproj create mode 100644 UpdateLib/Updater.cs diff --git a/SanSystem/SanSystem.csproj b/SanSystem/SanSystem.csproj index db82a9a..a3f124d 100644 --- a/SanSystem/SanSystem.csproj +++ b/SanSystem/SanSystem.csproj @@ -400,6 +400,10 @@ {e4979419-5eae-4b6d-a6a0-9632c1de87a0} TempCAN + + {cf95db30-247b-4382-948e-3bd5eb73c938} + UpdateLib + diff --git a/SanSystem/frmMain.Designer.cs b/SanSystem/frmMain.Designer.cs index e99b443..b408846 100644 --- a/SanSystem/frmMain.Designer.cs +++ b/SanSystem/frmMain.Designer.cs @@ -37,6 +37,7 @@ this.öffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.stammdatenImportierenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.auftraggeberToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.prefixSuffixToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.speichernToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.massenstatistikToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.projektordnerÖffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -48,7 +49,7 @@ this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatus_projekt_Label = new System.Windows.Forms.ToolStripStatusLabel(); this.toolstrip_gesamtLiner = new System.Windows.Forms.ToolStripStatusLabel(); - this.prefixSuffixToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.update = new UpdateLib.Updater(); this.mainmenu.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -67,8 +68,7 @@ this.berichteToolStripMenuItem}); this.mainmenu.Location = new System.Drawing.Point(0, 0); this.mainmenu.Name = "mainmenu"; - this.mainmenu.Padding = new System.Windows.Forms.Padding(8, 2, 0, 2); - this.mainmenu.Size = new System.Drawing.Size(1084, 36); + this.mainmenu.Size = new System.Drawing.Size(813, 29); this.mainmenu.TabIndex = 1; this.mainmenu.Text = "menuStrip1"; // @@ -81,67 +81,74 @@ this.auftraggeberToolStripMenuItem, this.prefixSuffixToolStripMenuItem}); this.projektToolStripMenuItem.Name = "projektToolStripMenuItem"; - this.projektToolStripMenuItem.Size = new System.Drawing.Size(88, 32); + this.projektToolStripMenuItem.Size = new System.Drawing.Size(71, 25); this.projektToolStripMenuItem.Text = "Projekt"; // // neuToolStripMenuItem // this.neuToolStripMenuItem.Name = "neuToolStripMenuItem"; - this.neuToolStripMenuItem.Size = new System.Drawing.Size(318, 32); + this.neuToolStripMenuItem.Size = new System.Drawing.Size(254, 26); this.neuToolStripMenuItem.Text = "Neu"; this.neuToolStripMenuItem.Click += new System.EventHandler(this.neuToolStripMenuItem_Click); // // öffnenToolStripMenuItem // this.öffnenToolStripMenuItem.Name = "öffnenToolStripMenuItem"; - this.öffnenToolStripMenuItem.Size = new System.Drawing.Size(318, 32); + this.öffnenToolStripMenuItem.Size = new System.Drawing.Size(254, 26); this.öffnenToolStripMenuItem.Text = "Öffnen"; this.öffnenToolStripMenuItem.Click += new System.EventHandler(this.öffnenToolStripMenuItem_Click); // // stammdatenImportierenToolStripMenuItem // this.stammdatenImportierenToolStripMenuItem.Name = "stammdatenImportierenToolStripMenuItem"; - this.stammdatenImportierenToolStripMenuItem.Size = new System.Drawing.Size(318, 32); + this.stammdatenImportierenToolStripMenuItem.Size = new System.Drawing.Size(254, 26); this.stammdatenImportierenToolStripMenuItem.Text = "Stammdaten importieren"; this.stammdatenImportierenToolStripMenuItem.Click += new System.EventHandler(this.stammdatenImportierenToolStripMenuItem_Click); // // auftraggeberToolStripMenuItem // this.auftraggeberToolStripMenuItem.Name = "auftraggeberToolStripMenuItem"; - this.auftraggeberToolStripMenuItem.Size = new System.Drawing.Size(318, 32); + this.auftraggeberToolStripMenuItem.Size = new System.Drawing.Size(254, 26); this.auftraggeberToolStripMenuItem.Text = "Auftraggeber"; this.auftraggeberToolStripMenuItem.Click += new System.EventHandler(this.auftraggeberToolStripMenuItem_Click); // + // prefixSuffixToolStripMenuItem + // + this.prefixSuffixToolStripMenuItem.Name = "prefixSuffixToolStripMenuItem"; + this.prefixSuffixToolStripMenuItem.Size = new System.Drawing.Size(254, 26); + this.prefixSuffixToolStripMenuItem.Text = "Prefix / Suffix"; + this.prefixSuffixToolStripMenuItem.Click += new System.EventHandler(this.PrefixSuffixToolStripMenuItem_Click); + // // speichernToolStripMenuItem // this.speichernToolStripMenuItem.Name = "speichernToolStripMenuItem"; - this.speichernToolStripMenuItem.Size = new System.Drawing.Size(112, 32); + this.speichernToolStripMenuItem.Size = new System.Drawing.Size(91, 25); this.speichernToolStripMenuItem.Text = "Speichern"; this.speichernToolStripMenuItem.Click += new System.EventHandler(this.speichernToolStripMenuItem_Click); // // massenstatistikToolStripMenuItem // this.massenstatistikToolStripMenuItem.Name = "massenstatistikToolStripMenuItem"; - this.massenstatistikToolStripMenuItem.Size = new System.Drawing.Size(158, 32); + this.massenstatistikToolStripMenuItem.Size = new System.Drawing.Size(128, 25); this.massenstatistikToolStripMenuItem.Text = "Massenstatistik"; this.massenstatistikToolStripMenuItem.Click += new System.EventHandler(this.massenstatistikToolStripMenuItem_Click); // // projektordnerÖffnenToolStripMenuItem // this.projektordnerÖffnenToolStripMenuItem.Name = "projektordnerÖffnenToolStripMenuItem"; - this.projektordnerÖffnenToolStripMenuItem.Size = new System.Drawing.Size(211, 32); + this.projektordnerÖffnenToolStripMenuItem.Size = new System.Drawing.Size(170, 25); this.projektordnerÖffnenToolStripMenuItem.Text = "Projektordner Öffnen"; this.projektordnerÖffnenToolStripMenuItem.Click += new System.EventHandler(this.ProjektordnerÖffnenToolStripMenuItem_Click); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(14, 32); + this.toolStripMenuItem1.Size = new System.Drawing.Size(12, 25); // // imprägnierberichteToolStripMenuItem // this.imprägnierberichteToolStripMenuItem.Name = "imprägnierberichteToolStripMenuItem"; - this.imprägnierberichteToolStripMenuItem.Size = new System.Drawing.Size(193, 32); + this.imprägnierberichteToolStripMenuItem.Size = new System.Drawing.Size(155, 25); this.imprägnierberichteToolStripMenuItem.Text = "Imprägnierberichte"; this.imprägnierberichteToolStripMenuItem.Click += new System.EventHandler(this.ImprägnierberichteToolStripMenuItem_Click); // @@ -151,20 +158,20 @@ this.massenberichteToolStripMenuItem, this.verbrauchToolStripMenuItem}); this.berichteToolStripMenuItem.Name = "berichteToolStripMenuItem"; - this.berichteToolStripMenuItem.Size = new System.Drawing.Size(101, 32); + this.berichteToolStripMenuItem.Size = new System.Drawing.Size(82, 25); this.berichteToolStripMenuItem.Text = "Berichte "; // // massenberichteToolStripMenuItem // this.massenberichteToolStripMenuItem.Name = "massenberichteToolStripMenuItem"; - this.massenberichteToolStripMenuItem.Size = new System.Drawing.Size(234, 32); + this.massenberichteToolStripMenuItem.Size = new System.Drawing.Size(189, 26); this.massenberichteToolStripMenuItem.Text = "Massenberichte"; this.massenberichteToolStripMenuItem.Click += new System.EventHandler(this.MassenberichteToolStripMenuItem_Click); // // verbrauchToolStripMenuItem // this.verbrauchToolStripMenuItem.Name = "verbrauchToolStripMenuItem"; - this.verbrauchToolStripMenuItem.Size = new System.Drawing.Size(234, 32); + this.verbrauchToolStripMenuItem.Size = new System.Drawing.Size(189, 26); this.verbrauchToolStripMenuItem.Text = "Verbrauch"; this.verbrauchToolStripMenuItem.Click += new System.EventHandler(this.VerbrauchToolStripMenuItem_Click); // @@ -174,42 +181,38 @@ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatus_projekt_Label, this.toolstrip_gesamtLiner}); - this.statusStrip1.Location = new System.Drawing.Point(0, 532); + this.statusStrip1.Location = new System.Drawing.Point(0, 431); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 19, 0); - this.statusStrip1.Size = new System.Drawing.Size(1084, 26); + this.statusStrip1.Size = new System.Drawing.Size(813, 22); this.statusStrip1.TabIndex = 3; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatus_projekt_Label // this.toolStripStatus_projekt_Label.Name = "toolStripStatus_projekt_Label"; - this.toolStripStatus_projekt_Label.Size = new System.Drawing.Size(55, 20); + this.toolStripStatus_projekt_Label.Size = new System.Drawing.Size(44, 17); this.toolStripStatus_projekt_Label.Text = "Projekt"; // // toolstrip_gesamtLiner // this.toolstrip_gesamtLiner.Name = "toolstrip_gesamtLiner"; - this.toolstrip_gesamtLiner.Size = new System.Drawing.Size(138, 20); + this.toolstrip_gesamtLiner.Size = new System.Drawing.Size(111, 17); this.toolstrip_gesamtLiner.Text = "Insgesammt Einbau"; // - // prefixSuffixToolStripMenuItem + // update // - this.prefixSuffixToolStripMenuItem.Name = "prefixSuffixToolStripMenuItem"; - this.prefixSuffixToolStripMenuItem.Size = new System.Drawing.Size(318, 32); - this.prefixSuffixToolStripMenuItem.Text = "Prefix / Suffix"; - this.prefixSuffixToolStripMenuItem.Click += new System.EventHandler(this.PrefixSuffixToolStripMenuItem_Click); + this.update.UpdateUrl = "http://home.cosysda.de/sanverwaltung/UpdateInfo.dat"; // // frmMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1084, 558); + this.ClientSize = new System.Drawing.Size(813, 453); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.mainmenu); this.IsMdiContainer = true; this.MainMenuStrip = this.mainmenu; - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Name = "frmMain"; this.Text = "Kanalsanierungsverwaltung"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frm_main_FormClosing); @@ -243,6 +246,7 @@ private System.Windows.Forms.ToolStripMenuItem verbrauchToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel toolstrip_gesamtLiner; private System.Windows.Forms.ToolStripMenuItem prefixSuffixToolStripMenuItem; + private UpdateLib.Updater update; } } diff --git a/SanSystem/frmMain.cs b/SanSystem/frmMain.cs index 0c6e61a..d6142ac 100644 --- a/SanSystem/frmMain.cs +++ b/SanSystem/frmMain.cs @@ -30,6 +30,7 @@ namespace SanSystem public frmMain() { InitializeComponent(); + update.CheckForUpdates(); string sx = Properties.Settings.Default.DATABASEMAIN; diff --git a/SanSystem/frmMain.resx b/SanSystem/frmMain.resx index 907dbc2..fc6cfee 100644 --- a/SanSystem/frmMain.resx +++ b/SanSystem/frmMain.resx @@ -123,4 +123,7 @@ 127, 17 + + 243, 17 + \ No newline at end of file diff --git a/SanVerwaltung.sln b/SanVerwaltung.sln index df946f1..38ee013 100644 --- a/SanVerwaltung.sln +++ b/SanVerwaltung.sln @@ -33,6 +33,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{DDF8C748 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dichtheitsprüfung", "Dichtheitspruefung\Dichtheitsprüfung\Dichtheitsprüfung.csproj", "{324277C6-2EB3-47B7-9DD5-7FA520E7D349}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateLib", "UpdateLib\UpdateLib.csproj", "{CF95DB30-247B-4382-948E-3BD5EB73C938}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -91,6 +93,10 @@ Global {324277C6-2EB3-47B7-9DD5-7FA520E7D349}.Debug|Any CPU.Build.0 = Debug|Any CPU {324277C6-2EB3-47B7-9DD5-7FA520E7D349}.Release|Any CPU.ActiveCfg = Release|Any CPU {324277C6-2EB3-47B7-9DD5-7FA520E7D349}.Release|Any CPU.Build.0 = Release|Any CPU + {CF95DB30-247B-4382-948E-3BD5EB73C938}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF95DB30-247B-4382-948E-3BD5EB73C938}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF95DB30-247B-4382-948E-3BD5EB73C938}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF95DB30-247B-4382-948E-3BD5EB73C938}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UpdateLib/Data/UpdateFileInfo.cs b/UpdateLib/Data/UpdateFileInfo.cs new file mode 100644 index 0000000..b268a86 --- /dev/null +++ b/UpdateLib/Data/UpdateFileInfo.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UpdateLib.Data +{ + [Serializable] + public class UpdateFileInfo + { + public string Name { get; set; } + public string Description { get; set; } + + public UpdateFileInfo(string name, string desc) + { + this.Name = name; + this.Description = desc; + } + } +} diff --git a/UpdateLib/Data/UpdateSaveFile.cs b/UpdateLib/Data/UpdateSaveFile.cs new file mode 100644 index 0000000..76d1ac4 --- /dev/null +++ b/UpdateLib/Data/UpdateSaveFile.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UpdateLib.Data +{ + [Serializable] + public class UpdateSaveFile + { + public String VersionString { get; set; } + public List _coll; + + public List UpdateFileCollection + { + get + { + return _coll; + } + set + { + _coll = value; + } + + } + + public UpdateSaveFile(String version) + { + this.VersionString = version; + UpdateFileCollection = new List(); + } + } +} diff --git a/UpdateLib/Properties/AssemblyInfo.cs b/UpdateLib/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..90aad2d --- /dev/null +++ b/UpdateLib/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("UpdateLib")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UpdateLib")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("cf95db30-247b-4382-948e-3bd5eb73c938")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UpdateLib/UI/frmUpdater.Designer.cs b/UpdateLib/UI/frmUpdater.Designer.cs new file mode 100644 index 0000000..e4ee280 --- /dev/null +++ b/UpdateLib/UI/frmUpdater.Designer.cs @@ -0,0 +1,187 @@ +namespace UpdateLib.UI +{ + partial class frmUpdater + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/UpdateLib/UI/frmUpdater.cs b/UpdateLib/UI/frmUpdater.cs new file mode 100644 index 0000000..8186a3b --- /dev/null +++ b/UpdateLib/UI/frmUpdater.cs @@ -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; + } + } +} + diff --git a/UpdateLib/UpdateLib.csproj b/UpdateLib/UpdateLib.csproj new file mode 100644 index 0000000..636dd9e --- /dev/null +++ b/UpdateLib/UpdateLib.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {CF95DB30-247B-4382-948E-3BD5EB73C938} + Library + Properties + UpdateLib + UpdateLib + v4.7.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + frmUpdater.cs + + + Component + + + + + \ No newline at end of file diff --git a/UpdateLib/Updater.cs b/UpdateLib/Updater.cs new file mode 100644 index 0000000..a7cf261 --- /dev/null +++ b/UpdateLib/Updater.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using UpdateLib.Data; +using UpdateLib.UI; + +namespace UpdateLib +{ + public class Updater : Component + { + private const String localUpdateFile = @".\UpdateInfo"; + public String UpdateUrl { get; set; } + + public void CheckForUpdates() + { + try + { + CleanUp(); + WebClient downloadclient = new WebClient(); + downloadclient.DownloadFile(UpdateUrl, localUpdateFile); + downloadclient.Dispose(); + + if(!File.Exists(localUpdateFile)) + { + throw new FileNotFoundException("Lokale Update datei ist beschädigt"); + } + + UpdateSaveFile localFile = DecodeSaveFile(localUpdateFile); + + Version localVersion = Assembly.GetEntryAssembly().GetName().Version; + Version onlineVersion = Version.Parse(localFile.VersionString); + + if(onlineVersion > localVersion) + { + string MsgBox = String.Format("Version {0} verfügbar",onlineVersion); + if(MessageBox.Show(MsgBox,"Update",MessageBoxButtons.YesNo) == DialogResult.Yes) + { + frmUpdater updateform = new frmUpdater(localFile,GetPath(UpdateUrl)); + updateform.ShowDialog(); + } + } + else + { + MessageBox.Show(onlineVersion.ToString()); + MessageBox.Show(localVersion.ToString()); + MessageBox.Show("Software ist in der aktuellste Version"); + } + } + catch(Exception e) + { + MessageBox.Show("Fehler beim uberprüfen von Updates\nVersuchen Sie später nochmal!\n\nFehlertext: " + e.Message, "Update", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private string GetPath(string UpdateUrl) + { + StringBuilder sb = new StringBuilder(); + String[] updatePieces = UpdateUrl.Split('/'); + for(int i = 0; i < updatePieces.Length -1; i++) + { + sb.Append(updatePieces[i] + "/"); + } + return sb.ToString(); + } + + private UpdateSaveFile DecodeSaveFile(string localUpdateFile) + { + FileStream localFileStream = null; + BinaryFormatter decoder = null; + + try + { + localFileStream = File.Open(localUpdateFile, FileMode.Open, FileAccess.Read); + decoder = new BinaryFormatter(); + return (UpdateSaveFile)decoder.Deserialize(localFileStream); + } + catch(Exception e) + { + throw new InvalidDataException("Der lokale updatedatei ist beschädigt "+e.Message); + } + finally + { + if (localFileStream != null) + localFileStream.Dispose(); + } + } + + + private void CleanUp() + { + DirectoryInfo di = new DirectoryInfo(Application.StartupPath); + foreach (FileInfo fi in di.GetFiles("*.old", SearchOption.TopDirectoryOnly)) + fi.Delete(); + + } + } +}