2016-02-08 23:23:31 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2016-02-10 18:58:13 -05:00
|
|
|
|
using System.Security.Cryptography;
|
2016-02-08 23:23:31 -05:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Config;
|
2016-12-11 14:25:29 -05:00
|
|
|
|
using Mesen.GUI.Controls;
|
2016-02-08 23:23:31 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class frmUpdatePrompt : BaseForm
|
|
|
|
|
{
|
2016-02-10 18:58:13 -05:00
|
|
|
|
private string _fileHash;
|
2016-12-24 21:27:28 -05:00
|
|
|
|
private string _donateText;
|
2016-02-10 18:58:13 -05:00
|
|
|
|
|
2016-12-24 21:27:28 -05:00
|
|
|
|
public frmUpdatePrompt(Version currentVersion, Version latestVersion, string changeLog, string fileHash, string donateText)
|
2016-02-08 23:23:31 -05:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2016-12-24 21:27:28 -05:00
|
|
|
|
_donateText = donateText;
|
|
|
|
|
|
2016-12-11 14:25:29 -05:00
|
|
|
|
this.txtChangelog.Font = new System.Drawing.Font(BaseControl.MonospaceFontFamily, 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
|
|
|
|
2016-02-10 18:58:13 -05:00
|
|
|
|
_fileHash = fileHash;
|
|
|
|
|
|
2016-02-08 23:23:31 -05:00
|
|
|
|
lblCurrentVersionString.Text = currentVersion.ToString();
|
|
|
|
|
lblLatestVersionString.Text = latestVersion.ToString();
|
|
|
|
|
txtChangelog.Text = changeLog.Replace("\n", Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
2016-12-24 21:27:28 -05:00
|
|
|
|
if(_donateText != null) {
|
|
|
|
|
if(!string.IsNullOrEmpty(_donateText)) {
|
|
|
|
|
this.lblDonate.Text = _donateText;
|
|
|
|
|
}
|
|
|
|
|
this.lblDonate.Visible = true;
|
|
|
|
|
this.picDonate.Visible = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.lblDonate.Visible = false;
|
|
|
|
|
this.picDonate.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 23:23:31 -05:00
|
|
|
|
btnUpdate.Focus();
|
|
|
|
|
}
|
2016-02-10 18:58:13 -05:00
|
|
|
|
|
|
|
|
|
private void btnUpdate_Click(object sender, EventArgs e)
|
2016-02-08 23:23:31 -05:00
|
|
|
|
{
|
2017-05-22 22:12:57 -04:00
|
|
|
|
#if DISABLEAUTOUPDATE
|
|
|
|
|
MesenMsgBox.Show("AutoUpdateDisabledMessage", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
|
|
|
this.Close();
|
|
|
|
|
#else
|
2016-12-22 19:39:33 -05:00
|
|
|
|
string destFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
|
2016-02-10 18:58:13 -05:00
|
|
|
|
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");
|
|
|
|
|
|
2016-04-30 21:21:52 -04:00
|
|
|
|
if(!File.Exists(updateHelper)) {
|
|
|
|
|
MesenMsgBox.Show("UpdaterNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
} else if(!string.IsNullOrWhiteSpace(srcFilePath)) {
|
2016-07-17 17:48:26 -04:00
|
|
|
|
frmDownloadProgress frmDownload = new frmDownloadProgress("http://www.mesen.ca/Services/GetLatestVersion.php?a=download&p=win&v=" + InteropEmu.GetMesenVersion(), srcFilePath);
|
2016-02-10 18:58:13 -05:00
|
|
|
|
if(frmDownload.ShowDialog() == DialogResult.OK) {
|
|
|
|
|
FileInfo fileInfo = new FileInfo(srcFilePath);
|
|
|
|
|
if(fileInfo.Length > 0 && GetSha1Hash(srcFilePath) == _fileHash) {
|
2016-12-22 19:39:33 -05:00
|
|
|
|
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));
|
|
|
|
|
}
|
2016-02-10 18:58:13 -05:00
|
|
|
|
} else {
|
|
|
|
|
//Download failed, mismatching hashes
|
2016-02-19 13:05:04 -05:00
|
|
|
|
MesenMsgBox.Show("UpdateDownloadFailed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2016-02-10 18:58:13 -05:00
|
|
|
|
DialogResult = DialogResult.Cancel;
|
2016-02-08 23:23:31 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-22 22:12:57 -04:00
|
|
|
|
#endif
|
2016-02-08 23:23:31 -05:00
|
|
|
|
}
|
2016-02-10 18:58:13 -05:00
|
|
|
|
|
|
|
|
|
private string GetSha1Hash(string filename)
|
|
|
|
|
{
|
|
|
|
|
using(SHA1Managed sha1 = new SHA1Managed()) {
|
|
|
|
|
byte[] hash = sha1.ComputeHash(File.ReadAllBytes(filename));
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder(hash.Length * 2);
|
|
|
|
|
foreach(byte b in hash) {
|
|
|
|
|
sb.Append(b.ToString("x2"));
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-24 21:27:28 -05:00
|
|
|
|
|
|
|
|
|
private void picDonate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Process.Start("http://www.mesen.ca/Donate.php?l=" + ResourceHelper.GetLanguageCode());
|
|
|
|
|
}
|
2016-02-08 23:23:31 -05:00
|
|
|
|
}
|
|
|
|
|
}
|