Exemplo n.º 1
0
        /// <summary>
        /// Gets the current versions for a given network's dependency file path.
        /// </summary>
        /// <param name="dependencyPath">A dependency file path that from which to extract current versions.</param>
        /// <returns>Current versions of a given network's dependency file.</returns>
        public static Versions GetCurrentVersions(string dependencyPath)
        {
            XDocument dependency;

            try
            {
                dependency = XDocument.Load(dependencyPath);
            }
#pragma warning disable 0168
            catch (IOException exception)
#pragma warning restore 0168
            {
                // Couldn't find the dependencies file. The plugin is not installed.
                return(new Versions());
            }

            // <dependencies>
            //  <androidPackages>
            //      <androidPackage spec="com.applovin.mediation:network_name-adapter:1.2.3.4" />
            //  </androidPackages>
            //  <iosPods>
            //      <iosPod name="AppLovinMediationNetworkNameAdapter" version="2.3.4.5" />
            //  </iosPods>
            // </dependencies>
            string androidVersion      = null;
            string iosVersion          = null;
            var    dependenciesElement = dependency.Element("dependencies");
            if (dependenciesElement != null)
            {
                var androidPackages = dependenciesElement.Element("androidPackages");
                if (androidPackages != null)
                {
                    var adapterPackage = androidPackages.Descendants().FirstOrDefault(element => element.Name.LocalName.Equals("androidPackage") &&
                                                                                      element.FirstAttribute.Name.LocalName.Equals("spec") &&
                                                                                      element.FirstAttribute.Value.StartsWith("com.applovin"));
                    if (adapterPackage != null)
                    {
                        androidVersion = adapterPackage.FirstAttribute.Value.Split(':').Last();
                        // Hack alert: Some Android versions might have square brackets to force a specific version. Remove them if they are detected.
                        if (androidVersion.StartsWith("["))
                        {
                            androidVersion = androidVersion.Trim('[', ']');
                        }
                    }
                }

                var iosPods = dependenciesElement.Element("iosPods");
                if (iosPods != null)
                {
                    var adapterPod = iosPods.Descendants().FirstOrDefault(element => element.Name.LocalName.Equals("iosPod") &&
                                                                          element.FirstAttribute.Name.LocalName.Equals("name") &&
                                                                          element.FirstAttribute.Value.StartsWith("AppLovin"));
                    if (adapterPod != null)
                    {
                        iosVersion = adapterPod.Attributes().First(attribute => attribute.Name.LocalName.Equals("version")).Value;
                    }
                }
            }

            var currentVersions = new Versions();
            if (androidVersion != null && iosVersion != null)
            {
                currentVersions.Unity   = string.Format("android_{0}_ios_{1}", androidVersion, iosVersion);
                currentVersions.Android = androidVersion;
                currentVersions.Ios     = iosVersion;
            }
            else if (androidVersion != null)
            {
                currentVersions.Unity   = string.Format("android_{0}", androidVersion);
                currentVersions.Android = androidVersion;
            }
            else if (iosVersion != null)
            {
                currentVersions.Unity = string.Format("ios_{0}", iosVersion);
                currentVersions.Ios   = iosVersion;
            }

            return(currentVersions);
        }
Exemplo n.º 2
0
 public bool HasEqualSdkVersions(Versions versions)
 {
     return(versions != null &&
            AdapterSdkVersion(Android).Equals(AdapterSdkVersion(versions.Android)) &&
            AdapterSdkVersion(Ios).Equals(AdapterSdkVersion(versions.Ios)));
 }