Add self-update mechanism (fixes #3)#11
Conversation
Thanks to the url fetched while trying to determine if they were updates to Uplift, we can download the newer unitypackage and import it once opened.
|
|
||
| private static bool ShouldCheck() | ||
| { | ||
| string lastCheck = EditorPrefs.GetString(lastUpdateCheckKey); |
There was a problem hiding this comment.
Would that prevent update in a different project?
There was a problem hiding this comment.
I'm not sure. It could actually. I'll check this.
There was a problem hiding this comment.
It looks like the preferences are project specific!
| { | ||
| Debug.Log("No update for Uplift available"); | ||
| } | ||
| } |
| List<System.Object> releases = (List<System.Object>)obj; | ||
| foreach (Dictionary<string, object> release in releases) | ||
| { | ||
| if(VersionParser.GreaterThan((string)release ["tag_name"], About.Version)) |
There was a problem hiding this comment.
isn't tag_name formatted like "v1.0.0beta1".
Do we need to strip the v?
There was a problem hiding this comment.
Nope! The Version parser ignore the v by default. I have tested this and it works.
| EditorApplication.update -= EditorUpdate; | ||
| EditorPrefs.SetString( | ||
| lastUpdateCheckKey, | ||
| DateTime.UtcNow.ToString(dateFormat, provider) |
There was a problem hiding this comment.
why not store time in seconds?
There was a problem hiding this comment.
Because I'm not sure you can in C#. Or we would have to write our own method, something like
public static int convertDateTimeToSeconds(DateTime dateTimeToConvert)
{
int secsInAMin = 60;
int secsInAnHour = 60 * secsInAMin;
int secsInADay = 24 * secsInAnHour;
double secsInAYear = (int)365.25 * secsInADay;
int totalSeconds = (int)(dateTimeToConvert.Year * secsInAYear) +
(dateTimeToConvert.DayOfYear * secsInADay) +
(dateTimeToConvert.Hour * secsInAnHour) +
(dateTimeToConvert.Minute * secsInAMin) +
dateTimeToConvert.Second;
return totalSeconds;
}which would me more cumbersome than anything imo. DateTime.Second, .Minute etc... only returns the current seconds, minutes... (whithin the [0-60] range for instance)
There was a problem hiding this comment.
https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx
System.DateTime.Now.Ticks * 10000;
There was a problem hiding this comment.
The issue is that EditorPrefs does not accept long. Anyways if your first comment is true, then we should not use the Preferences, so we will not face the issue. I'm not sure I see why storing it as an integer is better than a string though.
There was a problem hiding this comment.
I was just not a fond of date parsing. I see that you use CultureInfo.InvariantCulture so it should be fine.
a94fadf to
11ca1b2
Compare
| DirectoryInfo assetsPath = new DirectoryInfo(Application.dataPath); | ||
| string destination = Path.Combine(assetsPath.Parent.FullName, unitypackageName); | ||
|
|
||
| ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; |
There was a problem hiding this comment.
We should be careful here. I am not fond of bypassing SSL.
See http://www.khalidabuhakmeh.com/validate-ssl-certificate-with-servicepointmanager for I think a better solution.
5cb5ab7 to
e9977f1
Compare
6a429a1 to
371fbf5
Compare
lacostej
left a comment
There was a problem hiding this comment.
There are a few small things we can do to improve, but it's already great as is. Let's have this in!
| } | ||
| EditorGUILayout.LabelField("SSL Certificates:", EditorStyles.boldLabel); | ||
| EditorGUILayout.HelpBox( | ||
| "Unknown certificates could be the result of our registered certificates being outdated or the result of a potential attack. Trusting unknown certificates could lead to security breaches. Use at your own risk!", |
There was a problem hiding this comment.
We could explain where we use SSL certificates. Only in the updater.
| using Uplift.Windows; | ||
| using Uplift.Updating; | ||
| using System; | ||
| using System.Collections.Generic; |
There was a problem hiding this comment.
we will have to clean this up.
| if(VersionParser.GreaterThan((string)release ["tag_name"], About.Version)) | ||
| { | ||
| Debug.Log("There is a new version of Uplift available!"); | ||
| UpdatePopup popup = EditorWindow.GetWindow(typeof(UpdatePopup), true) as UpdatePopup; |
There was a problem hiding this comment.
I am not sure how that works if we have had multiple updates, e.g. upgrade from 1.0.0beta1 to 1.0.0beta4.
- Extract GitHub release fetching to new separate namespace, GitHubModule - Display all possible updates in the update popup
Enable Uplift to check for updates and act consequently.
Automated daily check to see if an update is available
MenuItem to force this check
Fixes #3