2014-04-28 17:34:54 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using MatterHackers.Agg;
|
2014-06-19 16:09:38 -07:00
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
2014-04-28 17:34:54 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2014-06-10 09:25:38 -07:00
|
|
|
|
using MatterHackers.MatterControl.SettingsManagement;
|
2014-04-28 17:34:54 -07:00
|
|
|
|
using MatterHackers.MatterControl.VersionManagement;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UpdateControlData
|
|
|
|
|
|
{
|
2014-05-12 11:44:07 -07:00
|
|
|
|
WebClient webClient;
|
|
|
|
|
|
|
|
|
|
|
|
int downloadPercent;
|
|
|
|
|
|
int downloadSize;
|
|
|
|
|
|
|
|
|
|
|
|
public int DownloadPercent { get { return downloadPercent; } }
|
|
|
|
|
|
|
2014-06-10 09:25:38 -07:00
|
|
|
|
public enum UpdateRequestType { UserRequested, Automatic, FirstTimeEver };
|
|
|
|
|
|
UpdateRequestType updateRequestType;
|
|
|
|
|
|
|
2014-08-16 11:18:12 -07:00
|
|
|
|
public enum UpdateStatusStates { MayBeAvailable, CheckingForUpdate, UpdateAvailable, UpdateDownloading, ReadyToInstall, UpToDate, UnableToConnectToServer };
|
2014-06-10 09:25:38 -07:00
|
|
|
|
|
|
|
|
|
|
bool WaitingToCompleteTransaction()
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(UpdateStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case UpdateStatusStates.CheckingForUpdate:
|
|
|
|
|
|
case UpdateStatusStates.UpdateDownloading:
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-08-08 10:40:01 -07:00
|
|
|
|
|
2014-08-19 11:41:13 -07:00
|
|
|
|
public RootedObjectEventHandler UpdateStatusChanged = new RootedObjectEventHandler();
|
2014-05-11 19:26:37 -07:00
|
|
|
|
|
|
|
|
|
|
static string applicationDataPath = DataStorage.ApplicationDataStorage.Instance.ApplicationUserDataPath;
|
|
|
|
|
|
static string updateFileLocation = Path.Combine(applicationDataPath, "updates");
|
2014-04-28 17:34:54 -07:00
|
|
|
|
|
|
|
|
|
|
UpdateStatusStates updateStatus;
|
|
|
|
|
|
public UpdateStatusStates UpdateStatus
|
|
|
|
|
|
{
|
2014-05-12 11:44:07 -07:00
|
|
|
|
get
|
2014-04-28 17:34:54 -07:00
|
|
|
|
{
|
2014-05-12 11:44:07 -07:00
|
|
|
|
return updateStatus;
|
2014-04-28 17:34:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-05-12 11:44:07 -07:00
|
|
|
|
void CheckVersionStatus()
|
|
|
|
|
|
{
|
|
|
|
|
|
string currentBuildToken = ApplicationSettings.Instance.get("CurrentBuildToken");
|
|
|
|
|
|
string updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension));
|
|
|
|
|
|
|
|
|
|
|
|
string applicationBuildToken = VersionInfo.Instance.BuildToken;
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationBuildToken == currentBuildToken || currentBuildToken == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.MayBeAvailable);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (System.IO.File.Exists(updateFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.ReadyToInstall);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpdateAvailable);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetUpdateStatus(UpdateStatusStates updateStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.updateStatus != updateStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.updateStatus = updateStatus;
|
|
|
|
|
|
OnUpdateStatusChanged(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string InstallerExtension
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2014-06-20 09:27:17 -07:00
|
|
|
|
if (OsInformation.OperatingSystem == OSType.Mac)
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
return "pkg";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return "exe";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-28 17:34:54 -07:00
|
|
|
|
static UpdateControlData instance;
|
|
|
|
|
|
static public UpdateControlData Instance
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (instance == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
instance = new UpdateControlData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-10 09:25:38 -07:00
|
|
|
|
public void CheckForUpdateUserRequested()
|
|
|
|
|
|
{
|
|
|
|
|
|
updateRequestType = UpdateRequestType.UserRequested;
|
2014-06-20 09:47:52 -07:00
|
|
|
|
CheckForUpdate();
|
2014-06-10 09:25:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CheckForUpdate()
|
2014-05-12 11:44:07 -07:00
|
|
|
|
{
|
2014-06-10 09:25:38 -07:00
|
|
|
|
if (!WaitingToCompleteTransaction())
|
2014-05-12 11:44:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.CheckingForUpdate);
|
|
|
|
|
|
RequestLatestVersion request = new RequestLatestVersion();
|
|
|
|
|
|
request.RequestSucceeded += new EventHandler(onVersionRequestSucceeded);
|
|
|
|
|
|
request.RequestFailed += new EventHandler(onVersionRequestFailed);
|
|
|
|
|
|
request.Request();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-10 11:44:16 -07:00
|
|
|
|
string updateAvailableMessage = "There is a recommended update avalible for MatterControl. Would you like to download it now?".Localize();
|
|
|
|
|
|
string updateAvailableTitle = "Recommended Update Available".Localize();
|
|
|
|
|
|
string downloadNow = "Download Now".Localize();
|
|
|
|
|
|
string remindMeLater = "Remind Me Later".Localize();
|
2014-05-12 11:44:07 -07:00
|
|
|
|
void onVersionRequestSucceeded(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
string currentBuildToken = ApplicationSettings.Instance.get("CurrentBuildToken");
|
|
|
|
|
|
string updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension));
|
|
|
|
|
|
|
|
|
|
|
|
string applicationBuildToken = VersionInfo.Instance.BuildToken;
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationBuildToken == currentBuildToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpToDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (System.IO.File.Exists(updateFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.ReadyToInstall);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-06-10 11:44:16 -07:00
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpdateAvailable);
|
|
|
|
|
|
if (updateRequestType == UpdateRequestType.FirstTimeEver)
|
2014-05-12 11:44:07 -07:00
|
|
|
|
{
|
2014-06-10 11:44:16 -07:00
|
|
|
|
UiThread.RunOnIdle((state) =>
|
2014-06-10 09:25:38 -07:00
|
|
|
|
{
|
2014-10-21 21:20:09 -07:00
|
|
|
|
StyledMessageBox.ShowMessageBox(ProcessDialogResponse, updateAvailableMessage, updateAvailableTitle, StyledMessageBox.MessageType.YES_NO, downloadNow, remindMeLater);
|
2014-06-10 11:44:16 -07:00
|
|
|
|
// show a dialog to tell the user there is an update
|
2014-10-21 21:20:09 -07:00
|
|
|
|
|
2014-06-10 11:44:16 -07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-21 21:20:09 -07:00
|
|
|
|
void ProcessDialogResponse(bool messageBoxResponse)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (messageBoxResponse)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitiateUpdateDownload();
|
|
|
|
|
|
// Switch to the about page so we can see the download progress.
|
|
|
|
|
|
GuiWidget aboutTabWidget = FindNamedWidgetRecursive(ApplicationController.Instance.MainView, "About Tab");
|
|
|
|
|
|
Tab aboutTab = aboutTabWidget as Tab;
|
|
|
|
|
|
if (aboutTab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
aboutTab.TabBarContaningTab.SelectTab(aboutTab);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-10 11:44:16 -07:00
|
|
|
|
static GuiWidget FindNamedWidgetRecursive(GuiWidget root, string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (GuiWidget child in root.Children)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (child.Name == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget foundWidget = FindNamedWidgetRecursive(child, name);
|
|
|
|
|
|
if (foundWidget != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return foundWidget;
|
2014-05-12 11:44:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-06-10 11:44:16 -07:00
|
|
|
|
|
|
|
|
|
|
return null;
|
2014-05-12 11:44:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onVersionRequestFailed(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2014-05-13 17:00:50 -07:00
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpToDate);
|
2014-05-12 11:44:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-16 11:18:12 -07:00
|
|
|
|
int downloadAttempts = 0;
|
|
|
|
|
|
string updateFileName;
|
2014-05-11 19:26:37 -07:00
|
|
|
|
public void InitiateUpdateDownload()
|
2014-08-16 11:18:12 -07:00
|
|
|
|
{
|
|
|
|
|
|
downloadAttempts = 0;
|
|
|
|
|
|
DownloadUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DownloadUpdate()
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-06-10 09:25:38 -07:00
|
|
|
|
if (!WaitingToCompleteTransaction())
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-08-16 11:18:12 -07:00
|
|
|
|
|
2014-05-11 19:26:37 -07:00
|
|
|
|
string downloadToken = ApplicationSettings.Instance.get("CurrentBuildToken");
|
|
|
|
|
|
|
2014-08-16 10:44:56 -07:00
|
|
|
|
if (downloadToken == null)
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-08-16 11:18:12 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
throw new Exception("Build token should not be null");
|
|
|
|
|
|
#endif
|
2014-08-16 10:44:56 -07:00
|
|
|
|
//
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
2014-08-16 10:44:56 -07:00
|
|
|
|
else
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-08-16 11:18:12 -07:00
|
|
|
|
downloadAttempts++;
|
2014-08-16 10:44:56 -07:00
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpdateDownloading);
|
|
|
|
|
|
string downloadUri = string.Format("https://mattercontrol.appspot.com/downloads/development/{0}", ApplicationSettings.Instance.get("CurrentBuildToken"));
|
2014-05-11 19:26:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
2014-08-16 10:44:56 -07:00
|
|
|
|
//Make HEAD request to determine the size of the download (required by GAE)
|
|
|
|
|
|
System.Net.WebRequest request = System.Net.WebRequest.Create(downloadUri);
|
|
|
|
|
|
request.Method = "HEAD";
|
2014-05-11 19:26:37 -07:00
|
|
|
|
|
2014-08-16 10:44:56 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
WebResponse response = request.GetResponse();
|
|
|
|
|
|
downloadSize = (int)response.ContentLength;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
//Unknown download size
|
|
|
|
|
|
downloadSize = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!System.IO.Directory.Exists(updateFileLocation))
|
|
|
|
|
|
{
|
|
|
|
|
|
System.IO.Directory.CreateDirectory(updateFileLocation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-16 11:18:12 -07:00
|
|
|
|
updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", downloadToken, InstallerExtension));
|
2014-08-16 10:44:56 -07:00
|
|
|
|
|
|
|
|
|
|
webClient = new WebClient();
|
|
|
|
|
|
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
|
|
|
|
|
|
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
|
|
|
|
|
|
webClient.DownloadFileAsync(new Uri(downloadUri), updateFileName);
|
|
|
|
|
|
}
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (downloadSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.downloadPercent = (int)(e.BytesReceived * 100 / downloadSize);
|
|
|
|
|
|
}
|
2014-06-10 11:44:16 -07:00
|
|
|
|
UiThread.RunOnIdle((state) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateStatusChanged.CallEvents(this, e);
|
|
|
|
|
|
});
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
2014-08-16 11:18:12 -07:00
|
|
|
|
|
|
|
|
|
|
void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-08-16 11:18:12 -07:00
|
|
|
|
if (e.Error != null)
|
2014-06-10 09:25:38 -07:00
|
|
|
|
{
|
2014-08-16 11:18:12 -07:00
|
|
|
|
//Delete empty/partially downloaded file
|
|
|
|
|
|
if (System.IO.File.Exists(updateFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
System.IO.File.Delete(updateFileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Try downloading again - one time
|
|
|
|
|
|
if (downloadAttempts == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
DownloadUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle((state) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UnableToConnectToServer);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle((state) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.ReadyToInstall);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-10 11:44:16 -07:00
|
|
|
|
|
|
|
|
|
|
webClient.Dispose();
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-28 17:34:54 -07:00
|
|
|
|
private UpdateControlData()
|
|
|
|
|
|
{
|
2014-05-12 11:44:07 -07:00
|
|
|
|
CheckVersionStatus();
|
2014-06-10 09:25:38 -07:00
|
|
|
|
if (ApplicationSettings.Instance.get("ClientToken") != null
|
|
|
|
|
|
|| OemSettings.Instance.CheckForUpdatesOnFirstRun)
|
2014-05-12 11:44:07 -07:00
|
|
|
|
{
|
2014-06-10 09:25:38 -07:00
|
|
|
|
if (ApplicationSettings.Instance.get("ClientToken") == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
updateRequestType = UpdateRequestType.FirstTimeEver;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
updateRequestType = UpdateRequestType.Automatic;
|
|
|
|
|
|
}
|
2014-05-12 11:44:07 -07:00
|
|
|
|
//If we have already requested an update once, check on load
|
|
|
|
|
|
CheckForUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DataStorage.ApplicationSession firstSession;
|
|
|
|
|
|
firstSession = DataStorage.Datastore.Instance.dbSQLite.Table<DataStorage.ApplicationSession>().OrderBy(v => v.SessionStart).Take(1).FirstOrDefault();
|
|
|
|
|
|
if (firstSession != null
|
|
|
|
|
|
&& DateTime.Compare(firstSession.SessionStart.AddDays(7), DateTime.Now) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUpdateStatus(UpdateStatusStates.UpdateAvailable);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-04-28 17:34:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnUpdateStatusChanged(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateStatusChanged.CallEvents(this, e);
|
|
|
|
|
|
}
|
2014-05-11 19:26:37 -07:00
|
|
|
|
|
2014-05-13 17:00:50 -07:00
|
|
|
|
public bool InstallUpdate(GuiWidget windowToClose)
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
string downloadToken = ApplicationSettings.Instance.get("CurrentBuildToken");
|
|
|
|
|
|
|
|
|
|
|
|
string updateFileName = Path.Combine(updateFileLocation, "{0}.{1}".FormatWith(downloadToken, InstallerExtension));
|
|
|
|
|
|
string releaseVersion = ApplicationSettings.Instance.get("CurrentReleaseVersion");
|
|
|
|
|
|
string friendlyFileName = Path.Combine(updateFileLocation, "MatterControlSetup-{0}.{1}".FormatWith(releaseVersion, InstallerExtension));
|
|
|
|
|
|
|
|
|
|
|
|
if (System.IO.File.Exists(friendlyFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
System.IO.File.Delete(friendlyFileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//Change download file to friendly file name
|
|
|
|
|
|
System.IO.File.Move(updateFileName, friendlyFileName);
|
|
|
|
|
|
|
|
|
|
|
|
int tries = 0;
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
|
} while (tries++ < 100 && !File.Exists(friendlyFileName));
|
|
|
|
|
|
|
|
|
|
|
|
//Run installer file
|
|
|
|
|
|
Process installUpdate = new Process();
|
|
|
|
|
|
installUpdate.StartInfo.FileName = friendlyFileName;
|
|
|
|
|
|
installUpdate.Start();
|
|
|
|
|
|
|
2014-05-12 11:44:07 -07:00
|
|
|
|
while (windowToClose != null && windowToClose as SystemWindow == null)
|
2014-05-11 19:26:37 -07:00
|
|
|
|
{
|
2014-05-12 11:44:07 -07:00
|
|
|
|
windowToClose = windowToClose.Parent;
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Attempt to close current application
|
2014-05-12 11:44:07 -07:00
|
|
|
|
SystemWindow topSystemWindow = windowToClose as SystemWindow;
|
2014-05-11 19:26:37 -07:00
|
|
|
|
if (topSystemWindow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
topSystemWindow.CloseOnIdle();
|
2014-05-13 17:00:50 -07:00
|
|
|
|
return true;
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
if (System.IO.File.Exists(friendlyFileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
System.IO.File.Delete(friendlyFileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-05-13 17:00:50 -07:00
|
|
|
|
|
|
|
|
|
|
return false;
|
2014-05-11 19:26:37 -07:00
|
|
|
|
}
|
2014-04-28 17:34:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|