// Decompiled with JetBrains decompiler // Type: Toya.Upgrade.FrmMain // Assembly: Toya.Upgrade, Version=1.0.0.0, Culture=neutral, PublicKeyToken=17364d3304d11368 // MVID: 0375251D-E018-4B03-B16E-A2B257E37C3F // Assembly location: C:\Users\Administrateur\Downloads\Virusshare.00004-msil\Virus.Win32.Virut.af-aff9bba96e482313952036dcb188d1e61b55115cab9bc23c4a365ea2decdb065.exe using ICSharpCode.SharpZipLib.Zip; using System; using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Drawing; using System.IO; using System.Net; using System.Threading; using System.Windows.Forms; namespace Toya.Upgrade { public class FrmMain : Form { private IContainer components; private Label label1; private Label label2; private Label lblStatus; private Label lblSpeed; private Label lblMessage; private ProgressBar progressBarControlDownload; private Thread ThreadDown; private bool IsDownFile = true; private string StrFileName; private string StrUrl; private bool ReTransfers; private string FileName = string.Empty; private string Caption; private string UpdateUrl; private string[] args; protected override void Dispose(bool disposing) { if (disposing && this.components != null) this.components.Dispose(); base.Dispose(disposing); } private void InitializeComponent() { ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (FrmMain)); this.label1 = new Label(); this.label2 = new Label(); this.lblStatus = new Label(); this.lblSpeed = new Label(); this.lblMessage = new Label(); this.progressBarControlDownload = new ProgressBar(); this.SuspendLayout(); this.label1.AutoSize = true; this.label1.Location = new Point(2, 20); this.label1.Name = "label1"; this.label1.Size = new Size(89, 12); this.label1.TabIndex = 7; this.label1.Text = "下载文件状态:"; this.label2.AutoSize = true; this.label2.Location = new Point(2, 44); this.label2.Name = "label2"; this.label2.Size = new Size(89, 12); this.label2.TabIndex = 8; this.label2.Text = "下载文件速率:"; this.lblStatus.AutoSize = true; this.lblStatus.Location = new Point(86, 20); this.lblStatus.Name = "lblStatus"; this.lblStatus.Size = new Size(113, 12); this.lblStatus.TabIndex = 9; this.lblStatus.Text = "正在初始化下载……"; this.lblSpeed.AutoSize = true; this.lblSpeed.Location = new Point(86, 44); this.lblSpeed.Name = "lblSpeed"; this.lblSpeed.Size = new Size(41, 12); this.lblSpeed.TabIndex = 10; this.lblSpeed.Text = "0KB/秒"; this.lblMessage.ForeColor = Color.Red; this.lblMessage.Location = new Point(12, 107); this.lblMessage.Name = "lblMessage"; this.lblMessage.Size = new Size(532, 21); this.lblMessage.TabIndex = 11; this.progressBarControlDownload.Location = new Point(5, 71); this.progressBarControlDownload.Name = "progressBarControlDownload"; this.progressBarControlDownload.Size = new Size(539, 23); this.progressBarControlDownload.TabIndex = 12; this.AutoScaleDimensions = new SizeF(6f, 12f); this.AutoScaleMode = AutoScaleMode.Font; this.ClientSize = new Size(556, 137); this.Controls.Add((Control) this.progressBarControlDownload); this.Controls.Add((Control) this.lblMessage); this.Controls.Add((Control) this.lblSpeed); this.Controls.Add((Control) this.lblStatus); this.Controls.Add((Control) this.label2); this.Controls.Add((Control) this.label1); this.FormBorderStyle = FormBorderStyle.FixedDialog; this.Icon = (Icon) componentResourceManager.GetObject("$this.Icon"); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = nameof (FrmMain); this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.CenterScreen; this.Text = "通亚物流软件在线升级系统V3.5"; this.TopMost = true; this.Load += new EventHandler(this.FrmMain_Load); this.ResumeLayout(false); this.PerformLayout(); } public static string CompanyCode { get { string companyCode = string.Empty; if (companyCode == string.Empty) { companyCode = ConfigurationManager.AppSettings[nameof (CompanyCode)]; if (string.IsNullOrEmpty(companyCode)) companyCode = ""; } return companyCode; } } public FrmMain() => this.InitializeComponent(); public FrmMain(string[] args) { this.InitializeComponent(); this.args = args; } private void FrmMain_Load(object sender, EventArgs e) { if (this.args.Length == 0) { int num = (int) MessageBox.Show("升级程序启动失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand); Application.Exit(); } this.UpdateUrl = AppFile.Read("UpgrateConfig", "UpdateUrl", " http://www.youlm.com/Upgrade", 32); this.Caption = AppFile.Read("UpgrateConfig", "UpdateText", "通亚物流软件在线升级系统V3.5", 32); this.Text = this.Caption; this.FileName = "/Toya.Upgrade." + FrmMain.CompanyCode + ".zip"; this.Upgrade(); } private void Upgrade() { this.ReTransfers = true; this.StrUrl = this.UpdateUrl + this.FileName; if (System.IO.File.Exists(Application.StartupPath + this.FileName)) { System.IO.File.Delete(Application.StartupPath + this.FileName); System.IO.File.Delete(Application.StartupPath + "/Toya.Upgrade.Dos.exe"); } this.StrFileName = Application.StartupPath + this.FileName; this.ThreadDown = new Thread(new ThreadStart(this.DownFile)); this.ThreadDown.Start(); } private void SetStatusText(string value) => this.lblStatus.Text = value; private void SetSpeedText(string value) => this.lblSpeed.Text = value; private void SetMessageText(string value) => this.lblMessage.Text = value; private void progressBarControlDownloadValue(int value) => this.progressBarControlDownload.Value = value; private void progressBarControlDownloadMaximum(int value) => this.progressBarControlDownload.Maximum = value; private void DownFile() { long num = 0; FileStream fileStream; if (this.ReTransfers & System.IO.File.Exists(this.StrFileName)) { fileStream = new FileStream(this.StrFileName, FileMode.Open, FileAccess.ReadWrite); num = fileStream.Length; fileStream.Seek(num, SeekOrigin.Current); } else fileStream = new FileStream(this.StrFileName, FileMode.Create, FileAccess.Write); try { this.lblStatus.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetStatusText), (object) "读取远程文件大小..."); HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(this.StrUrl); if (num > 0L) httpWebRequest.AddRange((int) num); Stream responseStream = httpWebRequest.GetResponse().GetResponseStream(); this.progressBarControlDownload.BeginInvoke((Delegate) new FrmMain.ChangeInt(this.progressBarControlDownloadMaximum), (object) (int) httpWebRequest.GetResponse().ContentLength); this.lblStatus.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetStatusText), (object) "正在下载数据...."); byte[] buffer = new byte[204800]; DateTime now = DateTime.Now; int count; while ((count = responseStream.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, count); num += (long) count; TimeSpan timeSpan = DateTime.Now - now; this.lblSpeed.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetSpeedText), (object) string.Format("{0}KB/秒", (object) (int) ((double) num / timeSpan.TotalSeconds / 1024.0))); this.progressBarControlDownload.BeginInvoke((Delegate) new FrmMain.ChangeInt(this.progressBarControlDownloadValue), (object) (int) num); if (!this.IsDownFile) break; } fileStream.Close(); responseStream.Close(); this.lblStatus.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetStatusText), (object) "文件下载完毕!"); this.lblStatus.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetStatusText), (object) "正在解压软件包和更新!"); Thread.Sleep(5000); if (!this.UnZIP()) return; AppFile.Write("system", "VersionMain", this.args[0]); if (System.IO.File.Exists(Application.StartupPath + "/Toya.Upgrade.Dos.exe")) new Process() { StartInfo = { FileName = "Toya.Upgrade.Dos.exe", UseShellExecute = true } }.Start(); new Process() { StartInfo = { FileName = "Toya.exe", UseShellExecute = true } }.Start(); Application.Exit(); } catch (Exception ex) { fileStream.Close(); this.lblStatus.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetStatusText), (object) ("下载出错," + ex.Message)); } } private bool UnZIP() { try { using (ZipInputStream zipInputStream = new ZipInputStream((Stream) System.IO.File.OpenRead(Application.StartupPath + this.FileName))) { label_13: ZipEntry nextEntry; while ((nextEntry = zipInputStream.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(nextEntry.Name); string fileName = Path.GetFileName(nextEntry.Name); if (directoryName.Length > 0) Directory.CreateDirectory(directoryName); if (fileName != string.Empty) { using (FileStream fileStream = System.IO.File.Create(nextEntry.Name)) { byte[] buffer = new byte[2048]; while (true) { int count = ((Stream) zipInputStream).Read(buffer, 0, buffer.Length); if (count > 0) fileStream.Write(buffer, 0, count); else goto label_13; } } } } } return true; } catch (Exception ex) { int num = (int) MessageBox.Show(ex.Message); this.lblMessage.BeginInvoke((Delegate) new FrmMain.ChangeString(this.SetMessageText), (object) "升级出现错误,请关闭通亚物流软件,然后尝试从新升级。"); return false; } } private void btnUpgrade_Click(object sender, EventArgs e) => this.Upgrade(); private delegate void ChangeInt(int value); private delegate void ChangeString(string value); } }