diff --git a/FS2020PlanePath/MainPage.Designer.cs b/FS2020PlanePath/MainPage.Designer.cs index 6a36d24..f1d6691 100644 --- a/FS2020PlanePath/MainPage.Designer.cs +++ b/FS2020PlanePath/MainPage.Designer.cs @@ -332,7 +332,7 @@ private void InitializeComponent() this.Controls.Add(this.GoogleEarthGB); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainPage"; - this.Text = "Pilot Path Recorder v1.2.0"; + this.Text = "Pilot Path Recorder v"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainPage_FormClosing); this.Shown += new System.EventHandler(this.MainPage_Shown); this.ResumeLayout(false); diff --git a/FS2020PlanePath/MainPage.cs b/FS2020PlanePath/MainPage.cs index 5baf421..83a1c51 100644 --- a/FS2020PlanePath/MainPage.cs +++ b/FS2020PlanePath/MainPage.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Media; +using System.Net; using System.Security.Policy; using System.Text; using System.Threading.Tasks; @@ -25,10 +26,12 @@ public partial class MainPage : Form int nCurrentFlightID; DateTime dtLastDataRecord; FlightPlan flightPlan; + string sAppVersion = "1.2.1"; public MainPage() { InitializeComponent(); + this.Text += sAppVersion; FlightPathDB = new FS2020_SQLLiteDB(); FlightPathDB.CreateTables(); flightPlan = new FlightPlan(); @@ -68,7 +71,13 @@ private void LogFolderBrowser_Click(object sender, EventArgs e) private void MainPage_Shown(object sender, EventArgs e) { + string sAppLatestVersion; + simConnectIntegration.FForm = this; + sAppLatestVersion = ReadLatestAppVersionFromWeb(); + if (sAppLatestVersion.Equals(sAppVersion) == false) + if (MessageBox.Show("There is a newer version of the application available. Do you wish to download it now?", "New Version Available", MessageBoxButtons.YesNo) == DialogResult.Yes) + System.Diagnostics.Process.Start("https://github.com/SAHorowitz/MSFS2020-PilotPathRecorder"); AttemptSimConnection(); } @@ -618,5 +627,52 @@ private void MainPage_FormClosing(object sender, FormClosingEventArgs e) else FlightPathDB.WriteTableOption("SpeedUpVideoPlayback", "false"); } + + private string ReadLatestAppVersionFromWeb() + { + string sRetVal; + + WebClient client = new WebClient(); + try + { + Stream stream = client.OpenRead("https://raw.githubusercontent.com/SAHorowitz/MSFS2020-PilotPathRecorder/master/docs/latest_version.txt"); + StreamReader reader = new StreamReader(stream); + sRetVal = reader.ReadToEnd(); + + var sb = new StringBuilder(sRetVal.Length); + foreach (char i in sRetVal) + { + if (i == '\n') + { + sb.Append(Environment.NewLine); + } + else if (i != '\r' && i != '\t') + sb.Append(i); + } + sRetVal = sb.ToString(); + if (sRetVal.Contains("general") == true) + { + var vals = sRetVal.Split( + new[] { Environment.NewLine }, + StringSplitOptions.None + ) + .SkipWhile(line => !line.StartsWith("[general]")) + .Skip(1) + .Take(1) + .Select(line => new + { + Key = line.Substring(0, line.IndexOf('=')), + Value = line.Substring(line.IndexOf('=') + 1).Replace("\"", "").Replace(" ", "") + }); + sRetVal = vals.FirstOrDefault().Value; + } + } + catch (Exception e) + { + sRetVal = sAppVersion; + } + + return sRetVal; + } } }