private void checkForDeviceUpdatesToolStripMenuItem_Click(object sender, EventArgs e) { if (HIDDevice.TheHIDDevice == null) { toolStripStatusLabel3.Text = "No Device,Cann't Update"; MessageBox.Show("No Device,Cann't Update,Please insert the Device!!!"); return; } toolStripStatusLabel3.Text = "connecting to server for device update"; System.Windows.Forms.Application.DoEvents(); WFHttpWebResponse WebResponse = new WFHttpWebResponse(); string url; url = "http://qc.iehlj.com/index.php?m=content&a=yingupdate&device="; url += WFNetLib.Strings.StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, ""); HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url); DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(JsonSoftData)); MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content)); JsonSoftData calldata = (JsonSoftData)s.ReadObject(stream); if (calldata.status == 0)//有更新 { string strcurBin = HIDDevice.TheHIDDevice.HexVer[0].ToString("X2") + "." + HIDDevice.TheHIDDevice.HexVer[1].ToString("X2"); float serBin = float.Parse(calldata.to_version.Substring(1)); float curBin = float.Parse(strcurBin); if (serBin > curBin) { //下载lic toolStripStatusLabel3.Text = "Updating for Device"; progressBar1.Value = 0; progressBar1.Visible = true; System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 float percent = 0; try { string URL = calldata.fileurl; //string filename = "123.lic"; System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL); System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse(); long totalBytes = myrp.ContentLength; byte[] theBIN = new byte[totalBytes]; long BINOffset = 0; System.IO.Stream st = myrp.GetResponseStream(); //System.IO.Stream so = new System.IO.FileStream("123.bin", System.IO.FileMode.Create); long totalDownloadedByte = 0; byte[] by = new byte[1024]; int osize = st.Read(by, 0, (int)by.Length); while (osize > 0) { totalDownloadedByte = osize + totalDownloadedByte; System.Windows.Forms.Application.DoEvents(); //so.Write(by, 0, osize); for (int i = 0; i < osize; i++) { theBIN[BINOffset++] = by[i]; } osize = st.Read(by, 0, (int)by.Length); percent = (float)totalDownloadedByte / (float)totalBytes * 100; progressBar1.Value = (int)(percent); toolStripStatusLabel3.Text = "Download for device " + percent.ToString("f2") + "%"; System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 } toolStripStatusLabel3.Text = "Download device OK,wait for update device..."; System.Windows.Forms.Application.DoEvents(); //so.Close(); st.Close(); WFGlobal.WaitMS(2000); UpdateDevice(theBIN); progressBar1.Visible = false; progressBar1.Value = 0; } catch (System.Exception ex) { if (bMessge) { MessageBox.Show(ex.Message); } toolStripStatusLabel3.Text = "Device Update is error"; progressBar1.Visible = false; progressBar1.Value = 0; //throw; //break; } } else { svd.SetVerifyData_BINUpdateTime(DateTime.Now); if (bMessge) { MessageBox.Show("This is the latest Device version"); } toolStripStatusLabel3.Text = "This is the latest Device version"; } } else { toolStripStatusLabel3.Text = "This is the latest Device version"; if (bMessge) { MessageBox.Show("This is the latest Device version"); } svd.SetVerifyData_BINUpdateTime(DateTime.Now); } }
private void checkForDeviceUpdatesToolStripMenuItem1_Click(object sender, EventArgs e) { if (HIDDevice.TheHIDDevice == null) { toolStripStatusLabel3.Text = "No Device,Cann't Update"; MessageBox.Show("No Device,Cann't Update,Please insert the Device!!!"); return; } toolStripStatusLabel3.Text = "connecting to server for lic update"; System.Windows.Forms.Application.DoEvents(); WFHttpWebResponse WebResponse = new WFHttpWebResponse(); string url; url = "http://qc.iehlj.com/index.php?m=content&a=shouupdate&device="; url += WFNetLib.Strings.StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, ""); HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url); DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(JsonSoftData)); MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content)); JsonSoftData calldata = (JsonSoftData)s.ReadObject(stream); if (calldata.status == 0)//有更新 { DateTime licdt = DateTime.Parse(calldata.to_version); if (licdt.Date > svd.LicUpdateTime.Date || !File.Exists("Mercedes Key Tool.lic")) { //下载lic toolStripStatusLabel3.Text = "Updating for Lic"; progressBar1.Value = 0; progressBar1.Visible = true; System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 float percent = 0; try { ProgressBar prog = progressBar1; string URL = calldata.fileurl; string filename = "Mercedes Key Tool.lic"; System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL); System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse(); long totalBytes = myrp.ContentLength; if (prog != null) { prog.Maximum = (int)totalBytes; } System.IO.Stream st = myrp.GetResponseStream(); System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create); long totalDownloadedByte = 0; byte[] by = new byte[1024]; int osize = st.Read(by, 0, (int)by.Length); while (osize > 0) { totalDownloadedByte = osize + totalDownloadedByte; System.Windows.Forms.Application.DoEvents(); so.Write(by, 0, osize); if (prog != null) { prog.Value = (int)totalDownloadedByte; } osize = st.Read(by, 0, (int)by.Length); percent = (float)totalDownloadedByte / (float)totalBytes * 100; toolStripStatusLabel3.Text = "Downloading for lic " + percent.ToString("f2") + "%"; System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 } toolStripStatusLabel3.Text = "Download Lic OK!"; svd.SetVerifyData_LicUpdateTime(licdt); so.Close(); st.Close(); if (bMessge) { MessageBox.Show("Lic update completed!!"); } progressBar1.Visible = false; progressBar1.Value = 0; } catch (System.Exception ex) { if (bMessge) { MessageBox.Show(ex.Message); } toolStripStatusLabel3.Text = "Lic Update is error"; progressBar1.Visible = false; progressBar1.Value = 0; //throw; //break; } } else { toolStripStatusLabel3.Text = "This is the latest lic version"; //svd.SetVerifyData_LicUpdateTime(licdt); if (bMessge) { MessageBox.Show("This is the latest lic version"); } } } else { toolStripStatusLabel3.Text = "This is the latest lic version"; //svd.SetVerifyData_LicUpdateTime(DateTime.Now); if (bMessge) { MessageBox.Show("This is the latest lic version"); } } }
private void checkForSoftUpdatesToolStripMenuItem2_Click(object sender, EventArgs e) { if (HIDDevice.TheHIDDevice == null) { toolStripStatusLabel3.Text = "No Device,Cann't Update"; MessageBox.Show("No Device,Cann't Update,Please insert the Device!!!"); return; } toolStripStatusLabel3.Text = "connecting to server for soft update"; System.Windows.Forms.Application.DoEvents(); WFHttpWebResponse WebResponse = new WFHttpWebResponse(); string url; url = "http://qc.iehlj.com/index.php?m=content&a=softupdate&device="; url += WFNetLib.Strings.StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, ""); url += "&version=V0"; //url += HIDDevice.SoftVersion.ToString("f2"); HttpWebResponse hr = WebResponse.CreateGetHttpResponse(url); DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(JsonSoftData)); MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content)); JsonSoftData calldata = (JsonSoftData)s.ReadObject(stream); if (calldata.status == 0)//有更新 { float sersoft = float.Parse(calldata.to_version.Substring(1)); if (sersoft > svd.SoftVersion) { try { ProcessHelper.StartProcess("Update MKT.exe"); this.Close(); bClose = true; } catch// (System.Exception ex) { toolStripStatusLabel3.Text = "cannot find 'Update MKT.exe'"; if (bMessge) { MessageBox.Show("cannot find 'Update MKT.exe'!!!"); } } } else { svd.SetVerifyData_SoftUpdateTime(DateTime.Now); toolStripStatusLabel3.Text = "This is the latest soft version"; if (bMessge) { MessageBox.Show("This is the latest soft version!!"); } } } else { svd.SetVerifyData_SoftUpdateTime(DateTime.Now); toolStripStatusLabel3.Text = "This is the latest soft version"; if (bMessge) { MessageBox.Show("This is the latest soft version!!"); } } }