Finished messages and fixed upgrade logic

Have managed to fix the logic for the messages functionality and the upgrade logic for the MSI installer so that it can install same versions.
This commit is contained in:
Terry MacDonald 2021-10-01 21:39:20 +13:00
parent e64e836525
commit efc5fc43c7
6 changed files with 26212 additions and 6 deletions

View File

@ -977,6 +977,11 @@ namespace DisplayMagician {
try try
{ {
json = client.DownloadString(indexUrl); json = client.DownloadString(indexUrl);
if (String.IsNullOrWhiteSpace(json))
{
logger.Trace($"Program/ShowMessages: There were no messages in the {indexUrl} message index.");
return;
}
messageIndex = JsonConvert.DeserializeObject<List<MessageItem>>(json); messageIndex = JsonConvert.DeserializeObject<List<MessageItem>>(json);
} }
catch (Exception ex) catch (Exception ex)
@ -985,9 +990,20 @@ namespace DisplayMagician {
return; return;
} }
ProgramSettings programSettings = ProgramSettings.LoadSettings();
foreach (MessageItem message in messageIndex) foreach (MessageItem message in messageIndex)
{ {
// Skip if we've already shown it
if (message.Id <= programSettings.LastMessageIdRead)
{
// Unless it's one coming up that we're monitoring
if (!programSettings.MessagesToMonitor.Contains(message.Id))
{
continue;
}
}
// Firstly, check that the version is correct // Firstly, check that the version is correct
Version myAppVersion = Assembly.GetEntryAssembly().GetName().Version; Version myAppVersion = Assembly.GetEntryAssembly().GetName().Version;
if (!string.IsNullOrWhiteSpace(message.MinVersion)) if (!string.IsNullOrWhiteSpace(message.MinVersion))
@ -1017,6 +1033,7 @@ namespace DisplayMagician {
if (!(myAppVersion <= maxVersion)) if (!(myAppVersion <= maxVersion))
{ {
logger.Debug($"Program/ShowMessages: Message is for version <= {maxVersion} and this is version {myAppVersion} so not showing message."); logger.Debug($"Program/ShowMessages: Message is for version <= {maxVersion} and this is version {myAppVersion} so not showing message.");
// Save it if it's one coming up that we're monitoring and we haven't already saved it
continue; continue;
} }
} }
@ -1035,6 +1052,11 @@ namespace DisplayMagician {
if (!(DateTime.Now >= startTime)) if (!(DateTime.Now >= startTime))
{ {
logger.Debug($"Program/ShowMessages: Message start date for \"{message.HeadingText}\" (#{message.Id}) not yet reached so not ready to show message."); logger.Debug($"Program/ShowMessages: Message start date for \"{message.HeadingText}\" (#{message.Id}) not yet reached so not ready to show message.");
if (!programSettings.MessagesToMonitor.Contains(message.Id))
{
programSettings.MessagesToMonitor.Add(message.Id);
programSettings.SaveSettings();
}
continue; continue;
} }
} }
@ -1061,6 +1083,19 @@ namespace DisplayMagician {
myMessageWindow.HeadingText = message.HeadingText; myMessageWindow.HeadingText = message.HeadingText;
myMessageWindow.ButtonText = message.ButtonText; myMessageWindow.ButtonText = message.ButtonText;
myMessageWindow.ShowDialog(); myMessageWindow.ShowDialog();
// If this the list of messages is still trying to monitor this message, then remove it if we've shown it to the user.
if (programSettings.MessagesToMonitor.Contains(message.Id))
{
programSettings.MessagesToMonitor.Remove(message.Id);
programSettings.SaveSettings();
}
// Update the latest message id to keep track of where we're up to
if (message.Id > programSettings.LastMessageIdRead)
{
programSettings.LastMessageIdRead = message.Id;
}
} }
} }

View File

