Esempio n. 1
0
 [NotNull] private static string GetQueryString()
 {
     return(EditorMetadata.GetQueryString(
                "welcome_window",
                IntegrationMetadata.FindIntegrations().Select(a => new KeyValuePair <string, string>(WWW.EscapeURL(a.Id), WWW.EscapeURL(a.ReleasedWithDissonanceVersion.ToString())))
                ));
 }
Esempio n. 2
0
        protected override void DrawContent()
        {
            EditorGUILayout.LabelField("There is an update for Dissonance Voice Chat available on the asset store:", LabelFieldStyle);
            EditorGUILayout.LabelField(" - Current Version: " + Current, LabelFieldStyle);
            EditorGUILayout.LabelField(" - Latest Version: " + Latest, LabelFieldStyle);

            if (GUILayout.Button("Open Release Notes"))
            {
                Application.OpenURL(string.Format("https://placeholder-software.co.uk/dissonance/releases/{0}.html{1}", Latest, EditorMetadata.GetQueryString()));
            }

            EditorGUILayout.Space();

            var enabled  = UpdateLauncher.GetUpdaterEnabled();
            var disabled = !enabled;

            using (new EditorGUILayout.HorizontalScope())
            {
                disabled = EditorGUILayout.Toggle(disabled, GUILayout.MaxWidth(25));
                EditorGUILayout.LabelField("Do not notify me about new versions again", LabelFieldStyle);
            }

            if (disabled == enabled)
            {
                UpdateLauncher.SetUpdaterEnabled(!disabled);
            }
        }
        private static IEnumerable <bool> CheckUpdateVersion()
        {
            //Exit if the update check is not enabled
            if (!GetUpdaterEnabled())
            {
                yield return(false);
            }

            //Exit if the next update isn't due yet
            var state = GetUpdateState();

            if (state.NextCheck >= DateTime.UtcNow)
            {
                yield return(false);
            }

            //setup some helpers for later
            var    random  = new System.Random();
            Action failed  = () => SetUpdateState(new UpdateState(state.ShownForVersion, DateTime.UtcNow + TimeSpan.FromMinutes(random.Next(10, 70))));
            Action success = () => SetUpdateState(new UpdateState(state.ShownForVersion, DateTime.UtcNow + TimeSpan.FromHours((random.Next(12, 72)))));

            //Begin downloading the manifest of all Dissonance updates
            var request = UnityWebRequest.Get(string.Format("https://placeholder-software.co.uk/dissonance/releases/latest-published.html{0}", EditorMetadata.GetQueryString()));

            request.Send();

            //Wait until request is complete
            while (!request.isDone && !request.isError)
            {
                yield return(true);
            }

            //If it's an error give up and schedule the next check fairly soon
            if (request.isError)
            {
                request.Dispose();
                failed();
                yield return(false);
            }

            //Get the response bytes and discard the request
            var bytes = request.downloadHandler.data;

            request.Dispose();

            //Parse the response data. If we fail give up and schedule the next check fairly soon
            SemanticVersion latest;

            if (!TryParse(bytes, out latest) || latest == null)
            {
                failed();
                yield return(false);
            }
            else
            {
                //Check if we've already shown the window for a greater version
                if (latest.CompareTo(state.ShownForVersion) <= 0)
                {
                    success();
                    yield return(false);
                }

                //Check if the new version is greater than the currently installed version
                if (latest.CompareTo(DissonanceComms.Version) <= 0)
                {
                    success();
                    yield return(false);
                }

                //Update the state so that the window does not show up again for this version
                SetUpdateState(new UpdateState(latest, DateTime.UtcNow + TimeSpan.FromHours((random.Next(12, 72)))));
                UpdateWindow.Show(latest, DissonanceComms.Version);
                success();
            }
        }
Esempio n. 4
0
        private static IEnumerable <bool> CheckUpdateVersion()
        {
            //Exit if the update check is not enabled
            if (!GetUpdaterEnabled())
            {
                Log.Trace("Updater not enabled");
                yield return(false);
            }

            //Fill the cache if it's empty
            if (_cachedNextCheckTime == null)
            {
                Log.Trace("Caching next update time");
                _cachedNextCheckTime = GetUpdateState().NextCheck;
            }

            //Exit if the next update check isn't due yet
            if (_cachedNextCheckTime.Value >= DateTime.UtcNow)
            {
                Log.Trace("Updater not yet time to check");
                yield return(false);
            }

            //Take a single frame break before starting the update check process
            yield return(true);

            var state = GetUpdateState();

            Log.Trace("Beginning version check. Current state:'{0}' Current version:'{1}'", state, DissonanceComms.Version);

            //setup some helpers for later
            //On failure, check again after a short time
            //On success, check again after a long time
            var    random = new System.Random();
            Action failed = () => SetUpdateState(new UpdateState(state.ShownForVersion, DateTime.UtcNow + TimeSpan.FromMinutes(random.Next(10, 70))));
            Action <SemanticVersion> success = v => SetUpdateState(new UpdateState(v, DateTime.UtcNow + TimeSpan.FromHours((random.Next(24, 144)))));

            //Begin downloading the manifest of all Dissonance updates
            using (var request = UnityWebRequest.Get(string.Format("https://placeholder-software.co.uk/dissonance/releases/latest-published.html{0}", EditorMetadata.GetQueryString("update_checker"))))
            {
                //Wait until request is complete
                var wait = request.SendWebRequest();
                while (!wait.isDone)
                {
                    yield return(true);
                }

                //If it's an error give up and schedule the next check fairly soon
                if (request.isNetworkError)
                {
                    request.Dispose();
                    failed();
                    Log.Trace("Update request failed");
                    yield return(false);
                }

                //Get the response bytes and discard the request
                var bytes = request.downloadHandler.data;
                request.Dispose();

                //Parse the response data. If we fail give up and schedule the next check fairly soon
                SemanticVersion latest;
                if (!TryParse(bytes, out latest) || latest == null)
                {
                    failed();
                    Log.Trace("Update response parsing failed");
                    yield return(false);
                }
                else
                {
                    Log.Trace("Received updater response, remote latest version is: '{0}'", latest);

                    //Check if we've already shown the window for a greater version
                    if (latest.CompareTo(state.ShownForVersion) <= 0)
                    {
                        success(state.ShownForVersion);
                        Log.Trace("Update success, window already shown for higher version '{0}'", state.ShownForVersion);
                        yield return(false);
                    }

                    //Check if the new version is greater than the currently installed version
                    if (latest.CompareTo(DissonanceComms.Version) <= 0)
                    {
                        success(state.ShownForVersion);
                        Log.Trace("Update success, newer version '{0}' already installed", DissonanceComms.Version);
                        yield return(false);
                    }

                    //Update the state so that the window does not show up again for this version
                    success(latest);
                    UpdateWindow.Show(latest, DissonanceComms.Version);
                    Log.Trace("Update success, showing update notification window for version '{0}'", latest);
                }
            }
        }
Esempio n. 5
0
 [NotNull] private static string GetQueryString()
 {
     return(EditorMetadata.GetQueryStringWithIntegrations("welcome_window"));
 }