Example #1
0
    static void DoRequest(Uri uri, Action <string> callback)
    {
        var request = WebRequest.Create(uri);

        request.ContentType = "application/json; charset=utf-8";

        var authorizationHeader =
            LumosRequest.GenerateAuthorizationHeader(LumosCredentialsManager.GetCredentials(), null);

        request.Headers.Add("Authorization", authorizationHeader);

        var failedSSLCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

        ServicePointManager.ServerCertificateValidationCallback += failedSSLCallback;

        string text;

        try {
            var response = (HttpWebResponse)request.GetResponse();
            using (var sr = new StreamReader(response.GetResponseStream())) {
                text = sr.ReadToEnd();
                callback(text);
            }
        } catch (WebException e) {
            LumosUnity.Debug.Log("Web exception: " + e.Message);
        } finally {
            ServicePointManager.ServerCertificateValidationCallback -= failedSSLCallback;
        }
    }
    void OnEnable()
    {
        credentials = LumosCredentialsManager.GetCredentials();

        if (LumosPackages.package == LumosPackages.Update.None || LumosPackages.package == LumosPackages.Update.CheckingVersion)
        {
            LumosPackages.CheckForUpdates();
        }
    }
    static void PromptLumosInstall()
    {
        EditorApplication.projectWindowChanged   -= PromptLumosInstall;
        EditorApplication.hierarchyWindowChanged -= PromptLumosInstall;

        credentials = LumosCredentialsManager.GetCredentials();

        if (credentials.apiKey.Length >= 32)
        {
            return;
        }

        // Make window pop up
        EditorWindow.GetWindow <LumosInstall>(true, "Install Lumos");
    }
    public static void PreferencesGUI()
    {
        if (!prefsLoaded)
        {
            prefsLoaded = true;
            credentials = LumosCredentialsManager.GetCredentials();
            LumosPackages.CheckForUpdates();
        }

        // General settings.
        GUILayout.Label("General", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Version", Lumos.version);
        credentials.apiKey = EditorGUILayout.TextField(apiKeyLabel, credentials.apiKey);

        EditorGUILayout.Space();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (GUILayout.Button(new GUIContent("Run Setup Scripts", "Attaches required powerup scripts to the Lumos GameObject. Click this if you subscribed to new powerups since first installing Lumos."), GUILayout.Width(Screen.width / 2.9f)))
        {
            LumosPackages.RunSetupScripts();
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.Space();

        // Checking for updates
        GUILayout.Label("Updates", EditorStyles.boldLabel);

        switch (LumosPackages.package)
        {
        case LumosPackages.Update.CheckingVersion:
            GUILayout.Label("Checking for updates...");
            break;

        case LumosPackages.Update.OutOfDate:
            GUILayout.Label("An update is available.");

            EditorGUILayout.Space();

            if (GUILayout.Button("Download Lumos " + LumosPackages.latestVersion, GUILayout.Width(Screen.width / 3)))
            {
                Application.OpenURL("https://www.lumospowered.com/downloads");
            }

            break;

        case LumosPackages.Update.UpToDate:
            GUILayout.Label("You are up to date!");
            break;
        }

        EditorGUILayout.Space();

        // Save changed preferences.
        if (GUI.changed)
        {
            EditorUtility.SetDirty(credentials);
        }
    }