2014-04-22 19:02:41 -07:00
|
|
|
|
/*
|
2017-06-20 06:01:47 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
2014-04-22 19:02:41 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-04-22 19:02:41 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-04-22 19:02:41 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-04-22 19:02:41 -07:00
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-04-22 19:02:41 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-06-20 06:01:47 -07:00
|
|
|
|
using System;
|
2014-04-22 19:02:41 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2014-04-22 19:02:41 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2016-04-25 13:35:36 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2014-04-22 19:02:41 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class UpdateControlView : FlowLayoutWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private Button downloadUpdateLink;
|
|
|
|
|
|
private Button checkUpdateLink;
|
|
|
|
|
|
private Button installUpdateLink;
|
|
|
|
|
|
private TextWidget updateStatusText;
|
|
|
|
|
|
|
2016-12-29 06:55:12 -08:00
|
|
|
|
private EventHandler unregisterEvents;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-06-20 06:09:01 -07:00
|
|
|
|
public UpdateControlView(ThemeConfig theme)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
this.BackgroundColor = theme.MinimalShade;
|
|
|
|
|
|
this.Padding = theme.ToolbarPadding.Clone(left: 8);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-01-11 22:11:43 -08:00
|
|
|
|
this.AddChild(updateStatusText = new TextWidget(string.Format(""), textColor: ActiveTheme.Instance.PrimaryTextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
});
|
2017-06-20 06:15:19 -07:00
|
|
|
|
|
|
|
|
|
|
this.AddChild(new HorizontalSpacer());
|
2017-06-20 06:12:57 -07:00
|
|
|
|
|
2018-01-11 22:11:43 -08:00
|
|
|
|
checkUpdateLink = new IconButton(AggContext.StaticData.LoadIcon("fa-refresh_14.png", IconColor.Theme), ApplicationController.Instance.Theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
ToolTipText = "Check for Update".Localize(),
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Cursor = Cursors.Hand,
|
|
|
|
|
|
Visible = false
|
|
|
|
|
|
};
|
2017-06-20 06:12:57 -07:00
|
|
|
|
checkUpdateLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateControlData.Instance.CheckForUpdateUserRequested();
|
|
|
|
|
|
};
|
2017-06-20 06:15:19 -07:00
|
|
|
|
this.AddChild(checkUpdateLink);
|
2017-06-20 06:12:57 -07:00
|
|
|
|
|
2018-01-11 22:11:43 -08:00
|
|
|
|
this.MinimumSize = new Vector2(0, checkUpdateLink.Height);
|
|
|
|
|
|
|
|
|
|
|
|
downloadUpdateLink = new TextButton("Download Update".Localize(), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Visible = false
|
|
|
|
|
|
};
|
2017-06-20 06:12:57 -07:00
|
|
|
|
downloadUpdateLink.Click += (s, e) =>
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-20 06:12:57 -07:00
|
|
|
|
downloadUpdateLink.Visible = false;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "Retrieving download info...".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-06-20 06:12:57 -07:00
|
|
|
|
UpdateControlData.Instance.InitiateUpdateDownload();
|
|
|
|
|
|
};
|
2017-06-20 06:15:19 -07:00
|
|
|
|
this.AddChild(downloadUpdateLink);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-01-11 22:11:43 -08:00
|
|
|
|
installUpdateLink = new TextButton("Install Update".Localize(), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Visible = false
|
|
|
|
|
|
};
|
2017-06-20 06:12:57 -07:00
|
|
|
|
installUpdateLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
2017-06-20 06:01:47 -07:00
|
|
|
|
{
|
2017-06-20 06:12:57 -07:00
|
|
|
|
if (!UpdateControlData.Instance.InstallUpdate())
|
2017-06-20 06:01:47 -07:00
|
|
|
|
{
|
|
|
|
|
|
installUpdateLink.Visible = false;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "Oops! Unable to install update.".Localize();
|
2017-06-20 06:01:47 -07:00
|
|
|
|
}
|
2017-06-20 06:12:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget.BreakInDebugger();
|
|
|
|
|
|
installUpdateLink.Visible = false;
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "Oops! Unable to install update.".Localize();
|
2017-06-20 06:12:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2017-06-20 06:15:19 -07:00
|
|
|
|
this.AddChild(installUpdateLink);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(UpdateStatusChanged, ref unregisterEvents);
|
|
|
|
|
|
|
2017-06-20 06:12:57 -07:00
|
|
|
|
this.UpdateStatusChanged(null, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-03 13:06:08 -08:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-01-23 14:03:04 -08:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 22:11:43 -08:00
|
|
|
|
string recommendedUpdateAvailable = "There is a recommended update available".Localize();
|
|
|
|
|
|
string requiredUpdateAvailable = "There is a required update available".Localize();
|
2016-08-03 14:45:33 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void UpdateStatusChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (UpdateControlData.Instance.UpdateStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.MayBeAvailable:
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "New updates may be available".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
checkUpdateLink.Visible = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.CheckingForUpdate:
|
|
|
|
|
|
updateStatusText.Text = "Checking for updates...".Localize();
|
2018-01-11 22:11:43 -08:00
|
|
|
|
//checkUpdateLink.Visible = false;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.UnableToConnectToServer:
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "Oops! Unable to connect to server".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
downloadUpdateLink.Visible = false;
|
|
|
|
|
|
installUpdateLink.Visible = false;
|
|
|
|
|
|
checkUpdateLink.Visible = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.UpdateAvailable:
|
2016-08-03 14:45:33 -07:00
|
|
|
|
if (UpdateControlData.Instance.UpdateRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
updateStatusText.Text = requiredUpdateAvailable;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
updateStatusText.Text = recommendedUpdateAvailable;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
downloadUpdateLink.Visible = true;
|
|
|
|
|
|
installUpdateLink.Visible = false;
|
|
|
|
|
|
checkUpdateLink.Visible = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.UpdateDownloading:
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = string.Format(
|
|
|
|
|
|
"{0} {1}%",
|
|
|
|
|
|
"Downloading updates...".Localize(),
|
|
|
|
|
|
UpdateControlData.Instance.DownloadPercent);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.ReadyToInstall:
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "New updates are ready to install".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
downloadUpdateLink.Visible = false;
|
|
|
|
|
|
installUpdateLink.Visible = true;
|
|
|
|
|
|
checkUpdateLink.Visible = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case UpdateControlData.UpdateStatusStates.UpToDate:
|
2018-01-11 22:11:43 -08:00
|
|
|
|
updateStatusText.Text = "Your application is up-to-date".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
downloadUpdateLink.Visible = false;
|
|
|
|
|
|
installUpdateLink.Visible = false;
|
|
|
|
|
|
checkUpdateLink.Visible = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|