@ -1,5 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
@ -22,6 +23,8 @@ namespace DisplayMagician
private bool _startOnBootUp = false; private bool _startOnBootUp = false;
private bool _minimiseOnStart = false; private bool _minimiseOnStart = false;
private bool _upgradeToPrereleases = false; private bool _upgradeToPrereleases = false;
private int _lastMessageIdRead = 0;
private List<int> _messagesToMonitor = new List<int>();
private string _logLevel = NLog.LogLevel.Info.ToString(); private string _logLevel = NLog.LogLevel.Info.ToString();
private Keys _hotkeyMainWindow = Keys.None; private Keys _hotkeyMainWindow = Keys.None;
private Keys _hotkeyDisplayProfileWindow = Keys.None; private Keys _hotkeyDisplayProfileWindow = Keys.None;
@ -79,6 +82,40 @@ namespace DisplayMagician
} }
} }
public int LastMessageIdRead
{
get
{
return _lastMessageIdRead;
}
set
{
_lastMessageIdRead = value;
// Because a value has changed, we need to save the setting
// to remember it for later.
if (_programSettingsLoaded)
SaveSettings();
}
}
public List<int> MessagesToMonitor
{
get
{
return _messagesToMonitor;
}
set
{
_messagesToMonitor = value;
// Because a value has changed, we need to save the setting
// to remember it for later.
if (_programSettingsLoaded)
SaveSettings();
}
}
public string LogLevel public string LogLevel
{ {
get get

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information // Version information
[assembly: AssemblyVersion("2.0.0.15")] [assembly: AssemblyVersion("2.0.0.20")]
[assembly: AssemblyFileVersion("2.0.0.15")] [assembly: AssemblyFileVersion("2.0.0.20")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -29,6 +29,7 @@ namespace DisplayMagician.UIForms
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(StartMessageForm));
this.lbl_heading_text = new System.Windows.Forms.Label(); this.lbl_heading_text = new System.Windows.Forms.Label();
this.rtb_message = new System.Windows.Forms.RichTextBox(); this.rtb_message = new System.Windows.Forms.RichTextBox();
this.btn_back = new System.Windows.Forms.Button(); this.btn_back = new System.Windows.Forms.Button();
@ -57,7 +58,7 @@ namespace DisplayMagician.UIForms
this.rtb_message.Location = new System.Drawing.Point(20, 20); this.rtb_message.Location = new System.Drawing.Point(20, 20);
this.rtb_message.Name = "rtb_message"; this.rtb_message.Name = "rtb_message";
this.rtb_message.ReadOnly = true; this.rtb_message.ReadOnly = true;
this.rtb_message.Size = new System.Drawing.Size(1209, 687); this.rtb_message.Size = new System.Drawing.Size(1205, 683);
this.rtb_message.TabIndex = 21; this.rtb_message.TabIndex = 21;
this.rtb_message.Text = ""; this.rtb_message.Text = "";
// //
@ -80,6 +81,7 @@ namespace DisplayMagician.UIForms
// pnl_richtextbox // pnl_richtextbox
// //
this.pnl_richtextbox.BackColor = System.Drawing.Color.White; this.pnl_richtextbox.BackColor = System.Drawing.Color.White;
this.pnl_richtextbox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pnl_richtextbox.Controls.Add(this.rtb_message); this.pnl_richtextbox.Controls.Add(this.rtb_message);
this.pnl_richtextbox.Location = new System.Drawing.Point(13, 63); this.pnl_richtextbox.Location = new System.Drawing.Point(13, 63);
this.pnl_richtextbox.Name = "pnl_richtextbox"; this.pnl_richtextbox.Name = "pnl_richtextbox";
@ -92,6 +94,8 @@ namespace DisplayMagician.UIForms
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black; this.BackColor = System.Drawing.Color.Black;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(1274, 844); this.ClientSize = new System.Drawing.Size(1274, 844);
this.Controls.Add(this.pnl_richtextbox); this.Controls.Add(this.pnl_richtextbox);
this.Controls.Add(this.btn_back); this.Controls.Add(this.btn_back);

File diff suppressed because it is too large Load Diff

View File

@ -16,8 +16,8 @@
<!-- Upgrade settings. This will be explained in more detail in a future post --> <!-- Upgrade settings. This will be explained in more detail in a future post -->
<Upgrade Id="$(var.UpgradeCode)"> <Upgrade Id="$(var.UpgradeCode)">
<UpgradeVersion OnlyDetect="yes" Minimum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMinimum="no" Property="NEWERFOUND" /> <UpgradeVersion OnlyDetect="yes" Minimum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMinimum="no" Property="NEWERFOUND" />
<UpgradeVersion OnlyDetect="yes" Minimum="!(bind.fileVersion.DisplayMagicianExe)" Maximum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMinimum="yes" IncludeMaximum="yes" Property="SELFFOUND" /> <!--<UpgradeVersion OnlyDetect="yes" Minimum="!(bind.fileVersion.DisplayMagicianExe)" Maximum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMinimum="yes" IncludeMaximum="yes" Property="SELFFOUND" />-->
<UpgradeVersion Minimum="0.0.0.0" IncludeMinimum="no" Maximum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMaximum="no" Property="OLDER_VERSION_FOUND" IgnoreRemoveFailure="yes" /> <UpgradeVersion Minimum="0.0.0.0" IncludeMinimum="no" Maximum="!(bind.fileVersion.DisplayMagicianExe)" IncludeMaximum="yes" Property="OLDER_VERSION_FOUND" IgnoreRemoveFailure="yes" />
</Upgrade> </Upgrade>
<CustomAction Id='AlreadyUpdated' Error='!(loc.ProductName) has already been updated to !(bind.fileVersion.DisplayMagicianExe) or newer. If you want to reinstall this version then uninstall !(loc.ProductName) first.' /> <CustomAction Id='AlreadyUpdated' Error='!(loc.ProductName) has already been updated to !(bind.fileVersion.DisplayMagicianExe) or newer. If you want to reinstall this version then uninstall !(loc.ProductName) first.' />