private void UpdateDependency(string nameDependency, string previous, string latest)
        {
            var path = AppodealDependencyUtils.Network_configs_path + nameDependency +
                       AppodealDependencyUtils.Dependencies + ".xml";

            if (!File.Exists(path))
            {
                AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                "Can't find config with path " + path, $"path - {nameDependency}");
            }
            else
            {
                string contentString;
                using (var reader = new StreamReader(path))
                {
                    contentString = reader.ReadToEnd();
                    reader.Close();
                }

                contentString = Regex.Replace(contentString, previous, latest);

                using (var writer = new StreamWriter(path))
                {
                    writer.Write(contentString);
                    writer.Close();
                }
            }
        }
        private IEnumerator GetAppodealSDKData()
        {
            yield return(null);

            #region Internal

            if (AppodealDependencyUtils.GetInternalDependencyPath() != null)
            {
                foreach (var fileInfo in AppodealDependencyUtils.GetInternalDependencyPath())
                {
                    if (!File.Exists(AppodealDependencyUtils.Network_configs_path + fileInfo.Name))
                    {
                        AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                        $"File doesn't exist - {AppodealDependencyUtils.Network_configs_path + fileInfo.Name}",
                                                                        string.Empty);
                    }
                    else
                    {
                        GetInternalDependencies(AppodealDependencyUtils.Network_configs_path + fileInfo.Name);
                    }
                }
            }
            else
            {
                AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                "Can't find internal dependencies.", string.Empty);
            }

            #endregion

            #region Plugin

            var requestPlugin = UnityWebRequest.Get(AppodealDependencyUtils.PluginRequest);
            yield return(requestPlugin.Send());

            if (requestPlugin.isError)
            {
                Debug.LogError(requestPlugin.error);
                AppodealDependencyUtils.ShowInternalErrorDialog(this, requestPlugin.error, string.Empty);
            }
            else
            {
                if (string.IsNullOrEmpty(requestPlugin.downloadHandler.text))
                {
                    yield break;
                }

                if (AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION.Contains("-Beta"))
                {
                    appodealUnityPlugin = JsonHelper.FromJson <AppodealUnityPlugin>(JsonHelper.fixJson(requestPlugin.downloadHandler.text))
                                          .ToList().FirstOrDefault(x => x.build_type.Equals("beta"));
                }
                else
                {
                    appodealUnityPlugin = JsonHelper.FromJson <AppodealUnityPlugin>(JsonHelper.fixJson(requestPlugin.downloadHandler.text))
                                          .ToList().FirstOrDefault(x => x.build_type.Equals("stable"));
                }
            }

            #endregion

            #region Adapters

            var requestAdapters = UnityWebRequest.Get(AppodealDependencyUtils.AdaptersRequest +
                                                      AppodealDependencyUtils.ReplaceBetaVersion(AppodealAds.Unity.Api
                                                                                                 .Appodeal.APPODEAL_PLUGIN_VERSION));

            yield return(requestAdapters.Send());

            if (requestAdapters.isError)
            {
                Debug.LogError(requestAdapters.error);
                AppodealDependencyUtils.ShowInternalErrorDialog(this, requestAdapters.error, string.Empty);
            }
            else
            {
                if (string.IsNullOrEmpty(requestAdapters.downloadHandler.text))
                {
                    yield break;
                }
                if (requestAdapters.downloadHandler.text.Contains("error"))
                {
                    AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                    $"Can't find network configs by {AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION} version",
                                                                    string.Empty);
                    yield break;
                }
                var networkDependencies = JsonHelper.FromJson <NetworkDependency>(
                    JsonHelper.fixJson(requestAdapters.downloadHandler.text));

                if (networkDependencies.Length > 0)
                {
                    foreach (var networkDependency in networkDependencies)
                    {
                        if (!string.IsNullOrEmpty(networkDependency.name) &&
                            !networkDependency.name.Equals(AppodealDependencyUtils.TwitterMoPub))
                        {
                            latestDependencies.Add(networkDependency.name, networkDependency);
                        }
                    }
                }
            }

            #endregion

            coroutine = null;

            isPluginInfoReady = true;
        }
        private IEnumerator DownloadUnityPlugin(string source, string pluginVersion)
        {
            yield return(null);

            var       ended = false;
            var       cancelled = false;
            Exception error = null;
            int       oldPercentage = 0, newPercentage = 0;
            var       path = Path.Combine("Assets/Appodeal", AppodealDependencyUtils.AppodealUnityPlugin + pluginVersion);

            progress   = 0.01f;
            downloader = new WebClient {
                Encoding = Encoding.UTF8
            };
            downloader.DownloadProgressChanged += (sender, args) => { newPercentage = args.ProgressPercentage; };
            downloader.DownloadFileCompleted   += (sender, args) =>
            {
                ended     = true;
                cancelled = args.Cancelled;
                error     = args.Error;
            };

            if (!string.IsNullOrEmpty(source))
            {
                Debug.LogFormat("Downloading {0} to {1}", source, path);
                Debug.Log(source);
                downloader.DownloadFileAsync(new Uri(source), path);
            }
            else
            {
                AppodealDependencyUtils.ShowInternalErrorDialog(this, "Can't find internal dependencies.",
                                                                string.Empty);
            }

            while (!ended)
            {
                Repaint();
                var percentage = oldPercentage;
                yield return(new WaitUntil(() => ended || newPercentage > percentage));

                oldPercentage = newPercentage;
                progress      = oldPercentage / 100.0f;
            }

            if (error != null)
            {
                Debug.LogError(error);
                cancelled = true;
            }

            downloader = null;
            coroutine  = null;
            progress   = 0;
            EditorUtility.ClearProgressBar();
            if (!cancelled)
            {
                AssetDatabase.ImportPackage(path, true);
            }
            else
            {
                Debug.Log("Download terminated.");
            }
        }
        private void OnGUI()
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition,
                                                             false,
                                                             false);
            GUILayout.BeginVertical();

            progressPB = EditorApplication.timeSinceStartup - startValPB;

            if (progressPB < secsPB)
            {
                if (EditorUtility.DisplayCancelableProgressBar(
                        AppodealDependencyUtils.AppodealSdkManager,
                        AppodealDependencyUtils.Loading,
                        (float)(progressPB / secsPB)))
                {
                    Debug.Log(AppodealDependencyUtils.ProgressBar_cancelled);
                    startValPB = 0;
                }
            }
            else
            {
                EditorUtility.ClearProgressBar();
            }

            if (isPluginInfoReady)
            {
                #region Plugin

                GUILayout.Space(5);
                EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealUnityPlugin, labelStyle,
                                           GUILayout.Height(20));

                if (appodealUnityPlugin != null)
                {
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        if (!string.IsNullOrEmpty(AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION) &&
                            !string.IsNullOrEmpty(appodealUnityPlugin.version) &&
                            !string.IsNullOrEmpty(appodealUnityPlugin.source))
                        {
                            GuiPluginRow(appodealUnityPlugin);
                        }
                        else
                        {
                            AppodealDependencyUtils.ShowInternalErrorDialog(this, "Can't find plugin information.",
                                                                            "Can't find plugin information. - {180}");
                        }
                    }
                }
                else
                {
                    AppodealDependencyUtils.ShowInternalErrorDialog(this, "Can't find plugin information.",
                                                                    "appodealUnityPlugin != null - {175}");
                }

                #endregion

                #region CoreInfo

                if (internalDependencies.Count > 0 && latestDependencies.Count > 0)
                {
                    EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealCoreDependencies, labelStyle,
                                               GUILayout.Height(20));
                    EditorGUILayout.LabelField(AppodealDependencyUtils.iOS, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiCoreRow(AppodealDependencyUtils.GetAppodealDependency(internalDependencies),
                                   AppodealDependencyUtils.GetAppodealDependency(latestDependencies), PlatformSdk.iOS);
                    }

                    EditorGUILayout.LabelField(AppodealDependencyUtils.Android, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiCoreRow(AppodealDependencyUtils.GetAppodealDependency(internalDependencies),
                                   AppodealDependencyUtils.GetAppodealDependency(latestDependencies), PlatformSdk.Android);
                    }
                }

                #endregion

                #region NetworksAdaptersInfo

                if (internalDependencies.Count > 0)
                {
                    EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealNetworkDependencies, labelStyle,
                                               GUILayout.Height(20));
                    EditorGUILayout.LabelField(AppodealDependencyUtils.iOS, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiAdaptersRows(PlatformSdk.iOS);
                    }

                    EditorGUILayout.LabelField(AppodealDependencyUtils.Android, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiAdaptersRows(PlatformSdk.Android);
                    }
                }

                #endregion
            }

            GUILayout.Space(5);
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
示例#5
0
        private void OnGUI()
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition,
                                                             false,
                                                             false);
            GUILayout.BeginVertical();

            if (isPluginInfoReady)
            {
                GUILayout.Space(10);
                if (GUI.Button(new Rect(10, 5, 50, 20), "Refresh"))
                {
                    UpdateWindow();
                }

                GUILayout.Space(15);

                #region Plugin

                GUILayout.Space(5);
                EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealUnityPlugin, labelStyle,
                                           GUILayout.Height(20));

                if (appodealUnityPlugin != null)
                {
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        if (!string.IsNullOrEmpty(AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION) &&
                            !string.IsNullOrEmpty(appodealUnityPlugin.version) &&
                            !string.IsNullOrEmpty(appodealUnityPlugin.source))
                        {
                            GuiPluginRow(appodealUnityPlugin);
                        }
                        else
                        {
                            AppodealDependencyUtils.ShowInternalErrorDialog(this, "Can't find plugin information.",
                                                                            "Can't find plugin information. - {180}");
                        }
                    }
                }
                else
                {
                    AppodealDependencyUtils.ShowInternalErrorDialog(this, "Can't find plugin information.",
                                                                    "appodealUnityPlugin != null - {175}");
                }

                #endregion

                #region CoreInfo

                if (internalDependencies.Count > 0 && latestDependencies.Count > 0)
                {
                    EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealCoreDependencies, labelStyle,
                                               GUILayout.Height(20));
                    EditorGUILayout.LabelField(AppodealDependencyUtils.iOS, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiCoreRow(AppodealDependencyUtils.GetAppodealDependency(internalDependencies),
                                   AppodealDependencyUtils.GetAppodealDependency(latestDependencies), PlatformSdk.iOS);
                    }

                    EditorGUILayout.LabelField(AppodealDependencyUtils.Android, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiCoreRow(AppodealDependencyUtils.GetAppodealDependency(internalDependencies),
                                   AppodealDependencyUtils.GetAppodealDependency(latestDependencies), PlatformSdk.Android);
                    }
                }

                #endregion

                #region NetworksAdaptersInfo

                if (internalDependencies.Count > 0)
                {
                    EditorGUILayout.LabelField(AppodealDependencyUtils.AppodealNetworkDependencies, labelStyle,
                                               GUILayout.Height(20));
                    EditorGUILayout.LabelField(AppodealDependencyUtils.iOS, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiAdaptersRows(PlatformSdk.iOS);
                    }

                    EditorGUILayout.LabelField(AppodealDependencyUtils.Android, labelStyle, GUILayout.Height(20));
                    using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle, GUILayout.Height(45)))
                    {
                        AppodealDependencyUtils.GuiHeaders(headerInfoStyle, btnFieldWidth);
                        GuiAdaptersRows(PlatformSdk.Android);
                    }
                }

                #endregion
            }

            GUILayout.Space(5);
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }