Skip to content

Commit

Permalink
v 1.2.1 - Added ability for the application to check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SAHorowitz committed Oct 27, 2020
1 parent 720cdb9 commit b99ece8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FS2020PlanePath/MainPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions FS2020PlanePath/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit b99ece8

Please sign in to comment.