private void btnUpdate_Click(object sender, EventArgs e) { string destFilePath = Process.GetCurrentProcess().MainModule.FileName; string srcFilePath = Path.Combine(ConfigManager.DownloadFolder, "Mesen." + lblLatestVersionString.Text + ".exe"); string backupFilePath = Path.Combine(ConfigManager.BackupFolder, "Mesen." + lblCurrentVersionString.Text + ".exe"); string updateHelper = Path.Combine(ConfigManager.HomeFolder, "MesenUpdater.exe"); if (!File.Exists(updateHelper)) { MesenMsgBox.Show("UpdaterNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } else if (!string.IsNullOrWhiteSpace(srcFilePath)) { frmDownloadProgress frmDownload = new frmDownloadProgress("http://www.mesen.ca/Services/GetLatestVersion.php?a=download&p=win&v=" + InteropEmu.GetMesenVersion(), srcFilePath); if (frmDownload.ShowDialog() == DialogResult.OK) { FileInfo fileInfo = new FileInfo(srcFilePath); if (fileInfo.Length > 0 && GetSha1Hash(srcFilePath) == _fileHash) { Process.Start(updateHelper, string.Format("\"{0}\" \"{1}\" \"{2}\"", srcFilePath, destFilePath, backupFilePath)); } else { //Download failed, mismatching hashes MesenMsgBox.Show("UpdateDownloadFailed", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } } } }
private void btnUpdate_Click(object sender, EventArgs e) { #if DISABLEAUTOUPDATE MesenMsgBox.Show("AutoUpdateDisabledMessage", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.Cancel; this.Close(); #else string destFilePath = System.Reflection.Assembly.GetEntryAssembly().Location; string srcFilePath = Path.Combine(ConfigManager.DownloadFolder, "Mesen." + lblLatestVersionString.Text + ".exe"); string backupFilePath = Path.Combine(ConfigManager.BackupFolder, "Mesen." + lblCurrentVersionString.Text + ".exe"); string updateHelper = Path.Combine(ConfigManager.HomeFolder, "MesenUpdater.exe"); if (!File.Exists(updateHelper)) { MesenMsgBox.Show("UpdaterNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } else if (!string.IsNullOrWhiteSpace(srcFilePath)) { frmDownloadProgress frmDownload = new frmDownloadProgress("http://www.mesen.ca/Services/GetLatestVersion.php?a=download&p=win&v=" + InteropEmu.GetMesenVersion(), srcFilePath); if (frmDownload.ShowDialog() == DialogResult.OK) { FileInfo fileInfo = new FileInfo(srcFilePath); if (fileInfo.Length > 0 && ResourceManager.GetSha1Hash(File.ReadAllBytes(srcFilePath)) == _fileHash) { if (Program.IsMono) { Process.Start("mono", string.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\"", updateHelper, srcFilePath, destFilePath, backupFilePath)); } else { Process.Start(updateHelper, string.Format("\"{0}\" \"{1}\" \"{2}\"", srcFilePath, destFilePath, backupFilePath)); } } else { //Download failed, mismatching hashes MesenMsgBox.Show("UpdateDownloadFailed", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } } } #endif }