private void openFileUpdataClick(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = ".zmc"; ofd.Filter = "zjk@MaiCe 固件|*.zmc"; if (ofd.ShowDialog() == true) { filePath = ofd.FileName; fileName = texbockFileName.Text = ofd.SafeFileName; fileStream = new FileStream(@filePath, FileMode.Open, FileAccess.Read); BinaryReader fileRead = new BinaryReader(fileStream); byte[] jsonLenBuf = fileRead.ReadBytes(2); int jsonLenghts = jsonLenBuf[0] << 8 | jsonLenBuf[1]; byte[] jsonBuf = fileRead.ReadBytes(jsonLenghts); string jsonCfg = Encoding.Default.GetString(jsonBuf); versionApp = JsonConvert.DeserializeObject <VersionApp>(jsonCfg); binBuf = fileRead.ReadBytes(versionApp.Filesize); crc16Module crc_check = new crc16Module(); binCrc = crc_check.crc16(binBuf); fileSize = Convert.ToUInt16(versionApp.Filesize); //Match mc = Regex.Match(versionApp.TimeCreate, @"\d{4}/\d{1,2}/\d{1,2}"); //string time = mc.ToString().Replace("/",""); textBlockFileSize.Text = versionApp.Filesize.ToString(); if (binCrc == versionApp.Crc16Modulbus) { MessageBoxResult dr = MessageBox.Show("文件校验成功,点击确认升级", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (dr == MessageBoxResult.OK) { btn_upload(); } } else { MessageBox.Show("文件校验失败。。。"); } //此处做你想做的事 ...=ofd.FileName; } }
/// <summary> /// QuangNHD: Get version, path /// </summary> public static VersionApp GetVerionsFromServer() { var client = new HttpClient(); var version = new VersionApp(); try { // {"file_path":"http://h2618679.stratoserver.net:8080/update/setup.exe","version":"2.6"} var response = client.GetAsync("http://h2618679.stratoserver.net:8080/api/apps/version").Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; version = JsonConvert.DeserializeObject <VersionApp>(result); } return(version); } catch (Exception ex) { } return(null); }
public ApplicationInfo(NameApp nameApp, CodeApp codeApp, VersionApp versionApp) : base() { NameApp = nameApp; CodeApp = codeApp; VersionApp = versionApp; }