Skip to content

Commit eae6bdb

Browse files
committed
Fix bugs in license displaying.
1 parent c53d26e commit eae6bdb

5 files changed

Lines changed: 69 additions & 22 deletions

File tree

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The navigation data (all files in `/QSimPlanner/[Version]/NavData` folder)
1+
The navigation data (all files in /QSimPlanner/[Version]/NavData folder)
22
shipped with this program is Aerosoft's property and is under Aerosoft's
33
NavDataPro license.
44

src/QSP/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,30 @@ internal static void Main(string[] args)
6565
#if !DEBUG
6666
UpdateOnFirstRun();
6767
#endif
68+
69+
ShowLicenseIfNeeded();
6870
var mainFrm = new QspForm();
6971
mainFrm.Init();
7072

7173
Application.Run(mainFrm);
7274
}
7375
}
7476

77+
private static void ShowLicenseIfNeeded()
78+
{
79+
if ( ShouldShowLicense())
80+
{
81+
var frm = new LicenseForm()
82+
{
83+
StartPosition = FormStartPosition.CenterScreen
84+
};
85+
86+
frm.Init();
87+
frm.ShowDialog();
88+
if (!frm.Agreed) Environment.Exit(0);
89+
}
90+
}
91+
7592
// @Throws
7693
private static bool UsingLatestVersion()
7794
{

src/QSP/UI/Forms/LicenseForm.Designer.cs

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QSP/UI/Forms/LicenseForm.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Data;
5-
using System.Drawing;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
2+
using System.IO;
93
using System.Windows.Forms;
104

115
namespace QSP.UI.Forms
@@ -19,9 +13,23 @@ public LicenseForm()
1913
InitializeComponent();
2014
}
2115

16+
public void Init()
17+
{
18+
try
19+
{
20+
richTextBox1.Text = File.ReadAllText("LICENSE.txt");
21+
}
22+
catch
23+
{
24+
richTextBox1.Text =
25+
"Build the application with InstallerBuilder to have this work properly.";
26+
}
27+
}
28+
2229
private void agreeBtn_Click(object sender, EventArgs e)
2330
{
2431
Agreed = true;
32+
this.Close();
2533
}
2634
}
2735
}

src/QSP/Updates/Utilities.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using QSP.Common.Options;
2+
using System;
23
using System.IO;
34
using System.Xml.Linq;
45

@@ -13,11 +14,13 @@ public static string GetFolder(Version ver)
1314
return Path.Combine("..", ver.ToString());
1415
}
1516

16-
// @Throws
17-
// The versions are strings of the format major.minor.build.
18-
// Backup version is empty string if the application was never updated.
19-
// Do NOT use reflection to get the current version so that it is easier to test the
20-
// updater system.
17+
/// <summary>
18+
/// The versions are strings of the format major.minor.build.
19+
/// Backup version is empty string if the application was never updated.
20+
/// Do NOT use reflection to get the current version so that it is easier to test the
21+
/// updater system.
22+
/// </summary>
23+
/// <exception cref="Exception"></exception>
2124
public static VersionInfo GetVersions()
2225
{
2326
var root = GetVersionXDoc().Root;
@@ -29,12 +32,33 @@ public static VersionInfo GetVersions()
2932
};
3033
}
3134

32-
// @Throws
35+
/// <exception cref="Exception"></exception>
3336
public static XDocument GetVersionXDoc()
3437
{
3538
return XDocument.Load(VersionXmlPath);
3639
}
3740

3841
public class VersionInfo { public string Backup, Current; }
42+
43+
// @NoThrow
44+
/// <summary>
45+
/// Shows the license only if the current version of application is never run,
46+
/// and the license text changed from the previous version which the user has.
47+
/// </summary>
48+
public static bool ShouldShowLicense()
49+
{
50+
try
51+
{
52+
if (File.Exists(OptionManager.DefaultPath)) return false;
53+
54+
var ver = GetVersions();
55+
var prevTxt = Path.Combine("..", ver.Backup, "LICENSE.txt");
56+
return File.ReadAllText(prevTxt) == File.ReadAllText("LICENSE.txt");
57+
}
58+
catch
59+
{
60+
return true;
61+
}
62+
}
3963
}
4064
}

0 commit comments

Comments
 (0)