private void Generate(object sender, EventArgs e) { UpdateSaveFile file = new UpdateSaveFile(txtVersion.Text); foreach (ListViewItem item in listView1.Items) { file.UpdateFileCollection.Add(new UpdateFileInfo(item.SubItems[0].Text, item.SubItems[1].Text)); } BinaryFormatter bf = new BinaryFormatter(); FileStream bfStream = File.Open(@".\UpdateInfo.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite); bf.Serialize(bfStream, file); bfStream.Close(); }
public void CheckForUpdates() { try { CleanUp(); if (File.Exists(LocalUpdateFile)) { UpdateSaveFile CheckVersion = DecodeSaveFile(LocalUpdateFile); Check = Version.Parse(CheckVersion.VersionString); } else { Version.TryParse("0.0.0.0", out Check); } WebClient downloadClient = new WebClient(); downloadClient.DownloadFile(UpdateUrl, LocalUpdateFile); downloadClient.Dispose(); if (!File.Exists(LocalUpdateFile)) { throw new FileNotFoundException("The local update file is missing!", LocalUpdateFile); } UpdateSaveFile localFile = DecodeSaveFile(LocalUpdateFile); //Version localVersion = Assembly.GetEntryAssembly().GetName().Version; Version onlineVersion = Version.Parse(localFile.VersionString); if (onlineVersion > Check) { if (MessageBox.Show(String.Format("Version {0} available,\nInstall it now?", onlineVersion.ToString()), "NXT Updater", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { frmUpdater updateForm = new frmUpdater(localFile, GetPath(UpdateUrl)); updateForm.ShowDialog(); } } else { MessageBox.Show("You already have the latest version!", "NXT Updater", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { MessageBox.Show("Error checking for updates\ntry again later!\n\nError Message:" + e.Message, "NXT Updater", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }